<link rel="stylesheet" type="text/css" href="script/tabcontent.css" />
<script type="text/javascript" src="script/tabcontent.js"></script>
<script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/dynamicRow.js"></script>

<script type="text/javascript">
function showbalance(str)
{
     
    var StockBalance=document.getElementById("stockbal").value;	
	var Issuequantity=document.getElementById("issueqty").value;	
	var RemaningBalance =StockBalance-Issuequantity;
	document.getElementById('remaningbalance').value =RemaningBalance;
	
}

</script>
<script language="javascript">
 var xmlHttp
function showsitename(str)
{ 
 
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="sitename.php";
	url=url+"?site_name="+str;
	xmlHttp.onreadystatechange=change1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function change1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   document.getElementById("txtsite").innerHTML=xmlHttp.responseText;
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
</script>

<?php

/* $Revision: 1.31 $ */

/*
*      AddIssueSlip.php
*
*      webERP Linux-Apache-MySQL-PHP based accounting system
*      Copyright Logic Works Ltd - 2007 - Contact: info@acgil.com
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
*  MA 02110-1301, USA.
*
*
*  modifications and add-ons started from:
*   Revision: 1.18
*  by Thomas Pulina
*  <hollerland@nord-com.net>|<thomas.pulina@wagner-bremen.de>
*  2008
*
*/

$PageSecurity = 4;
ob_start();
include('includes/DefinePOClass.php');
include('includes/session.inc');
if (isset($_GET['ModifyOrderNumber']) and $_SESSION[UserStockLocation]== "HO")  {
	$title = _('Modify Purchase Order') . ' ' . $_GET['ModifyOrderNumber'];
} else {
	//$title = _('Add Issue Slip');

}


 if(isset($_GET['issueid'])  && isset($_GET['issueid']) !='')
 {

  $title = _('Update OutWard Get Pass');
 }
 else
 {
  $title = _('OutWard Get Pass');
 }

include('includes/header.inc');
//include('includes/SQL_CommonFunctions.inc');

/*If the page is called is called without an identifier being set then
 * it must be either a new order, or the start of a modification of an
 * order, and so we must create a new identifier.
 * 
 * The identifier only needs to be unique for this php session, so a 
 * unix timestamp will be sufficient.
 */
 
  /*$date1=date('M-Y');
  $date2=date('Y-m-d');*/
 
		if (empty($_GET['identifier'])) {
			 $identifier=date('U');
		} else {
			 $identifier=$_GET['identifier'];
			
		}
		
		/*Page is called with NewOrder=Yes when a new order is to be entered
		 * the session variable that holds all the PO data $_SESSION['MR'][$identifier] 
		 * is unset to allow all new details to be created */
		///////////////////////////////////////////// Add IUssue Slip  Form  By Amit Kumar////////////////////////////////////////
		 $date = date($_SESSION['DefaultDateFormat']);
		 
if(isset($_POST['Submit']))
{
	//echo "<pre>";print_r($_POST); 	
	 $_POST['PRDate']=Date($_SESSION['DefaultDateFormat']);
	$_POST['DatePrinted']=Date($_SESSION['DefaultDateFormat']);
	ConvertSQLDate($_SESSION['MR'.$identifier]->Orig_OrderDate);
	
	 $sql='select id, issue_slipno from addissue order by id desc limit 0,1';
	 $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	 if($numrows>0)
	 {
	
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
			 if($myrow['issue_slipno'] !='')
			 {
			         $val= substr($myrow['issue_slipno'],19);
					   $strChar = substr($myrow['issue_slipno'],0,19);
					
				
					 if($val!="")
					 {
						 $arr[$i] = $val;
						 $i++;
					}
			
			if(is_array($arr))
			{ 
				$maxval =  max($arr);
			}
			else
			{
				$maxval=0;
			}
		}
		else
		{
			$strChar = ISSUE."/".$_SESSION[UserStockLocation]."/".'2011 2012/';
		}
	  }
	$strChar = ISSUE."/".$_SESSION[UserStockLocation]."/".'2011 2012/';
	$strFinal = $maxval+1;
	$strBothFinal = $strChar.str_pad($strFinal,4,"0",STR_PAD_LEFT);
	$qty=$_REQUEST['itemcode'];
	$qty1=count($qty);
	if($_POST['requestionno'] !='')
	{
    $sql = "INSERT INTO addissue (`id`,
								   `site_code`, 
								   `site_name`, 
								   `issue_slipno`, 
								   `requisitionno`, 
								   `jobno`, 
								   `stocktype`,
									`issueto`, 
									`partycode`, 
									`pcorderno`, 
									`store_code`, 
									`store_name`, 
									`issue_date`, 
									`req_date`, 
									`issue_category`, 
									`referred_by`, 
									`machine_code`, 
									`machine_name`, 
									`order_date`, 
									`expected_return_date`, 
									`remark`, 
									`createdby`)
										VALUES('Null',
									  '".$_POST['sitecode']."', 
									  '".$_POST['sitename']."', 
									  '".$strBothFinal."', 
									  '".$_POST['requestionno']."', 
									  '".$_POST['jobno']."', 
									  '".$_POST['stocktype']."', 
									  '".$_POST['issueto']."', 
									  '".$_POST['partytype']."', 
									  '".$_POST['pcworkorder']."', 
									  '".$_POST['storecode']."',
									   '".$_POST['storename']."',
									   '".FormatDateForSQL($_POST['issuedate'])."', 
									   '".FormatDateForSQL($_POST['reqdate'])."', 
									   '".$_POST['issuecategory']."', 
									   '".$_POST['refferedby']."', 
									   '".$_POST['machinecode']."', 
									   '".$_POST['machinename']."', 
									   '".FormatDateForSQL($_POST['orderdate'])."',
										'".FormatDateForSQL($_POST['expecteddate'])."', 
										'".$_POST['remark']."',
										'".$_SESSION[UserID]."')";
   
          	 	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
				$insertResult = DB_query($sql,$db,$ErrMsg);
			 	$Lastreq_id=DB_Last_Insert_ID($db,'addissue',$ErrMsg);
			 
				for($i=0;$i<$qty1;$i++)
					 {
			       echo   $sql = "INSERT INTO issueqty(`id`,
				    `issue_id`, 
					`issue_qty`, 
					`requno`,
					`itemcode`, 
					`desc`, 
					`Make`, 
					`Color`, 
					`Gread`, 
					`UOM`, 
					`StockBlance`, 
					`Blance`) 
					Values('NULL', 
					'".$Lastreq_id."', 
					 '".$_POST['issuebalanc'][$i]."', 
					'".$_POST['requestionno']."',
					'".$_REQUEST['itemcode'][$i]."',
				    '".$_POST['desc'][$i]."', 
				    '".$_POST['make'][$i]."', 
				    '".$_POST['color'][$i]."', 
				    '".$_POST['gread'][$i]."', 
				    '".$_POST['uom'][$i]."', 
				    '".$_POST['Stockblance'][$i]."', 
				    '".$_POST['remaningbalance'][$i]."')";					
					   $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
				      $insertResult = DB_query($sql,$db,$ErrMsg);
					 }
					
				
			  if($insertResult == true)
			 {
			// $errormsg = "Record Save Successfully";
		     header('location:Issue_show.php?NewOrder=Yes');
			 }
		   }
			else
			{
			echo'<br/><br/><div align="center"><a href="AddIssueSlip.php">'."Back To IssueSlip".'</a></div><br/><br/><br/>';
			 prnMsg (_('An error occurred Record Not Save ! Please Enter Requisition Number ! The error says'), 'error');
			
			}	
			exit;	
 }
 else
 {
    $issueid = $_GET['issueid'];
  
 
 
 }
	
	if(isset($_GET['issueid'])  && isset($_GET['issueid']) !='')
 {
 
$sql = 'SELECT addissue.site_code,
				addissue.site_name,
				addissue.issue_slipno,
				addissue.requisitionno,   
				addissue.jobno,  
				addissue.issueto,     
				addissue.partycode,  
				addissue.pcorderno,  
				addissue.store_code,
				addissue.store_name,
				addissue.issue_date,
				addissue.req_date,   
				addissue.issue_category,  
				addissue.referred_by,     
				addissue.machine_code,  
				addissue.machine_name,  
				addissue.order_date,
				addissue.expected_return_date,
				issueqty.issue_qty,
				addissue.createdby   
				 FROM addissue JOIN issueqty ON(addissue.id=issueqty.issue_id ) where addissue.id='.$_GET['issueid'].'';
				 $showresult = DB_query($sql,$db);
				 $mysqlrow=DB_fetch_array($showresult);
 
 ?>
 <?php } else {?>
 
<form name="form1"  action="" method="post">
<table width="100%" border="2" cellspacing="0" cellpadding="0">

  <tr>
    <td height="40" colspan="5" align="center" bgcolor="#999999"> <div align="center"><b><font color="#FFFFFF"><?php echo $title; ?></font></b></div> </td>
  </tr>
  <tr>
    <td height="20" colspan="5" align="center" bgcolor="#999999"> <div align="Left"><b><font color="#FFFFFF">General Details</font></b></div> </td>
  </tr>
  
  <tr>
    <td>Date</td>
    <td><input type="text" name="date" id="date" value="<?php echo $date; ?>" /></td>
    <td id="txtsite" >&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td width="17%">Site Code </td>
    <td width="15%">
	<?php
	    $sql = 'SELECT loccode, locationname FROM locations';
		$resultStkLocs = DB_query($sql,$db);
		?>
		<select name="sitecode" onchange="showsitename(this.value);" >
		<?php 
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				?>
				<option Value="<?php echo $myrow['loccode']; ?>"><?php echo $myrow['loccode'];?></option>
		     
			 <?  }	?>
		</select>	 	</td>
    <td width="22%" id="txtsite" ><input type="text" name="sitename" id="sitename"></td>
    <td width="16%">Store Code </td>
    <td width="30%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="39%">	
		
		<?php
	     $sql_store = 'select StoreCode, StoreName from storetype Order BY ID ASC';
		 $resultStkLocs = DB_query($sql_store,$db);
		?>
		<select name="storecode" onChange="changestorename(this.value)">
		<?php 
		while ($myrow=DB_fetch_array($resultStkLocs))
				{
				
				
					echo '<option selected Value="' . $myrow['StoreCode'] . '">' . $myrow['StoreCode'];
				}
		
		?>
		</select>			</td>
        <td width="61%" id="txtid"><input type="text" name="storename" id="storename"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>DC Category </td>
    <td colspan="2"><input type="text" name="dccategory" id="dccategory" readonly="readonly"></td>
    <td>DC No. </td>
    <td><input type="text" name="dcno" id="dcno" value=""></td>
  </tr>
  <tr>
    <td>Returnable Category </td>
    <td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="29%">
		
 		
		<input name="retcategory" type="text" id="retcategory" onblur="requisition_detail(this.value);" >			</td>
        <td width="71%">&nbsp;	        </td>
      </tr>
    </table></td>
    <td>Status</td>
    <td id="txtreqid" ><input type="text" name="status" id="status" ></td>
  </tr>
  <tr>
    <td>NonReturnable Category </td>
    <td colspan="2"><input name="nonretcategory" type="text" id="nonretcategory" onblur="requisition_detail(this.value);"></td>
    <td>Date</td>
    <td><input type="text" name="date2" id="date2" value="<?php echo $date; ?>"></td>
  </tr>
  <tr>
    <td>Delivery Aganist Ref.No. </td>
    <td colspan="2"><select name="DARefno"  id="DARefno">
      <option value="Employee" selected="selected"> Employee </option>
	   <option value="PCcontractors "> PC Contractors </option>
    </select></td>
    <td>Stock Type </td>
    <td><select name="stocktype">
      <option value="Usable" selected="selected">Usable </option>
      <option value="NonUsable "> Non Usable </option>
    </select></td>
  </tr>
  <tr>
    <td>Party Type </td>
    <td colspan="2"><select name="partytype"  id="partytype">
      <option value=""> Select </option>
    </select></td>
    <td>Party  Code </td>
    <td><select name="partycose"  id="partycose">
      <option value=""> Select </option>
	 
    </select></td>
  </tr>
  <tr>
    <td>Remarks</td>
    <td colspan="4"><textarea name="remark" cols="60" id="remark"></textarea></td>
    </tr>
  
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td colspan="5">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5" bgcolor="#999999"><b><font color="#FFFFFF">Item Details</font></b> </td>
  </tr>
  <tr>
    <td colspan="5">



