<?
session_start();
include("../opendb.php");
include("../test.php");
if($save)
{
$pinvdate=$y.'-'.$m.'-'.$d;
$entrydate=$y1.'-'.$m1.'-'.$d1;

$sql="insert into vehopstock (tono,pinvno,pinvdate, config,amt,taxp,taxamt, amt2 ,msno ,engno ,entrydate, brcode,model) values('$tono','$pinvno','$pinvdate', '$config', '$amt', '$taxp', '$taxamt', '$amt2' ,'$msno' ,'$engno','$entrydate', '$brcode', '$model','op')";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error());

print "<script> document.location='veh_opstock.php'</script>";
return;
}
//$re=mysqli_query($db,"select * from configmaster");
//$row=mysqli_fetch_array($re);
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
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.msno.focus();
  }
function valid()
{
 if(document.f1.pinvno.value.length<=0)
 {
   alert("Invalid Purchase invoice no");
   document.f1.pinvno.focus();
   return false;
 }
 if(document.f1.d.value.length<=0)
 {
   alert("Invalid Purchase invoice date");
   document.f1.d.focus();
   return false;
 }
 if(document.f1.d1.value.length<=0)
 {
   alert("Invalid Entry date");
   document.f1.d1.focus();
   return false;
 }

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

}
</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()">
<table cellspacing=1 cellpadding=3>
<th colspan=6><font size=3>VEHICLE OPENING STOCK</th>
<tr><td>Tel Ord No </td><td><input type=text name='tono'  size=4 value='<?print $tono?>'></td>
    <td>P.Inv No.</td><td><input type=text name='pinvno' ></td>
    <td>Inv Date</td><td>dd<input type=text name='d' size=2 >
mm<input type=text name='m' size=2 value='<?print date('m')?>'>
yy<input type=text name='y' size=4 value='<?print date('Y')?>'>
</td></tr>
<tr>
<td>Entry Date</td><td>dd<input type=text name='d1' size=2 value='<?print date('d')?>'>
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>
<td>Model </td><td colspan='4'><select name='model'>
<?
$re=mysqli_query($db,"select * from configmaster order by model");
while($row=mysqli_fetch_array($re))
{
print "<option>$row[model]</option>";
}
?>
</select>
</td></tr>
<tr><td>Config </td><td colspan='5'><select name='config'>
<?
$re1=mysqli_query($db,"select * from configmaster order by model");
while($row1=mysqli_fetch_array($re1))
{
print "<option>$row1[config]</option>";
}
?>
</select>
</td>
<tr><td>Amount </td><td><input type=text name='amt' onChange='javascript:calctax()'></td>
	<td>Tax %</td><td><input type=text name='taxp' value='12.5'></td>
        <td>Tax Amt </td><td  align=right><input type=text name='taxamt'></td></td>
</tr>
<tr><td>Amt Payable </td><td><input type=text name='amt2' readonly>
    <td>M Ser No </td><td><input type=text name='msno'></td>
	<td>Engine No </td><td align=right><input type=text name='engno'></td>
</tr>
<th colspan=6><input type=submit value='Save' name='save'></td></tr>
</table>
</form>
</td></tr>
</table>
<br>
<table cellspacing=1 cellpadding=5 bgcolor='orange'>
<th>No <th>Tel No <th>P. Inv <th>MSer No<th>Amount <th>Edit <th>Del<th>Config
<?
$i=1;
$res=mysqli_query($db,"select * from vehopstock order by entrydate");
while($row=mysqli_fetch_array($res))
{
 print "<tr bgcolor='white' onMouseOver=bgColor='b8d7b4'; onMouseOut=bgColor='white'>";
 print "<td>".$i++."</td><td>$row[tono]</td><td>$row[pinvno]</td>";
 print "<td>$row[msno]</td><td align=right>".putComa($row[amt2])."</td></td>";
 print "<td><input type=button value='Edit' name='ed' onClick=window.open('editopstock.php?tono=$row[tono]',menubar=false,resizable=false)></td>";
 print "<td><input type=button value='Del' name='del' onClick='delfun($row[tono])'></td><td>$row[config]</td></tr>";
}
?>
</table>


<script>
 function delfun(x)
 {
  if (confirm('do you want to delete '+x+' ?'))
   document.location='delvehopstock.php?tono='+x;
 }
  
</script>
