<?php 
$PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
$data1="";
$data2="";
?>
<link rel="stylesheet" type="text/css" href="css/professional/table_frize.css">
<?php
if($_REQUEST['POType']=='IO' && $_REQUEST['ReciveAng']!='INV')
{          
           
			$sqlPurchord=DB_query("SELECT * FROM purchorders WHERE id='".$_REQUEST['POID']."'",$db);
			$PurchOrdData=DB_fetch_array($sqlPurchord);
			$data1.="<div>
				<div>";
			$data1.="<table width='100%' cellpadding='3' cellspacing='0' border='0' class='thborder'>";
			$data1.="<tr>";
			$data1.="<th width='4%'>S. No.</th>";
			$data1.="<th width='10%'>Part Code</th>";
			$data1.="<th>Part Name</th>";
			$data1.="<th width='8%'>PO Qty.</th>";
            $data1.="<th width='8%'>Pending Qty.</th>";
		    $data1.="<th width='10%'>Batch No.</th>";
            $data1.="<th width='10%'>Qty. as per Bill</th>";
            $data1.="<th width='10%'>Qty. Received</th>";
            $data1.="<th width='10%'>Short Qty.</th>";
		$data1.="</tr>"; 
$sqlPoRec=DB_query("SELECT * FROM purchorderdetails where parantId='".$_REQUEST['POID']."' and status='Pending'",$db);
$i=0;
while($PORecDetails=DB_fetch_array($sqlPoRec)){
$ItemCode=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'StockID');
$Itemname=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'item_name');
$Tolrance=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'item_mst_form_rate');

$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
where order_no='".$_REQUEST['POID']."' and mst_itemid='".$PORecDetails['mst_itemid']."' and grn_type='Indirect'";
$last_mrn_res=DB_query($check_last_mrn,$db);

$last_mrn_row=DB_fetch_array($last_mrn_res);

$check_short_close=DB_query("Select sum(short_close) AS short_close from po_short_close 
where po_id='".$_REQUEST['POID']."' and item_id='".$PORecDetails['mst_itemid']."'",$db);
$short_close_res=DB_fetch_array($check_short_close);
if(DB_num_rows($check_short_close)>0){
    $short_close=$short_close_res['short_close'];
}else{
    $short_close=0;
}

if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
{
 $pending_qty=($PORecDetails['Quantity']+$last_mrn_row['POQty'])-($last_mrn_row['sum(reciveqty)']+$short_close);
}
else
{
$pending_qty=$PORecDetails['Quantity'];
}	



			$data1.="<tr>";
					$data1.="<td><input type='checkbox'  /></td>";
					$data1.="<td>".$ItemCode."<input type='hidden' name='mst_itemid[$i]' id='itemid' value='".$PORecDetails['mst_itemid']."' />
					<input type='hidden' name='' id='tolerance_".$i."' value='".$Tolrance."' />
					</td>";
					$data1.="<td>".$Itemname."</td>";
					$data1.="<td>".$PORecDetails['Quantity']."
					<input type='hidden' name='poqty[$i]' id='poqty_".$i."' value='".$PORecDetails['Quantity']."' />
					</td>";
					$data1.="<td>".$pending_qty."
					<input type='hidden' name='pending_qty[$i]' id='pending_qty_".$i."' value='".$pending_qty."' />
					</td>";
					$data1.="<td><input   type='text' name='batch_no[$i]' id='batch_no'/></td>";
					$data1.="<td><input   type='text' name='qty_as_per_bill[$i]' id='qty_as_per_bill_".$i."' onkeyup='check_bill_qty(this.value,".$i.")'/></td>";
					$data1.="<td><input   type='text' name='qty_received[$i]' id='qty_received_".$i."' onkeyup='check_po_qty1(".$i.")'/></td>";
					$data1.="<td><input   type='text' name='short_qty[$i]' id='short_qty_".$i."' onfocus='calculate_poshort(".$i.");'/></td>";
		$data1.="</tr>"; 
		
$i++;}	
$data1.=" <input type='hidden' id='conterimp' value='".$i."' />";
	$data1.="</table>";
	$data1.="</div></div>";
}

