<?
 session_start();
 $brcode = $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
$df = $_REQUEST['df'];
$dt = $_REQUEST['dt'];
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d799}
.mnu{margin-left:5}
</style>
<center>
<H3><?print $branch?> <br>PURCHASE REGISTER<br>
From <?print implode('-', array_reverse(explode('-', $df))).' To '.implode('-', array_reverse(explode('-', $dt)))?>
</H3>
<?

//   $df=$y.'-'.$m.'-'.$d;
//   $dt=$y1.'-'.$m1.'-'.$d1;
$tnet=0;
$ttax=0;
$tb=0;
$result=mysqli_query($db,"select * from veh_purchase where entrydate>='$df' and entrydate<='$dt' and brcode='$brcode'  order by taxp,entrydate ") or die(mysqli_error());
if(mysqli_num_rows($result)>0)
{
?>
<table bgcolor=silver cellspacing=1 cellpadding=1>
<th>No.<th>Ref.No<th>From <th>GSTIN<th>Inv NO.<th>Inv. Date <th>Entry Date<th>DA <th>MCode <th>Config 
<th>Before Tax  <th>Tax% <th>Tax <th>Cess% <th>Cess<th>Total<th>TCS Amt</th><th>Invoice Amt</th><th>HSNCODE</th>
<?
$i=1;
$tax_per = 0;
     	while($row=mysqli_fetch_array($result))
     	{
		if($i==1)
			$tax_per = $row['taxp'];
		else
		{
			if($tax_per != $row['taxp'])
			{
			  	print "<tr><td colspan=9 align=center><b>Total</td><td align=right><b>".putComa($tb)."</td>";
  				print "<td align=right><b>".putComa($ttax)."</td><td>&nbsp;</td>";
			  	print "<td></td><td align=right><b>".putComa($cesstot)."</td><td align=right><b>".putcoma($tnet)."</td></tr>";
				$tnet=0;
				$ttax=0;
				$tb=0;
			}
		}
		$rrcat=mysqli_query($db,"select cat from veh_master where config='$row[config]' and brcode='$brcode'");
$rowcat=mysqli_fetch_row($rrcat);
$rrstin=mysqli_query($db,"select tin from sup_master where supname ='$row[0]' and branch='$brcode'");
$rowstin=mysqli_fetch_row($rrstin);
		print "<tr bgcolor=white><td>".$i++."</td><td>".$row['refno']."</td><td>$row[ledger]</td><td>$rowstin[0]</td><td>$row[invno]</td><td>".implode('-', array_reverse(explode('-', $row['invdate'])))."</td><td>".implode('-', array_reverse(explode('-', $row['entrydate'])))."</td>";
      		print "<td>$row[da]</td><td>$row[mcode]</td><td>$row[config]</td>";
      		print "<td align=right>$row[amt2]</td>";
      		print "<td align=right>$row[taxp]</td><td align=right>$row[tax]</td>";
    		print "<td align=right>$row[cessp]</td><td align=right>$row[cessamt]</td>";
    		$mnetamt1=$row['netamt']-$row['tcsamt'];
    		print "<td align=right>$mnetamt1</td>";
    		print "<td align=right>$row[tcsamt]</td>";
    		$mnetamt=$row['netamt'];
    		print "<td align=right>$mnetamt</td><td align=right>$row[hsncode]</td>";
		$tnet+=$mnetamt1;
		$ttax+=$row['tax'];
		$tb+=$row['amt2'];
		$cesstot+=$row['cessamt'];
		$tax_per = $row['taxp'];
		$mtcstot+=$row['tcsamt'];
		$mnettot += $row['netamt'];
    	}
  	print "<tr><td colspan=10 align=center><b>Total</td><td align=right><b>".putComa($tb)."</td>";
  	print "<td></td><td align=right><b>".putComa($ttax)."</td><td>&nbsp;</td>";
  	print "<td></td><td align=right><b>".putComa($tnet)."</td><td align=right><b>$mtcstot</td><td align=right><b>$mnettot</td></tr>";
}
else
 print "Record does not exist";
$result=mysqli_query($db,"select * from item_purchase where pdate>='$df' and pdate<='$dt' and brcode='$brcode' order by pno") or die(mysqli_error());
if(mysqli_num_rows($result)>0)
{
	?>
	<table>
	<tr><td><b>IMPORT PURCHASE</td></tr>
	<tr>
	<th>No.<th>Invoice No<th>Ref.No<th>Supplier <th>Inv. Date <th>Net Amt.
	<th>Total</tr>
	<?
	$i=1;
     	while($row=mysqli_fetch_array($result))
     	{
	      	print "<td align=center>".$i++."</td>";
		$rrcat=mysqli_query($db,"select supname from sup_master where code='$row[sup]' ");
		$rowcat=mysqli_fetch_row($rrcat);
		$supname = $rowcat[0];
	      	print "<td>$row[purinvoice]</td><td>$row[pno]</td><td>$supname</td><td>".implode('-', array_reverse(explode('-', $row['pdate'])))."</td>";
	      	print "<td>$row[net]</td>";
	      	print "<td align=right>$row[gtot]</td></tr>";
	}
}

?>
</table>
