<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 2;
include('includes/SQL_CommonFunctions.inc');
include('includes/DefinePOClass.php');
$title = _('Job Work Return List');
$PageName ='Job Work Return List';
$_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];

if($_REQUEST['id']!='' && $_REQUEST['act']=='delete')
{
	$delete1=DB_query("Delete from job_work_return where id='".$_REQUEST['id']."'",$db);
	$delete2=DB_query("Delete from job_return_details where masterId='".$_REQUEST['id']."'",$db);
	prnMsg( _('Record Deleted Successfully'),'success');
echo "<script>location.href='index.php?route=JobWorkReturnList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

?>

<?php if($_REQUEST['id']==''){?>

<div class="body_contain">
<div class="tab_div">

<h1>Job Work Return List</h1>
<?php
if($_SESSION['frmAdd']=='1'){?>
<p align="left">
<a href="index.php?route=JobWorkReturn&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name='' value="ADD NEW RETURN SLIP" class="search"></a></p><?php } ?>

<table width="99%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px; margin-bottom:5px;" align="center">
  <tr>
    <td class="tabledata2"><strong>Return No.</strong></td>
    <td class="tabledata2"><strong>Return Date</strong></td>
    <td class="tabledata2"><strong>Site</strong></td>
    <td class="tabledata2"><strong>Vendor</strong></td>
    <td class="tabledata2"><strong>Challan No.</strong></td>
    <td class="tabledata2"><strong>Party Challan No.</strong></td>
    <td class="tabledata2"><strong>View</strong></td>
    <td class="tabledata2"><strong>Edit</strong></td>
	<td class="tabledata2"><strong>Delete</strong></td>
  </tr>
<?php 

$sql=DB_query("Select * from job_work_return where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
while($myrow=DB_fetch_array($sql))
{
?>
<tr bgcolor="#dedede">
    <td><?php echo $myrow['returnSlipNo'];?></td>
    <td><?php echo ConvertSQLDate($myrow['returnDate']);?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['site'],'locationname');
	echo $sitename;?></td>
    <td><?php 
	$vendorname=$s->getField('suppliers','id',$myrow['vendor'],'vendor_name');
	echo $vendorname;?></td>  
    <td><?php 
	$challan=$s->getField('job_work_issue','id',$myrow['challanNo'],'challanNumber');
	echo $challan;?></td>
    <td><?php echo $myrow['partyChallanNo'];?></td>
    <td><?php if($_SESSION['frmView']=='1'){?><a href="index.php?route=JobWorkReturnList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id']?>&act=view"><img src="images/search.gif" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
    <td><?php if($_SESSION['frmEdit']=='1'){?><a href="index.php?route=JobWorkReturn_edit&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id']?>&act=Edit"><img src="images/icon-edit.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
	<td><?php if($_SESSION['frmDelete']=='1'){?><a href="index.php?route=JobWorkReturnList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id']?>&act=delete" onclick="return confirm('This record will be deleted. Are you sure?')"><img src="images/Icon_Delete.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
  </tr>
<?php } ?>
</table>
</div></div>
<?php } 
if($_REQUEST['id']!='' && $_REQUEST['act']=='view')
{
$sql="Select * from job_work_return where id='".$_REQUEST['id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
	$result=DB_query($sql,$db);
	$myrow=DB_fetch_array($result);
?>

<div class="body_contain">
<div class="tab_div">

<h1>View Job Work Return Slip</h1>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata1">Branch</td>
    <td style="width:250px;"><input type="text" value="<?php echo $myrow['site'];?>" readonly style="width:100%" /></td>
   <?php 
	$challan_sql=DB_query("Select * from job_work_issue where id='".$myrow['challanNo']."'",$db);
	$challan_row=DB_fetch_array($challan_sql);
	?>
	<td class="tabledata1">Challan Date </td>
    <td><input type="text" name="challanDate" readonly value="<?php echo ConvertSQLDate($challan_row['challanDate']);?>"  style="width:100%"/></td>
 
    <td class="tabledata1">Vendor</td>
    <td><input type="text" value="<?php echo $myrow['vendor'];?>" readonly  style="width:100%" /></td>
	
	<td class="tabledata1">Job Work Date </td>
    <td><input type="text" name="jobDate" readonly value="<?php echo ConvertSQLDate($challan_row['jobDate']);?>"  style="width:100%"/></td>
	
  </tr>
  <tr>
    <td class="tabledata1">57 F Challan No. </td>
    <td><input type="text" value="<?php echo $challan_row['challanNumber'];?>" readonly  style="width:100%" /></td>
	
	<td class="tabledata1">Party Job Work No. </td>
	<td><input type="text" name="partyJWNo" readonly value="<?php echo $challan_row['partyJWNo'];?>"  style="width:100%" /></td>
	

  <td class="tabledata1">Return Slip No. </td>
<td><input name="returnSlipPrefix" value="<?php echo $myrow['returnSlipNo'];?>"  style="width:100%" readonly/> </td>
  
  <td class="tabledata1">JOB WORK NO.</td>
	<?php 
	$job_sql=DB_query("Select jobNumber from job_work where id='".$challan_row['jobNumber']."'",$db);
	$job_row=DB_fetch_array($job_sql);
	?>
	<td><input type="text" name="jobNumber" readonly value="<?php echo $job_row['jobNumber'];?>"  style="width:100%" /></td>
  
  </tr>
  <tr>
  <td class="tabledata1">PARTY CHALLAN NO. </td>
  <td><input type="text" value="<?php echo $myrow['partyChallanNo'];?>" readonly  style="width:100%" /></td>
  <td class="tabledata1">Return Date </td><?php if(isset($_REQUEST['returnDate']))$returnDate=$_REQUEST['returnDate']; else $returnDate=date('d/m/Y');?>
  <td><input type="text" name="returnDate" id="returnDate" value="<?php echo $returnDate;?>" readonly style="width:100%" /></td>
  </tr>
</table>

<div style="overflow:auto; width:1280px; height:auto;"> 
 <h1>Item Details</h1>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata">Item Code </td>
<td class="tabledata">Item Name </td>
<td class="tabledata">Item Description </td>
<td class="tabledata">Uom</td>
<td class="tabledata">Order Quantity</td>
<td class="tabledata">Received Quantity</td>

<td class="tabledata">Flexo/Offset</td>
</tr>
<?php 
$details_sql2="Select * from job_return_details where masterId='".$_REQUEST['id']."'";
$details_res2=DB_query($details_sql2,$db);
	
	$j=0;
	while($details_row2=DB_fetch_array($details_res2))
	{
		$item_sql="Select * from item_master where id ='".$details_row2['mst_itemId']."'";
		$item_result=DB_query($item_sql,$db);
		$item_row=DB_fetch_array($item_result);
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $item_row['StockID'];?><input type="hidden" name="itemCode[<?php echo $j;?>]" value="<?php echo $item_row['StockID'];?>"></td>
<td><?php echo $item_row['item_name'];?></td>
<td><?php echo $item_row['item_desc'];?></td>
<td><?php 
$unitname=$s->getField('unitsofmeasure','unitid',$item_row['mst_unitid'],'unitname');
echo $unitname;?></td>
<td><input type="hidden" name="rate[<?php echo $j;?>]" id="rate_<?php echo $j;?>" value="<?php echo $details_row2['rate'];?>" size="15">	
<input type="text"  readonly value="<?php echo $details_row2['orderQty'];?>" size="15" name="orderQty[<?php echo $j;?>]">
</td>
<td><input type="hidden" name="qty[]" value="<?php echo $details_row2['id'];?>" /><input type="text" readonly name="receivedQty[<?php echo $j;?>]" id="receivedQty_<?php echo $j;?>" value="<?php echo $details_row2['receivedQty'];?>" size="15" /></td>

<td><select name="process[]" id="process" style="width:100px" >
	<option value="0">Select</option>
	<?php 
	$floor_sql=DB_query("select * from job_work_master",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{
	if($details_row2['process']==$floor_row['id']) { $t='selected'; } else { $t=''; }
	?>
	<option value="<?php echo $floor_row['id'];?>" <?php echo $t; ?>><?php echo $floor_row['jobwork_name'];?></option>
	<?php 	
	}
	?>
    </select></td>
</tr>
<?php $j++;} ?>
</table>
</div>
<?php
$check1=DB_query("select * from job_return_details1 where masterId='".$_REQUEST['id']."' ",$db);
$check=DB_num_rows($check1);
if($check>0) {
?>

<div style="overflow:auto; width:1280px; height:auto;"> 
 <h1>Raw Material Details</h1>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata">Item Code </td>
<td class="tabledata">Item Name </td>
<td class="tabledata">Item Description </td>
<td class="tabledata">Uom</td>
<td class="tabledata">Issue Qty</td>
<td class="tabledata">Received Qty</td>

<td class="tabledata">Waste Qty</td>
</tr>
<?php 
$details_sql21="Select * from job_return_details1 where masterId='".$_REQUEST['id']."'";
$details_res21=DB_query($details_sql21,$db);
	
	$j1=0;
	while($details_row21=DB_fetch_array($details_res21))
	{
		$item_sql1="Select * from item_master where id ='".$details_row21['mst_itemId']."'";
		$item_result1=DB_query($item_sql1,$db);
		$item_row1=DB_fetch_array($item_result1);
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $item_row['StockID'];?></td>
<td><?php echo $item_row['item_name'];?></td>
<td><?php echo $item_row['item_desc'];?></td>
<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$item_row['mst_unitid'],'unitname');
echo $unitname;?></td>
<td><?php echo $details_row21['issue_qty']; ?></td>
<td></td<td><?php echo $details_row21['qty']; ?></td>
<td><?php echo $details_row21['waste_qty']; ?></td>
</tr>
   <?php $j1++; } ?>

</table>
</div>
<?php } ?>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata1">REMARKS</td>
<td><textarea name="remarks" id="remarks"  style="width:100%; height:50px;" readonly><?php echo $myrow['remarks'];?></textarea></td>
</tr>
</table>
</div></div>


<?php 	
}
?>


<script>
 function showqty(str,id)
{
 var pend=document.getElementById("pending_"+id).value;
 
 if(pend<str)
 {
 alert("Receiving Qty Should be less then  pending qty");
 document.getElementById("receivedQty_"+id).value='';
 document.getElementById("receivedQty_"+id).focus();
 
 return false;
 }
return true;
 
}

function showwaste(str,id)
{
 
 var pend=document.getElementById("pendingqty1_"+id).value;
 var privious=document.getElementById("old1_"+id).value;
 
 if(pend<str)
 {
 alert("Receiving Qty Should be less then  pending qty");
 document.getElementById("recqty_"+id).value=privious;
 document.getElementById("recqty_"+id).focus();
 
 
 return false;
 }
 
return true;
 
}
function wastqty(str,id)
{
  var pend=document.getElementById("issueqty_"+id).value;
 var receive=document.getElementById("recqty_"+id).value;
  var old=document.getElementById("oldwaste_"+id).value;
          
 
  var totalpending=parseFloat(pend)-parseFloat(receive);
  if(totalpending<str)
  {
 alert("Plz check Waste Qty");
 document.getElementById("waste_"+id).value=old;
 document.getElementById("waste_"+id).focus();
  }
 
   return true;
}
 </script>