<?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];


	

?>

<table width=999  border=0>
 <thead>
<tr> 
<td colspan="100%"  align="center"><div align="center"><font size="+2" face="Arial, Helvetica, sans-serif"> <?=$company?></font></td>  </tr>
<tr><td width="993" align ="center"><h5>Sales Register from &nbsp;<? echo($stdt);?> to  &nbsp;<? echo($edt);?>&nbsp;&nbsp;(<?=$invoice_type?>&nbsp;Sales)</td></tr></table>

				
<table width="995" border="0">
  <tr> 
<td  colspan="100%"><hr width="100%"></td>
  </tr>
  <tr> 
    <td width="79" height="20" align="left">Date</td>
    <td width="67" align="right">Inv. No</td>

    <td width="86" align="right">Gross</td>
    <td width="87" align="right">VAT AMT</td>
    <td width="63" align="right">CESS AMT</td>    
    <td width="98" align="right">Total Amount</td>
  </tr>
  <tr> 
<td  colspan="100%"><hr width="100%"></td>
  </tr>
   </thead>
  <?

	$gvalue=0;
	$gtaxamt=0;
	$ge1taxamt=0;
	$ground_off=0;
	$gtot=0;
	$net =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);

$invresult= mysqli_query($conn,"select distinct inv_date from salesreg  where inv_date >='$startdt' and inv_date <='$enddt'  and compcode='$compcode'  and taxtype='$invoice_type' and prodcode = 'TOTAL' order by inv_date,inv_no,record ")or die(mysqli_error());

while($invrow = mysqli_fetch_row($invresult))
{
		$minres = mysqli_query($conn,"select min(inv_no) from salesreg where inv_date = '$invrow[0]' and  taxtype='$invoice_type' ");
		$minrow = mysqli_fetch_row($minres);
		$inv = $minrow[0];

		$minres = mysqli_query($conn,"select max(inv_no) from salesreg where inv_date = '$invrow[0]'  and taxtype='$invoice_type'");
		$minrow = mysqli_fetch_row($minres);
		$inv = $inv.'-'.$minrow[0];

		$presult = mysqli_query($conn,"select sum(vat_amount),sum(total),sum(vatcess_amt),sum(value) from salesreg where inv_date ='$invrow[0]' and compcode='$compcode' and   taxtype = '$invoice_type'  order by inv_date ")or die(mysqli_error());
		$prow = mysqli_fetch_row($presult);
		$taxamt=$prow[0];
		$gtot = $prow[1];
		$cessamt = $prow[2];
		$value = $gtot -$taxamt - $cessamt;
		
		$gvalue=$gvalue+$value;
		$gtaxamt=$gtaxamt+$taxamt;
		$gcessamt = $gcessamt + $cessamt;
		$net = $net+$gtot;
		$ground_off=$ground_off+$round_off;
		?>
        <tr> 
        <td width="79" align="left"><?  echo(british($invrow[0]));?>
        </td>
        <td width="67" align="center"><?  echo($inv);?>
        </td>
        <td width="86" align="right"><? if($value>0)  echo(number_format($value,2,'.',''));?>
        </td>
        <td width="87" align="right"><? if($taxamt>0)  echo($taxamt);?>
        </td>
        <td width="63" align="right"><? if($cessamt>0)  echo($cessamt);?>
        </td>
        <td width="98" align="right"><? if( $gtot>0)  echo(number_format($gtot,2,'.','')); ?>
        </td>      
        </tr>
<?
		
}										
?>
<td  colspan="100%"><hr width="100%"></td>
  </tr>
 

<tr>


<td colspan="3" align="right"><? if($gvalue>0)  echo(number_format($gvalue,2,'.',''));?></td>

<td   align="right"><? if($gtaxamt>0)  echo(number_format($gtaxamt,2,'.',''));?>
</td>
<td   align="right"><? if($gcessamt>0)  echo(number_format($gcessamt,2,'.',''));?>
</td>								
<td width="90" align="right"><? if($net>0)  echo(number_format($net,2,'.',''));?>
</td>				
</tr>
</table>			 

</table>


</body>
</form>