if($_REQUEST['POType']=='DO' && $_REQUEST['ReciveAng']!='INV')
{	
	$sqlPurchord=DB_query("SELECT * FROM purchorders WHERE id='".$_REQUEST['POID']."'",$db);
	$PurchOrdData=DB_fetch_array($sqlPurchord);
	$data1.="<div>
	<div>";
$data1.="<table width='100%' cellpadding='3' cellspacing='0' border='0' class='thborder'>";
					$data1.="<tr>";
						$data1.="<th width='5%'>Select</th>";
						$data1.="<th width='10%'>Part Code</th>";
						$data1.="<th>Part Name</th>";
						$data1.="<th width='8%'>PO Qty.</th>";
						$data1.="<th width='8%'>Pending Qty.</th>";
						$data1.="<th width='10%'>Batch No.</th>";
						$data1.="<th width='10%'>Qty. as per Bill</th>";
						$data1.="<th width='10%'>Qty. Received</th>";
						$data1.="<th width='10%'>Short Qty.</th>";
					$data1.="</tr>";

$sqlPoRec=DB_query("SELECT * FROM purchorderdetails where parantId='".$_REQUEST['POID']."' and status='Pending'",$db);
$i=0;
while($PORecDetails=DB_fetch_array($sqlPoRec)){
$ItemCode=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'StockID');
$Itemname=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'item_name');
$Tolrance=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'item_mst_form_rate');



$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
where order_no='".$_REQUEST['POID']."' and mst_itemid='".$PORecDetails['mst_itemid']."' and grn_type='Indirect'";
$last_mrn_res=DB_query($check_last_mrn,$db);

$last_mrn_row=DB_fetch_array($last_mrn_res);

$check_short_close=DB_query("Select sum(short_close) AS shortclose from po_short_close 
where po_id='".$_REQUEST['POID']."' and item_id='".$PORecDetails['mst_itemid']."'",$db);
$short_close_res=DB_fetch_array($check_short_close);
if(DB_num_rows($check_short_close)>0){
    $short_close=$short_close_res['shortclose'];
}else{
     $short_close=0;
}

if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
{
$pending_qty=$last_mrn_row['POQty']-($last_mrn_row['sum(reciveqty)']+$short_close);
}
else
{
$pending_qty=$PORecDetails['Quantity'];
}

if($PORecDetails['Excise_type']=='NonExcisable' || $PORecDetails['Excise_type']=='IncludeTax')
{
	$disabled='disabled';
}
else
{
	$disabled='';
}
	

					$data1.="<tr>";
					$data1.="<td><input type='checkbox'  /></td>";
					$data1.="<td>".$ItemCode."<input type='hidden' name='mst_itemid[$i]' id='itemid' value='".$PORecDetails['mst_itemid']."' />
					<input type='hidden' name='' id='tolerance_".$i."' value='".$Tolrance."' />
					</td>";
					$data1.="<td>".$Itemname."</td>";
					$data1.="<td>".$PORecDetails['Quantity']."
					<input type='hidden' name='poqty[$i]' id='poqty_".$i."' value='".$PORecDetails['Quantity']."' />
					</td>";
					$data1.="<td>".$pending_qty."
					<input type='hidden' name='pending_qty[$i]' id='pending_qty_".$i."' value='".$pending_qty."' />
					</td>";
					$data1.="<td><input   type='text' name='batch_no[$i]' id='batch_no'/></td>";
					$data1.="<td><input   type='text' name='qty_as_per_bill[$i]' 
					id='qty_as_per_bill_".$i."' onkeyup='check_bill_qty(this.value,".$i.")'/></td>";
					$data1.="<td><input   type='text' name='qty_received[$i]' 
					id='qty_received_".$i."' onkeyup='check_po_qty1(".$i.")'/></td>";
					$data1.="<td><input   type='text' name='short_qty[$i]' 
					id='short_qty_".$i."' onfocus='calculate_poshort(".$i.");'/></td>";
		$data1.="</tr>"; 
		
$i++;}	
$data1.=" <input type='hidden' id='conterimp' value='".$i."' />";
	$data1.="</table>";
	$data1.="</div></div>";			
		
}

