<?
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");
?>
<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>
<H3>SALES REGISTER</H3>
<form action='<?print $PHP_SELF?>' method='POST'>
<table bgcolor='silver'>
<tr><td> Date from </td><td>dd<input type=text name='d' size=2 value='<?print date("d",time())?>'>
				mm<input type=text name='m' size=2 value='<?print date("m",time())?>'>
				yy<input type=text name='y' size=4 value='<?print date("Y",time())?>'>
			</td></tr>

<tr><td> To </td><td>dd<input type=text name='d1' size=2 value='<?print date("d",time())?>'>
				mm<input type=text name='m1' size=2 value='<?print date("m",time())?>'>
				yy<input type=text name='y1' size=4 value='<?print date("Y",time())?>'>
			</td>
</tr>
<tr><td>Type</td><td><select name='tp'><option>All</option>
<option>8A</option>
<option>8B</option>
<option>8</option>
</select>
</td></tr>
<tr><td colspan=2 align=center><input type=submit name='show' value='Show'>
<input type=submit name='prn' value='Print'>
</td></tr>
</table>
</form>
<?
if(isset($_POST['prn']))
{
    $d = $_REQUEST['d'];
$m = $_REQUEST['m'];
$y = $_REQUEST['y'];
$d1 = $_REQUEST['d1'];
$m1 = $_REQUEST['m1'];
$y1 = $_REQUEST['y1'];
$tp = $_REQUEST['tp'];
  	$df=$y.'-'.$m.'-'.$d;
	$dt=$y1.'-'.$m1.'-'.$d1;
       print "<script> window.open('prnvehsreg_new.php?df=$df&dt=$dt&tp=$tp');</script>";
}
if(isset($_POST['show']))
{
    $d = $_REQUEST['d'];
$m = $_REQUEST['m'];
$y = $_REQUEST['y'];
$d1 = $_REQUEST['d1'];
$m1 = $_REQUEST['m1'];
$y1 = $_REQUEST['y1'];
$tp = $_REQUEST['tp'];
   	$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 taxp,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 taxp,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>TIN<th>Inv NO.<th>Inv. Date <th>DA <th>Eng.No<th>Ch.No<th>MCode <th>Config<th>Catag<th>Net Amt.
		<th>Tax <th>Tax% <th>Before Tax<th>Tax Type<th>Disc
		<?
		$i=1;
		while($row=mysqli_fetch_array($result))
     		{
 			if($row['type']=='-' || $row['type']=='sale-ret')
  			{ 
   				$cus_result=mysqli_query($db,"select custname,tin from cust_master where code='$row[cust]'")or die  (mysqli_error());
				$cus_row=mysqli_fetch_row($cus_result);
    				$cust=$cus_row[0];
  			}
	 		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];
			$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>$cus_row[1]</td>";
			if ($brcode=='PSN672')
			{
				print "<td align=center>GEN-$row[invno]</td>";
			}
			else
			{
				if ($row['taxtype']=='CST')
					print "<td align=center>CST$row[invno]</td>";
				else
					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[model_code]</td><td>$row[config]</td><td>$rowcat[0]</td><td align=right>$row[netamt]</td>";
      			print "<td align=right>$row[tax]</td><td align=right>$row[taxp]</td><td align=right>$row[amt2]</td><td align=right>$row[taxtype]</td><td align=right>$row[disc]</td></tr>";
    		}
	}
	else
	 	print "Record does not exist";
}
?>
</table>
