<?
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)
{
 $chfound="N";
 if(strlen($chasis)>0)
 {
  $re=mysqli_query($db,"select chno from vehopstock where chno='$chasis'");
  if(mysqli_num_rows($re)>0)
   $chfound="Y";
  else
   {
    $re=mysqli_query($db,"select chasis from veh_purchase where chasis='$chasis'");
    if(mysqli_num_rows($re)>0)
      $chfound="Y";
   }
 }
  if($chfound=='N'&&strlen($chasis)>0)
   { 
    print "<font color=red>Invalid Chasis</font>";
    print "<script> alert('Invalid chasis no.'); history.back(1); </script>";
    return;
   }
$dt=$y.'-'.$m.'-'.$d;

$sql="insert into itmadjin (item_code,chasis,amt,brcode,date) values('$item','$chasis','$amt','$brcode','$dt')";
mysqli_query($db,$sql) or die(mysqli_error());

$code=substr($chasis,0,3).date("dmys");

$sql="insert into item_purchase (code,item_code,uni_amt,qty,gross,net,gtot,brcode,chasis,curdate) values('$code','$item', '$amt','1','$amt','$amt', '$amt','$brcode','$chasis','$dt')";
mysqli_query($db,$sql) or die(mysqli_error());

print "Record has been saved";
} // end save fun

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

<script>
function validate()
{
 var sub="true";
 if(document.f1.amt.value.length<=0 || isNaN(document.f1.amt.value))
 {
   alert('Invalid Amount');
    sub="false";
 }
 if(sub=="false")
  return false;
 else
  return true; 
}
</script>
<body bgcolor='ivory' onSubmit="return validate()">
<CENTER>
<BR>
ITEM STOCK ADJUSTMENT (INWARD)
<form name='f1' action='<?print $PHP_SELF?>'>
<table cellspacing=1 cellpadding=1 bgcolor='darkbrown'>
<tr><td align=center>
<table>
<tr>
 <td>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>Item </td><td>
<select name='item'>
<?
 $re=mysqli_query($db,"select * from itemmaster order by itname");
 while($row=mysqli_fetch_row($re))
 {
  print "\n<option value='$row[0]'>$row[1]</option>";
 }
?>
</select>
</td>
</tr>
<tr>
 <td>Chasis </td><td><input type=text name='chasis'></td> 
</tr>
<tr>
 <td>Amount </td><td><input type=text name='amt'></td> 
</tr>
<tr>
 <td colspan=2 align=center><input type=submit value='Save' name='save'> <input type=button value='Cancel'>
</td> 
</tr>
</table>
</form>
</table>
<br>
<?
$re=mysqli_query($db,"select a.itname,b.* from itemmaster a,itmadjin b where a.code=b.item_code and b.brcode='$brcode'") or die(mysqli_error());
print "<table border=1><th>Item Name <th>Chasis <th>Amount <th>Date<th>Del";
while($row=mysqli_fetch_array($re))
{
 print "<tr><td>$row[0]</td><td>$row[chasis]</td><td align=right>$row[amt]</td><td>".datetohtml($row[date])."</td>";
 print "<td><input type=button value='Del' onClick=del('$row[2]','$row[chasis]')></tr>";
}
?>
</table>
<script>
function del(x,y)
{
 if(confirm('Do you want to delete chasis '+y))
  document.location='deladjitm.php?code='+x+'&chas='+y;
}
</script>

