<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$PageSecurity = 2;
$title = _('Material Issue Slip');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];
?>
<?php
if(isset($_POST['Update']))
{	
///////////////////////////////////////////// Add IUssue Slip  Form  By Amit Kumar////////////////////////////////////////
	$date = date($_SESSION['DefaultDateFormat']);
	//echo "<pre>";print_r($_POST); 	
	 $_POST['PRDate']=Date($_SESSION['DefaultDateFormat']);
	$_POST['DatePrinted']=Date($_SESSION['DefaultDateFormat']);
	ConvertSQLDate($_SESSION['MR'.$identifier]->Orig_OrderDate);
	$qty=$_REQUEST['itemcode'];
	$qty1=count($qty);
	 $update1="update addissue set site='".$_REQUEST['sitecode']."',issueto='".$_REQUEST['issueto']."'
	                 ,remarks='".$_REQUEST['remarks']."' where id='".$_REQUEST['id']."'";
						$query=DB_query($update1,$db);
	   
	$qty=$_REQUEST['itemcode'];
	$qty1=count($qty);
	for($i=0;$i<$qty1;$i++)
	 {
	  $update="update issueqty set itemdesc='".$_REQUEST['desc'][$i]."',uom='".$_REQUEST['uom'][$i]."',itemcode='".$_REQUEST['itemcode'][$i]."',
	Stockbalance='".$_REQUEST['Stockbalance'][$i]."',issueqty='".$_REQUEST['issueqty'][$i]."',averageamt='".$_REQUEST['averageamt'][$i]."',
								totalamount='".$_REQUEST['totalamount'][$i]."' where id ='".$_REQUEST['id11'][$i]."'";
	
	 $totalqty=$totalqty+$_REQUEST['issueqty'][$i];
					      $insertResult2 = DB_query($update,$db);
					 
					
$updateQty=DB_query("update addissue set totalqty='".$totalqty."' where id='".$_REQUEST['id']."'",$db);	
	}
echo "<script>location.href='index.php?route=Issue_show&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
 ?>

 <?php if($_REQUEST['action']==''){?>
<div class="body_contain">
<div class="tab_div">	

 <h1>Material Issue Slip</h1>
<?php if($_SESSION['frmAdd']=='1') {?>
<div align="center"><a href="index.php?route=AddIssueSlip&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewIssue=yes">Add New Issue Slip</a></div>
<?php }?>
<br />
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px;">
  <tr>
    <td class="tabledata">Issue Slip No. </td>
    <td class="tabledata">Issue Date </td>
    <td class="tabledata">Branch</td>
    <td class="tabledata">Godown</td>
	<td class="tabledata">Issue To</td>
	<td class="tabledata">View</td>
	<td class="tabledata">Edit</td>
	<td class="tabledata">Delete</td>
  </tr>
  <?php
 
  $sql=DB_query("Select * from addissue where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
  $i=0;
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
  ?>
 <tr bgcolor="#c1c1c1">
    <td><?php echo $myrow['issue_slipno'];?></td>
    <td><?php echo ConvertSQLDate($myrow['issuedate']);?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['sitecode'],'locationname');
	echo $sitename;?></td>
    <td><?php 
	$storename=$s->getField('storetype','StoreCode',$myrow['storecode'],'StoreName');
	echo $storename;?></td>
	<td><?php 
	$productionFloor=$s->getField('floor_master','id',$myrow['issueto'],'floorName');
	echo $productionFloor;?></td>
	<td><?php if($_SESSION['frmView']=='1'){?>
	<a href="index.php?route=Issue_show&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=view&id=<?php echo $myrow['id']; ?>&loccode=<?php echo $myrow['sitecode']; ?>">View</a><?php }else{echo "No Permission";}?></td>
	<td>
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="index.php?route=Issue_show&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Edit&id=<?php echo $myrow['id']; ?>&loccode=<?php echo $myrow['sitecode']; ?>">Edit</a><?php }else{echo "No Permission";}?>
	</td>
	<td>
	<?php if($_SESSION['frmDelete']=='1'){?>
	<a href="index.php?route=Issue_show&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Delete&id=<?php echo $myrow['id']; ?>&loccode=<?php echo $myrow['sitecode']; ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a><?php }else{echo "No Permission";}?>
	</td>
  </tr>
  <?php $i++;} }
  else
  {?>
  <tr>
  <td colspan="12"><h3 align="center"><strong>No Record Found</strong></h3></td>
  </tr>
  <?php 	
  }
  ?>
</table>

</div></div>


