<?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);

$linecount=3;

$ind=0;
$bcheck=' ';

$months=array("January","February","March","April","May","June","July","August","September","October","November","December");



?>
		
			

			<TABLE cellSpacing=0 width="1000">

			<TR>
			<TD align=center width="1000"  height=25> <img src="wilson.jpg"></TD></TR>
			<TR>
			<TD align=center width="971"  height=25><FONT 
			face=arial  size=+1 color="#0000FF" >SCHEDULE FOR THE MONTH OF <? echo($months[$month-1]);?>&nbsp;&nbsp;<? echo($year);?></FONT></TD></TR>			
			</TABLE>

<?

$normalvalue =schedule($month,$year,'Normal');

?>
<TABLE cellSpacing=0 width="1000"  >
			<TR>
			<TD align=center width="1000"  height=25> <img src="wilson.jpg"></TD></TR>
			<TR>
			<TD align=center width="1000"  height=25><FONT 
			face=arial  size=+1  color="#CC0000"><U>ADDITIONAL</U></FONT>
			<FONT face=arial  size=+1 color="#0000FF" >SCHEDULE FOR THE MONTH OF <? echo($months[$month-1]);?>&nbsp;&nbsp;<? echo($year);?></FONT></TD></TR>			
			</TABLE>

<?


$addvalue=schedule($month,$year,'Additional');

?>
	<hr  align="left"  align="left"width="1000">
	<table width=1000>
	<TR  colspan="3">	
	<td width=137 align=center>&nbsp;</td>
	<td width=352 align=center><FONT  size=2 face=arial 
	height="15">&nbsp;</FONT></td>
	<td width=284 align=right><FONT  size=+1 face=arial 
	height="15" color="#FF0066">Grand Total (Normal+Additional)</FONT></td>		
	<td width=99 align=right><FONT  size=+1 face=arial 
	height="15" color="#FF0066"><? echo(number_format($normalvalue[0]+$addvalue[0],2,'.',''));?></FONT></td>
	<td width=104 align=right><FONT  size=+1 face=arial 
	height="15" color="#FF0066"><? echo(number_format($normalvalue[1]+$addvalue[1],2,'.',''));?></FONT></td>	
	
	</table>

<hr  align="left" width="1000">
<?