if($_REQUEST['POType']=='Indent')
{
			$sqlPurchord=DB_query("SELECT * FROM materialrequisitions WHERE requisitionno='".$_REQUEST['POID']."'",$db);
			$PurchOrdData=DB_fetch_array($sqlPurchord);
			$data1.="<div>
				<div>";
			$data1.="<table width='100%' cellpadding='3' cellspacing='0' border='0' class='thborder'>";
			$data1.="<tr>";
			$data1.="<th width='4%''>S. No.</th>";
			$data1.="<th width='10%'>Part Code</th>";
			$data1.="<th>Part Name</th>";
			$data1.="<th width='8%'>PO Qty.</th>";
            $data1.="<th width='8%'>Pending Qty.</th>";
		    $data1.="<th width='10%'>Batch No.</th>";
            $data1.="<th width='10%'>Qty. as per Bill</th>";
            $data1.="<th width='10%'>Qty. Received</th>";
            $data1.="<th width='10%'>Short Qty.</th>";
		$data1.="</tr>"; 
		
$sqlPoRec=DB_query("SELECT * FROM requisitionorderdetails where requsitionno='".$_REQUEST['POID']."' and mrn_status='Pending'",$db);
$i=0;
while($PORecDetails=DB_fetch_array($sqlPoRec)){
$ItemCode=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'StockID');
$Itemname=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'item_name');
$Tolrance=$s->GetFieldValue('item_master',"id='".$PORecDetails['mst_itemid']."'",'item_mst_form_rate');



$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
where order_no='".$_REQUEST['POID']."' and mst_itemid='".$PORecDetails['mst_itemid']."' and grn_type='Indent'";
$last_mrn_res=DB_query($check_last_mrn,$db);

$last_mrn_row=DB_fetch_array($last_mrn_res);

$check_short_close=DB_query("Select sum(short_close) AS shortclose from po_short_close 
where po_id='".$_REQUEST['POID']."' and item_id='".$PORecDetails['mst_itemid']."'",$db);
$short_close_res=DB_fetch_array($check_short_close);
if(DB_num_rows($check_short_close)>0){
    $short_close=$short_close_res['shortclose'];
}else{
     $short_close=0;
}

if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
{
 $pending_qty=($PORecDetails['App_quantity']+$last_mrn_row['POQty'])-($last_mrn_row['sum(reciveqty)']+$short_close);
}
else
{
$pending_qty=$PORecDetails['App_quantity'];
}	



			$data1.="<tr>";
					$data1.="<td><input type='checkbox'  /></td>";
					$data1.="<td>".$ItemCode."<input type='hidden' name='mst_itemid[$i]' id='itemid' value='".$PORecDetails['mst_itemid']."' />
					<input type='hidden' name='' id='tolerance_".$i."' value='".$Tolrance."' />
					</td>";
					$data1.="<td>".$Itemname."</td>";
					$data1.="<td>".$PORecDetails['App_quantity']."
					<input type='hidden' name='poqty[$i]' id='poqty_".$i."' value='".$PORecDetails['App_quantity']."' />
					</td>";
					$data1.="<td>".$pending_qty."
					<input type='hidden' name='pending_qty[$i]' id='pending_qty_".$i."' value='".$pending_qty."' />
					</td>";
					$data1.="<td><input   type='text' name='batch_no[$i]' id='batch_no'/></td>";
					$data1.="<td><input   type='text' name='qty_as_per_bill[$i]'
					 id='qty_as_per_bill_".$i."' onkeyup='check_bill_qty(this.value,".$i.")'/></td>";
					$data1.="<td><input   type='text' name='qty_received[$i]' 
					id='qty_received_".$i."' onkeyup='check_po_qty1(".$i.")'/></td>";
					$data1.="<td><input   type='text' name='short_qty[$i]' 
					id='short_qty_".$i."' onfocus='calculate_poshort(".$i.");'/></td>";
		$data1.="</tr>"; 
		
$i++;}	
$data1.=" <input type='hidden' id='conterimp' value='".$i."' />";
	$data1.="</table>";
	$data1."</div></div>";	
}

