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

$pgno=1;
$kount=1;

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

$string1='B2B (Only for Registered Dealers) 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>B2B Sales  from &nbsp;<? echo($stdt);?> to  &nbsp;<? echo($edt);?></td></tr>
<tr><td colspan="100%"><hr/></td></tr>

				<tr>
				
                				<td width="46" align="left"><div align="center"><font size="-1">GSTIN </font></div></td>

				<td width="64" align="left"><div align="center"><font size="-1">Receiver    Name </font></div></td>	
				<td width="33" align="right"><div align="center"><font size="-1">Inv. No</font></div></td>    
<td width="38" align="left"><div align="center"><font size="-1">Date</font></div></td>
<td width="61" align="right"><div align="center"><font size="-1">Invoice Value</font></div></td>					<td width="172" align="right"><div align="center"><font size="-1">Place of Supply</font></div></td>      
				<td width="41" align="right"><div align="center"><font size="-1">Reverse Charge</font></div></td> 
                      	
				<td width="41" align="right"><div align="center"><font size="-1">Tax Rate</font></div></td> 
				<td width="41" align="right"><div align="center"><font size="-1">Invoice Type</font></div></td>         
				<td width="41" align="right"><div align="center"><font size="-1">E-Commerce GSTN</font></div></td>                         

				<td width="41" align="right"><div align="center"><font size="-1">Rate</font></div></td>    
				<td width="49" align="right"><div align="center"><font size="-1">Taxable Amount</font></div></td>                                  

				<td width="41" ><div align="right"><font size="-1">Cess Amount</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><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 = 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;

	$invresult= mysqli_query($conn,"select distinct inv_no,account_year,sum(value-discount_amt+vat_amount),bcode from salesreg8b  where inv_date >='$startdt' and inv_date <='$enddt'  and compcode='$compcode' group by inv_no order by inv_no,inv_date,record ")or die(mysqli_error());


while($invrow = mysqli_fetch_row($invresult))
{
	$account_year = $invrow[1];

			$bslct= mysqli_query($conn,"select name,gstin,taxtype from buy where bcode = '$invrow[3]' ") or die(mysqli_error());
		$brow=mysqli_fetch_row($bslct);
		$bname = $brow[0];
		$gstin = $brow[1];

		$state_code = substr($gstin,0,2);
		$sresult = mysqli_query($conn,"select state_name from states where state_code = '$state_code' ") or die(mysqli_error());
		$srow = mysqli_fetch_row($sresult);
		$state = $srow[0];
if($gstin !='')					
{
	$presult = mysqli_query($conn,"select inv_date ,bcode,inv_no,sum(value -discount_amt),vat_percent,sum(vat_amount),sum(vatcess_amt)   from salesreg8b where inv_date >='$startdt' and inv_date <='$enddt'  and compcode='$compcode' and inv_no = '$invrow[0]' and prodcode != 'TOTAL' group by vat_percent order by record ")or die(mysqli_error());
	while($prow = mysqli_fetch_row($presult))
	{
		
		$total=0;
		//$inv_date = substr($prow[0],8,2).'/'.substr($prow[0],5,2).'/'.substr($prow[0],0,4);


		$inv_date = date("d-M-Y", strtotime($prow[0]));

		 
		$bcode= $prow[1];
		$inv_no= $prow[2];		
		$value=$prow[3];
		$vat_percent=$prow[4];
		$cessamt = $prow[6];
	
		?>

		<tr>

												
		<td width="46" align="left"><font size="-1"><?  echo($gstin);?> </font></td>	
		<td width="64" align="left"><font size="-1"><?  echo($bname);?> </font></td>
		<td width="33" align="center"><font size="-1"><?  echo(substr($account_year,2,6).'/'.$inv_no);?></font></td>        
           		<td width="38" align="left"><font size="-1"><?  echo($inv_date);?></font></td>	
        
		<td width="61" align="right"><font size="-1"  color="#CC0000"><?   echo(round($invrow[2],2)); ?></font></td>                													
		<td width="172" align="left"><font size="-1"  color="#CC0000">
	    <?=$state?>
		  </font></td>
		<td width="172" align="center"><font size="-1"  color="#CC0000">
	    N
		  </font></td>          
		<td width="172" align="left"><font size="-1"  color="#CC0000">&nbsp;
	    
		  </font></td> 
		<td width="172" align="center"><font size="-1"  color="#CC0000">
	    Regular		  </font></td>    
		<td width="172" align="left"><font size="-1"  color="#CC0000">&nbsp;
	    
		  </font></td>                       
		<td width="41" align="right"><font size="-1"  color="#CC0000"><?   echo($vat_percent);?></font></td>	      

		<td width="49" align="right"><font size="-1">  <?=round($value,2);?></font></td>
		<td width="172" align="right"><font size="-1"  color="#CC0000">&nbsp;<?=$cessamt?>
	    
		  </font></td>        
		</tr>
		 

		<?  
		

} // second while loop
} // If GSTN != blank 

} // invoice 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><td><hr></td><td><hr></td><td><hr></td></tr>

 
<?
/*
<tr>



<td width="49" align="right"><font size="-1" color="#CC0000"><? if($gvalue>0)  echo(number_format($gvalue,2,'.',''));?></font></td>

<td width="49" align="right"><font size="-1" color="#CC0000"><? if($gvalue-$disc_total>0)  echo(number_format($gvalue-$disc_total,2,'.',''));?></font></td>

				
<td width="41" align="right"><font size="-1">&nbsp;</font></td>		<td width="39" align="right"><font size="-1"  color="#CC0000"><? if($sgst_tot>0)  echo(number_format($sgst_tot,2));?></font></td>
       
		<td width="42" align="right"><font size="-1"  color="#CC0000"><?   echo(number_format($sgst_tot,2,'.',''));?></font></td>		
		<td width="44" align="right"><font size="-1"  color="#CC0000"><? if($igst_tot >0)  echo(number_format($igst_tot,2,'.',''));?></font></td>	  

		<td width="42" align="right"><font size="-1"  color="#CC0000"><? if($sgst_tot+$igst_tot+$igst_tot >0)  echo(number_format($sgst_tot+$igst_tot+$igst_tot,2,'.',''));?></font></td>	               	
								
<td width="61" align="right"><font size="-1" color="#CC0000"><? if($net>0)  echo(number_format($net,2,'.',''));?></font></td>				
			
		
		</tr>
		*/
		?>

</table>			 



</table>


</body>
</form>

<?



