<?php include("../../include/dbconnect.php"); 
$result = mysqli_fetch_array(mysqli_query($conn,"select name from company  ")) or die(mysqli_error());
$startdt = us($stdt);
?>

<table width=658  border=1 rules="all">
<tr><td height="26" colspan="100%" align ="center"><h4><font face="Arial, Helvetica, sans-serif"><?=$result['name']?></font></h4></td></tr>
<tr><td align ="center" colspan="100%"><h4><font face="Arial, Helvetica, sans-serif">Closing Stock as on &nbsp;<?=british($startdt)?></font></h4></td></tr>

<tr>
<td width="46"><font face="Arial, Helvetica, sans-serif">Sl No</font></td>
<td width="418"><font face="Arial, Helvetica, sans-serif">Product</font></td>
<td width="83"  align="right"><font face="Arial, Helvetica, sans-serif">Closing Stock</font></td>
<td width="83"  align="right"><font face="Arial, Helvetica, sans-serif">Minimum Stock</font></td>
<td width="83"  align="right"><font face="Arial, Helvetica, sans-serif">Rate</font></td>
<td width="83"  align="right"><font face="Arial, Helvetica, sans-serif">Value</font></td>
</tr>


<?
$temp=' ';
$totvalue=0;
$subtot=0;
$qtytot=0;

	$sl=1;
$grtotal = 0;
$qtyonhand = $prow[0];
for($ind=0;$ind<count($prodcode1);$ind++)
{
	$category=$crow[0];

	
	$subtotal = 0;
	$mresult = mysqli_query($conn,"select distinct prodcode,prodname,minimum_qty,rate from product where prodcode = '$prodcode1[$ind]'") or die(mysqli_error());
	while($mrow = mysqli_fetch_row($mresult))
	{
	

		$prodname=$mrow[1];
		$minimum_qty=$mrow[2];
		
		if($ratetype == 'Sales')
		{
			$rate = $mrow[3];
		}
		if($ratetype =='actual')
		{
			$rate = $mrow[3] - $mrow[3]*$percent/100;
		}
		if($ratetype == 'Purchase')
		{
			$qresult = mysqli_query($conn,"select max(rate) from purchasereg where  prodcode = '$mrow[0]' and compcode = '$compcode' && poinv_date <= '$startdt'   order by poinv_date,batch_no") or die(mysqli_error());
			$qrow = mysqli_fetch_row($qresult);		
			$rate = $qrow[0];
		}

		$qresult = mysqli_query($conn,"select sum(inqty) - sum(outqty) from stktrans where  acctcode = '$mrow[0]'  and date <= '$startdt' ") or die(mysqli_error());
		$qrow = mysqli_fetch_row($qresult);
		$qty = $qrow[0];
		$amount = $rate * $qty;
		$subtotal = $subtotal + $amount;
		$grtotal = $grtotal + $amount;
		
		if($qrow[0] != 0 )
		{
		
			if($qrow[0] < $minimum_qty)
			{
				echo("<tr bgcolor=\"#FFCECE\">");
			}
			else
			{
				echo("<tr bgcolor=\"#C184FF\">");		
			}
			?>
	
			<td width="46"><font face="Arial, Helvetica, sans-serif"><? echo($sl);?>  </font></td>		
			<td width="418"><font face="Arial, Helvetica, sans-serif"><? echo($prodname);?>  </font></td>
			<td width="83" align="right"><font face="Arial, Helvetica, sans-serif"><? echo($qrow[0]);?></font></td>
			<td width="83" align="right"><font face="Arial, Helvetica, sans-serif"><? echo($minimum_qty);?></font></td>
						<td width="83" align="right"><font face="Arial, Helvetica, sans-serif"><? echo(number_format($rate,2));?></font></td>
									<td width="83" align="right"><font face="Arial, Helvetica, sans-serif"><? echo(number_format($amount,2));?></font></td>
			</tr>
	
			<?  
			$sl++;
		}
	}

}
?>

		<tr>
	<td height="50"  colspan="5"><font size="+1" color="#CC0000">Total Stock Value </font></td>
	<td align="right" ><font size="+1" color="#CC0000"><?=number_format($grtotal,2)?> </font></td>
	</tr>


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




