<?php include("../../include/dbconnect.php");


// Get all _POST VALUES HERE..

foreach($_POST as $p=>$t)
{
	$_POST[$p] = trim($t);
}

$myCustomer = $_POST['Customer'];



foreach($_POST as $q=>$r)
{
	$_POST[$q] = trim($r);
}

$myProduct = $_POST['Product'];

foreach($_POST as $m=>$n)
{
	$_POST[$m] = trim($n);
}

$myCat = $_POST['Cat'];
?>
<title>Product wise Pending Orders</title>

<center> 
<table cellpadding=0 cellspacing=4 width=590>
  <tr> 
    <td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font face="Verdana, Arial, Helvetica, sans-serif"><b><b>Product wise pending Orders</b></font></td>
  </tr>
  <tr valign="top"> 
    <td colspan=2> <font >&nbsp;</font> </td>
  </tr>
</table>
<table border=0 cellpadding=3 cellspacing=4 width="590">
<tr> 
<td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Customer / Client
  &nbsp;</b></font></td><td>
<?

// Pull all the data from Customer master & populate it

$stQuery = mysql_query("select bcode,name,unit,buyertype from buy where buyertype != 'TEMP'order by name")or die( mysql_error() );



?>
<form name='myForm01' method='POST' action='<?=$_SERVER[PHP_SELF]?>'>
  <SELECT name='Customer' onChange="javascript:submit();">
    <?
echo "<option selected value=\" 0\"> Select Customer";
while($row = mysql_fetch_row($stQuery))
{
	
	   if($row[3]== 'LABOUR')
	   {
		   	$type='------>>'.$row[3];
		}
		elseif($row[3]!= 'LABOUR')
		{
			$type ='';
		}	
	$temp = $row[1].'&nbsp;&nbsp;'.$row[2].$type;
	if(isset($myCustomer) && eregi("$myCustomer",$row[0]))
	{
		echo "<option selected value=\"$row[0]\">$temp";
	}
	else{
		echo "<option value=\"$row[0]\">$temp";
	}
}
?>
  </SELECT></td></tr>
  
<tr> 
<td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Category
  &nbsp;</b></font></td><td>

<?  
$result= mysql_query(" select catcode,category from prodcat order by category")or die( mysql_error() );
 ?>
  <SELECT name='Cat' onChange="javascript:submit();">
    <?
echo "<option selected value=\" 0\"> Select Category";
while($row = mysql_fetch_row($result))
{
	
	//$temp = $row[1].'&nbsp;&nbsp;'.$row[2];
	if(isset($myCat) && eregi("$myCat",$row[0]))
	{
		echo "<option selected value=\"$row[0]\">$row[1]";
	}
	else{
		echo "<option value=\"$row[0]\">$row[1]";
	}
}
?>
  </SELECT></td></tr>  

  
<?
$result = mysql_query("SELECT distinct product.prodcode,product.prodname,product.drawing_no FROM product WHERE   product.bcode= '$myCustomer'  and groupcode ='$myCat'  order by prodname,drawing_no ") or die(mysql_error());
 ?> 
  
<tr > 
  <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Product & Drawing No    &nbsp;</b></font></td><td>

  <SELECT name='Product' onChange="javascript:submit();">
<?php 
	 echo "<option selected value=\" 0\"> Select Product";	  
      while ( $row1= mysql_fetch_row($result))
      {

	  	$temp = $row1[1].'&nbsp;&nbsp;(&nbsp;'.$row1[2].'&nbsp;)';
	  	if(isset($myProduct) && eregi("$myProduct",$row1[0]))
		{
			echo "<option selected value=\"$row1[0]\">$temp";
	  	}
	  	else
	  	{
			echo "<option value=\"$row1[0]\">$temp";
	  	}
	}
