<?  session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
if($upd)
{
 $orddate=$y.'-'.$m.'-'.$d;
 $ch_da=mysqli_query($db,"select * from purorder where dano='$dano' and brcode='$brcode'");
  if(mysqli_num_rows($ch_da)>1)
  {
    print "<script> alert('Duplicate DA'); history.back(1); </script>";
    return;
  }
  $sql="update purorder set ordby='$ordby',orddate='$orddate', dano='$dano',mcode='$mcode', 
config='$config', supplier='$supplier', amount='$amt' where code='$code' and brcode='$brcode' ";
mysqli_query($db,$sql) or die(mysqli_error());
include("pur_order.php");
return;
} 

$re=mysqli_query($db,"select * from purorder where code='$code' and brcode='$brcode'");
$p_row=mysqli_fetch_array($re);
?>
<script>
var ar1=[];
function fun1()
{
 var x=document.f1.mcode.selectedIndex;
 document.f1.config.value=ar1[document.f1.mcode.selectedIndex];
}

function valid()
{
var p1=document.f1.orno.value
var dano=document.f1.dano.value
var mcode=document.f1.mcode.seletedIndex

 submit="true";
 if(p1.length<=0)
  {submit="false"; alert('Invalid Order Number');}
 if(dano.length<=0)
  {submit="false"; alert('Invalid DA Number');}
 if(mcode<=0)
  {submit="false"; alert('Invalid Model Code');}

 if(submit=="false")
  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;}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<CENTER>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()">
<input type=hidden name=code value='<?print $code?>'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr  bgColor='c1d7bb'><td align=center>
<table cellspacing=1 cellpadding=2>
<tr bgColor='c1d7bb'><td colspan=4 align=center bgcolor='green'>
<font color='ivory'><STRONG>PURCHASE ORDER</TD></TR>
<tr><td>Order No</td><td colspan=3>
<input type=text name='orno' readonly  size=6 value='<?print $p_row[ordno]?>'></td></tr>
<tr><td>Order by </td><td><select name='ordby'>
<option><?print $p_row[ordby]?></option>
<option>AMPL</option>
<option>Eicher</option> 
<option>PSN</option>
</select> </td>
<td>Order Date </td>
<?
$df=explode('-',$p_row[orddate]);
?>
<td>dd  <input type=text name=d size=2 value='<?print $df[2]?>'>
mm  <input type=text name=m size=2 value='<?print  $df[1] ?>'>
yy  <input type=text name=y size=4 value='<?print  $df[0]?>'>
</td></tr>
<tr><td>DA Number </td><td colspan=3><input type=text name='dano' size=20 value='<?print $p_row[dano]?>' onKeyDown=chkey(this)>
Supplier <select name='supplier'>
<?$r=mysqli_query($db,"select code, supname from sup_master where code='$p_row[supplier]'")or die(mysqli_error());
    $su_row=mysqli_fetch_array($r);
print "<option value='$su_row[code]'> $su_row[supname]</option>";
     $i=1;
     $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></tr>
<tr><td>Model Code</td><td colspan=3>
<!-- <input type=text name='model' size=10>-->
<select name='mcode' onChange=fun1()>
<option><?print $p_row[mcode]?></option>
    <?$i=0;
       print "\n<script>ar1[$i]='".strtoupper($p_row[config])."'</script>";
     $i=1;
     $res=mysqli_query($db,"select * from veh_master where brcode='$brcode'");
     while($row=mysqli_fetch_row($res))
     {
       print "\n<option>$row[1]</option>"; 
       print "\n<script>ar1[$i]='".strtoupper($row[2])."'</script>";$i++;
     }
    ?>
  </select>

 Config <input type=text name='config' size=40 value='<?print $p_row[config]?>'></td>
</tr>
<tr><td>Amount </td><td>
  <input type=text name='amt' size=10 style={text-align:right} value='<?print $p_row[amount]?>'></td></tr>
<tr><td colspan=5 align=right><input type=submit value='   UPDATE   ' name='upd'>
 <input type=button value='   CANCEL   ' onClick=history.back(1)> </td></tr>
</table>
</form>
</table>
