<?php

ob_start();
$PageSecurity = 4;
$PageName = 'View Purchase Requisition';
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
$title = _('View Purchase Requisition');

$req_sql=DB_query("Select * from inv_material_return where id='".$_REQUEST['Id']."'",$db);


$req_row=DB_fetch_array($req_sql);


 $mrn_sql=DB_query("Select * from addmrn where id='".$req_row['MRNno']."'",$db);


$mrn_row=DB_fetch_array($mrn_sql);


//print_r($req_row);
?>
<h2 align="center"><strong>Material Return To Vendor</strong></h2>
<br />
<table width="80%" border="0" cellspacing="1" cellpadding="1" align="center" style="border: solid 1px #CCC; background-color: #FFFFFF">
  <tr>
    <th nowrap="nowrap"><strong>Branch</strong></th>
     <?php
    $site_sql=DB_query("Select locationname from locations where loccode='".$req_row['sitecode']."'",$db);
	$site_row=DB_fetch_array($site_sql)
    
    ?>
    <td><input name="site" type="text" id="site" value="<?php echo $site_row['locationname'];?>" style="width:100%" readonly="true" />
    </td>
    <th nowrap="nowrap"><strong>Requisition No</strong></th>
  	
  		<td><input name="requisition_no" type="text" id="requisition_no" value="<?php echo $req_row['Reqno'];?>" style="width:100%" readonly="true" /></td>
<th><strong>Date</strong></th>
  	  <td> <input name="returnDate" type="text" style="width:100%"  value="<?php echo $req_row['Reqdate'];?>"/></td>
  	
    
      </tr>
  <tr>
      <th nowrap="nowrap"><strong>Vendor</strong></th>
   <?php

    $vendor_sql=DB_query("Select vendor_name from suppliers where id='".$req_row['vendor_code']."'",$db);
	$vendor_row=DB_fetch_array( $vendor_sql)
    
    ?>
    <td>
     <input name="vendor" type="text" id="site" value="<?php echo $vendor_row['vendor_name'];?>" style="width:100%" readonly="true" />   </td>
  
    <th nowrap="nowrap"><strong>Return Against</strong></th>
   <td>
	<input name="returnagainst" type="text" id="returnagainst" value="<?php echo $req_row['returnagainst'];?>" style="width:100%"  readonly="true" /> 	</td>
 <th><strong>MRN</strong></th>
    <td>
   <div id='hidmrndiv'> 
	<input name="mrn" id="mrn"  type="text" value="<?php echo $mrn_row['MRNNo'];?>" style="width:100%">
	  
	  
	  
      </div>
      </td>
  </tr>
  <?php if($req_row['returnagainst']=='MRN'){?>
   <tr>
 <th width="5%" nowrap="nowrap"><strong>MRN Date</strong></th>
 <td width="22%"><input name="mrnDate" id="mrnDate" type="text" style="width: 100%"  value="<?php echo $mrn_row['MRNDate'];?>"/></td>
 <th width="15%" nowrap="nowrap"><strong>PO No</strong></th>
 <?php
  $poSql="SELECT PO_Orderno FROM purchorders WHERE orderno='".$req_row['PONo']."'";
$poResult=DB_query($poSql,$db);
$poRow=DB_fetch_array($poResult);
 
 ?>
 <td widtyh="30%"><input name="poNo" id="poNo" type="text" style="width: 100%"  value="<?php echo $poRow['PO_Orderno'];?>"/></td>
 <th nowrap="nowrap"><strong>PO Date</strong></th>
 <td><input name="poDate" id="poDate" type="text" style="width: 100%"  value="<?php echo $req_row['PODate'];?>"/>
 </td>
 </tr>
<?php }?>
 </table>

<br />
<br />
<br />
<div align="center">
<div style="overflow:auto; width:800px; height:200px" >
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <th width="4%">Item Code</th>
    <th width="5%">Item Name</th>
     <th width="5%">UOM</th>
	<th width="9%">Description</th>
	 <?php if($req_row['returnagainst']=='MRN'){?>
	<th width="3%">PO Qty</th>
    <th width="5%">Qty As Per Bill</th>
    <th width="7%">Qty Accepted</th>
    <?php }?>
    <th width="5%">Rate</th>
    <th width="8%">Total Value</th>
    <th width="6%">Return Qty</th>
	<th width="7%">Remarks</th>
  </tr>
<?php 
    $get_sql="Select * from inv_material_return_details where parentId='".$req_row['id']."'";
$get_result=DB_query($get_sql,$db);
$i=0;

while($get_row=DB_fetch_array($get_result))
{
if($i%2==0)
{$bg="#C8BECB";}
else
$bg="#CCCCCC";
//echo $get_row['id'];

$item_sql="Select * from item_master where id='".$get_row['itemid']."'";
$item_result=DB_query($item_sql,$db);
$item_row=DB_fetch_array($item_result);
?>
  <tr bgcolor="#FFFFFF" onmouseover="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onmouseout="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
    <td><?php echo $item_row['StockID'];?></td>          
    <td><?php echo $item_row['item_name'];?></td>    
    <td><?php $unitname=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname'); echo $unitname;?></td>
	<td><?php echo $item_row['item_name'];?></td>   
  	 <?php if($req_row['returnagainst']=='MRN'){?>
	 <td><?php echo $get_row['POQty'];?></td>
	 <td><?php echo $get_row['QtyAsPerBill'];?></td>
	 <td><?php echo $get_row['QtyAccepted'];?></td> <?php }?>
	 <td><?php echo $get_row['ItemPrice'];?></td>
	 <td><?php echo $get_row['TotalValue'];?></td>
	<td><?php echo $get_row['ReturnQty'];?></td>	
	<td><?php echo $get_row['Remarks'];?></td>	
  </tr>
  <?php $i++; }?>  <input type="hidden" name="ctr" value="<?php echo $i;?>" />
</table>
</div></div>
<p align="center">
<a href="index.php?route=Inventory/transation/Material_Return_To_Vendor_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" value="Cancel" name="Back" /></a></p>
<?php 
include('includes/footer.inc');
   
?>