<?php

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

$book_type=$_POST['type'];

if($book_type=='pendingorder')
{       
	$sql="SELECT prodname, SUM(qnty-issued) as 'pending' FROM `sordervar` group by prodname having SUM(qnty-issued) >0";
        
	$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'>PROD. CODE</th><th align='center'>PENDING QTY</th></thead>";
		echo "<tbody>";
		while($row = mysqli_fetch_array($items)) {
				
				echo "<tr><td align='center' class='prodcode'>$row[prodname]</td><td align='center' class='qty'>$row[pending]</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 "";
	}

}
else if($book_type=='pendingorderdetails')
{       
	$sql="SELECT ord.entryid as entryid, orddet.orderid, prodname, size,qnty, issued, ( qnty-ord.issued)  AS  'pending', buyercode, DATE_FORMAT( orderdate,  '%d/%m/%Y' ) AS orderdate
FROM  `sorderreg` AS orddet INNER JOIN sordervar AS ord ON orddet.orderid = ord.job_id  where   prodname = '$_POST[prodcode]' order by entryid asc ";
       
	$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' class='pproddetiss'><thead><th align='center'>ORDER ID</th><th align='center'>SIZE</th><th align='center'>TOTAL</th><th align='center'>PENDING</th><th align='center'>ISSUED</th><th align='center'>BUYER</th><th align='center'>ORDERDATE</th>";
		echo "<tbody>";
		while($row = mysqli_fetch_array($items)) {
				
				echo "<tr><td align='center' style='display:none'><textarea class='entryid_pis' name='entryid_pis[]'>$row[entryid]</textarea></td><td align='center' ><textarea class='orderidissued' name='orderidissued[]' readonly='readonly'>$row[orderid]</textarea></td><td align='center' style='display:none'><textarea class='prodname_pis' name='prodname_pis[]'>$row[prodname]</textarea></td><td align='center' name ='issuedsize[]' class='issuedsize'>$row[size]</td><td align='center'><textarea  >$row[qnty]</textarea></td><td align='center'>$row[pending]</td><td align='center'><textarea name ='issuedqty[]' class='issuedqty' >$row[issued]</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></table>";
	}
	else
	{
		echo 0;
	}

}
mysqli_close($con);


?>