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


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

?>
<style>
#slidingDiv {
    display: none;
	height:100px;
	background-color: #D9D6DA;
	padding:20px;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<?php if($_REQUEST['action']=='') {?>
<style type="text/css">
<!--
.style2 {color: #00CC33}
-->
</style>
<h3 align="left"><strong><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></strong></h3>
<div align="left">
<?php if($_SESSION['frmAdd']=='1') { ?>
<a href="index.php?route=Inventory/transation/job_work&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" class="search" value="Add New RGP" /></a>
<?php } ?>

</div>
<?php //}?>
<br />

<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr class="row1">
  <td><strong>RGP SLIP NO. </strong></td>
  <td><strong>DATE </strong></td>
  <td><strong>BRANCH</strong></td>
  <td><strong>Document Type</strong></td>
	<td><strong>Items Details</strong></td>
	<td><strong>Vendor</strong></td>
	<td><strong>Expected Date</strong></td>
	<td><strong>Status</strong></td>
	<td colspan="2"><strong>Follow Up</strong><strong>/Action</strong></td>
	</tr>
  <?php
  if($_SESSION['AssignedBranch']!='0')
  {
  $sql=DB_query("Select * from rgp_tab where branch in ('".$_SESSION['AssignedBranch']."')",$db);
  }
  else
  {
    $sql=DB_query("Select * from rgp_tab",$db);
  }
  $i=0;  
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
   $sql2=DB_query("select * from  rgp_tab_details where parent_id='".$myrow['id']."'",$db);
   $numdata=DB_num_rows($sql2);
   $sql3=DB_query("select * from  rgp_tab_details where parent_id='".$myrow['id']."' and status='N'",$db);
    $numdata1=DB_num_rows($sql3);
     $sql4=DB_query("select * from  rgp_tab_details where parent_id='".$myrow['id']."' and status='P'",$db);
   $numdata2=DB_num_rows($sql4);
   if($numdata2>=1)
   $status="Partial Received";
   else if($numdata==$numdata1)
   $status="Pending";
   else
   $status="Received";  
  
  if($status=='Received')
   $bg='#CCFFFF';
  
  else if($status=='Partial Received')
  $bg='#FFFF00';
  else
  $bg='#FFFFFF';
 
  
  ?>
  <tr bgcolor="<?php echo $bg; ?>">
    <td><?php echo $myrow['rgp_no'];?></td>
    <td><?php echo ConvertSQLDate($myrow['date']);?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');
	echo $sitename;?></td>
    <td><?php echo 	$myrow['document_typ'];	?></td>
	
	<td><div style="overflow:auto; width:270px; height:40px;">
	     <?php
		 $sql1=DB_query("select mst_itemid,qty
		  from rgp_tab_details where parent_id='".$myrow['id']."'",$db);
		  $numrow=DB_num_rows($sql1);
		  $t=1;
		 while($row=DB_fetch_array($sql1))
		 {		 
		 ?>
		  <strong><?php if($t==1) {
		   echo ">> ".$s->getField('item_master','id',$row['mst_itemid'],'item_name')."   "."<<"."  Issue Qty :  ".
		   $row['qty']; }
		    else { echo $s->getField('item_master','id',$row['mst_itemid'],'item_name')."   "."<<"."  Issue Qty :  ".
		   $row['qty']; }
		 if($t<$numrow) { 
		  echo "<br>".">>";  }?></strong>
		  
		 <?php $t++; } ?>
	    </div></td>
		<td><?php echo $productionFloor1=$s->getField('suppliers','id',$myrow['supplier'],'vendor_name');	?></td>
		
		<td><?php echo ConvertSQLDate($myrow['expected_date']); ?></td>
		<td><?php echo  $status; ?>	</td>
<td><a href="#" onclick="javascript:popup('Finished_FollowUp.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>',700,700)" title="Follow up" ><img src="images/activities.jpg" height="15" width="15"></a></td>
	
	
	<td>
	<?php if($_SESSION['frmView']=='1'){?>
	<a href="index.php?route=Inventory/transation/Rgp_index&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=View&ViewId=<?php echo $myrow['id']; ?>" title="View"><img src="images/search.gif" height="15" width="15"></a>
	
	<?php }else{echo "No Permission";}?>
	
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="index.php?route=Inventory/transation/job_work_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=Edit&ID=<?php echo $myrow['id']; ?>" title="Edit"><img src="images/icon-edit.png" height="15" width="15"></a>
	<?php }else{echo "No Permission";}?>
	
	
	<?php if($_SESSION['frmDelete']=='1'){?>
	<a href="index.php?route=Inventory/transation/Rgp_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?')" title="Delete">
	<img src="images/Icon_Delete.png" height="15" width="15"></a>
	
	<?php }else{echo "No Permission";}?>
	
	<?php if($_SESSION['frmView']=='1'){?>
	
	<a href="#" onclick="javascript:popup('challan_print.php?id=<?php echo $myrow['id'];?>',1000,1000)" title="print"><img src="images/icon_print.jpg" height="25" width="25"></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>
<?php } ?>


<?php if($_REQUEST['action']=='View') {
$GetData=DB_query("select * from rgp_tab where id='".$_REQUEST['ViewId']."'",$db);
$FetRec=DB_fetch_array($GetData);
extract($FetRec);
?>
<h3 align="left"><strong><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></strong></h3>
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
    <th><strong>Branch</strong></th>
    <td style="width:250px;"><?php echo $s->GetFieldValue('locations',"loccode='".$branch."'",'locationname');?></td>
    <th>RGP No </th>
    <td style="width: 250px;"><?php echo $rgp_no; ?></td>
</tr>

<tr> <th><strong>Document Type .</strong></th>
    <td><?php echo $document_typ; ?></td>
    <th>Date</th>
    <td><?php echo ConvertSQLDate($date); ?></td>
</tr>

<tr>
    <th><strong>Supplier</strong></th>
    <td style="width:250px;"><?php echo $s->GetFieldValue('suppliers',"id='".$supplier."'",'vendor_name'); ?></td>
	
		<?php
		  $timezone = "Asia/Calcutta";
			if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
			  $t=date("g:i a", time()); 
		?>
    <th>Remove Date & Time</th>
    <td style="width:250px;"><?php echo ConvertSQLDate($remove_date); ?>&nbsp;<?php echo $remove_time; ?></td>
</tr>

<tr>
    <th><strong>Form No </strong></th>
    <td style="width:250px;"><?php echo $form_no; ?></td>
    <th>Vehicle No.</th>
    <td><?php echo $vehicle_no; ?></td>
</tr>

<tr></tr>
</table>

 

<table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
		<th><strong>S.R.</strong></th>
          <th><strong>Part Code</strong></th>
          <th><strong>Part Name</strong></th>
          <th><strong>Unit</strong></th>
		  <th><strong>Batch No.</strong></th>
		  <th><strong>Stock Qty.</strong></th>
          <th><strong>Qty</strong></th>
          <th><strong>Job Process</strong></th>
		   <th><strong>Job Rate</strong></th>
		    <th><strong>Job Value</strong></th>
		   
        </tr>
        <tbody id="dataTable">
<?php $i=0; $SQLdetails=DB_query("select * from rgp_tab_details where parent_id='".$_REQUEST['ViewId']."'",$db); 
while($FetchDetails=DB_fetch_array($SQLdetails)){
$unit=$s->GetFieldValue('item_master',"id='".$FetchDetails['mst_itemid']."'",'unit');
$unit_name=$s->GetFieldValue('unitsofmeasure',"unitid='".$unit."'",'unitname');
?>
           <tr bgcolor="#FFFFFF">
            <td><?php echo $i+1; ?></td>
            <td><?php echo $s->GetFieldValue('item_master',"id='".$FetchDetails['mst_itemid']."'",'StockID'); ?></td>
            <td><?php echo $s->GetFieldValue('item_master',"id='".$FetchDetails['mst_itemid']."'",'item_name'); ?></td>
            <td><?php echo $unit_name; ?></td>
            <td><?php echo $FetchDetails['batch_no']; ?></td>
			<td><?php echo $FetchDetails['stock_qty']; ?></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['jobvalue']; ?></td>
           
          </tr>
<?php $i++;} ?>
        </tbody>
</table>
	  
	  
	  
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Remarks </strong></th>
<td colspan="3"><?php echo $remarks; ?></td>
</tr>

<tr>
<th><strong>Expected time</strong></th>
<td style="width:150px;"><?php echo $expected_time; ?></td>
<th><strong>Appox. Value </strong></th>
<td style="width:150px;"><?php echo $appox_value; ?></td>
</tr>
</table>	  

<?php } ?>