<?php
$PageSecurity = 2;
$title = _('Material Return Slip');


if($_REQUEST['action']=='Delete')
{
	$condition1="parent_id='".$_REQUEST['ID']."'";
	$s->DeleteRecord('rgp_return_details',  $condition1);//DELETE FROM CHIELD TABLE
	
	$condition2="id='".$_REQUEST['ID']."'";
	$s->DeleteRecord('rgp_return',  $condition2);//DELETE FROM PARENT TABLE
	
	
	$s->pageLocation("index.php?route=Inventory/transation/rgp_return_index".$rurl);//PAGE REDIRCTION
}

?>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['action']=='') {?>
<h1><strong>RGP Return</strong></h1>
<p align="left">
<?php 

if($_SESSION['frmAdd']=='1') { ?>
<a href="index.php?route=Inventory/transation/rgp_return&modid=<?php  echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes" ><input type="button" class="search" value="Add New RGP Return" /></a>
<?php }?>
</p>
<?php //}?>

<form method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
    <th width="12%">RGP Slip No.</th>
    <th width="9%">Date</th>
    <th>Branch</th>
    <th width="12%">Vehicle No.</th>
	  <th width="20%">Vendor</th>
	  <th width="5%">View</th>
	  <th width="5%">Edit</th>
	  <th width="5%">Delete</th>
  </tr>
  <?php
  /* if($_SESSION['AssignedBranch']!='0')
	  { 
  $sql=DB_query("Select * from rgp_return where branch in (".$_SESSION['AssignedBranch'].")",$db);
      }
	  else
	  {*/
	   $sql=DB_query("Select * from rgp_return",$db);
	 // }
  $i=0;  
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
  ?>
  <tr>
    <td><?php echo $myrow['return_no'];?></td>
    <td><?php echo ConvertSQLDate($myrow['return_date']);?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
	echo $sitename;?></td>
    <td><?php echo 	$myrow['vehchile_no'];	?></td>
	<td><?php echo $productionFloor1=$s->getField('suppliers','id',$myrow['suplier'],'vendor_name');	?></td>
	<td class="text-center">
	<?php if($_SESSION['frmView']=='1'){?>
	<a href="index.php?route=Inventory/transation/rgp_return_index&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=View&ViewId=<?php echo $myrow['id']; ?>"><img src="images/search.gif" height="15" width="15"></a>
	<?php }else{echo "No Permission";}?>
	</td>
	<td class="text-center">
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="index.php?route=Inventory/transation/rgp_return_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=Edit&ID=<?php echo $myrow['id']; ?>"><img src="images/icon-edit.png" height="15" width="15"></a>
	
	<?php }else{echo "No Permission";}?>
	</td>
	<td class="text-center">
	<?php if($_SESSION['frmDelete']=='1'){?>
	<a href="index.php?route=Inventory/transation/rgp_return_index&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=Delete&ID=<?php echo $myrow['id']; ?>" onclick="return confirm('Are you sure you want to delete?')">
	<img src="images/Icon_Delete.png" height="15" width="15"></a>
	<?php }else{echo "No Permission";}?>
	</td>
  </tr>
  <?php $i++;} }
  else
  {?>
  <tr>
  <td colspan="12"><strong>No Record Found</strong></td>
  </tr>
  <?php 	
  }
  ?>
</table>
</form>
<?php } ?>


<?php if($_REQUEST['action']=='View') {
$GetData=DB_query("select * from rgp_return where id='".$_REQUEST['ViewId']."'",$db);
$FetRec=DB_fetch_array($GetData);
extract($FetRec);
?>
<h2 align="center"><strong>View RGP Return Details</strong></h2>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td width="13%" align="right">Branch</td>
    <td width="35%"><?php echo $s->GetFieldValue('locations',"loccode='".$branch."'",'locationname');?></td>
    <td width="13%" align="right">Return No.</td>
    <td><?php echo $return_no; ?></td>
  </tr>
  <tr class="row1">
    <td align="right">Supplier</td>
    <td><?php echo $s->GetFieldValue('suppliers',"id='".$suplier."'",'vendor_name'); ?></td>
    <td align="right">Return Date & Time</td>
    <td><?php echo ConvertSQLDate($return_date); ?>&nbsp;<?php echo $return_time; ?></td>
  </tr>
  <tr class="row1">
    <td align="right">RGP No.</td>
    <td><?php echo $s->GetFieldValue('rgp_tab',"id='".$rgp_no."'",'rgp_no'); ?></td>
    <td align="right">Vehicle No.</td>
    <td><?php echo $vehchile_no; ?></td>
  </tr>
  <tr class="row1">
    <td align="right">Remove Date & Time</td>
    <td><?php echo ConvertSQLDate($remove_date); ?>&nbsp;<?php echo $remove_time; ?></td>
    <td align="right">Form No.</td>
    <td><?php echo $form_no; ?></td>
  </tr>
</table> 

<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>
		<th width="4%">S. No.</th>
    <th width="10%">Part Code</th>
    <th>Part Name</th>
    <th width="7%">Unit</th>
		<th width="10%">Batch No.</th>
    <th width="9%">Qty.</th>
    <th width="10%">Job Process</th>
		<th width="10%">Job Rate</th>
		<th width="10%">Job Value</th>		   
  </tr>
        <tbody id="dataTable">
<?php $i=0; $SQLdetails=DB_query("select * from rgp_return_details where parent_id='".$_REQUEST['ViewId']."'",$db); 
while($FetchDetails=DB_fetch_array($SQLdetails)){
$unit=$s->GetFieldValue('item_master',"id='".$FetchDetails['item_id']."'",'unit');
$unit_name=$s->GetFieldValue('unitsofmeasure',"unitid='".$unit."'",'unitname');
?>
           <tr>
            <td><?php echo $i+1; ?></td>
            <td><?php echo $s->GetFieldValue('item_master',"id='".$FetchDetails['item_id']."'",'StockID'); ?></td>
            <td><?php echo $s->GetFieldValue('item_master',"id='".$FetchDetails['item_id']."'",'item_name'); ?></td>
            <td><?php echo $unit_name; ?></td>
            <td><?php echo $FetchDetails['batch_no']; ?></td>
			<td><?php echo $FetchDetails['qty']; ?></td>
           <td><?php echo $s->GetFieldValue('job_work_master',"id='".$FetchDetails['job_process']."'",'jobwork_name'); ?></td>
           <td><?php echo $FetchDetails['job_rate']; ?></td>
		    <td><?php echo $FetchDetails['job_value']; ?></td>
           
          </tr>
<?php $i++;} ?>
        </tbody>
      </table>
	  
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
  <td width="13%" align="right">Removal Remarks</td>
  <td width="20%" id="REMARK"><?php echo $removal_remarks; ?></td>
  <td width="13%" align="right">Expected Time</td>
  <td width="20%" id="EXPTEDTIME"><?php echo $exp_time; ?></td>
  <td width="13%" align="right">Total Value</td>
  <td id="EXPECTEDVALUE"><?php echo $exp_value; ?></td>
</tr>
<tr class="row1">
  <td align="right">Return Remarks</td>
  <td><?php echo $return_remark; ?></td>
  <td align="right">Return Time</td>
  <td colspan="3"><?php echo $rgp_return_time; ?></td>
</tr>
</table>	  

<?php } ?>

</div>
</div>