<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 = _('View Issue Slip');
 }
 else
 {
  $title = _('View Issue Slip');
 }

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['Update']))
{
	//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['iduses'];
	
    $sql = "UPDATE addissue SET
		   `site_code` ='".$_POST['sitecode']."', 
		   `site_name`='".$_POST['sitename']."', 
		   `issue_slipno`='".$strBothFinal."', 
		   `requisitionno` ='".$_POST['requestionno']."', 
		   `jobno`='".$_POST['jobno']."', 
		   `stocktype`='".$_POST['stocktype']."',
			`issueto`='".$_POST['partytype']."', 
			`partycode`='".$_POST['partytype']."', 
			`pcorderno`='".$_POST['pcworkorder']."', 
			`store_code`='".$_POST['storecode']."', 
			`store_name`='".$_POST['storename']."', 
			`issue_date`='".FormatDateForSQL($_POST['issuedate'])."', 
			`req_date`='".FormatDateForSQL($_POST['reqdate'])."', 
			`issue_category`='".$_POST['issuecategory']."', 
			`referred_by`='".$_POST['refferedby']."', 
			`machine_code`='".$_POST['machinecode']."', 
			`machine_name`='".$_POST['machinename']."', 
			`order_date`='".FormatDateForSQL($_POST['orderdate'])."', 
			`expected_return_date`='".FormatDateForSQL($_POST['expecteddate'])."', 
			`remark`='".$_POST['remark']."', 
			`createdby`='".$_SESSION[UserID]."'
			 Where id='".$_GET['issueid']."'";
   
          	 	$ErrMsg = _('An error occurred Record Note Update') . '. ' . _('The error says');
				$updateResult = DB_query($sql,$db,$ErrMsg);
			 	//$Lastreq_id=DB_Last_Insert_ID($db,'addissue',$ErrMsg);
			     $swp_sql ="select id from issueqty Where issue_id='".$_GET['issueid']."'";
				 $resdu =DB_query($swp_sql,$db);
				 $i=1;
				 while($mycol = DB_fetch_array($resdu))
				    {
				    $sql = "Update issueqty SET
					`issue_qty`='".$_POST['issuebalanc'][$i]."', 
					`requno`='".$_POST['requestionno']."',
					`itemcode`='".$_REQUEST['itemcode'][$i]."', 
					`desc`='".$_POST['desc'][$i]."', 
					`Make`='".$_POST['make'][$i]."', 
					`Color`='".$_POST['color'][$i]."', 
					`Gread`='".$_POST['gread'][$i]."', 
					`UOM`='".$_POST['Stockblance'][$i]."', 
					`StockBlance`='".$_POST['Stockblance'][$i]."', 
					`Blance`='".$_POST['remaningbalance'][$i]."',
					`required_qty`='".$_POST['reqiredbalance'][$i]."',
					`issu_qty`='".$_POST['issuebalanc'][$i]."'
					 WHERE id='".$mycol['id']."'"; 
					  
					  $ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
				      $Result = DB_query($sql,$db,$ErrMsg);
					$i++;
					
					 if($Result == true)
					 {
					 
					  header('location:Issue_show.php?NewOrder=Yes');
					  
					 }
				} 
				
				
			
		   	
 }
 
     $sql = "SELECT addissue.id,
				addissue.site_code, 
			   addissue.site_name, 
			   addissue.issue_slipno, 
			   addissue.requisitionno, 
			   addissue.jobno, 
			   addissue.stocktype, 
			   addissue.issueto, 
			   addissue.partycode, 
			   addissue.store_code, 
			   addissue.store_name, 
			   addissue.issue_date, 
			   addissue.req_date, 
			   addissue.issue_category, 
			   addissue.referred_by, 
			   addissue.machine_code, 
			   addissue.order_date, 
			   addissue.expected_return_date, 
			   addissue.remark, 
			   addissue.createdby FROM addissue where addissue.id='".$_GET['issueid']."'";
			   $showresult = DB_query($sql,$db);
			   $mysqlrow=DB_fetch_array($showresult);
			   $sitecode = $mysqlrow['store_code'];
 ?>
 <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>
    <th width="16%" >Site Code </th>
    <td width="16%"><?php echo	$mysqlrow['site_code']; ?>	</td>
    <td width="17%" id="txtsite" >&nbsp;</td>
    <th width="21%">Store Code </th>
    <td width="30%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="39%">	
		<?php echo $sitecode; ?>	</td>
        <td width="61%" id="txtid">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <th>Site Name </th>
    <td colspan="2"><?php echo $mysqlrow['site_name']; ?></td>
    <th>Store</th>
    <td><?php echo $mysqlrow['store_name']; ?></td>
  </tr>
  <tr>
    <th>Issue Slip No </th>
    <td colspan="2"><?php echo $mysqlrow['issue_slipno']; ?></td>
    <th>Issue Date </th>
    <td><?php echo ConvertSQLDate($mysqlrow['issue_date']); ?></td>
  </tr>
  <tr>
    <th>Requisition No </th>
    <td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="29%">
		
 		
		<?php echo $mysqlrow['requisitionno']; ?>			</td>
        <td width="71%">&nbsp;	        </td>
      </tr>
    </table></td>
    <th>Req.date</th>
    <td id="txtreqid" ><?php echo ConvertSQLDate($mysqlrow['req_date']); ?></td>
  </tr>
  <tr>
    <th>Stock Type </th>
    <td colspan="2"><?php echo $mysqlrow['stocktype']; ?>		</td>
    <th>Issue Category </th>
    <td>
	<?php echo $mysqlrow['issue_category']; ?>	</td>
  </tr>
  <tr>
    <th>Issue To </th>
    <td colspan="2">
	<?php echo $mysqlrow['issueto'];?>	</td>
    <th>Referred By </th>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="45%">
		<?php  echo $mysqlrow['referred_by']; ?></td>
        <td width="55%">
		<?php  echo $mysqlrow['referred_by']; ?></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <th>Party Code </th>
    <td colspan="2">
	<?php echo $mysqlrow['partycode'];  ?>	</td>
    <th>Machine Code </th>
    <td>
	<?php echo $mysqlrow['machine_code'];  ?>	</td>
  </tr>
  <tr>
    <th>PC Work Order No. </th>
    <td colspan="2"><?php echo $mysqlrow['pcorderno']; ?></td>
    <th>Machine Name </th>
    <td><?php echo $mysqlrow['machine_name']; ?></td>
  </tr>
  <tr>
    <th>Expected Return Date () </th>
    <td colspan="2"><?php echo ConvertSQLDate($mysqlrow['expected_return_date']); ?></td>
    <th>Order Date </th>
    <td><?php echo ConvertSQLDate($mysqlrow['order_date']); ?></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>
  <th width="3%">&nbsp;</th>
    <th width="16%">Item Code</th>
    <th width="18%">Description</th>
    <th width="9%">Make</th>
    <th width="4%">Color</th>
    <th width="6%">Grade</th>
    <th width="8%">UOM</th>
    <th width="10%">Stock Balance </th>
    <th width="10%">Required Qty </th>
    <th width="8%">Issue Qty </th>
	<th width="8%">Balance </th>
  </tr>
   <tr>

     <td colspan="11"><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="11"><table width="100%" border="2" cellspacing="0" cellpadding="0">
 
 <tbody id="dataTable">
 <?php     
 $Select_sql = 'select issueqty.id, 
				 issueqty.issue_id, 
				 issueqty.issue_qty, 
				 issueqty.itemcode, 
				 issueqty.desc, 
				 issueqty.Make, 
				 issueqty.Color, 
				 issueqty.Gread, 
				 issueqty.UOM, 
				 issueqty.StockBlance, 
				 issueqty.issu_qty,
				 issueqty.required_qty,
				 issueqty.Blance from issueqty Where issueqty.issue_id="'.$_GET['issueid'].'"';
			  $sresult = DB_query($Select_sql,$db);
			  $i=1;
			 while ($selectsqlrow=DB_fetch_array($sresult))
			 {
			 ?>
   <tr>
     <td width="19%">
<?php echo $selectsqlrow['itemcode']; ?>	 </td>
     <td width="7%"><?php echo $selectsqlrow['desc']; ?></td>
     <td width="8%"><?php echo  $selectsqlrow['Make'];  ?>	  </td>
     <td width="9%"><?php echo  $selectsqlrow['Color'];?>	 </td>
     <td width="9%"><?php $selectsqlrow['Gread']; ?>	  </td>
     <td width="9%"> <?php echo  $selectsqlrow['unitid']; 	?>	 </td>
		
     <td width="11%" align="center"><?php echo $mystockrow['maxlevel']; ?>	 </td>
	 
     <td width="8%" align="center"><?php echo $selectsqlrow['required_qty']; ?></td>
     <td width="5%" align="center"><?php echo $selectsqlrow['issu_qty']; ?></td>
     <td width="7%" align="center"><?php echo $selectsqlrow['Blance']; ?></td>
   </tr>
   <?php  }  ?>
   </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>
     <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="10"  bgcolor="#999999"><b><font color="#FFFFFF">Other Details</font> </b></td>
        </tr>
    </table></td>
    </tr>
   <tr>
    <th>Remarks </th>
    <td colspan="4"><?php echo $mysqlrow['remark']; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2" align="right">  </td>
    <td><input type="reset" name="Submit2" value="Back" onclick="javascript:history.go(-1)"></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>

