<?php
/*
include '../../db_connect.php';

$book_type=$_POST['type'];
$jobid=$_POST['jobid'];
if($book_type=='pendingproduct')
{     
	$sql="SELECT `job_id`,  `prodname`,  (`qnty` - `fresh`) as pending  FROM `jobvar` where `job_id` = '$jobid' group by  prodname ";
        
	$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>";
		}
	
		echo "</tbody>";
	}
	else
	{
		echo 0;
	}

}

mysqli_close($con);

*/

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

$book_type=$_POST['type'];

if($book_type=='pendingproduct')
{       
	$sql="SELECT prodname, SUM(qnty-pissued) as 'pending' FROM `sordervar` group by prodname having SUM(qnty-pissued) >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>";
		}
	
		echo "</tbody>";
	}
	else
	{
		echo 0;
	}

}
else if($book_type=='pendingproductdetails')
{    
     
   
	
		echo "<div class='closediv'> X </div><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>";
		
		$sql="SELECT orddet.`entryid`, orddet.`jobid`, orddet.`orderid`, orddet.`prodname`,  DATE_FORMAT( orddet.tracdate,  '%d/%m/%Y' ) AS tracdate, orddet.`size`, orddet.`type`, ord.`total`, orddet.`issue`, ord.`total` - orddet.`issue` as pending, orddet.`buyer`,DATE_FORMAT( orddet.`orderdate`,  '%d/%m/%Y' ) AS `orderdate`  FROM `tracking`  AS orddet INNER JOIN sordervar AS ord ON orddet.orderid = ord.job_id  where prodname = '$_POST[prodcode]' and jobid  = '$_POST[jobid]' ";
       
	$items = mysqli_query($con,$sql);
	//if result set is not empty
	if(mysqli_num_rows($items)!=0)
	{
		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' ><textarea name ='issuedsize[]' class='issuedsize'>$row[size]</textarea></td><td align='center'><textarea  class='totalqty_pis' name='totalqty_pis[]'>$row[total]</textarea></td><td align='center'>$row[pending]</td><td align='center'><textarea name ='issuedqty[]' class='issuedqty' >$row[issue]</textarea></td><td align='center'><textarea  class='buyercode_pis' name='buyercode_pis[]'>$row[buyer]</textarea></td><td align='center'><textarea class='orderdate_pis' name='orderdate_pis[]'>$row[orderdate]</textarea></td></tr>";
		}

		echo "</tbody></table>";
	}
		
	else
	{
		$sql="SELECT ord.entryid as entryid, orddet.orderid, prodname, size,qnty, pissued, ( qnty-ord.pissued)  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 ";
       //echo $sql;
	$items = mysqli_query($con,$sql);
	//if result set is not empty
		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' ><textarea name ='issuedsize[]' class='issuedsize'>$row[size]</textarea></td><td align='center'><textarea  class='totalqty_pis' name='totalqty_pis[]'>$row[qnty]</textarea></td><td align='center'>$row[pending]</td><td align='center'><textarea name ='issuedqty[]' class='issuedqty' >$row[pissued]</textarea></td><td align='center'><textarea  class='buyercode_pis' name='buyercode_pis[]'>$row[buyercode]</textarea></td><td align='center'><textarea  class='orderdate_pis' name='orderdate_pis[]'>$row[orderdate]</textarea></td></tr>";
		}

		echo "</tbody></table>";
	
	}

}
mysqli_close($con);

?>