<?php } 
if($_REQUEST['id']!='' && $_REQUEST['action']=='view') 
{ 
	$sql="SELECT * FROM `addissue` where id='".$_REQUEST['id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
	$result=DB_query($sql,$db);
	$myrow1=DB_fetch_array($result);
	?>
	
	
	
	
	
<div class="body_contain">
<div class="tab_div">	
	<h1 align="center">View Issue</h1>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#999999 solid 1px;">
<tr>
    <th><strong>View Branch</strong></th>
    <td>
	
      <input type="text" name="sitecode" value="<?php echo $myrow1['site']; ?>" style="width:100%" readonly>
     
    </td>
    <th>Godown</th>
    <td><?php
    
	     $sql_store =DB_query("select StoreName from storetype where StoreCode='".$myrow1['store']."' ",$db);
		  $resultStkLocs = DB_fetch_array($sql_store);?>
     
      <input type="text" name="storecode" style="width:100%;" value="<?php echo $resultStkLocs['StoreName'];?>" readonly>
        
        
   
      </td>
</tr>
  <tr>
    <th><strong>Issue Slip No.</strong></th>
    <td><input name="issue_slipno"  type="text" id="issue_slipno"  style="width:100%" readonly="readonly" value="<?php echo $myrow1['issue_slipno']; ?>"></td>
    <th><strong>Issue Date </strong></th>
    <td><input name="issuedate" type="text"  value="<?php echo $myrow1['issuedate']; ?>"  style="width:100%" readonly/></td>
  </tr>
  
  
  <tr>
    <th><strong>Issue To </strong></th>
    <td><?php 
	$floor_sql=DB_query("Select * from floor_master where id='".$myrow1['issueto']."'",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{ ?>
	<input type="text"  style="width:100%" name="issueto" id="issueto" value="<?php echo $floor_row['floorName'];?>" readonly >
	<?php 	
	}
	?>
	
	
	
    </select></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr></tr>
</table>


<br />

<div style="overflow:auto; width:810px; height:auto">

<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse; border:#999999 solid 1px;">
  <tr>
    
    <th><strong>Item Code</strong></th>
    <th><strong>Description</strong></th>
      <th><strong>UOM</strong></th>
    <th><strong>Stock Balance </strong></th>
    <th><strong>Issue Qty </strong></th>
  </tr>
  <tbody id="dataTable">
  	<?php 
  //	echo $_REQUEST['id'];
   $sql = "SELECT * FROM issueqty where issue_id ='".$_REQUEST['id']."'";
	  $resultStkLocs1 = DB_query($sql,$db);
	  while ($myrow2=DB_fetch_array($resultStkLocs1))
	  {
	  //	echo $myrow2['itemdesc'];
	  	//print_r($myrow2);	?>
  <tr bgcolor="#FFFFFF">  
  <td>  
  <input type="text"  tabindex=""  readonly="" id="washing_profile" name="itemcode"size="10" value="<?php echo $myrow2['itemcode']; ?>" />      </td>
  <td><input type="text" name="desc" value="<?php echo $myrow2['itemdesc']; ?>" id="desc" size="25" readonly/></td>
    <td><input type="text" name="uom" id="uom" value="<?php echo $myrow2['uom'] ?>" readonly/></td>
  <td><input type="text" name="Stockbalance"  id="Stockbalance"  size="10" value="<?php echo $myrow2['Stockbalance']; ?>" readonly/></td>
  <td><input type="text" name="issueqty"  id="issueqty" size="10" value="<?php echo $myrow2['issueqty']; ?>"/></td>  
  </tr>
  <?php } ?>
</tbody>
</table>

</div>

<hr />
<table>
<tr>
<th><strong>Remarks </strong></th>
<td><textarea name="remarks" cols="85" rows="3" id="remark"><?php echo $myrow1['remarks']; ?></textarea></td>
</tr>
</table>

</div></div>

<?php } ?>
<?php 
if($_REQUEST['id']!='' && $_REQUEST['action']=='Edit') 
    {
	 $sql="SELECT * FROM addissue where id='".$_REQUEST['id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
	$result=DB_query($sql,$db);
	$myrow1=DB_fetch_array($result);
	?>
	
	
<div class="body_contain">
<div class="tab_div">	
	<h1>Edit Issue</h1>

	<form name="form1" action="" method="post">

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
    <td class="tabledata1">View Branch</td>
    <td>
	<?php
			$sql = 'SELECT * FROM locations';
	    	  $resultStkLocs = DB_query($sql,$db);
		?>	
		<select name="sitecode" style="width:100%">
	  <?php 
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
					$s='';
		if($_REQUEST['loccode']==$myrow['loccode'])
		{$s="selected";}	
					
				?>
      <option value="<?php echo $myrow['loccode']; ?>"<?php echo $s;?>><?php echo $myrow['locationname'];?></option>
      
     <?php }	?></select>
    </td>
    <td class="tabledata1">Godown</td>
    <td><?php
	       $sql_store =DB_query("select StoreName from storetype where StoreCode='".$myrow1['store']."' ",$db);
		  $resultStkLocs = DB_fetch_array($sql_store);?>
     
      <input type="text" name="storecode" style="width:100%;" value="<?php echo $resultStkLocs['StoreName'];?>">
        
        
        
   
      </select></td>
</tr>
  <tr>
    <td class="tabledata1">Issue Slip No.</td>
    <td><input name="issue_slipno" type="text" id="issue_slipno" style="width:100%" readonly="readonly" value="<?php echo $myrow1['issue_slipno']; ?>"></td>
    <td class="tabledata1">Issue Date </td>
    <td><input name="issuedate" type="text"  value="<?php echo $myrow1['issuedate']; ?>" style="width:100%" readonly/></td>
  </tr>
  
  
  <tr>
    <td class="tabledata1">Issue To </td>
    <td>
	<select name="issueto" id="issueto" style="width:100%" onchange="Get_issuedetails(this.value)" >
	
	<?php 
	$floor_sql=DB_query("Select * from floor_master ",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{   $k='';
		if($_REQUEST['sid1']==$floor_row['id'])
		{$k="selected";}
		?>
	<option value="<?php echo $floor_row['id'];?>"<?php echo $k; ?>><?php echo $floor_row['floorName'];?></option>
	<?php 	
	}
	?>
    </select></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr></tr>
</table>



<div style="overflow:auto; width:810px; height:auto">

<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px; border-collapse:collapse;">
  <tr>
    
    
    <th><strong>Item Code</strong></th>
    <th><strong>Description</strong></th>
      <th><strong>UOM</strong></th>
    <th><strong>Stock Balance </strong></th>
    <th><strong>Issue Qty </strong></th>
  </tr>
  <tbody id="dataTable">
  	<?php 
  	//echo $_REQUEST['id'];
  	$sql = "SELECT * FROM issueqty where issue_id ='".$_REQUEST['id']."'";
	  $resultStkLocs1 = DB_query($sql,$db);
	  while ($myrow2=DB_fetch_array($resultStkLocs1))
	  {
	  		?>
  <tr bgcolor="#FFFFFF">

    <td><input type="hidden" name="id11[]" value="<?php echo $myrow2['id']; ?>" >
  <input type="text"  tabindex=""  readonly="" id="washing_profile" name="itemcode[]"size="10" value="<?php echo $myrow2['itemcode'] ?>" />      </td>
  <td><input type="text" name="desc[]" value="<?php echo $myrow2['itemdesc'] ?>" id="desc"  style="width:100%" readonly/></td>
    <td><input type="text" name="uom[]" id="uom" value="<?php echo $myrow2['uom'] ?>" readonly/></td>
  <td><input type="text" name="Stockbalance[]"  id="Stockbalance"  size="10" value="<?php echo $myrow2['Stockbalance']; ?>" readonly/></td>
  <td><input type="text" name="issueqty[]"  id="issueqty" size="10" value="<?php echo $myrow2['issueqty']; ?>"/></td>
 
  </tr> <?php } ?>
  </tbody>
  
</table>

</div>
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#999999 solid 1px; border-collapse:collapse;">
<tr>
<th><strong>Remarks </strong></th>
<td><textarea name="remarks" cols="85" rows="3" id="remark"><?php echo $myrow1['remarks']; ?></textarea></td>
</tr>
</table>
<p align="center"><input type="submit" name="Update" value="Update" /></p>
</form>


</div></div>






<script language="javascript" type="text/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=yes");
}
 var xmlHttp

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;
}

function getsitename(str)
{
if (str.length==0)
  {
  document.getElementById("txtsite").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtsite").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_sitename.php?site="+str,true);
xmlhttp.send();
}
function getsitename22(str)
{
if (str.length==0)
  {
  document.getElementById("txtsite22").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtsite22").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_sitename.php?q2="+str,true);
xmlhttp.send();
}
function Get_issuedetails(str)
{
  if (str.length==0)
  {
  document.getElementById("issueid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("issueid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssueDetails.php?q="+str,true);
xmlhttp.send();
}

function getpartyname(str)
{
	//alert(str);
	var hidparty=document.getElementById("hidden_party").value;
	//alert(hidparty);
	if (str.length==0)
  {
  document.getElementById("pname").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("pname").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssuePartyName.php?name="+str+"&partytype="+hidparty,true);
xmlhttp.send();
}
	

function get_referredby(str)
{
	if (str.length==0)
  {
  document.getElementById("rname").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("rname").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssueEmployeeName.php?q="+str,true);
xmlhttp.send();
}

 var xmlHttp
function requisition_detail(str)
{ 
   //alert(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 calculateTotalAmount(str)
{
	var str_BRK=str.split('_');
	if(str_BRK[1]==undefined)
	{
		var issue=document.getElementById("issueqty").value;
		var average=document.getElementById("averageamt").value;
		var TOTAL=issue*average;
		document.getElementById("totalamount").value=TOTAL.toFixed(2);
	}
	else
	{
		var issue=document.getElementById("issueqty_"+str_BRK[1]).value;
		var average=document.getElementById("averageamt_"+str_BRK[1]).value;
		var TOTAL=issue*average;
		document.getElementById("totalamount_"+str_BRK[1]).value=TOTAL.toFixed(2);
	}
}
</script>
<?php 	
}
?> 
<?php
if($_REQUEST['id']!='' && $_REQUEST['action']=='Delete') 
{ 
$del="delete from addissue where id='".$_REQUEST['id']."'";
$query=DB_query($del,$db);
$del1="delete from issueqty where issue_id='".$_REQUEST['id']."'";
$query1=DB_query($del1,$db);
header("location:index.php?route=Issue_show&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."");
exit;	
}	?>
<?php 
//include('includes/footer.inc');
?>
	