<?php
$PageSecurity = 2; 
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
?>

<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #333333;">
<tr>
	<td class="tabledata"><strong>Sr.No.</strong></td>
	<td class="tabledata"><strong>Item Code</strong></td>
	<td class="tabledata"><strong>Description</strong></td>
	<td class="tabledata"><strong>UOM</strong></td>
	<td class="tabledata"><strong>PO QTY</strong></td>
	<td class="tabledata"><strong>Pending QTY</strong></td>
	<td class="tabledata"><strong>QTY AS PER BILL </strong></td>
	<td class="tabledata"><strong>QTY Recieved</strong></td>
	<td class="tabledata"><strong>Short/Excess Quantity</strong></td>
  </tr>
  <?php 
$i=0;
$sql=DB_query("select * from direct_po_details where parent_id='".$_REQUEST['po']."' and status='Pending'",$db);
while($row=DB_fetch_array($sql))
{
	$itemcode=$s->getField('item_master','id',$row['mst_itemid'],'StockID');
	$itemname=$s->getField('item_master','id',$row['mst_itemid'],'item_name');
	$unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	$unit1=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
	$confac=$s->getField('item_master','id',$row['mst_itemid'],'conv_factor');
	$discount_type=$row['dis_type'];
	$discount=$row['dis_per'];
	$discount_amount=$row['dis_price'];
	$specialdiscounttype=$row['spl_dis_type'];
	$specialdiscount=$row['spl_dis_per'];
	$specialdiscount_amount=$row['spl_dis_amt'];
	$tax_type=$row['excise_flag'];
	$Excise_Duty=$row['excise_duty'];
	$ExcisePercentage=$row['ExcisePercentage'];
	$Edu_Cess_perc=$row['ECessPercentage'];
	$SHE_Cess_perc=$row['SAHCessPercentage'];
	
	$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty where order_no='".$_GET['orderno']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
	{
		$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']);
	}
	else
	{
		$pending_qty=$row['qty'];
	}	
	

?>
 
<tr bgcolor="#c1c1c1">
	<td><?php echo $i+1;?></td>
	<td><?php echo $itemcode;?>
	<input type="hidden" name="convfac[]" id="convfac_<?php echo $i; ?>" value="<?php echo $confac; ?>" />
	<input type="hidden" readonly="" id="mst_itemid_<?php echo $i; ?>" name="mst_itemid[]" size="15" value="<?php echo $row['mst_itemid']; ?>" />
	<input type="hidden" readonly="" id="itemcode_<?php echo $i; ?>" name="itemcode[]" size="15"  value="<?php echo $itemcode; ?>" />
	<input type="hidden" readonly="" id="tolerances_<?php echo $i; ?>" name="tolrancees[]" size="15"  value="<?php echo $tolerance; ?>" />
	<input type="hidden" readonly="" id="pending_<?php echo $i; ?>" name="pending[]" size="15"  value="<?php echo $pending_qty; ?>" />	</td>
	<td><?php echo $itemname ?></td>
	<td><?php $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
	echo $unitname;?></td>
	<td><?php   echo $poqty=$row['qty']; ?>
	<input name="poqty[]" type="hidden" id="poqty_<?php echo $i; ?>" value="<?php echo $poqty;?>" size="10"/></td>
	<td><?php   echo $pending_qty;?>
	<input type="hidden" name="pending_qty[]" id="pending_qty_<?php echo $i; ?>" value="<?php echo $pending_qty;?>" />	</td>
	<td><input name="qty_as_per_bill[]" type="text" id="qty_as_per_bill_<?php echo $i; ?>"  onkeyup="calTotalQty1(this.value,<?php echo $i; ?>);" size="8" onblur="check_bill_qty(this.value,<?php echo $i;?>)"/>	</td>
	<td><input name="reciveqty[]" type="text" id="reciveqty_<?php echo $i; ?>" onkeyup="calTotalQty(this.value,<?php echo $i; ?>);"  size="8" /></td>
	<td><input name="short_accessid[]" type="text" id="short_accessid_<?php echo $i; ?>" value="<?php echo $_REQUEST['short_accessid'][$i];?>" size="8" readonly="true" onfocus="calculate_poshort(<?php echo $i ?>);"/></td>
</tr>

  <?php $i++; }	 ?>
  <tr bgcolor="#c1c1c1">
<td colspan="6">Total Qty </td>
<td><input name="totalBillQty" type="text" id="short"  size="8" /></td>
<td colspan="2"><input name="totalRecQty" type="text" id="short1"  size="8" /></td>
</tr>
  <input type="hidden" name="countval3" value="<?php echo $i; ?>"  id="count"/>
</table>
