<link href="../css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>
<body >

<?
 session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>

<H3>SALES REGISTER - DETAILED</H3>
<form action='<?print $PHP_SELF?>'>
<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>
<?

 if($show)
  {
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
   
$tbl="vehsales".$brcode.$user;
$tbl1="newvehsales".$brcode.$user;

mysqli_query($db,"drop table $tbl");
mysqli_query($db,"drop table $tbl1");

mysqli_query($db,"CREATE TABLE $tbl select * from veh_invoice where brcode='$brcode'");
mysqli_query($db,"CREATE TABLE $tbl1 select * from oldinvoice");




mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb11516.veh_invoice where brcode='$brcode'");



mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb1415.veh_invoice where brcode='$brcode'");
mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
)  select * from psndb1314.veh_invoice where brcode='$brcode'");
mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb1213.veh_invoice where brcode='$brcode'");
mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb1112.veh_invoice where brcode='$brcode'");
mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb1011.veh_invoice where brcode='$brcode'");
mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb0910.veh_invoice where brcode='$brcode'");
mysqli_query($db,"insert into $tbl (cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp,cessp,cessamt,taxtype
) select * from psndb0809.veh_invoice where brcode='$brcode'");
print $m=("insert into $tbl select * from psndb0809.veh_invoice where brcode='$brcode'");


mysqli_query($db,"insert into $tbl(cust,formno,model_code,rep,area,fin,invno,invdate,da,config,unit,disc,netamt,taxp,tax,amt2,color,engno,segment,chasis,remark,brcode,type,jvno,emcode,tp)
 select * from psndb0708.veh_invoice where brcode='$brcode' ");


$result=mysqli_query($db,"select * from $tbl where invdate>='$df' and invdate<='$dt' and brcode='$brcode' and type!='trans-out' and type!='sale-ret' order by invdate,invno asc") or die(mysqli_error());
 
if(mysqli_num_rows($result)>0)
   {

$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,acname from cust_master where code='$row[cust]' and branch='$brcode' ")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=='care')
{
 $rep=getrep1($row[rep]);


 $sql="insert into $tbl1 (date,invoiceno,name,addr1,addr2,addr3,area,dist,phone,chasis,engno,config,fine,exec,brcode) values ('$row[invdate]','$row[invno]','$cust','$addr1','$addr2','$cus_row[city]','$cus_row[city]','$dist','$cus_row[phone1]','$row[chasis]','$row[engno]','$row[config]','$row[fin]','$rep','$brcode')";
mysqli_query($db,$sql);









    }
}
}
else
 print "Record does not exist";
}



if($show && $pswd=='care')
{

$result=mysqli_query($db,"select * from $tbl1 where date>='$df' and date<='$dt' and brcode='$brcode' order by date,invoiceno asc") or die(mysqli_error());
 

if(mysqli_num_rows($result)>0)
   {
?>
<b>Report From <?print datetohtml($df).' To '.datetohtml($dt)?></b></font> <br>
<table bgcolor=silver cellspacing=1 cellpadding=1 border=1>
<th>No.<th>To <th>Inv NO.<th>Inv. Date  <th>Addr1 <th>Addr2 <th>City <th>Dist.
<th>Phone1 <th>Fine <th>Config <th>Eng No. <th>Chasis <th>Exec.<th>RegNo<th>JobNo<th>Veh.Last in<th>Veh_in_Branch
<?
$i=1;
     while($row=mysqli_fetch_array($result))
{
$regno=GetRegno($row[chasis]);
$jcno=GetJcno($row[chasis]);
$jcdate=GetJcdate($row[chasis]);
$jcbr=GetJcbr($row[chasis]);


     print "<tr bgcolor=white><td align=center>".$i++."</td><td>$row[name]</td><td align=center>$row[invoiceno]</td><td>".datetohtml($row[date])."</td><td>$row[addr1]</td><td>$row[addr2]</td>";
print "<td>$row[addr3]</td><td>$row[dist]</td><td>$row[phone]</td>";
   print "<td>$row[fine]</td>";

      print "<td>$row[config]</td><td>$row[engno]</td>";
      print "<td>$row[chasis]</td><td>$row[exec]</td>";
      print "<td>$regno</td>";
      print "<td>$jcno</td>";
      print "<td>$jcdate</td>";
      print "<td>$jcbr</td>";

}

}

}

?>
</table>
