<?
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");
if($save)
{
$insdate=$y1.'-'.$m1.'-'.$d1;
$expdate=$y2.'-'.$m2.'-'.$d2;
$invdate=parseDate($invdate);
 $sql=" insert into insurdet (invno, invdate, cust, addr1, addr2, city, dist, state, ph1, ph2,
 chasis, engno, invamt, ins, polino, insamt, insdate, expdate, brcode)
values('$invno', '$invdate', '$cust', '$addr1', '$addr2', '$city', '$dist', '$state', '$ph1', '$ph2', '$chasis', '$engno', '$invamt', '$ins', '$polino', '$insamt', '$insdate', '$expdate', '$brcode')";
 mysqli_query($db,$sql) or die(mysqli_error()); 
 print "<font color=green> Data has been saved</font>";
}
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:e3ecd2}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<script>
 function valid()
 {
  if(document.f1.ins.selectedIndex<=0)
   {
     alert('Invalid Insurance company');
	document.f1.ins.focus();
     return false;
   }
  if(document.f1.polino.value.length<=0)
   {
     alert('Invalid Policy Number');
	document.f1.polino.focus();
     return false;
   }
  if(document.f1.insamt.value.length<=0 || isNaN(document.f1.insamt.value))
   {
     alert('Invalid Sum Assured');
	document.f1.insamt.focus();
     return false;
   }
if(document.f1.d1.value.length<=0 || isNaN(document.f1.d1.value))
   {
     alert('Invalid Date');
	document.f1.d1.focus();
     return false;
   }
if(document.f1.d2.value.length<=0 || isNaN(document.f1.d2.value))
   {
     alert('Invalid Date');
	document.f1.d2.focus();
     return false;
   }
 return true;
}
</script>

<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<fieldset style="width:400;color:red;border-color:black">
<legend>
<font size=3><B>NEW INSURANCE ENTRY</B></FONT></legend>
<?
if($next)
{
$chasis=trim($chasis);
$re=mysqli_query($db,"select * from veh_invoice where chasis='$chasis' and type='-' and brcode='$brcode'")or die(mysqli_error());
if(mysqli_num_rows($re)>0)
{
 $row=mysqli_fetch_array($re);
 $cusres=mysqli_query($db,"select * from cust_master where code='$row[cust]' and branch='$brcode'") or die(mysqli_error());
 $cusrow=mysqli_fetch_array($cusres);
}
else
{
 print "<script> alert('Chasis could not be found'); history.back(1); </script>";
 return;
}
$inres=mysqli_query($db,"select * from insurdet where chasis='$chasis'");
 if(mysqli_num_rows($inres)>0)
 { 
?>
<form action='<?print $PHP_SELF?>' method='post'>
<table border=1>
<tr><td>Chasis NO</td><td><input type=text name='chasis' size=20></td>
	<td><input type=submit value='Next->' name='next'></td></tr>
</table>
</FORM>
<?
  print "<font color=red>Insurance has already done </font>";
  return;
 }
?>
<table cellspacing=1 cellpadding=4>
<tr><td>Invoice No.</td><td><input type=text name='invno' size=5 value='<?print $row[invno]?>'>
    Invoice Date <input type=text name='invdate' value='<?print datetohtml($row[invdate])?>'>
</td></tr>
<tr><td>Customer</td><td><input type=text name='cust' size=40 value='<?print $cusrow[custname]?>'></td></tr>
<tr><td>Address 1</td><td><textarea name='addr1' cols=39><?print $cusrow[addr1]?></textarea></td></tr>
<tr><td>Address 2</td><td><textarea name='addr2' cols=39><?print $cusrow[addr2]?></textarea></td></tr>
<tr><td>City</td><td><input type=text name='city' size=40 value='<?print $cusrow[city]?>'></td></tr>
<tr><td>Dist</td><td><input type=text name='dist' size=40 value='<?print $cusrow[dist]?>'></td></tr>
<tr><td>State</td><td><input type=text name='state' size=40 value='<?print $cusrow[state]?>'></td></tr>
<tr><td>Phone 1</td><td>
  <input type=text name='ph1' size=40 value='<?print $cusrow[phone1]?>'></td></tr>
<tr><td>
  Phone 2 </td><td><input type=text name='ph2' size=40 value='<?print $cusrow[phone2]?>'>
</td></tr>

<tr><td colspan=2 align=center bgColor='lightsteelblue'>VEHICLE INFORMATION</td></tr>
<tr><td>Chasis No. </td><td><input type=text name='chasis' size=40 value='<?print $row[chasis]?>'></td></tr>
<tr><td>Engine No. </td><td><input type=text name='engno' size=40 value='<?print $row[engno]?>'></td></tr>
<tr><td>Invoice Amt </td><td><input type=text name='invamt' size=40 value='<?print $row[netamt]?>'></td></tr>

<tr><td colspan=2 align=center bgColor='lightsteelblue'>INSURANCE INFORMATION</td></tr>
<tr><td>Insured with </td><td>
<select name='ins'>
<option></option>
<?
 $ress=mysqli_query($db,"select code,cname from insurco where brcode='$brcode' order by cname");
  while($in_row=mysqli_fetch_array($ress))
  {
   print "\n<option value='$in_row[0]'>$in_row[cname]</option>";
  }
?>
</select>
</td></tr>
<tr><td>Policy No </td><td><input type=text name='polino' size=40></td></tr>
<tr><td>Ins. Amt. </td><td><input type=text name='insamt' size=40></td></tr>

<tr><td>Insure Date </td><td>dd <input type=text name='d1' size=2>
mm <input type=text name='m1' size=2 value='<?print date('m')?>'>
yy <input type=text name='y1' size=4 value='<?print date('Y')?>'>
</td></tr>

<tr><td>Exp Date </td><td>dd <input type=text name='d2' size=2>
mm <input type=text name='m2' size=2 value='<?print date('m')?>'>
yy <input type=text name='y2' size=4 value='<?print date('Y')+1?>'>
</td></tr>

<tr><td colspan=2 align=center bgColor='lightsteelblue'>
<input type=submit value='Save' name='save'> <input type=button value='Cancel' onClick=document.location='../blank.html'></td></tr>
</table>
</fieldset>
<?
return;
} // end if
?>


<form action='<?print $PHP_SELF?>' method='post'>
<table border=1>
<tr><td>Chasis NO</td><td><input type=text name='chasis' size=20></td>
	<td><input type=submit value='Next->' name='next'></td></tr>
</table>
</FORM>
