<?
session_start();
include("../opendb.php");
include("../test.php");
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
$res=mysqli_query($db,"select * from vehopstock where code='$code' and brcode='$brcode'");
$op_row=mysqli_fetch_array($res);

if($upd)
{
  if(strlen($mcode)<=0||strlen($config)<=0||strlen($dano)<=0)
   {
    print "<script> alert('Insufficient Entry'); history.back(1); </script>";
    return;
   }
  $pdate=$y.'-'.$m.'-'.$d;
if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}
$sql="update vehopstock set mcode='$mcode',chno='$chno',engno='$engno',dano='$dano', pval='$pval', pinv='$pinv',pdate='$pdate',loc='$loc',sup='$sup',config='$config', emcode='$emcode' where code='$code' and brcode='$brcode'";
mysqli_query($db,$sql) or die(mysqli_error());
log_entry($brcode,$user,$REMOTE_ADDR,"Edit veh opstock $dano");
print "<script>document.location='opstock.php' </script>";
}
?>

<script>
var ar1=[];
function fun1()
{
 var x=document.f1.config.selectedIndex;
 document.f1.mcode.value=ar1[document.f1.config.selectedIndex];
}
function valid()
{
 submitOK="true";
 if(document.f1.loc.selectedIndex==0)
 {
   submitOK="false";
   alert('Invalid Location');
 }

  if(submitOK=="true")
   return true;
  else
   return false;
}
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf(' ')>-1) 
  {
    alert('Space is not allowed');
    abc.value='';
  }
}
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>

<body bgcolor='ivory' onSubmit="return valid()">

<form name='f1' action='<?print $PHP_SELF?>'>
<input type=hidden name='code' value='<? print $op_row[code]?>'>
<table border=1 cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td bgColor='green' ALIGN=CENTER><FONT COLOR='IVORY'><B>E D I T &nbsp; O P E N I N G &nbsp; S T O C K 
&nbsp; E N T R Y</TD></TR>
<tr><td bgColor='IVORY'>

<table border=0 cellspacing=2 cellpadding=1>
<tr>
  <td><font color=red>config </td><td>
   <select name='config' onChange=fun1()>
   <option><?print $op_row[config]?></option>
 <?print "\n<script>ar1[0]='".strtoupper($op_row[1])."'</script>";?>
    <?
     $i=1;
     $res=mysqli_query($db,"select * from veh_master where brcode='$brcode'");
     while($row=mysqli_fetch_row($res))
     {
       print "\n<option>$row[2]</option>"; 
       print "\n<script>ar1[$i]='".strtoupper($row[1])."'</script>";$i++;
     }
    ?>
  </select>

</td> 

  <td>Model Code </td><td><input type=text readonly name='mcode' size=30 value='<?print $op_row[mcode]?>'></td> 


  <td>Chasis No </td><td>
   <input type=text name='chno'size=20 onKeyDown=chkey(this) value='<?print $op_row[chno]?>'></td> 

</tr>
<tr>
  <td>Engine No </td><td>
    <input type=text name='engno' size=20 onKeyDown=chkey(this); value='<?print $op_row[engno]?>'></td> 

  <td><font color=red>Da No</td><td>
   <input type=text name='dano' size=20 onKeyDown=chkey(this) value='<?print $op_row[dano]?>'></td> 


  <td>Purchase Value </td><td>
    <input type=text name='pval' size=20 value='<?print $op_row[pval]?>'></td> 

</tr>
<tr>
  <td>Purchase Inv No </td><td>
    <input type=text name='pinv' size=20 value='<?print $op_row[pinv]?>'></td> 

<? 
 $dd=explode('-',$op_row[pdate]);
?>
  <td>Purchase Inv Date</td><td>
	DD<input type=text name='d' size=2 value='<?print $dd[2]?>'>
	MM<input type=text name='m' size=2 value='<?print $dd[1]?>'>
	YY<input type=text name='y' size=4 value='<?print $dd[0]?>'>

  </td> 

  <td>Location </td><td><select name='loc'>
<?
     $res=mysqli_query($db,"select * from loc_master where lname='$op_row[loc]'");
     $loc_row=mysqli_fetch_row($res);
     print "<option value='$loc_row[0]'>$loc_row[1]</option>";

     $res=mysqli_query($db,"select * from loc_master where brcode='$brcode'");
     while($row=mysqli_fetch_row($res))
     {
       print "\n<option value='$row[0]'>".strtoupper($row[1])."</option>"; 
     }
    ?>
  </select>

</td>

<tr>
  <td>Supplier </td><td colspan=2><select name='sup'>
    <?
	$sql="select * from sup_master where code='$op_row[sup]' and branch='$brcode'"; print $sql;
     $res1=mysqli_query($db,$sql)or die(mysqli_error());
      $suprow=mysqli_fetch_row($res1);
       print "\n<option value='$suprow[0]'>$suprow[1]</option>"; 
     
     $res=mysqli_query($db,"select * from sup_master where branch='$brcode'");
     while($row=mysqli_fetch_row($res))
     {
       print "\n<option value='$row[0]'>$row[1]</option>"; 
     }
    ?>
  </select>
</td> 
<td>Eicher Model Code </td><td><input type=text name='emcode' size=10 value='<?print $op_row[emcode]?>'></td>
<td colspan=1 align=center><input type=submit name='upd' value=' U P D A T E'></td>
</tr>
</table>
</td></tr>
</table>
</form>
