<?php include("../../include/dbconnect.php"); 
$f_date = substr($from_date,6,4).'-'.substr($from_date,3,2).'-'.substr($from_date,0,2);
$t_date = substr($to_date,6,4).'-'.substr($to_date,3,2).'-'.substr($to_date,0,2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Item Wise Statement</title>
	<link type="text/css" href="Style.css" rel="stylesheet" />
	<script type="text/javascript" src="Script.js"></script>

</head>
<body>
	<h1>Item wise Statement</h1>

<?
$result=mysql_query(" select name from company where  compcode='$compcode' order by name") or die(mysql_error());
$row=mysql_fetch_row($result);
$company=$row[0];

?>
	
	<table class="scrollTable" id="scrollTable" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td>
				<div class="corner">
					<table cellpadding="0" cellspacing="0" border="0">
						<tr>
							<th><div>&nbsp;</div></th>
						</tr>
					</table>
				</div>
			</td>
			<td>
				<div class="headerRow">
					<table cellpadding="0" cellspacing="0" border="0">
						<tr>
							<th width="82"><div>Sl No</div></th>
							<th width="81"><div align="center">Inv. No</div></th>
							<th width="74"><div align="center">Date</div></th>
							<th width="93"><div align="center">Drawing No</div></th>
							<th width="84"><div align="center">Order No</div></th>
							<th width="110"><div align="center">Order Date</div></th>
							<th width="108"><div align="center">Quantity</div></th>
							<th width="106"><div align="center">Total Qty</div></th>

						</tr>
					</table>
				</div>
			</td>
		</tr>
		<tr>
			<td valign="top">
				<div class="headerColumn">
					<table cellpadding="0" cellspacing="0" border="0">
						<tr><th><div>&nbsp;</div></th></tr>


					</table>
				</div>
			</td>
			<td>
				<div class="body">
					<table cellpadding="0" cellspacing="0" border="0">			
<?
for($ind=0;$ind < count($bcode);$ind++)
{
		$sl=1;
	
	$bresult = mysql_query("select name,unit from buy where bcode = '$bcode[$ind]' ") or die(mysql_error());
	$brow = mysql_fetch_row($bresult);
	$bname = $brow[0].'&nbsp;&nbsp;'.$brow[1];
	$bstatus ='F';
	$totstatus ='F';
	$dresult = mysql_query("select distinct drawing_no  from salesreg where invdate >='$f_date' and invdate <='$t_date'  and compcode='$compcode' and bcode ='$bcode[$ind]'  and drawing_no != 'TOTAL' and drawing_no != 'CANCELLED' order by bcode,drawing_no ")or die(mysql_error());
	while($drow = mysql_fetch_row($dresult))
	{

				$drawing_total=0;
				$presult = mysql_query("select invdate,invno,prodcode,drawing_no,quantity,po_no,po_date  from salesreg where invdate >='$f_date' and invdate <='$t_date'  and compcode='$compcode' and bcode ='$bcode[$ind]' and drawing_no = '$drow[0]' order by bcode,drawing_no,invno,record ")or die(mysql_error());
				while($prow = mysql_fetch_row($presult))
				{
					
			
					$date = substr($prow[0],8,2).'-'.substr($prow[0],5,2).'-'.substr($prow[0],0,4);
					$invno= $prow[1];		
					$prodcode= $prow[2];		
					$drawing_no= $prow[3];
					$qty = $prow[4];
					$po_no=$prow[5];
					$po_date=substr($prow[6],8,2).'-'.substr($prow[6],5,2).'-'.substr($prow[6],0,4);
					$drawing_total = $drawing_total+$qty;
				/*	if($bstatus == 'F')
					{
						?>
						
						<tr bgcolor="#FAF8B4"><td colspan="20"><? echo($bname);?></td></tr>
						<?
						$bstatus='T';		
					}
					*/
				  ?>		
					
					<tr bgcolor="#D3E4D1">
			
					<td width="102" align="center"><font size="-1" color="<? echo($clr);?>"><? echo($sl);?></font></td>															
					<td width="100" align="center"><font size="-1" color="<? echo($clr);?>"><? echo($invno);?></font></td>
					<td width="95" align="left"><font size="-1" color="<? echo($clr);?>" ><?  echo($date);?></font></td>		
					<td width="113" align="left"><font size="-1" color="<? echo($clr);?>"><? echo($drawing_no);?> </font></td>				
					<td width="104" align="left"><font size="-1" color="<? echo($clr);?>"><?  echo($po_no);?> </font></td>															
					<td width="130" align="left"><font size="-1" color="<? echo($clr);?>"><? echo($po_date);?> </font></td>
					<td width="127" align="right"><font size="-1" color="<? echo($clr);?>"><?  echo(round($qty,0));?></font></td>				
			
					<?		
					$sl++;
				}
				?>
				<td width="127" align="right"><font size="-1" color="<? echo($clr);?>"> <? echo($drawing_total);?></font></td>
				</tr>	  
				<tr  ><td  colspan="100%">&nbsp;</td></tr>
				
				<?
		}

}	



?>
			
				</table>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>
<script language="javascript">
	paddingLeft = 10;
	paddingRight = 10;
	paddingTop = 1;
	paddingBottom = 1;
	
	ScrollTableRelativeSize(
		document.getElementById("scrollTable"), 
		50, 
		120);
		
	/*ScrollTableAbsoluteSize(
		document.getElementById("scrollTable"), 
		500, 
		550);*/
</script>
