<?php
$PageSecurity = 2; 
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
$sql=DB_query("select pr_date, mst_potype from direct_po where id='".$_REQUEST['po']."'",$db);
$row=DB_fetch_array($sql);
$data1="";
if($row['mst_potype']=='1') { $displayData='Import Order'; } 
elseif($row['mst_potype']=='2') { $displayData='Domestic Order'; }
elseif($row['mst_potype']=='3') { $displayData='Service Order'; }
elseif($row['mst_potype']=='4') { $displayData='Asset Order'; }

$data2="";
$data1.=ConvertSQLDate($row['pr_date']);
$data2.="<select id='GrnType' name='GrnType'  style='width:200px;'>";
$data2.="<option Value=".$row['mst_potype'].">".$displayData."</option>";
$data2.="</select>";

$data3.="<table width='100%' border='1' cellspacing='0' cellpadding='3' style='border:1px solid #333333;'>";
$data3.="<tr>";
	$data3.="<td class='tabledata'><strong>Sr.No.</strong></td>";
	$data3.="<td class='tabledata'><strong>Item Code</strong></td>";
	$data3.="<td class='tabledata'><strong>Description</strong></td>";
	$data3.="<td class='tabledata'><strong>UOM</strong></td>";
	$data3.="<td class='tabledata'><strong>PO QTY</strong></td>";
	$data3.="<td class='tabledata'><strong>Pending QTY</strong></td>";
	$data3.="<td class='tabledata'><strong>QTY AS PER BILL </strong></td>";
	$data3.="<td class='tabledata'><strong>QTY Recieved</strong></td>";
	$data3.="<td class='tabledata'><strong>Short/Excess Qty</strong></td>";
  $data3.="</tr>";
$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');
	$tolerance=$s->getField('item_master','id',$row['mst_itemid'],'item_mst_form_rate');
	$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 qty from direct_po_details 
	where parent_id='".$_REQUEST['po']."' and mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res=DB_query($check_last_mrn,$db);
	$last_mrn_row=DB_fetch_array($last_mrn_res);
	
	$check_last_mrn1="Select sum(reciveqty) from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id 
	where addmrn.PO_WO_MTO='".$_REQUEST['po']."' and addmrnqty.mst_itemid='".$row['mst_itemid']."'";
	$last_mrn_res1=DB_query($check_last_mrn1,$db);
	
	$last_mrn_row1=DB_fetch_array($last_mrn_res1);
	 $last_mrn_row1['sum(reciveqty)'];
	if($last_mrn_row['qty']>=$last_mrn_row1['sum(reciveqty)'])
	{
		$pending_qty=$last_mrn_row['qty']-($last_mrn_row1['sum(reciveqty)']);
		 $pending_qty;
	}
	else
	{
		$pending_qty=$last_mrn_row['qty'];
	}	
	


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

 $i++; }	
 $data3.="<tr bgcolor='#c1c1c1'>";
$data3.="<td colspan='6'><center><strong>Total Quantity</strong></center></td>";
$data3.="<td><input name='totalBillQty' type='text' id='short'  size='8' /></td>";
$data3.="<td colspan='2'><input name='totalRecQty' type='text' id='short1'  size='8' /></td>";
$data3.="</tr>";
  $data3.="<input type='hidden' name='countval3' value='".$i."'  id='count'/>";
$data3.="</table>";


echo $data=$data1."__".$data2."__".$data3;
?>
