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

<table width=600  border=0>
<tr><td align ="center"><h5>Stock as on &nbsp;<?echo(date(d).'-'.date(m).'-'.date(Y));?></td></tr></table>
<hr align="left" width = 600></hr>
<table width="600" border="0">
  <tr>
    <td width="500">Product</td>
    <td width="100"  align="right">Stock</td>

  </tr>
</table>
<hr align="left" width = 600 ></hr>

<?
$temp=' ';
$totvalue=0;
	$subtot=0;
$result = mysql_query("select distinct bcode,prodcode,prodname from product  order by bcode,prodcode,prodname");
while($row=mysql_fetch_row($result))
{
	$bcode=$row[0];
    $prodcode = $row[1];
	$prodname=$row[2];


	$presult = mysql_query("select balance from purreg where  prodcode = '$prodcode' and bcode ='$bcode' and balance >0   ");
	while($prow = mysql_fetch_row($presult))
	{
		$qtyonhand = $prow[0];

	
	
		if($qtyonhand>0)
		{
			$qtyonhand = $prow[0];
			if($temp != $bcode)
			{
				if($subtot>0)
				{
					?>
					
					<table><tr>
					<td width="492" align="center"><font size="+1" color="#CC0000"> <? echo($bname);?>&nbsp;Total</font></td><td width="98" align="right"><font size="+1" color="#CC0000"><b><? echo(number_format($subtot,2,'.',''));?></b></font></td></tr>
					</table>		
					<?
					$subtot=0;				
				}
			
				$cresult = mysql_query("select name,unit from buy where  bcode = '$bcode' ");
				$crow = mysql_fetch_row($cresult);
				$bname=$crow[0].'&nbsp;&nbsp;'.$crow[1];
				?>
				<table width="600" border="0">
				<tr>
				<td width="500"><font size="+1" color="#CC0000"><? echo($bname);?> </font></td>

				</tr>
				</table>
					
				<?
				$temp=$bcode;			
			}

		
			?>   
			<table width="600" border="0">
			<tr>
			<td width="500"><? echo($prodname);?> &nbsp; <? echo($name);?> </td>
			<td width="100" align="right"><? echo($qtyonhand);?></td>
			</tr>
			</table>			
			 <?  
			// $totvalue=$totvalue+($qtyonhand*$rate);
			// $subtot=$subtot+($qtyonhand*$rate);
		}	
	}

}

if($subtot>0)
{
	?>
	
	<table><tr>
	<td width="492" align="center"><font size="+1" color="#CC0000"><? echo($bname);?> Total</font></td><td width="98" align="right"><font size="+1" color="#CC0000"><b><? echo(number_format($subtot,2,'.',''));?></b></font></td></tr>
	</table>		
	<?
	$subtot=0;				
}
?>
 <hr align = "left" width = 600></hr>


</table>
    <br>
    <br><font size=1><center><a href= "../../index.html">Return to index page</center></font>
</body>
</form>



