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

$result=mysqli_query($conn," select name from company where  compcode='$compcode' order by name") or die(mysqli_error());
$row=mysqli_fetch_row($result);
$company=$row[0];


$todate = $stdt;
$temp = $stdt;
$startdt = substr($temp,6,4).substr($temp,3,2).substr($temp,0,2);

$temp=$edt;
$enddt = substr($temp,6,4).substr($temp,3,2).substr($temp,0,2);

?>

  <table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0>
			<tr>
			<td width="499" align="left"><h3><u><font color="#0000FF"><? echo($company);?> </td>
</tr>
			<tr>
			<td width="499" align="left"><font>&nbsp;</font>Sales Value (Van Sales) from &nbsp;<? echo($stdt);?> to  &nbsp;<? echo($edt);?></td>
			<td width="292" align="right"><font> <? echo($value);?></td></tr>
			<tr>

</table>

  <table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0>

			
			<td width="271" align="center">Product</td>
			<td width="106" align="right">Schedule</td>
			
			<td width="136" align="right">Tax Rate</td>			
			<td width="119" align="right">Tax Amount</td>
			<td width="129" align="right">Total Amount</td></tr>
			
			
			</table>

<hr width="100%">
<?
	

$x=0;
$presult = mysqli_query($conn,"select distinct prodcode,tax_rate from salesreg where date >='$startdt' and date <='$enddt' and compcode='$compcode' order by prodcode,tax_rate ")or die(mysqli_error());
while($row=mysqli_fetch_row($presult))
{
	$prodcode[$x]=$row[0];
	$tax_rate[$x]=$row[1];
	$x++;
}

$tottax=0;
$totamt=0;




for($ind=0;$ind< count($prodcode);$ind++)
{

	$prresult = mysqli_query($conn,"select prodname from product where prodcode ='$prodcode[$ind]' ") or die(mysqli_error());
	$prr = mysqli_fetch_row($prresult);
	$prodname = $prr[0];

	$temp=' ';
	$presult = mysqli_query($conn,"select sum(value),sum(taxamt),sum(tax_rate) from salesreg where date >='$startdt' and date <='$enddt' and compcode='$compcode' and prodcode='$prodcode[$ind]' and tax_rate = '$tax_rate[$ind]' order by inv_no,date,record ")or die(mysqli_error());
	$row=mysqli_fetch_row($presult);
	$value=$row[0];
	$taxamt=$row[1];
	$total =$value+$taxamt;




$tottax=$tottax+$taxamt;
$totamt=$totamt+$total;

?>

 
  <table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0>

			
			<td width="268" align="left"><font  color="#CC0000"><? echo($prodname);?></font></td>
			<td width="126" align="left"><font  color="#CC0000" > <? echo($schedule);?></font></td>			
			<td width="130" align="right"><font  color="#CC0000"><? echo($tax_rate[$ind]);?>&nbsp;%</font></td>			
			<td width="106" align="right"><font  color="#CC0000" > <? echo($taxamt);?></font></td>
			<td width="148" align="right"><font  color="#CC0000" > <? echo(number_format($value+$taxamt,2,'.',''));?></font></td></tr>
			
			
			</table>			 



<?
}
?>
<hr width="100%">
   <table width="780" border=0 cellpadding=0 cellspacing=0 class=MsoTableGrid>

			
			<td width="526" align="center"><font  color="#CC0000">Total</font></td>
				
			
			<td width="104" align="right"><font  color="#CC0000" > <? echo(number_format($tottax,2,'.',''));?></font></td>
			<td width="150" align="right"><font  color="#CC0000" > <? echo(number_format($totamt,2,'.',''));?></font></td></tr>
			
			
			</table>			 

    <br>
    <br><font size=0><center><a href= "../../index.php">Return to index page</center></font>
</body>
</form>