function schedule($month,$year,$plan_type)
{
	$linecount=3;
	$totvalue=0;

	$buyresult = mysql_query("select distinct buy.bcode from buy,orders where orders.plan_month='$month' and orders.plan_year='$year' and plan_type='$plan_type' and orders.bcode = buy.bcode order by buy.name") or die(mysql_error());
	while($buyrow = mysql_fetch_row($buyresult))
	{
		$bcode = $buyrow[0];
		if($linecount>=40 or $linecount<=3)
		{
			$linecount = heading();

		}
			
		
		$tprodcode='';
		$result = mysql_query("select distinct prodcode,drawing_no,schedule_no,schedule_date,due_date,order_qty,issued_qty,balance_qty,part_qty1,record,tentative_qty,rate,schedule_qty from orders where plan_month='$month' and plan_year='$year' and bcode = '$bcode' and plan_type='$plan_type' order by prodcode,due_date ") or die(mysql_error());
		while($row=mysql_fetch_row($result))
		{
	
			$prodcode =$row[0];
			$drawing_no=$row[1];
			$schedule_no=$row[2];
			$schedule_date = substr($row[3],8,2).'-'.substr($row[3],5,2).'-'.substr($row[3],0,4);
			$due_date=substr($row[4],8,2).'-'.substr($row[4],5,2).'-'.substr($row[4],0,4);
			$order_qty=$row[5];
			$issued_qty=$row[6];
			$balance_qty=$row[7];
			$part_qty1= $row[8];
			$record=$row[9];
			$tentative_qty=$row[10];
			$rate=$row[11];
			$schedule_qty=$row[12];
			$value=$rate * $schedule_qty;
			$totvalue=$totvalue+$value;
			$iss_value=$rate*$issued_qty;
			$totiss_value=$totiss_value+$iss_value;
			$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];
		
			$subresult = mysql_query("select prodname from product where bcode='$bcode' and prodcode='$prodcode' ") or die(mysql_error());
			$subrow = mysql_fetch_row($subresult);
			$prodname = $subrow[0];
			
			
			$result3 = mysql_query("select sum(balance) from purreg where bcode = '$bcode' and prodcode ='$prodcode' and balance > 0 ") or die(mysql_error());
			$row3 = mysql_fetch_row($result3);
			$stock_qty=$row3[0];
			
			if($bcheck != $bname)
			{
				?>
				<TABLE cellSpacing=0 width="1000"  >
				<TBODY>
				<tr><td>&nbsp;</td></tr>
				<TR>
				<TD align=center width="1000"  height=25><FONT 
				face=arial  size=+2 color="#FF3300"><? echo($bname);?></FONT></TD></TR></TBODY></TABLE>
				<?
				$bcheck = $bname;
				$linecount++;
				if($linecount>=40 or $linecount<=3)
				{
					$linecount = heading();
					
				}			
			}
	  if($tprodcode != $prodcode and $tprodcode != '') 
	  {
	  ?>
      	<tr  ><td  colspan="100%">&nbsp;</td></tr>
	  <?
	  }
	  		$tprodcode=$prodcode;	
	  ?>

			<table width=1000 >
			<TR  colspan="3">	
			<td width=47 align=center   bgcolor="#B0B6F9"><? echo($ind+1);echo(")");?></td>
			<td width=147 align=left bgcolor="#C0D1B1"><FONT  size=2 face=arial 
			height="15"><? echo($prodname );?></FONT></td>
			<td width=90 align=left  bgcolor="#E6F097"><FONT  size=2 face=arial 
			height="15"><? echo($drawing_no );?></FONT></td>
			<td width=73 align=right bgcolor="#7979FF"><FONT  size=2 face=arial 
			height="15"  color="#9100000"><? if($stock_qty>0) echo(number_format($stock_qty,0) );?></FONT></td>
					
			<td width=71 align=right bgcolor="#AECF96"><FONT  size=2 face=arial 
			height="15" ><? echo(number_format($schedule_qty,0) );?></FONT></td>
			<td width=88 align=right bgcolor="#C69AC9"><FONT  size=2 face=arial 
			height="15"><? if($due_date!= '00-00-0000') echo($due_date);?></FONT></td>
			<td width=78 align=right  bgcolor="#FFC993"><FONT  size=2 face=arial 
			height="15"  ><? if($issued_qty>0) echo(number_format($issued_qty,0));?></FONT></td>
			<td width=78 align=right  bgcolor="#9FA7E8"><FONT  size=2 face=arial 
			height="15"><? if($tentative_qty>0) echo(number_format($tentative_qty,0) );?></FONT></td>
			<td width=78 align=right  bgcolor="#B1CDE4"><FONT  size=2 face=arial 
			height="15"><? echo($rate );?></FONT></td>										
			<td width=98 align=right bgcolor="#F7CEC8"><FONT  size=2 face=arial 
			height="15" ><? echo(number_format($value,2,'.','') );?></FONT></td>
			<td width=104 align=right bgcolor="#8A96E6"><FONT  size=2 face=arial 
			height="15" ><? if($iss_value>0) echo(number_format($iss_value,2,'.','') );?></FONT></td>			
			
			</table>
			<?
			$linecount++;
			if($linecount>=40 or $linecount<=3)
			{
				$linecount = heading();


			}				
			if($part_qty1 >0)
			{
				$partresult = mysql_query("select part_qty1,due_date1,part_qty2,due_date2,part_qty3,due_date3,part_qty4,due_date4,part_qty5,due_date5 from orders where record='$record' ") or die(mysql_error());
				$partrow = mysql_fetch_row($partresult);
				$part_qty1=$partrow[0];
				$due_date1=substr($partrow[1],8,2).'-'.substr($partrow[1],5,2).'-'.substr($partrow[1],0,4);
				$part_qty2=$partrow[2];
				$due_date2=substr($partrow[3],8,2).'-'.substr($partrow[3],5,2).'-'.substr($partrow[3],0,4);
				$part_qty3=$partrow[4];
				$due_date3=substr($partrow[5],8,2).'-'.substr($partrow[5],5,2).'-'.substr($partrow[5],0,4);
				$part_qty4=$partrow[6];
				$due_date4=substr($partrow[7],8,2).'-'.substr($partrow[7],5,2).'-'.substr($partrow[7],0,4);
				$part_qty5=$partrow[8];
				$due_date5=substr($partrow[9],8,2).'-'.substr($partrow[9],5,2).'-'.substr($partrow[9],0,4);
				if($part_qty1 >0)
				{
					?>
					<table width=1000>
					<TR  colspan="3">	
					<td width=117 align=center>&nbsp;</td>
					<td width=227 align=center><FONT  size=2 face=arial 
					height="15" color="#9933CC">Part Qty</FONT></td>
					<td width=77 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo(number_format($part_qty1,0) );?></FONT></td>		
					<td width=86 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo($due_date1);?></FONT></td>
					<td width=419 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC">&nbsp;</FONT></td></table>			
					<?
					$linecount++;
					if($linecount>=40 or $linecount<=3)
					{
						$linecount = heading();

					}					
				}
				if($part_qty2 >0)
				{
					?>
					<table width=1000>
					<TR  colspan="3">	
					<td width=117 align=center>&nbsp;</td>
					<td width=227 align=center><FONT  size=2 face=arial 
					height="15" color="#9933CC">Part Qty</FONT></td>
					<td width=77 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo(number_format($part_qty2,0) );?></FONT></td>		
					<td width=86 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo($due_date2);?></FONT></td>
					<td width=419 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC">&nbsp;</FONT></td></table>			
					<?
					$linecount++;
					if($linecount>=40 or $linecount<=3)
					{
						$linecount = heading();
	
					}				
				}
				if($part_qty3 >0)
				{
					?>
					<table width=1000>
					<TR  colspan="3">	
					<td width=117 align=center>&nbsp;</td>
					<td width=227 align=center><FONT  size=2 face=arial 
					height="15" color="#9933CC">Part Qty</FONT></td>
					<td width=77 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo(number_format($part_qty3,0) );?></FONT></td>		
					<td width=86 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo($due_date3);?></FONT></td>
					<td width=419 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC">&nbsp;</FONT></td></table>			
			
					<?
				}	
				if($part_qty4 >0)
				{
					?>
					<table width=1000>
					<TR  colspan="3">	
					<td width=117 align=center>&nbsp;</td>
					<td width=227 align=center><FONT  size=2 face=arial 
					height="15" color="#9933CC">Part Qty</FONT></td>
					<td width=77 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo(number_format($part_qty4,0) );?></FONT></td>		
					<td width=86 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo($due_date4);?></FONT></td>
					<td width=419 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC">&nbsp;</FONT></td></table>			
			
					<?
					$linecount++;
					if($linecount>=40 or $linecount<=3)
					{
						$linecount = heading();

					}				
				}	
				if($part_qty5 >0)
				{
					?>
					<table width=1000>
					<TR  colspan="3">	
					<td width=117 align=center>&nbsp;</td>
					<td width=227 align=center><FONT  size=2 face=arial 
					height="15" color="#9933CC">Part Qty</FONT></td>
					<td width=77 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo(number_format($part_qty5,0) );?></FONT></td>		
					<td width=86 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC"><? echo($due_date5);?></FONT></td>
					<td width=419 align=right><FONT  size=2 face=arial 
					height="15" color="#9933CC">&nbsp;</FONT></td></table>			
			
					<?
					$linecount++;
					if($linecount>=40 or $linecount<=3)
					{
						$linecount = heading();

					}				
				}						
			?>
			</table>
				
			<?
			}
			$ind++;
		}
	}
	?>
	<table width=1000>
	<TR  colspan="3">	
	<td width=132 align=center>&nbsp;</td>
	<td width=399 align=center><FONT  size=2 face=arial 
	height="15">&nbsp;</FONT></td>
	<td width=241 align=right><FONT  size=+1 face=arial 
	height="15"  color="#000099">Total Value</FONT></td>		
	<td width=105 align=right><FONT  size=+1 face=arial 
	height="15" color="#000099"><? echo(number_format($totvalue,2,'.',''));?></FONT></td>
	<td width=99 align=right><FONT  size=+1 face=arial 
	height="15" color="#000099"><? echo(number_format($totiss_value,2,'.',''));?></FONT></td>	
	</table>	
	<?
	$temp[0]=$totvalue;
	$temp[1]=$totiss_value;
	return($temp);

}	
?>

