<?
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 - 3</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>
<td>Pswd <input type=password name='pswd'></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>
<?
$pswd = $_REQUEST['pswd'];
if($prn && $pswd=='age0910' || $brcode == 'PSN236')
{
    $d = $_REQUEST['d'];
$m = $_REQUEST['m'];
$y = $_REQUEST['y'];
$d1 = $_REQUEST['d1'];
$m1 = $_REQUEST['m1'];
$y1 = $_REQUEST['y1'];
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
       print "<script> window.open('prnvehsreg3.php?df=$df&dt=$dt');</script>";
}
if(isset($_POST['show']))
  {
      $d = $_REQUEST['d'];
$m = $_REQUEST['m'];
$y = $_REQUEST['y'];
$d1 = $_REQUEST['d1'];
$m1 = $_REQUEST['m1'];
$y1 = $_REQUEST['y1'];
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
   $result=mysqli_query($db,"select * from veh_invoice where invdate>='$df' and invdate<='$dt' and brcode='$brcode' and type!='trans-out'") or die(mysqli_error());
   if(mysqli_num_rows($result)>0)
   {
?>
<font size=3><b>Report From <?print implode('-', array_reverse(explode('-', $df))).' To '.implode('-', array_reverse(explode('-', $dt)))?></b></font> <br>
<table bgcolor=silver cellspacing=1 cellpadding=1>
<th>No.<th>To <th>TIN <th>Inv NO.<th>Inv. Date <th>DA <th>Addr1 <th>Addr2 <th>City <th>Dist.
<th>Phone1 <th>Phone 2<th>Model <th>Config <th>Eng No. <th>Chasis <th>Segment.
<?
$i=1;
     while($row=mysqli_fetch_array($result))
     {
    $addr1='';
    $dist='';
    
 if($row['type']=='-'||$row['type']=='sale-ret')
  { 
   $cus_result=mysqli_query($db,"select custname,addr1,addr2,city,dist,phone1,phone2,tin from cust_master where code='$row[cust]'")or die  (mysqli_error());
    $cus_row=mysqli_fetch_array($cus_result);
    $cust=$cus_row[0];
    $addr1=$cus_row['addr1'];
    $dist=$cus_row['dist'];
    $addr2=$cus_row['addr2'];
  }
 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($pswd=='age0910')
{
      print "<tr bgcolor=white><td align=center>".$i++."</td><td>$cust</td><td>$cus_row[tin]</td>";
if ($brcode=='PSN672')
{
print "<td align=center>GEN-$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>$addr1</td><td>$addr2</td><td>$cus_row[city]</td><td>$dist</td><td>$cus_row[phone1]</td>";
  print "<td>$cus_row[phone2]</td>";
      print "<td>$row[model_code]</td><td>$row[config]</td><td>$row[engno]</td>";
      print "<td>$row[chasis]</td><td>$row[segment]</td>";
 
}
   }
}
else
 print "Record does not exist";
}
?>
</table>