?>
</select>  
</td></tr>
</table>
  
  
  

  
</form>
  <table width="936" border="1" >

    <tr>
  <td width="85"  bgcolor="#88B7AF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">Order No</font></td>
    <td width="118"bgcolor="#88B7AF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">Schedule No</font></td>
  <td width="140"bgcolor="#88B7AF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">Schedule Date</font></td>
  <td width="113"bgcolor="#88B7AF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">Due Date</font></td>  
  <td width="86"bgcolor="#88B7AF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300">Order Qty</font></td>  
  <td width="71"bgcolor="#88B7AF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300">Rate</font></td> 
    <td width="99"bgcolor="#88B7AF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300">Schedule Qty</font></td> 
  <td width="88"bgcolor="#88B7AF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300">Issued Qty</font></td>
    <td width="96"bgcolor="#88B7AF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300">Balance Qty</font></td>		
  </tr>

<?

// Pull all Customers from Customer  based on Selected Customer id and populate it.

$sum_order_qty=0;
$sum_schedule_qty=0;
$sum_issued_qty=0;
$sum_balance_qty=0;
$result = mysql_query("SELECT distinct order_no,schedule_no,schedule_date,due_date,order_qty,rate,schedule_qty,issued_qty,balance_qty FROM orders,product WHERE (orders.bcode ='$myCustomer') and  orders.prodcode= '$myProduct' and (orders.prodcode=product.prodcode and product.bcode = '$myCustomer') and orders.balance_qty >0 group by orders.record order by schedule_date,due_date,schedule_no ") or die(mysql_error());
while($row = mysql_fetch_row($result))
{
 $order_no = $row[0];
 $schedule_no=$row[1];
 $schedule_date=substr($row[2],8,2).'-'.substr($row[2],5,2).'-'.substr($row[2],0,4);
 $due_date =substr($row[3],8,2).'-'.substr($row[3],5,2).'-'.substr($row[3],0,4);
 $order_qty = $row[4];
 $rate = $row[5];
 $schedule_qty = $row[6];
 $issued_qty = $row[7];
 $balance_qty = $row[8];
 $sum_order_qty=$sum_order_qty+$order_qty;
 $sum_issued_qty=$sum_issued_qty+$issued_qty;
 $sum_schedule_qty=$sum_schedule_qty+$schedule_qty;
 $sum_balance_qty=$sum_balance_qty+$balance_qty;
 

?>
    <tr>
  <td width="85"   bgcolor="#E5E5E5"align="left"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo($order_no);?></font></td>
    <td width="118"bgcolor="#E5E5E5" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo($schedule_no);?></font></td>
  <td width="140"bgcolor="#E5E5E5" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo($schedule_date);?></font></td>
  <td width="113"bgcolor="#E5E5E5" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo($due_date);?></font></td>  
  <td width="86"bgcolor="#E5E5E5" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($order_qty,0));?></font></td>  
  <td width="71"bgcolor="#E5E5E5" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo($rate);?></font></td> 
    <td width="99"bgcolor="#E5E5E5" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($schedule_qty,0));?></font></td> 
  <td width="88"bgcolor="#E5E5E5" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($issued_qty,0));?></font></td>
    <td width="96"bgcolor="#E5E5E5" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($balance_qty,0));?></font></td>		
  </tr>

<?

}
?>
    <tr>
  <td width="85"   bgcolor="#6699FF"align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">&nbsp;</font></td>
    <td width="118"bgcolor="#6699FF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">&nbsp;</font></td>
  <td width="140"bgcolor="#6699FF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">&nbsp;</font></td>
  <td width="113"bgcolor="#6699FF" align="left"><font face="Arial, Helvetica, sans-serif" color="#993300">Total </font></td>  
  <td width="86"bgcolor="#6699FF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($sum_order_qty,0));?></font></td>  
  <td width="71"bgcolor="#6699FF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300">&nbsp;</font></td> 
    <td width="99"bgcolor="#6699FF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($sum_schedule_qty,0));?></font></td> 
  <td width="88"bgcolor="#6699FF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($sum_issued_qty,0));?></font></td>
    <td width="96"bgcolor="#6699FF" align="right"><font face="Arial, Helvetica, sans-serif" color="#993300"><? echo(number_format($sum_balance_qty,0));?></font></td>		
  </tr>
</table>
<input type="hidden" name="fname" value="<?echo $filename;?>">
<form><br><br><font size=1><center><a href= "../../index.html">Return to index page</center></font>
</body>
