<?
 session_start();
 $brcode = $_SESSION['brcode'];
 $dt = $_REQUEST['dt'];
 $df = $_REQUEST['df'];
 $tp = $_REQUEST['tp'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<?
$df1=implode('-', array_reverse(explode('-', $df)));
$dt1 = implode('-', array_reverse(explode('-', $dt)));;
?>
<H3>GST SALES REGISTER FROM : <?print $df1." TO ".$dt1?></H3>
<form action='<?print $PHP_SELF?>'>
</form>
<?
//   	$df=$y.'-'.$m.'-'.$d;
//   	$dt=$y1.'-'.$m1.'-'.$d1;
	if($tp=='All')
	{
   		$result=mysqli_query($db,"select * from veh_invoice where invdate>='$df' and invdate<='$dt' and brcode='$brcode' and type!='trans-out' order by cgstp,igstp,invno") or die(mysqli_error());
	}
	else
	{
   		$result=mysqli_query($db,"select * from veh_invoice where invdate>='$df' and invdate<='$dt' and brcode='$brcode' and type!='trans-out' and tp='$tp' order by cgstp,igstp,invno") or die(mysqli_error());
	}

   	if(mysqli_num_rows($result)>0)
   	{
// 		print "<b>Type = ".$tp;
		?>
		<table bgcolor=silver cellspacing=1 cellpadding=1>
		<th>No.<th>To <th>GSTIN<th>PAN No.<th>Ledger<th>Inv NO.<th>Inv. Date <th>DA <th>Eng.No<th>Ch.No<th>HSNCode <th>Config<th>Before Tax<th>CGST%<th>CGST Amt<th>SGST%<th>SGST Amt<th>IGST%<th>IGST Amt<th>Tax Type<th>Net Amount<th>Cess Amt<th>TCS<th>Total
		<?
		$i=1;
		while($row=mysqli_fetch_array($result))
     		{
     		    
     		$sqqry="select partic from journal2 where type='Dr' and dramt>100 and jvno='$row[jvno]' and brcode='$brcode'";
     		$custledrs=mysqli_query($db,$sqqry);
     		$custledrw=mysqli_fetch_array($custledrs);
     		    $ledgername=$custledrw[0];
 			if($row['type']=='-' || $row['type']=='sale-ret'|| strlen($row['da'])<=0 )
  			{ 
   				$cus_result=mysqli_query($db,"select custname,tin,addr1,kgst from cust_master where code='$row[cust]' or custname='$row[cust]'")or die  (mysqli_error());
				$cus_row=mysqli_fetch_row($cus_result);
    				$cust=$cus_row[0].", ".$cus_row[2];
				if($cust==', ')
					$cust = $row['cust'];		
  			}
	 		else if($row['type']=='trans-out')
 			{
   				$cus_result=mysqli_query($db,"select brname from br_master where code='$row[cust]'")or die  (mysqli_error());
    				$cus_row=mysqli_fetch_row($cus_result);
    				$cust="<font color='brown'>".$cus_row[0];
			}  
			else
 				$cust="<font color='green'>".$row[0];
			if($row['area']=='DEALER')
			{
				$cus_result=mysqli_query($db,"select supname,tin,addr1 from sup_master where code='$row[cust]' ")or die  (mysqli_error());
				$cus_row=mysqli_fetch_row($cus_result);
    				$cust=$cus_row[0].", ".$cus_row[2];
				if($cust==', ')
					$cust = $row['cust'];				
			}

			$gst_no = $cus_row[1];
			if($gst_no<='')
			{
			       $r=mysqli_query($db,"select * from sup_master where supname='$row[cust]'")or die(mysqli_error());
			       $cus_row12=mysqli_fetch_array($r);
				$gst_no = $cus_row12[10];
			}
			$rrcat=mysqli_query($db,"select cat from veh_master where config='$row[config]' and brcode='$brcode'");
			$rowcat=mysqli_fetch_row($rrcat);			
      			print "<tr bgcolor=white><td align=center>".$i++."</td><td>$cust</td><td>$gst_no</td><td>$cus_row[3]</td><td>$ledgername</td>";
			print "<td align=center>$row[invno]</td>";

      			print "<td>".implode('-', array_reverse(explode('-', $row['invdate'])))."</td><td>$row[da]</td><td>$row[engno]</td><td>$row[chasis]</td><td>$row[hsncode]</td><td>$row[config]</td><td align=right>$row[amt2]</td>";
			$bef_tcs = $row['amt2']+$row['cgstamt']+$row['sgstamt']+$row['igstamt'];
      			print "<td align=right>$row[cgstp]</td><td align=right>$row[cgstamt]</td><td align=right>$row[sgstp]</td><td align=right>$row[sgstamt]</td><td align=right>$row[igstp]</td><td align=right>$row[igstamt]</td><td align=right>$row[taxtype]</td><td align=right>$bef_tcs</td><td>$row[cessamt]</td><td>$row[tcsamt]</td><td>$row[netamt]</td></tr>";
      			//print "<td align=right>$row[cgstp]</td><td align=right>$row[cgstamt]</td><td align=right>$row[sgstp]</td><td align=right>$row[sgstamt]</td><td align=right>$row[igstp]</td><td align=right>$row[igstamt]</td><td align=right>$row[taxtype]</td><td align=right>$row[netamt]</td></tr>";
    		}
	}
	else
	 	print "Record does not exist";
?>
</table>
