<?php

include '../../db_connect.php';

$book_type=$_POST['type'];

if($book_type=='pendingpackinglist')
{       
$sql="SELECT pkgdet.orderid AS pkgid, pkgdet.prodcode AS prdcode, (qty - salesissued) AS  'pending', buyercode AS bycode, DATE_FORMAT( orderdate,  '%d/%m/%Y' ) AS packingdate, 'PKL' as frm  FROM  `sinvoiceregdet` AS pkgdet INNER JOIN sinvoicereg AS spkgreg ON pkgdet.orderid = spkgreg.orderid WHERE (qty - salesissued) >0 AND buyercode =  '$_POST[buyercode]' ";
        
	$items = mysqli_query($con,$sql);
	//if result set is not empty
	if(mysqli_num_rows($items)!=0)
	{
		echo "<table width='100%' cellspacing='0' border='0'><thead><th align='center'>PACKING ID</th><th align='center'>PROD. CODE</th><th align='center'>PENDING QTY</th><th align='center'>FRM</th></thead>";
		echo "<tbody>";
		while($row = mysqli_fetch_array($items)) {
				
				echo "<tr><td align='center' class='packingid'>$row[pkgid]</td><td align='center' class='prodcode'>$row[prdcode]</td><td align='center' class='qty'>$row[pending]</td><td align='center' class='frm'>$row[frm]</td></tr>";
		}
	/*for($i=0;$i<50;$i++)
	echo "<tr><td align='center'><a title='Click to View\ Edit Duty' href='carrental_entry.php?bookid=tesr' onClick='positionedPopup(this.href,660);return false'>test</a></td><td align='center'>trst</td><td align='center'>test</td></tr>";*/
		echo "</tbody>";
	}
	else
	{
		echo 0;
	}

}
else if($book_type=='pendingorderdetails')
{       
	$sql="SELECT orddet.orderid, prodcode,( qty-salesissued)  AS  'pending', buyercode, DATE_FORMAT( orderdate,  '%d/%m/%Y' ) AS orderdate FROM  `spacklistregdet` AS orddet
INNER JOIN sorderreg AS ord ON orddet.orderid = ord.orderid  where ( qty-salesissued) > 0 and prodcode = '$_POST[prodcode]' and agentcode = '$_POST[agent]' order by orderdate desc ";
        
	$items = mysqli_query($con,$sql);
	//if result set is not empty
	if(mysqli_num_rows($items)!=0)
	{
		echo "<table width='100%' cellspacing='0' border='0'><thead><th align='center'>ORDER ID</th><th align='center'>PROD. CODE</th><th align='center'>PENDING QTY</th><th align='center'>ISSUED QTY</th><th align='center'>BUYER</th><th align='center'>ORDERDATE</th>";
		echo "<tbody>";
		while($row = mysqli_fetch_array($items)) {
				
				echo "<tr><td align='center' ><textarea class='orderidissued' name='orderidissued' readonly='readonly'>$row[orderid]</textarea></td><td align='center'>$row[prodcode]</td><td align='center'>$row[pending]</td><td align='center'><textarea name ='issuedqty' class='issuedqty' style='width=50%'>$row[pending]</textarea></td><td align='center'>$row[buyercode]</td><td align='center'>$row[orderdate]</td></tr>";
		}
	/*for($i=0;$i<50;$i++)
	echo "<tr><td align='center'><a title='Click to View\ Edit Duty' href='carrental_entry.php?bookid=tesr' onClick='positionedPopup(this.href,660);return false'>test</a></td><td align='center'>trst</td><td align='center'>test</td></tr>";*/
		echo "</tbody>";
	}
	else
	{
		echo $sql;
	}

}
mysqli_close($con);


?>