<?
session_start();
include("../opendb.php");
include("../test.php");
$res=mysqli_query($db,"select * from veh_purchase where tono='$tono' and brcode='$brcode'");
$resrow=mysqli_fetch_array($res);
$dt1=explode('-',$resrow[pinvdate]);
$dt2=explode('-',$resrow[entrydate]);

if($save)
{
 if($pswd=='editveh')
{
$pinvdate=$y.'-'.$m.'-'.$d;
$entrydate=$y1.'-'.$m1.'-'.$d1;

$sql="update veh_purchase set tono='$tono',pinvno='$pinvno',pinvdate='$pinvdate', config='$config',msno='$msno' ,engno='$engno' ,entrydate='$entrydate', model='$model' where tono='$oldtono'";
//,amt='$amt',taxp='$taxp',taxamt='$taxamt', amt2='$amt2' ,
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error());
$sql="update purorder set pinvoice='$pinvno' where tono='$tono'";
mysqli_query($db,$sql) or die('Upd error:'.mysqli_error());
log_entry($brcode,$user,$REMOTE_ADDR,"Edit veh purchase tono:$tono,msno:$msno,pinvno:$pinvno");
print "<script> opener.document.location='veh_purch1.php';window.close() </script>";
return;
}
else
{
 print "<script> alert('Invalid Password')</script>";
}
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
tr{background-color:white}
th{background-color:steelblue;color:white}
</style>
<script>
 function calctax()
  {
     document.f1.taxamt.value=(parseFloat(document.f1.amt.value)*parseFloat(document.f1.taxp.value)/100).toFixed(2);
   document.f1.amt2.value=parseFloat(document.f1.amt.value)+parseFloat(document.f1.taxamt.value);
   document.f1.mser.focus();
  }
function valid()
{
 if(document.f1.pinvno.value.length<=0)
 {
   alert("Invalid Purchase invoice no");
   document.f1.pinvno.focus();
   return;
 }
 if(document.f1.d.value.length<=0)
 {
   alert("Invalid Purchase invoice date");
   document.f1.d.focus();
   return;
 }
 if(document.f1.d1.value.length<=0)
 {
   alert("Invalid Entry date");
   document.f1.d1.focus();
   return;
 }

 if(document.f1.amt.value.length<=0)
 {
   alert("Invalid Amount");
   document.f1.amt.focus();
   return;
 }
 if(isNaN(document.f1.amt.value))
 {
   alert("Invalid Amount");
   document.f1.pinvno.focus();
   return;
 }
 if(document.f1.msno.value.length<=0)
 {
   alert("Invalid Machine Serial NO.");
   document.f1.msno.focus();
   return;
 }
 if(document.f1.engno.value.length<=0)
 {
   alert("Invalid Engine NO.");
   document.f1.engno.focus();
   return;
 }

}
</script>

<center>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='white'>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<input type=hidden name='oldtono' value='<?print $tono?>'>
<table cellspacing=1 cellpadding=3>
<th colspan=6><font size=3>VEHICLE PURCHASE</th>
<tr><td>Tel Ord No </td><td><input type=text name='tono' readonly size=4 value='<?print $tono?>'></td>
    <td>P.Inv No.</td><td><input type=text name='pinvno' value='<?print $resrow[pinvno]?>'></td>
    <td>Inv Date</td><td>dd<input type=text name='d' size=2 value='<?print $dt1[2]?>'>
mm<input type=text name='m' size=2  value='<?print $dt1[1]?>'>
yy<input type=text name='y' size=4  value='<?print $dt1[0]?>'>
</td>
<tr>
<td>Entry Date</td><td>dd<input type=text name='d1' size=2 value='<?print $dt2[2]?>'>
mm<input type=text name='m1' size=2 value='<?print $dt2[1]?>'>
yy<input type=text name='y1' size=4 value='<?print $dt2[0]?>'>
</td>
<td>Model</td><td>
<select name='model'>
<option><?print $resrow[model]?></option>
<?
$re1=mysqli_query($db,"select * from configmaster order by model");
while($row1=mysqli_fetch_array($re1))
{
  print "<option>$row1[model]</option>";
}
?>
</select> </td></tr>
<tr><td>Config</td><td colspan=6><select name='config'>
<?
print "<option>$resrow[config]</option>";
$re=mysqli_query($db,"select * from configmaster order by model");
while($row=mysqli_fetch_array($re))
{

print "<option>$row[config]</option>";
}
?>
</select>
</td></tr>
<tr><td>Amount </td><td><input type=text readonly name='amt' onChange='javascript:calctax()' value='<?print $resrow[amt]?>'></td>
	<td>Tax %</td><td><input type=text readonly  name='taxp' value='<?print $resrow[taxp]?>'></td>
        <td>Tax Amt </td><td  align=right><input  readonly type=text name='taxamt' value='<?print $resrow[taxamt]?>'></td></td>
</tr>
<tr><td>Amt Payable </td><td><input type=text  readonly name='amt2'  value='<?print $resrow[amt2]?>' readonly>
    <td>M Ser No </td><td><input type=text name='msno' value='<?print $resrow[msno]?>'></td>
	<td>Engine No</td><td align=right><input type=text name='engno' value='<?print $resrow[engno]?>'></td>
</tr>
<tr><td>Password</td><td><input type=password name='pswd'></td></tr>
<th colspan=6><input type=submit value='Update' name='save'> <input type=button value='Cancel' onClick=window.close()></td></tr>
</table>
</form>
</td></tr>
</table>


