<?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>B2C  Sales  from &nbsp;<? echo($stdt);?> to  &nbsp;<? echo($edt);?></td></tr>
<tr><td colspan="100%"><hr/></td></tr>

				<tr>
				
                				<td width="68" align="left"><div align="center"><font size="-1">TYPE</font></div></td>
		<td width="251" align="right"><div align="center"><font size="-1">Place of Supply</font></div></td>      
                    	
				<td width="251" align="right"><div align="center"><font size="-1">Tax Rate</font></div></td> 
				<td width="61" align="right"><div align="center"><font size="-1">Rate</font></div></td>  
				<td width="168" align="right"><div align="center"><font size="-1">Taxable Value</font></div></td>                                  

				<td width="195" align="right"><div align="center"><font size="-1">Cess Amount</font></div></td>   

				<td width="217" align="right"><div align="center"><font size="-1">E-Commerce GSTN</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></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.state_name, sr.vat_percent, SUM(sr.value) AS total_value
FROM salesreg8b sr
LEFT JOIN buy b ON sr.bcode = b.bcode
LEFT JOIN states s ON (CASE WHEN sr.bcode = '0' THEN '32' ELSE b.state_code END) = s.state_code
WHERE sr.inv_date BETWEEN '$startdt' AND '$enddt'
  AND (b.gstin IS NULL OR b.gstin = '')
GROUP BY s.state_name, sr.vat_percent; ")or die(mysqli_error());
	while($prow = mysqli_fetch_row($presult))
	{
		
		$state = $prow[0];		

		$vat_percent=$prow[1];
		$value=$prow[2];	
		$cessamt = $prow[3];	
	
		?>

		<tr>

												
		<td width="68" align="left"><font size="-1"> OE </font></td>	

                													
		<td width="251" align="left"><font size="-1"  color="#CC0000">
	    <?=$state?>
		  </font></td>
		<td width="251" align="center"><font size="-1"  color="#CC0000">&nbsp;
	    
		  </font></td>      
		<td width="61" align="right"><font size="-1"  color="#CC0000"><?   echo($vat_percent);?></font></td>	               
		<td width="168" align="right"><font size="-1">  <?=round($value,2);?></font></td>
		<td width="195" align="center"><font size="-1"  color="#CC0000">
	   		  </font></td>    
		<td width="217" align="left"><font size="-1"  color="#CC0000"><?=round($cessamt,2);?>
	    
		  </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></tr>

 


</table>			 



</table>


</body>
</form>

<?



