<?
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;
}
if($submit)
{
  if(strlen($mcode)<=0||strlen($config)<=0||strlen($dano)<=0)
   {
    print "<script> alert('Insufficient Entry'); history.back(1); </script>";
    return;
   }
 $chk=mysqli_query($db,"select * from vehopstock where (chno='$chno' or dano='$dano') and brcode='$brcode'"); 
 if(mysqli_num_rows($chk)>0)
 {
    print "<script> alert('Duplicate 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;
}

 $code=substr($config,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);

$sql="insert into vehopstock values('$code','$mcode','$chno','$engno','$dano','$pval', '$pinv','$pdate','$loc','$sup','$brcode','-','op','$config','','$emcode')";
 mysqli_query($db,$sql) or die(mysqli_error());
 print "<font color=green>Data has been saved</font>";
}      
?>
<script>
var ar1=[];
function fun1()
{
 var x=document.f1.config.selectedIndex;
 if(x<=0)
   document.f1.mcode.value='';
 else
 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?>'>
<table border=1 cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td bgColor='green' ALIGN=CENTER><FONT COLOR='IVORY'><B>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></option>
    <?
     $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></td> 


  <td>Chasis No </td><td><input type=text name='chno'size=20 onKeyDown=chkey(this)></td> 

</tr>
<tr>
  <td>Engine No </td><td><input type=text name='engno' size=20 onKeyDown=chkey(this)></td> 

  <td><font color=red>Da No</td><td><input type=text name='dano' size=20 onKeyDown=chkey(this)></td> 


  <td>Purchase Value </td><td><input type=text name='pval' size=20></td> 

</tr>
<tr>
  <td>Purchase Inv No </td><td><input type=text name='pinv' size=20></td> 


  <td>Purchase Inv Date</td><td>
	DD<input type=text name='d' size=2>
	MM<input type=text name='m' size=2>
	YY<input type=text name='y' size=4>

  </td> 

  <td>Location </td><td><select name='loc'>
<option></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'>
    <?
     $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></td>
<td colspan=1 align=center><input type=submit name='submit' value='Save'></td>
</tr>
</table>
</td></tr>
</table>
</form>
<br>
<style>
.x,th{font-size:13.95}
</style>
<table border=1>
<th>No.<th>Model Code<th>Config <th>Chasis <th>Engine NO. <th>D.A No <th>Purch. Value <th> Invoice
<th>Purch. Date <th>Location <th>Supplier<th>Edt<th>Del

<?
 $i=1;
 $result=mysqli_query($db,"select * from vehopstock where brcode='$brcode' and optype='op' order by pdate");
 while($row=mysqli_fetch_array($result))
 {
     $r=mysqli_query($db,"select * from veh_master where mcode='$row[1]' ")or die(mysqli_error());
      $con_row=mysqli_fetch_row($r);

    print "\n<tr class=x><td>".$i++."</td><td>$row[1]</td><td>$con_row[2]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td>";
    print "<td align=right>".putComa($row[5])."</td><td>$row[6]</td><td>".datetohtml($row[7])."</td>";
     $r=mysqli_query($db,"select * from loc_master where code='$row[loc]' and brcode='$brcode'")or die(mysqli_error());
      $loc_row=mysqli_fetch_row($r);
     print "<td>$loc_row[1]</td>";
     $r1=mysqli_query($db,"select * from sup_master where code='$row[sup]'")or die(mysqli_error());
      $sup_row=mysqli_fetch_row($r1);
  
    print "<td>$sup_row[1]</td>\n<td>";
    print "<a href=javascript:edit('$row[2]','$row[0]')><img src='../img/signit.gif' border=0> </td>";
    print "<td>Del</td></tr>";
//print "<a href=javascript:del('$row[2]','$row[0]')><img src='../img/delete2.gif' border=0 title='Delete'></a></td></tr>";
 }
?>
</table>
<script>
function del1(x,code)
{
 if(confirm("Do you want to delete the record "+x+" ?"))
  document.location='delvehopstock.php?code='+code;
}
function edit(x,code)
{
  document.location='editvehopstock.php?code='+code;
}

</script>
