<?php include("../../include/dbconnect.php");?>
<title>Order Print</title>
<body bgcolor="#ffffff"  topmargin=0>
<?

$todate = $startdt;
$sdate = $startdt;
$edt = $enddt;
$startdt = substr($startdt,6,4).'-'.substr($startdt,3,2).'-'.substr($startdt,0,2);
$enddt = substr($enddt,6,4).'-'.substr($enddt,3,2).'-'.substr($enddt,0,2);
?>
			<TABLE cellSpacing=0 width="1007"  >
			<TR>
			<TD align=center width="1003"  height=25><FONT 
			face=arial  size=+1  color="#0000FF">WILSON PRESS TOOLS</FONT></TD></TR>
			<TR>
			<TD align=center width="1003"  height=25><FONT 
			face=arial  size=+1 color="#0000FF" >ORDER BOOK FROM &nbsp; <? echo($sdate);?>&nbsp;TO&nbsp;<? echo($edt);?></FONT></TD></TR>			
			</TABLE>
<?

$areatotal=0;
$areadebit=0;
$areacredit=0;
$grtotal=0;
$ind=0;
$bcheck=' ';

$subresult = mysql_query("select name,unit from buy where bcode ='$bcode' ") or die(mysql_error());
$subrow = mysql_fetch_row($subresult);
$bname = $subrow[0].'&nbsp;&nbsp;'.$subrow[1];

?>
	<TABLE cellSpacing=0 width="1900"  bgColor=#cef1ff>
	<TBODY>
	<TR>
	<TD align=left width="1001" bgColor=#cbe1fa height=25><FONT 
	face=arial color=#000080 size=2><? echo($bname);?></FONT></TD></TR></TBODY></TABLE>

	   
	<table width="1900" border=1 cellspacing=0 cellpadding=0>
  	<tr  > 
    <td width=48 align=center><font color=#000080 size=2 
	height="15">Ref. No</font></td>	
    <td width=48 align=center><font color=#000080 size=2 
	height="15">Sl.No</font></td>
    <td width=218 align=left><font color=deeppink size=2 face=arial
	height="15">Purchase Order No & Date</font></td>
    <td width=247 align=center><font color=#000080 size=2 face=arial
	height="15">Description of Items</font></td>
    <td width=73 align=right><font color=#000080 size=2 face=arial
	height="15">Qty Ordered</font></td>
    <td width=70 align=right><font color=#000080 size=2 face=arial
	height="15">Rate</font></td>
    <td width=166 align=center><font color=#000080 size=2 face=arial	
	height="15">Schedule No & Date</font></td>
    <td width=80 align=right><font color=#000080 size=2 face=arial
	height="15">Schedule Qty</font></td>
    <td width=92 align=center><font  color="#CC0066" size=2 face=arial
	height="15">Due Date</font></td>
    <td width=80 align=right><font color=#000080 size=2 face=arial
	height="15">Qty Supplied</font></td>
    <td width=238 align=center><font  color="#660000" size=2 face=arial
	height="15">Invoice No & Date</font></td>
    <td width=124 align=center><font color=#000080  size=2 face=arial
	
	height="15">MIN No & Date</font></td>
    <td width=69 align=right><font color=#000080 size=2 face=arial
	height="15">Approved Qty</font></td>
    <td width=124 align=right><font color=#000080 size=2 face=arial
	height="15">Rejected Qty & Return Date</font></td>
    <td width=241 align=center><font color=#000080 size=2 face=arial
	height="15">Remarks</font></td>
  	<tr>
    <td height="21">&nbsp;</td>
  	</tr>
<?
	$ind=1;
