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

$pgno=1;
$kount=1;

$result=mysqli_query($conn," select name,gstin from company where  compcode='$compcode' order by name") or die(mysqli_error());
$row=mysqli_fetch_row($result);
$company=$row[0];
$statecode = substr($row[1],0,2);
$sresult = mysqli_query($conn,"select state_name from states where state_code = '$statecode' ") or die(mysqli_error());
$srow = mysqli_fetch_row($sresult);
$st = $srow[0];
$string1='B2C (Small) from '. $stdt. ' to  ' .$edt;



$kount=$kount+6;	

?>

<table width=1241  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  colspan="100%" align ="center"><h5>HSN Summary  from &nbsp;<? echo($stdt);?> to  &nbsp;<? echo($edt);?></td></tr>
<tr><td colspan="100%"><hr/></td></tr>

				<tr>
				
                				<td width="54" align="left"><div align="center"><font size="-1">HSN</font></div></td>
		<td width="191" align="right"><div align="center"><font size="-1">Description</font></div></td>      
                    	
				<td width="181" align="right"><div align="center"><font size="-1">UOM</font></div></td> 
				<td width="147" align="right"><div align="right"><font size="-1">Total Qty</font></div></td>  
				<td width="131" align="right"><div align="right"><font size="-1">Total Value</font></div></td>    
				<td width="131" align="right"><div align="right"><font size="-1">Taxable Value</font></div></td>                                               
				<td width="123" align="right"><div align="right"><font size="-1">IGST</font></div></td>

				<td width="125" align="right"><div align="right"><font size="-1">CGST</font></div></td>   


				<td width="125" align="right"><div align="right"><font size="-1">SGST</font></div></td>   

				<td width="126" align="right"><div align="right"><font size="-1">CESS</font></div></td>                               								
				</tr>
			 <tr><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td></tr>

 </thead>

<?



	$gvalue=0;
	$sgst_tot=0;
	$cgst_tot=0;
	$igst_tot=0;
	$ge1vat_amount=0;
	$ground_off=0;
	$gtot=0;
	$net =0;
	$disc_total = 0;
	
$todate = $stdt;
$temp = $stdt;
$startdt = us($temp);

$temp=$edt;
$enddt = us($temp);

$temp=' ';
$temptot=0;


	$presult = mysqli_query($conn,"SELECT 
  s.schedule,
  p.prodname,
  p.packing,
  SUM(s.quantity) AS total_quantity,
  SUM(s.value - s.discount_amt + s.vat_amount) AS total_taxed_value,
  SUM(s.value - s.discount_amt) AS total_value,
  CASE
    WHEN (b.taxtype = 'STATE' OR (s.bcode = '0' AND b.taxtype IS NULL)) THEN SUM(s.vat_amount / 2)
    WHEN b.taxtype = 'INTERSTATE' THEN SUM(s.vat_amount)
  END AS sgst_igst
FROM salesreg8b AS s
LEFT JOIN buy AS b ON s.bcode = b.bcode
LEFT JOIN product AS p ON s.prodcode = p.prodcode
WHERE s.inv_date BETWEEN '$startdt' AND '$enddt'
GROUP BY s.schedule")or die(mysqli_error());
	while($prow = mysqli_fetch_row($presult))
	{
		

		?>

		<tr>

												
		<td width="54" align="left"><font size="-1"> <?=$prow[0]?></font></td>	

                													
		<td width="191" align="left"><font size="-1"  color="#CC0000">
	    <?=$prow[1]?>
		  </font></td>
		<td width="181" align="center"><font size="-1"  color="#CC0000"><?=$prow[2]?>
	    
		  </font></td>      
		<td width="147" align="right"><font size="-1"  color="#CC0000"><?=round($prow[3],2);?> </font></td>	               
		<td width="131" align="right"><font size="-1">  <?=round($prow[4],2);?></font></td>
		<td width="123" align="right"><font size="-1">  <?=round($prow[5],2);?></font></td>        
		<td width="125" align="right"><font size="-1">  <?=round($prow[8],2);?></font></td>          
		<td width="125" align="right"><font size="-1">  <?=round($prow[6],2);?></font></td>        

		<td width="125" align="right"><font size="-1">  <?=round($prow[6],2);?></font></td>     
           
		<td width="126" align="right"><font size="-1">&nbsp;  </font></td>        
		</tr>
		 

		<?  
		

} // second while loop
?>

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

 


</table>			 



</table>


</body>
</form>

<?



