<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include("../opendb.php");
include("../test.php");
if($save)
{
 $purdate=$py.'-'.$pm.'-'.$pd;
 $vehtxduedt=$pyt.'-'.$pmt.'-'.$pdt;

 $vehfitduedt=$fityt.'-'.$fitmt.'-'.$fitdt;
 $vehpermdt=$peryt.'-'.$permt.'-'.$perdt;
 $polludt=$polyt.'-'.$polmt.'-'.$polmt;
 $advtdt=$advyt.'-'.$advmt.'-'.$advdt;
 $purdate=$puryt.'-'.$purmt.'-'.$purdt;
 $insudt=$inyt.'-'.$inmt.'-'.$indt;
 $agrdate=$agryt.'-'.$agrmt.'-'.$agrdt;
 $premredt=$renyt.'-'.$renmt.'-'.$rendt;
 $ondate=date("Y-m-d");
 $acres=mysqli_query($db,"select * from vehmast where regno='$regno' and brcode='$brcode'");
 if(mysqli_num_rows($acres)>0)
 {
  print "<script> alert('Duplicate Asset Code'); history.back(1); </script>";
  return;
 }
 $sql="create table vehmast (regno varchar(20), vehmodel varchar(10),vehtxduedt date, vehfitduedt date, vehpermdt date, polludt date, advtdt date, orgrc varchar(200),purdate date,dealer varchar(200), puramt double(14,2), insuco varchar(250), policyno varchar(50),insudt date, chasisno varchar(50),engineno varchar(50),seating varchar(10),brand varchar(50),vehname varchar(50),brcode varchar(10),user varchar(50),odo double(10,2),mobile varchar(200),smscounter int(10),smsdate date";
mysqli_query($db,$sql);// or die(mysqli_error($db));
print  $vehtxduedt;
 $sql="insert into vehmast values('$regno', '$vehmodel','$vehtxduedt','$vehfitduedt','$vehpermdt','$polludt','$advtdt','$orgrc','$purdate','$dealer', '$puramt', '$insuco', '$policyno','$insudt', '$chasisno', '$engineno', '$seating','$brand', '$vehname','$brcode','$user','$odo','$mobile','$smscounter','0000-00-00','$smsbeforedays')";
mysqli_query($db,$sql) or die(mysqli_error($db));

$sql="insert into vledger values('$regno','INVESTMENTS','$op','Dr','$code','$brcode')";
mysqli_query($db,$sql) or die('<b>Ledger creation error:'.mysqli_error($db));

 print "<script> alert('Data has been saved'); </script>";
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
body,td{font-family:arial narrow;font-size:14}
th{background-color:silver}
</style>
<script>
 function valid()
 {
 if(document.f1.acode.value.length<=0)
 {
   alert('Invalid Asset Code');
   document.f1.acode.focus();
   return false;
 }
 if(document.f1.aname.value.length<=0)
 {
   alert('Invalid Asset Name');
   document.f1.aname.focus();
   return false;
 }

 if(document.f1.odo.value.length<=0)
 {
   alert('Invalid Reading');
   document.f1.odo.focus();
   return false;
 }
 if(document.f1.agroup.selectedIndex<=0)
 {
   alert('Invalid Asset Group');
   document.f1.agroup.focus();
   return false;
 }
 if(document.f1.insure.selectedIndex==0)
 {
  
 if(document.f1.insuco.value.length<=0)
 {
   alert('Invalid Insurance Details');
   document.f1.insuco.focus();
   return false;
 }
 }

 }
</script>

<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<tr><td>
<table border=1  width=80%>
<tr><td bgcolor='e4ecc4'><center>VEHICLE DETAILS</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2>
<tr><td>Reg No</td><td><input type=text name='regno'></td><td>Model/Year</td><td><input type=text name='vehmodel'></td></tr>

<tr><td>Tax Due Date</td><td colspan=3>dd<input type=text name='pdt' size=2> 
mm <input type=text name='pmt' size=2> yy
<input type=text name='pyt' size=4> </td></tr>


<tr><td>Fit Certi Due Date</td><td colspan=3>dd<input type=text name='fitdt' size=2> 
mm <input type=text name='fitmt' size=2> yy
<input type=text name='fityt' size=4> </td></tr>

<tr><td>Permit Due Date</td><td colspan=3>dd<input type=text name='perdt' size=2> 
mm <input type=text name='permt' size=2> yy
<input type=text name='peryt' size=4> </td></tr>

<tr><td>Pollution Certi. Due Date</td><td colspan=3>dd<input type=text name='poldt' size=2> 
mm <input type=text name='polmt' size=2> yy
<input type=text name='polyt' size=4> </td></tr>

<tr><td>Advt License Due Date</td><td colspan=3>dd<input type=text name='advdt' size=2> 
mm <input type=text name='advmt' size=2> yy
<input type=text name='advyt' size=4> </td></tr>

<tr><td>Original RC at</td><td colspan=3><input type=text name='orgrc' size=30> </td></tr>


<tr><td>Purchase Date</td><td colspan=3>dd<input type=text name='purdt' size=2> 
mm <input type=text name='purmt' size=2> yy
<input type=text name='puryt' size=4> </td></tr>

<tr><td>DealerName</td><td colspan=3><input type=text name='dealer' size=30> </td></tr>
<tr><td>Purchase Amount</td><td colspan=3><input type=text name='puramt' size=10> </td></tr>
</table>
</td></tr>
<table border=1  width=80%>
<tr><td bgcolor='e4ecc4'><center>INSURANCE DETAILS</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2>
<tr><td>Insurance Company</td><td colspan=3><input type=text name='insuco'  size=30> </td></tr>

<tr><td>Policy Number</td><td colspan=3><input type=text name='policyno'  size=30> </td></tr>

<tr><td>Due Date</td><td colspan=3>dd<input type=text name='indt' size=2> 
mm <input type=text name='inmt' size=2> yy
<input type=text name='inyt' size=4> </td></tr>
</TABLE>
</td></tr>
</table>
<table border=1  width=80%>
<tr><td bgcolor='e4ecc4'><center>Other Details</TD></TR>
<TR><TD>
<table cellspacing=1 cellpadding=2>
<tr><td>ChasisNo</td><td colspan=3><input type=text name='chasisno'  size=30> </td></tr>
<tr><td>Engine No.</td><td colspan=3><input type=text name='engineno'  size=30> </td></tr>


<tr><td>Seating Capacity</td><td colspan=3><input type=text name='seating'  size=30> </td></tr>
<tr><td>Brand Name</td><td><select name='brand'>
<option></option>
<?
$ares=mysqli_query($db,"select * from brand where brcode='$brcode' order by agrp");
while($arow=mysqli_fetch_array($ares))
{
  print "<option>$arow[0]</option>";
}
?>	</select>
	</td>
</tr>
<tr><td>VehicleName</td><td colspan=3><input type=text name='vehname'  size=30> </td></tr>
<tr><td>Odometer</td><td colspan=3><input type=text name='odo'  size=30> </td></tr>
<tr><td>MobileNos for SMS</td><td colspan=3><input type=text name='mobile'  size=30> </td></tr>
<tr><td>No.of SMS</td><td colspan=3><input type=text name='smscounter'  size=30> </td></tr>
<tr><td>Alert Before (Days)</td><td colspan=3><input type=text name='smsbeforedays'  size=30> </td></tr>

</table>

<tr><td colspan=4 align=center BGCOLOR='LIGHTSTEELBLUE'><INPUT TYPE=SUBMIT VALUE='SAVE' name='save'></TD></TR>
</table>
</form>

