<?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"></div><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);?></td></tr></table>

				
<table width="995" border="0">
  <tr> 
<td  colspan="100%"><hr width="100%"></td>
  </tr>
  <tr> 

    <td width="67" align="right"><font size="-1">Inv. No</font></td>
    <td width="79" height="20" align="left"><font size="-1">Date</font></td>
	<td width="90" align="right"><font size="-1">Tin</font></td>			
    <td width="307" align="left"><font size="-1">Customer  Name </font></td>
    <td width="307" align="left"><font size="-1">Customer  Address </font></td>	
    <td width="86" align="right"><font size="-1">Amount</font></td>
    <td width="87" align="right"><font size="-1">VAT AMT</font></td>
 
    <td width="98" align="right"><font size="-1">Total Amount</font></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);

$temp=' ';
$temptot=0;

$result = mysqli_query($conn,"select tax,cess from salestax  where taxtype = '$Tax' ");
$row=mysqli_fetch_row($result);
$tax_rate = $row[0];


$invresult= mysqli_query($conn,"select distinct inv_no,bcode,inv_date from salesreg  where inv_date >='$startdt' and inv_date <='$enddt'  and compcode='$compcode'   order by inv_no,inv_date,record ")or die(mysqli_error());
while($invrow = mysqli_fetch_row($invresult))
{

		$bcode = $invrow[1];

		$inv_date = substr($invrow[2],8,2).'-'.substr($invrow[2],5,2).'-'.substr($invrow[2],0,4);
		$inv_no= $invrow[0];
		
		$presult = mysqli_query($conn,"select sum(value),sum(vat_amount) from salesreg where inv_date >='$startdt' and inv_date <='$enddt'  and compcode='$compcode' and inv_no = '$invrow[0]'  order by record ")or die(mysqli_error());
		$prow = mysqli_fetch_row($presult);
		
		
		$value=$prow[0];
		$taxamt=$prow[1];
		
		
		$gtot = $value + $taxamt;

		
		$gvalue=$gvalue+$value;
		$gtaxamt=$gtaxamt+$taxamt;
		$net = $net+$gtot;
		
	
		$bslct= mysqli_query($conn,"select name,tin from buy where bcode = '$bcode' ") or die(mysqli_error());
		$brow=mysqli_fetch_row($bslct);
		$bname = $brow[0];
		$tin = $brow[1];
	
		$bslct= mysqli_query($conn,"select name,address1,address2,city from bill_patient where inv_no= '$inv_no' and inv_date = '$invrow[2]'  ") or die(mysqli_error());
		$brow=mysqli_fetch_row($bslct);
		$bname = $brow[0];
		$badd = $brow[1].','.$brow[2].','.$brow[3];
	

		?>
  <tr> 

    <td width="67" align="center"><font size="-1"> 
      <?  echo($inv_no);?>
      </font></td>
    <td width="79" align="left"><font size="-1"> 
      <?  echo($inv_date);?>
      </font></td>	  
      
    <td width="90" align="right"><font size="-1"  > 
      <?=$tin?>
      </font></td>	  	  
    <td width="307" align="left"><font size="-1"> 
      <?  echo($bname);?>
      </font></td>
    <td width="307" align="left"><font size="-1"> 
      <?  echo($badd);?>
      </font></td>	  
    <td width="86" align="right"><font size="-1"> 
      <? if($value>0)  echo(number_format($value,2,'.',''));?>
      </font></td>
    <td width="87" align="right"><font size="-1"  >
      <? if($taxamt>0)  echo($taxamt);?>
      </font></td>


    <td width="98" align="right"><font size="-1"  > 
      <? if( $gtot>0)  echo(number_format($gtot,2,'.','')); ?>
      </font></td>      

  </tr>
  <?  



}										
?>

 
  <tr> 
<td  colspan="100%"><hr width="100%"></td>
  </tr>
 

<tr>

<td>&nbsp;</td>
<td colspan="4" align="right"><font size="-1" ></font></td>
<td   align="right"><font size="-1" >&nbsp;<? if($gvalue>0)  echo(number_format($gvalue,2,'.',''));?></font></td>	
<td  align="right"><font size="-1" ><? if($gtaxamt>0)  echo(number_format($gtaxamt,2,'.',''));?></font></td>
							
<td width="90" align="right"><font size="-1" ><? if($net>0)  echo(number_format($net,2,'.',''));?></font></td>				

</tr>
</table>			 
<?
					
?>


</table>


</body>
</form>

<?

