<?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);?>&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"><font size="-1">Date</font></td>
    <td width="67" align="right"><font size="-1">Inv. No</font></td>
    <td width="307" align="left"><font size="-1">Customer Name </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="87" align="right"><font size="-1">Others</font></td>
    <td width="63" align="right"><font size="-1">Round Off</font></td>    
    <td width="98" align="right"><font size="-1">Total Amount</font></td>
<td width="90" align="right"><font size="-1">Tin</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;
$st = 'T';
$dayvalue = 0;
$daytax = 0;
$daycess = 0;
$daytotal =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'  and invoice_type='$invoice_type' and prodcode = 'TOTAL' order by inv_date,inv_no,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];

		if($st =='T')
		{
			$tempdt = $invrow[2];
			$st ='F';
		}

		$presult = mysqli_query($conn,"select sum(vat_amount),sum(value-discount_amt) from salesreg where inv_date ='$invrow[2]' and compcode='$compcode' and inv_no = '$invrow[0]'  order by record ")or die(mysqli_error());
		$prow = mysqli_fetch_row($presult);
		$value = $prow[1];
		$taxamt=$prow[0];

		$presult = mysqli_query($conn,"select packing,round_off,total from salesreg where inv_date ='$invrow[2]' and compcode='$compcode' and inv_no = '$invrow[0]'  and prodcode = 'TOTAL' order by record ")or die(mysqli_error());
		$prow = mysqli_fetch_row($presult);
		$packing=$prow[0];
		$round_off = $prow[1];
		$gtot = $prow[2];
		
		$gvalue=$gvalue+$value;
		$gtaxamt=$gtaxamt+$taxamt;
		$gnet = $gnet+$gtot;
		$ground=$ground +$round_off;
		$gpack = $gpack + $packing;
		
		$dayvalue = $dayvalue + $value;
		$daytax = $daytax + $taxamt;
		$daypacking = $daypacking + $packing;
		$dayround = $dayround + $round_off;
		$daynet = $daynet + $net;
	
		$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 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];
	

        
        
		if($tempdt != $invrow[2])
		{

	
			?>
			<tr bgcolor="#D5D3E7">
					<td  align="right"><font size="-1" >Day Total</font></td>
					<td>&nbsp;</td><td>&nbsp;</td>
			<td  align="right"><font size="-1" ><? if($dayvalue>0)  echo(number_format($dayvalue,2,'.',''));?></font></td>
			<td align="right"><font size="-1" ><? if($daytax>0)  echo(number_format($daytax,2,'.',''));?></font></td>
			<td   align="right"><font size="-1" ><? if($daypacking>0)  echo(number_format($daypacking,2,'.',''));?></font></td>								
			<td width="90" align="right"><font size="-1" ><? if($dayround)  echo(number_format($dayround,2,'.',''));?></font></td>
			<td width="90" align="right"><font size="-1" ><? if($daynet)  echo(number_format($daynet,2,'.',''));?></font></td>
							<td>&nbsp;</td>
			</tr>	
			<?

			$tempdt = $invrow[2];
			$dayvalue = 0;
			$daytax =0;
			$daypacking = 0;
			$dayround = 0;
			$daynet = 0;
		}	
		?>
        
        
        <tr> 
        <td width="79" align="left"><font size="-1"> 
        <?  echo($inv_date);?>
        </font></td>
        <td width="67" align="center"><font size="-1"> 
        <?  echo($inv_no);?>
        </font></td>
        <td width="307" align="left"><font size="-1"> 
        <?  echo($bname);?>
        </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="63" align="right"><font size="-1"  >
        <? if($packing>0)  echo($packing);?>
        </font></td>
		        
        <td width="63" align="right"><font size="-1"  >
        <? if($round_off>0)  echo($round_off);?>
        </font></td>
        <td width="98" align="right"><font size="-1"  > 
        <? if( $gtot>0)  echo(number_format($gtot,2,'.','')); ?>
        </font></td>      
        
        <td width="90" align="right"><font size="-1"  > 
        <?=$tin?>
        </font></td>	  
        </tr>

	
<?
		
}										

			?>
			<tr bgcolor="#D5D3E7">
					<td  align="right"><font size="-1" >Day Total</font></td>
					<td>&nbsp;</td><td>&nbsp;</td>
			<td  align="right"><font size="-1" ><? if($dayvalue>0)  echo(number_format($dayvalue,2,'.',''));?></font></td>
			<td align="right"><font size="-1" ><? if($daytax>0)  echo(number_format($daytax,2,'.',''));?></font></td>
			<td   align="right"><font size="-1" ><? if($daypacking>0)  echo(number_format($daypacking,2,'.',''));?></font></td>								
			<td width="90" align="right"><font size="-1" ><? if($dayround)  echo(number_format($dayround,2,'.',''));?></font></td>
			<td width="90" align="right"><font size="-1" ><? if($daynet)  echo(number_format($daynet,2,'.',''));?></font></td>
							<td>&nbsp;</td>
			</tr>	
			

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

<tr>

<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
<td align="right"><font size="-1" ><? 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   align="right"><font size="-1" ><? if($gpack>0)  echo(number_format($gpack,2,'.',''));?></font></td>

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

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


</table>


</body>
</form>

<?