if($_REQUEST['ReciveAng']=='INV')
{                     
			$sqlPurchord=DB_query("SELECT * FROM invoice WHERE invoice_id='".$_REQUEST['POID']."'",$db);
			$PurchOrdData=DB_fetch_array($sqlPurchord);
			$data1.="<div>
				<div>";
			$data1.="<table width='100%' cellpadding='3' cellspacing='0' border='0' class='thborder'>";
			$data1.="<tr>";
			$data1.="<th width='4%'>S. No.</th>";
			$data1.="<th width='10%'>Part Code</th>";
			$data1.="<th>Part Name</th>";
			$data1.="<th width='10%'>Invoice Qty.</th>";
            $data1.="<th width='10%'>Pending Qty.</th>";
		    $data1.="<th width='10%'>Batch No.</th>";
            $data1.="<th width='10%'>Qty. as per Bill</th>";
            $data1.="<th width='10%'>Qty. Received</th>";
            $data1.="<th width='10%'>Short Qty.</th>";
		$data1.="</tr>"; 
$sqlPoRec=DB_query("SELECT * FROM invoice_details where invoiceid='".$_REQUEST['POID']."'",$db);
$i=0;
while($PORecDetails=DB_fetch_array($sqlPoRec)){
$ItemCode=$s->GetFieldValue('item_master',"id='".$PORecDetails['ItemCode']."'",'StockID');
$Itemname=$s->GetFieldValue('item_master',"id='".$PORecDetails['ItemCode']."'",'item_name');
$Tolrance=$s->GetFieldValue('item_master',"id='".$PORecDetails['ItemCode']."'",'item_mst_form_rate');

$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
where order_no='".$_REQUEST['POID']."' and mst_itemid='".$PORecDetails['ItemCode']."' and grn_type='Indirect'";
$last_mrn_res=DB_query($check_last_mrn,$db);

$last_mrn_row=DB_fetch_array($last_mrn_res);

$check_short_close=DB_query("Select sum(short_close) AS short_close from po_short_close where po_id='".$_REQUEST['POID']."' and item_id='".$PORecDetails['ItemCode']."'",$db);
$short_close_res=DB_fetch_array($check_short_close);
if(DB_num_rows($check_short_close)>0){
    $short_close=$short_close_res['short_close'];
}else{
    $short_close=0;
}

if($last_mrn_row['POQty']!='' && $last_mrn_row['sum(reciveqty)']!='' )
{
 $pending_qty=($PORecDetails['Quantity'])-($last_mrn_row['sum(reciveqty)']+$short_close);
}
else
{
$pending_qty=$PORecDetails['Quantity'];
}	



			$data1.="<tr>";
					$data1.="<td><input type='checkbox'  /></td>";
					$data1.="<td>".$ItemCode."<input type='hidden' name='mst_itemid[$i]' id='itemid' value='".$PORecDetails['ItemCode']."' />
					<input type='hidden' name='' id='tolerance_".$i."' value='".$Tolrance."' />
					</td>";
					$data1.="<td>".$Itemname."</td>";
					$data1.="<td>".$PORecDetails['Quantity']."
					<input type='hidden' name='poqty[$i]' id='poqty_".$i."' value='".$PORecDetails['Quantity']."' />
					</td>";
					$data1.="<td>".$pending_qty."
					<input type='hidden' name='pending_qty[$i]' id='pending_qty_".$i."' value='".$pending_qty."' />
					</td>";
					$data1.="<td><input   type='text' name='batch_no[$i]' id='batch_no'/></td>";
					$data1.="<td><input   type='text' name='qty_as_per_bill[$i]' id='qty_as_per_bill_".$i."' onkeyup='check_bill_qty(this.value,".$i.")'/></td>";
					$data1.="<td><input   type='text' name='qty_received[$i]' id='qty_received_".$i."' onkeyup='check_po_qty1(".$i.")'/></td>";
					$data1.="<td><input   type='text' name='short_qty[$i]' id='short_qty_".$i."' onfocus='calculate_poshort(".$i.");'/></td>";
		$data1.="</tr>"; 
		
$i++;}	
$data1.=" <input type='hidden' id='conterimp' value='".$i."' />";
	$data1.="</table>";
	$data1.="</div></div>";
}


$data2.="";
echo $data=$data1."__".$data2;

 ?>