for($prodind=0;$prodind < count($prodcode);$prodind++)
{
	
	$linechk = 'T';

	$temp= ' ';
	$tprodcode='';	
	if($order_type=='schedule_date')
	{
		$result = mysql_query("select  bcode,prodcode,drawing_no,schedule_no,schedule_date,due_date,order_qty,issued_qty,balance_qty,part_qty1,record,order_no,order_date,inv_nos,inv_date,min_no,app_qty,rejected_qty,return_date,remarks,schedule_qty,rate,record from orders where bcode='$bcode' and prodcode = '$prodcode[$prodind]' and (schedule_date >='$startdt' and schedule_date <='$enddt')   order by bcode,prodcode,schedule_date ") or die(mysql_error());
	}
	elseif($order_type=='order_date')
	{
		$result = mysql_query("select  bcode,prodcode,drawing_no,schedule_no,schedule_date,due_date,order_qty,issued_qty,balance_qty,part_qty1,record,order_no,order_date,inv_nos,inv_date,min_no,app_qty,rejected_qty,return_date,remarks,schedule_qty,rate,record from orders where bcode='$bcode' and prodcode = '$prodcode[$prodind]'  and (order_date >='$startdt' and order_date <='$enddt')   order by bcode,prodcode,order_date ") or die(mysql_error());
	}			
	elseif($order_type=='inv_date')
	{
		$result = mysql_query("select  bcode,prodcode,drawing_no,schedule_no,schedule_date,due_date,order_qty,issued_qty,balance_qty,part_qty1,record,order_no,order_date,inv_nos,inv_date,min_no,app_qty,rejected_qty,return_date,remarks,schedule_qty,rate,record from orders where bcode='$bcode' and prodcode = '$prodcode[$prodind]'  and (inv_date >='$startdt' and inv_date <='$enddt')   order by bcode,prodcode,order_no,inv_date ") or die(mysql_error());
	}			
	elseif($order_type=='due_date')
	{
		$result = mysql_query("select  bcode,prodcode,drawing_no,schedule_no,schedule_date,due_date,order_qty,issued_qty,balance_qty,part_qty1,record,order_no,order_date,inv_nos,inv_date,min_no,app_qty,rejected_qty,return_date,remarks,schedule_qty,rate,record from orders where bcode='$bcode' and prodcode = '$prodcode[$prodind]'  and (due_date >='$startdt' and due_date <='$enddt')  or (due_date1 >='$startdt' and due_date1 <='$enddt') or (due_date2 >='$startdt' and due_date2 <='$enddt') or (due_date3 >='$startdt' and due_date3 <='$enddt') or (due_date4 >='$startdt' and due_date4 <='$enddt') or (due_date5 >='$startdt' and due_date5 <='$enddt') order by due_date,bcode,prodcode,order_no,due_date ") or die(mysql_error());
	}
				
	while($row=mysql_fetch_row($result))
	{
	
	

		$drawing_no=$row[2];
		$schedule_no=$row[3].'&nbsp;/&nbsp;'.substr($row[4],8,2).'-'.substr($row[4],5,2).'-'.substr($row[4],0,4);
		$due_date=substr($row[5],8,2).'-'.substr($row[5],5,2).'-'.substr($row[5],0,4);
		$order_qty=$row[6];
		$issued_qty=$row[7];
		$balance_qty=$row[8];
		$part_qty1= $row[9];
		$record=$row[10];
		$order_no= $row[11].'&nbsp;/&nbsp;'.substr($row[12],8,2).'-'.substr($row[12],5,2).'-'.substr($row[12],0,4);
		$invno = $row[13];
		$min_no=$row[15];
		$approved_qty=$row[16];
		$rejected_qty=$row[17].'&nbsp;/&nbsp;'.substr($row[18],8,2).'-'.substr($row[18],5,2).'-'.substr($row[18],0,4);;
		$remarks=$row[19];
		$schedule_qty=$row[20];
		$rate=$row[21];
		$record = $row[22];
	
	
		$subresult = mysql_query("select prodname from product where bcode='$bcode' and prodcode='$prodcode[$prodind]' ") or die(mysql_error());
		$subrow = mysql_fetch_row($subresult);
		$prodname = $subrow[0].'&nbsp;(&nbsp;'.$drawing_no.'&nbsp;)';
		if($linechk== 'T')
		{		
		?>
      	<tr  ><td  colspan="100%">&nbsp;</td></tr>
	
		<?
		$linechk = 'F';
		}
		
 ?>	
  <tr bgcolor="#EEEFAF"> 
    <td width=48 align=center><font color=#000080 size=2 face=arial><a href = "editview.php?record=<? echo($record);?>"><? echo($record);?></a></font></td>  
    <td width=48 align=center><font color=#000080 size=2 face=arial><? echo($ind);?></font></td>
    <td width=218 align=left><font color=deeppink size=2 face=arial
		height="15"><? echo($order_no);?></font></td>
    <td width=247 align=left><font color=#000080 size=2 face=arial
		height="15"><? echo($prodname);?></font></td>
    <td width=73 align=right><font color=#000080 size=2 face=arial
		height="15">
      <? if($drawing_no != $temp and $order_qty >0) echo($order_qty);else echo("&nbsp;");?>
      </font></td>
    <td width=70 align=right><font color=#000080 size=2 face=arial
		height="15">
      <? if( $rate >0) echo($rate);else echo("&nbsp;");?>
      </font></td>
    <td width=166 align=left><font color=#000080 size=2 face=arial
		height="15">
      <? if($row[4]!='0000-00-00') echo($schedule_no);else echo("&nbsp;");?>
      </font></td>
    <td width=80 align=right><font color=#000080 size=2 face=arial
		height="15">
      <? if($schedule_qty>0) echo($schedule_qty);else echo("&nbsp;");?>
      </font></td>
    <td width=92 align=right><font color="#CC0066"  size=2 face=arial
		height="15">
      <? if($due_date != '00-00-0000') echo($due_date);else echo("&nbsp;");?>
      </font></td>
    <td width=80 align=right><font color=#000080 size=2 face=arial
		height="15">
      <? if($issued_qty>0) echo($issued_qty);else echo("&nbsp;");?>
      </font></td>
    <td width=238 align=left><font color="#660000" size=2 face=arial
		height="15"><? if(!empty($invno)){echo($invno);}else echo("&nbsp;");?></font></td>
    <td width=124 align=right><font color=#000080 size=2 face=arial
		height="15"><? if(!empty($min_no))echo($min_no);else echo("&nbsp;");?></font></td>
    <td width=69 align=right><font color=#000080 size=2 face=arial
		height="15"> 
      <? if($approved_qty>0) echo($approved_qty);else echo("&nbsp;");?>
      </font></td>
    <td width=124 align=right><font color=#000080 size=2 face=arial
		height="15">
      <?  if($row[17]>0)echo($rejected_qty);else echo("&nbsp;");?>
      </font></td>
    <td width=241 align=left><font color=#000080 size=2 face=arial
		height="15"><? if(!empty($remarks)) echo($remarks);else echo("&nbsp;");?></font></td>
  </tr>

<?
		$tprodcode=$prodcode[$prodind];
		$ind++;
	}
}
?>
</table>
<br>
<br><font size=1><center><a href="../../index.html">Return to Index page</a></center></font>