<table width="100%" border="1" cellspacing="0" cellpadding="0" >
  <tr>
  <td width="3%">&nbsp;</td>
    <td width="16%">Item Code</td>
    <td width="18%">Description</td>
    <td width="9%">Make</td>
    <td width="4%">Color</td>
    <td width="6%">Grade</td>
    <td width="8%">UOM</td>
    <td width="10%">Stock Balance </td>
    <td width="10%">DC Qty </td>
    </tr>
   <tr>

     <td colspan="9"><div style="float:left">
	 <input type="button" class="crmbutton small delete"  onclick="addRow('dataTable')" value="Add" />&nbsp;
	 <input type="button" class="crmbutton small delete"  onclick="deleteRow('dataTable')" value="Delete" />
	 </div>	 </td>
     </tr>
    <tr>
 <td colspan="9"><table width="100%" border="2" cellspacing="0" cellpadding="0">
 
 <tbody id="dataTable">
   <tr>
     <td width="3%"><input type="checkbox" name="chk" /></td>
	 <td width="2%"><input type="hidden" value="" id="user_shipping" name="user_shipping[]"></td>
	 <td width="3%"><input type="button" name="profile_popup" value="+" id="profile_popup"  onclick="openPopupProfile(this.id);" /> </td>
     <td width="10%"><input type="text" value="" tabindex=""  readonly="" id="washing_profile" name="itemcode[]"size="15" />	 </td>
     <td width="16%"><input type="text" name="desc[]"  id="" size="25"/></td>
     <td width="8%">
	 <select name="make[]" id="" >
	 <option name ="">select</option>
	 <?php  $rs=DB_query("select * from product_manufacture", $db);
     while($row=DB_fetch_assoc($rs)) 
	{
     ?>
	  <option name ="<?=$row['id'];?>"><?=$row['manufacturer'];?></option>
	 <?php } ?>
	 </select></td>
     <td width="8%"> <select name="color[]" id="" >
	 <option name ="">select</option>
	 <?php  $rs=DB_query("select * from product_color", $db);
     while($row=DB_fetch_assoc($rs)) 
	{
     ?>
	  <option name ="<?=$row['id'];?>"><?=$row['color'];?></option>
	 <?php } ?>
	 </select></td>
     <td width="8%"> <select name="gread[]" id="" >
	 <option name ="">select</option>
	  <?php  $rs=DB_query("select * from product_grade", $db);
     while($row=DB_fetch_assoc($rs)) 
	{
     ?>
	  <option name ="<?=$row['id'];?>"><?=$row['grade'];?></option>
	 <?php } ?>
	 </select></td>
     <td width="8%"> <select name="uom[]" id="">
	 <option name ="">select</option>
	  	<?php  $rs=DB_query("Select unitid,unitname from unitsofmeasure ", $db);
		 while($row=DB_fetch_assoc($rs)) 
		{
     	?>
	 <option name ="<?=$row['unitid'];?>"><?=$row['unitname'];?></option>
	   <?php } ?>
	   	 </select></td>
		 <?php 
	    $StockSql="SELECT *FROM stockmaster WHERE stockid =''";
		$Stockresult = DB_query($StockSql,$db);	
		while($mystockrow=DB_Fetch_array($Stockresult))
		{
		?>
     <td width="10%" align="center">
	 <input type="text" name="descriptionW"  size="15" value="<?php echo $mystockrow['maxlevel']; ?>"/>	 </td>
	 <?php } ?>
     <td width="7%" align="center"><input name="Stockblance[]" type="text" id=""  size="10"/></td>
     <td width="7%" align="center"><input type="text" name="reqiredbalance[]"  size="10"/></td>
     </tr>
   </tbody>
 </table></td>
  </tr>
  
  
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     </tr>
  </table></td>
  </tr>
  
  <tr>
    <td colspan="5">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="19"  bgcolor="#999999"><b><font color="#FFFFFF">Other Details</font> </b></td>
        </tr>
    </table></td>
    </tr>
   <tr>
    <td colspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="50%" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0">
          <tr bgcolor="#999999">
            <td width="50%" ><div align="center"><b><font color="#FFFFFF">Charges</font></b></div></td>
            <td width="50%" ><div align="center"><b><font color="#FFFFFF">Amount</font></b></div></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
        <td width="50%"><table width="100%" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td width="53%" bgcolor="#999999" ><div align="center"><b><font color="#FFFFFF">Item Amount</font></b> </div></td>
            <td width="47%"><input name="itemamount" type="text" id="itemamount" size="30" /></td>
          </tr>
          <tr>
            <td bgcolor="#999999" align="center"><div align="center"><b><font color="#FFFFFF">Charges Amount</font></b> </div></td>
            <td><input name="ChargeAmount" type="text" id="ChargeAmount" size="30" /></td>
          </tr>
          <tr>
            <td bgcolor="#999999" align="center"><div align="center"><b><font color="#FFFFFF">Grand Total </font></b></div></td>
            <td><input name="GrandTotal" type="text" id="GrandTotal" size="30" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2" align="right"> <div align="right"><input type="submit" name="Submit" value="Save"> </div>    </td>
    <td><input type="reset" name="Submit2" value="Cancel"></td>
    <td>&nbsp;</td>
  </tr>
</table>

</form>

 <?
}
include('includes/footer.inc');
?>


<script type="text/javascript">

var countries=new ddtabcontent("countrytabs")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init()

</script>
<script language="javascript">
function openPopupProfile(i)
				{
		window.open("issu_searchpopup.php?rowcount="+i,"profiles_popup_window","height=425,width=640,toolbar=no,menubar=no,dependent=yes,resizable =no");
	}

 var xmlHttp
function changestorename(str)
{ 
 
 // alert('hi');
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="storename.php";
	url=url+"?store_code="+str;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function NumberChanged1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   document.getElementById("txtid").innerHTML=xmlHttp.responseText;
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
</script>

<script language="javascript">
 var xmlHttp
function requisition_detail(str)
{ 
   
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="reqdetail.php";
	url=url+"?req_number="+str;
	
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=changedetail;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function changedetail() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   var responsestr = xmlHttp.responseText;
	   resstr = responsestr.split("@@##@");
	   document.getElementById("reqdate").value=resstr[0];
	   document.getElementById("txtdetail").innerHTML=resstr[1];
	  
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
</script>