<br><br><font size=1><center><a href="../../index.html">Return to Index page</a></center></font>
<?
function heading()
{
		?>
		<hr  align="left" width="1000">	
		<table width=1000>
		<TR  colspan="3">	
		<td width=50 align=center  bgcolor="#B0B6F9"><FONT  size=2 face=arial 
		height="15">Sl.No</td>
		<td width=144 align=left  bgcolor="#C0D1B1"><FONT  size=2 face=arial 
		height="15" color="#FF6600" >Party's Name & Product</FONT></td>
		<td width=88 align=left  bgcolor="#E6F097"><FONT  size=2 face=arial 
		height="15">Drawing No</FONT></td>
		<td width=78 align=right bgcolor="#7979FF"><FONT  size=2 face=arial 
		height="15" color="#9100000">Stock</FONT></td>				
		<td width=63 align=right bgcolor="#AECF96"><FONT  size=2 face=arial 
		height="15" color="#CC0099">Order Qty</FONT></td>
		
		<td width=91 align=right bgcolor="#C69AC9"><FONT  size=2 face=arial 
		height="15">Delivery Dates</FONT></td>
		<td width=80 align=right   bgcolor="#FFC993"><FONT  size=2 face=arial 
		height="15"  color="#6600CC" >Issued Qty</FONT></td>		
		<td width=80 align=right  bgcolor="#9FA7E8"><FONT  size=2 face=arial 
		height="15">Tentative Qty</FONT></td>
		<td width=75 align=right bgcolor="#B1CDE4"><FONT  size=2 face=arial 
		height="15" color="#006600">Rate</FONT></td>										
		<td width=100 align=right bgcolor="#F7CEC8"><FONT  size=2 face=arial 
		height="15" color="#FF00CC">Order Value</FONT></td>										
		<td width=103 align=right bgcolor="#8A96E6"><FONT  size=2 face=arial 
		height="15" color="#6600CC">Issued Value</FONT></td></tr>										
		
		</table>
		<hr  align="left" width="1000">
		<?
		$linecount=4;
		return $linecount;
}
