<?php
$PageSecurity = 2;
$title = _('Material Return Slip');
include('includes/stockcalculation.php');
if($_REQUEST['action']=='Delete')
{
	$condition1="parant_id='".$_REQUEST['ID']."'";
	$s->DeleteRecord('nrgp_challan_details',  $condition1);//DELETE FROM CHIELD TABLE
	
	$condition2="id='".$_REQUEST['ID']."'";
	$s->DeleteRecord('nrgp_challan',  $condition2);//DELETE FROM PARENT TABLE
	
	
	$s->pageLocation("index.php?route=Inventory/transation/nrgpchallan_index".$rurl);//PAGE REDIRCTION
}

/***************************************************************************************************************/

 


/*****************************************************************************************************************/




?>
<link rel="stylesheet" href="css/new_mxerp.css">

<style>
#slidingDiv {
display: none;
height:100px;
background-color: #D9D6DA;
padding:20px;
}
</style>
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['action']=='') {?>
<h1 align="center"><strong>NRGP Details</strong></h1>
<div align="left">
<?php if($_SESSION['frmAdd']=='1') {?>
<a href="index.php?route=Inventory/transation/nr_gp_challan&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" name="Add" value="Add New NRGP" class="search" /> </a><?php }?>
</div>
<?php //}?>
<br />
<form method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td class="tabledata1"><strong>NRGP SLIP NO. </strong></td>
    <td class="tabledata1"><strong>DATE </strong></td>
    <td class="tabledata1"><strong>BRANCH</strong></td>
    <td class="tabledata1"><strong>Document Type</strong></td>
	<td class="tabledata1"><strong>Vendor</strong></td>
	<td class="tabledata1"><strong>VIEW</strong></td>
	<td class="tabledata1"><strong>EDIT</strong></td>
	<td class="tabledata1"><strong>DELETE</strong></td>
  </tr>
  <?php
 /* if($_SESSION['AssignedSites']!='0')
  { 
  $sql=DB_query("Select * from nrgp_challan where branch in ('".$_SESSION['AssignedSites']."')",$db);
  }
  else
  {*/
  $sql=DB_query("Select * from nrgp_challan",$db);
//  }
  $i=0;  
  if(DB_num_rows($sql)>0)
  {
  while($myrow=DB_fetch_array($sql))
  {
  ?>
    <tr>
    <td class="tabledata1"><?php echo $myrow['nrgpno'];?></td>
    <td class="tabledata1"><?php echo ConvertSQLDate($myrow['date']);?></td>
    <td class="tabledata1"><?php 	$sitename=$s->getField('locations','loccode',$myrow['branch'],'locationname');	echo $sitename;?></td>
    <td class="tabledata1"><?php echo 	$myrow['document_type'];	?></td>
	<td class="tabledata1"><?php echo $productionFloor1=$s->getField('suppliers','id',$myrow['supplier'],'vendor_name');	?></td>
    <td class="tabledata1">
	<?php if($_SESSION['frmView']=='1'){?>
	<a href="index.php?route=Inventory/transation/nr_gp_challan_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=View&ID=<?php echo $myrow['id']; ?>"><img src="images/search.gif" height="15" width="15"></a>
	<?php }else{echo "No Permission";} ?>
	
	</td>
    <td class="tabledata1">
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="index.php?route=Inventory/transation/nr_gp_challan_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="tabledata1">
	<?php if($_SESSION['frmDelete']=='1'){?>
	<a href="index.php?route=Inventory/transation/nrgpchallan_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"><h3 align="center"><strong>No Record Found</strong></h3></td>
  </tr>
  <?php 	
  }
  ?>
</table>
</form>
<?php } ?>


<?php if($_REQUEST['action']=='View') {
$GetData=DB_query("select * from nrgp_challan where id='".$_REQUEST['ViewId']."'",$db);
$FetRec=DB_fetch_array($GetData);
extract($FetRec);
$function_filter[]=$branch;
$function_filter[]=$store;
$function_filter[]=date('Y-m-d');

?>
<h1 align="center"><strong>View NRGP Details</strong></h1>
<table width="100%" border="1" cellpadding="3" cellspacing="0">
   <tr>
    <td class="tabledata1"><strong>Branch</strong></td>
    <td style="width:250px;"><?php echo $s->GetFieldValue('locations',"loccode='".$branch."'",'locationname');?></td>
    <td class="tabledata1">NRGP No </td>
    <td style="width: 250px;"><?php echo $nrgpno; ?></td>
   </tr>
   <tr>
    <td class="tabledata1"><strong>Document Type .</strong></td>
    <td class="tabledata1"><?php echo $document_type; ?></td>
    <td class="tabledata1">Date</td>
    <td class="tabledata1"><?php echo ConvertSQLDate($date); ?></td>
   </tr>
   <tr>
    <td class="tabledata1"><strong>Supplier</strong></td>
    <td style="width:250px;"><?php echo $s->GetFieldValue('suppliers',"id='".$supplier."'",'vendor_name'); ?></td>
    <td class="tabledata1">Remove Date & Time</td>
    <td style="width:250px;"><?php echo ConvertSQLDate($removal_date); ?>&nbsp;<?php echo $removal_time; ?></td>
</tr>
<tr>
    <td class="tabledata1"><strong>Form No </strong></td>
    <td style="width:250px;"><?php echo $form_no; ?></td>
    <td class="tabledata1">Vehicle No.</td>
    <td class="tabledata1"><?php echo $vehicle_no; ?></td>
</tr>
<tr></tr>
</table>
 <table width="100%" border="1" cellpadding="3" cellspacing="0">
        <tr>
		<td class="tabledata1"><strong>S.R.</strong></td>
          <td class="tabledata1"><strong>Part Code</strong></td>
          <td class="tabledata1"><strong>Part Name</strong></td>
          <td class="tabledata1"><strong>Unit</strong></td>
		  <td class="tabledata1"><strong>Batch No.</strong></td>
		  <td class="tabledata1"><strong>Stock Qty.</strong></td>
          <td class="tabledata1"><strong>Qty</strong></td>
          <td class="tabledata1"><strong>Job Process</strong></td>
        </tr>
        <tbody id="dataTable">
<?php $i=0; $SQLdetails=DB_query("select * from nrgp_challan_details where parant_id='".$_REQUEST['ViewId']."'",$db); 
while($FetchDetails=DB_fetch_array($SQLdetails))
{
$op=openingBalance($function_filter,$FetchDetails['item_code']);
//echo "openingBalance"."<br>";
$in_1=receivedMRN($function_filter,$FetchDetails['item_code']);
//echo "receivedMRN"."<br>";
$out_1=issueSlip($function_filter,$FetchDetails['item_code']);
//echo "issueSlip"."<br>";
$out_2=issueSiteToSite($function_filter,$FetchDetails['item_code']);		
//echo "issuesitetosite"."<br>";
$in_2=receivedSiteToSite($function_filter,$FetchDetails['item_code']);
//echo " receivesitetosite"."<br>";
$out_3=issueMatarialReturn($function_filter,$FetchDetails['item_code']);
//echo "issuematerialreturn"."<br>";
$in_3=receivedReturn($function_filter,$FetchDetails['item_code']);	
//echo "receivedReturn"."<br>";
$out_4=Rgpchallan($function_filter,$FetchDetails['item_code']);
//echo "Rgpchallan"."<br>";
$out_5=Nrgp($function_filter,$FetchDetails['item_code']);
//echo "Nrgp"."<br>";
//echo $out_6=invoice($function_filter,$record_edit['mst_itemid']);
//echo "invoice"."<br>";
//$out_7=disptch($function_filter,$FetchDetails['item_code']);
//echo "disptch"."<br>";
$in_4=Rgpreturn($function_filter,$FetchDetails['item_code']);
//echo "Rgpreturn"."<br>";	 
$in_5=FinishedMR($function_filter,$FetchDetails['item_code']);
//echo "FinishedMR"."<br>";	
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
$tot=$invalue-$outvalue;



$unit=$s->GetFieldValue('item_master',"id='".$FetchDetails['item_code']."'",'mst_unitid');
$unit_name=$s->GetFieldValue('unitsofmeasure',"unitid='".$unit."'",'unitname');
?>
           <tr bgcolor="#FFFFFF">
            <td class="tabledata1"><?php echo $i+1; ?></td>
            <td class="tabledata1"><?php echo $s->GetFieldValue('item_master',"id='".$FetchDetails['item_code']."'",'StockID'); ?></td>
            <td class="tabledata1"><?php echo $s->GetFieldValue('item_master',"id='".$FetchDetails['item_code']."'",'item_name'); ?></td>
            <td class="tabledata1"><?php echo $unit_name; ?></td>
            <td class="tabledata1"><?php echo $FetchDetails['batch_no']; ?></td>
			<td class="tabledata1"><?php echo $tot; ?></td>
			<td class="tabledata1"><?php echo $FetchDetails['qty']; ?></td>
           <td class="tabledata1"><?php echo $s->GetFieldValue('job_work_master',"id='".$FetchDetails['reason']."'",'jobwork_name'); ?></td>
           
          </tr>
<?php $i++;} ?>
        </tbody>
      </table>
	  
	  
	  
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="tabledata1"><strong>Remarks </strong></td>
<td colspan="3"><?php echo $remarks; ?></td>
</tr>

</table>	  

<?php } ?>