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

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

?>
<title>Area wise outstanding</title>
<form>
<body bgcolor="#ffffff"  topmargin=0>
<font face="Arial, Helvetica, sans-serif">
<?

$startdt = us($stdt);
$enddt = us($edt);
?>
</font>
<TABLE  width="453" BORDER=1 CELLPADDING=4 RULES=COLS  >

<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>
<COLGROUP></COLGROUP>

				
<thead>
<tr>
<td height="34" colspan="100%" ALIGN ="left"><h4><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><?echo($compname);?></font></h4></td></tr>
<tr>
      <td colspan="100%"><font face="Arial, Helvetica, sans-serif">Sales Summary From <? echo($stdt);?> To <?echo($edt);?></font></td>
    </tr>
<tr bgcolor="#DAF1A9">

<td width="129" align=center><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Particulars</font></td>


<td width="138" align=center><div align="right"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Sold Items </font></div></td>
<td width="146" align=center><div align="right"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">Stock available</font></div></td>

</tr>
<tr>
<td><hr></td>


<td><hr></td>
<td><hr></td>

</tr>

</thead>
<tbody>
<?
mysqli_query($conn,"truncate tpurch1");
$result = mysqli_query($conn,"select distinct prodcode from salesreg8b where inv_date >='$startdt' and inv_date <= '$enddt' and prodcode != 'TOTAL' ") or die(mysqli_error());
while($row = mysqli_fetch_row($result))
{
	$sresult = mysqli_query($conn,"select sum(quantity) from salesreg8b where prodcode = '$row[0]' and inv_date >='$startdt' and inv_date <= '$enddt' ") or die(mysqli_error());
	$sold = mysqli_fetch_row($sresult);
	
	$stresult = mysqli_query($conn,"select sum(inqty)-sum(outqty) from stktrans where acctcode = '$row[0]' ") or die(mysqli_error());
	$stock = mysqli_fetch_row($stresult);
	
	mysqli_query($conn,"insert into tpurch1(accthead,qty,rate) values('$row[0]','$sold[0]','$stock[0]')") or die(mysqli_error());
}
if($reporttype =='Sales')
{
	$sresult = mysqli_query($conn,"select accthead,qty,rate from tpurch1 order by qty desc ") or die(mysqli_error());
}
elseif($reporttype =='Stock' )
{
	$sresult = mysqli_query($conn,"select accthead,qty,rate from tpurch1 order by rate desc ") or die(mysqli_error());
}

while($srow = mysqli_fetch_row($sresult))
{

	$presult = mysqli_query($conn,"select prodname from product where prodcode = '$srow[0]' ") or die(mysqli_error());
	$prow = mysqli_fetch_row($presult);
	
				?>
				
				<tr>
				<td align=left><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><?echo($prow[0]);?></font></td>
				
				<td align=right><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">
				<? if($srow[1]!=0) echo $srow[1];?> 
				</font></td>
				<td align=right><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif">
				<? if($srow[2]!=0) echo $srow[2];?>
				</font></td></tr>
<?                
                
  }
  ?>
				</tbody>
		
</table>

<?
mysqli_query($conn,"truncate tpurch1");
?>


