<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
if($save)
{
$dt=$y.'-'.$m.'-'.$d;

if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}
$sql="update orderform set dt='$dt',cust='$cust',addr='$addr',phone='$phone',rname='$rname', model='$model', config='$config',seg='$seg',fine='$fine',exch='$exch', descr='$descr', exvalue='$exvalue', invalue='$invalue', disamt='$disamt',netamt='$netamt', oinf='$oinf', location='$loc' where formno='$code' and brcode='$brcode'";
mysqli_query($db,$sql) or die (mysqli_error());
print "<script>opener.document.location='advform.php?ordno=$code'; window.close();</script>";
 return;
}
$result=mysqli_query($db,"select * from orderform where formno='$code' and brcode='$brcode'");
$frm_row=mysqli_fetch_array($result);
?>
<script>
resizeTo(550,640);
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>
<center>
<form action='<?print $PHP_SELF?>' method='post'>
<input type=hidden name='code' value='<?print $code ?>'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td bgcolor='green' align=center> <font color=ivory><b>EDIT ORDER FORM</td></tr>
<tr><td bgcolor='ivory' align=center>
<table border=0>
<tr><td>Order form number <td>
<?
$re=mysqli_query($db,"select max(formno) from orderform where brcode='$brcode'");
$r=mysqli_fetch_row($re);
if($r[0]<=0)
 $form_no=1;
else
 $form_no=$r[0]+1;
?>
<input type=text name='formno' readonly size=10 value='<?print $frm_row[0]?>'> 
<?
$dt=explode('-',$frm_row[dt]);
?>
Date dd <input type=text name='d' size=2 value='<?print $dt[2]?>'>
mm <input type=text name='m' size=2 value='<?print $dt[1]?>'>
yy <input type=text name='y' size=4 value='<?print $dt[0]?>'>
</td></tr>
<tr><td>Customer Name</td><td colspan=3><input type=text name='cust' size=50 value='<?print strtoupper($frm_row[cust])?>'></td></tr>
<tr><td>Address</td><td colspan=3><textarea name='addr' cols=48><?print $frm_row[addr]?></textarea></td></tr>
<tr><td>Phone</td><td colspan=3>
	<input type=text name='phone' size=50 value='<?print $frm_row[phone]?>'>
    </td></tr>

<tr><td>Rep.Name</td><td colspan=3><select name='rname'>
<?
 $result=mysqli_query($db,"select * from rep_master where code='$frm_row[rname]'");
 $rep_row=mysqli_fetch_row($result);
?>
<option value='<?print $rep_row[0]?>'> <?print $rep_row[1]?> </option>
<?
 $result=mysqli_query($db,"select * from rep_master order by repname");
 while($row=mysqli_fetch_row($result))
 {
   print "<option value='$row[0]'>".strtoupper($row[1])."</option>";
 }
?>
</select>
Location 
<select name='loc'>
<?
 $result=mysqli_query($db,"select code,brname from br_master where code='$frm_row[location]'");
  $loc_row=mysqli_fetch_row($result);
 print "<option value='$loc_row[0]'>$loc_row[1]</option>";

 $result=mysqli_query($db,"select * from br_master order by brname");
 while($row=mysqli_fetch_row($result))
 {
   print "<option value='$row[0]'>".strtoupper($row[1])."</option>";
 }
?>
</select>
</td></tr>
<tr><td>Model Code</td><td colspan=3><input type=text name='model' size=10 value='<?print $frm_row[model]?>'>
 Config <input type=text name='config' size=30 value='<?print $frm_row[config]?>'></td>

</tr>
<tr><td>Segment</td><td><select name='seg'>
<?
 $result=mysqli_query($db,"select * from seg_master where code='$frm_row[seg]'");
 $seg_row=mysqli_fetch_row($result);
 print "<option value='$seg_row[0]'>$seg_row[1]</option>";


 $result=mysqli_query($db,"select * from seg_master order by sname");
 while($row=mysqli_fetch_row($result))
 {
   print "<option value='$row[0]'>".strtoupper($row[1])."</option>";
 }
?>
</select>
</td></tr>


<tr><td>Financier/Bank</td><td colspan=3><select name='fine'>
<?
 $result=mysqli_query($db,"select code,finname from fin_master where code='$frm_row[fine]'");
 $fin_row=mysqli_fetch_row($result);
   print "<option value='$fin_row[0]'>".strtoupper($fin_row[1])."</option>";
 
 $result=mysqli_query($db,"select * from fin_master order by finname");
 while($row=mysqli_fetch_row($result))
 {
   print "<option value='$row[0]'>".strtoupper($row[1])."</option>";
 }
?>
</select>
</td></tr>

<tr><td>Exchange (y/n)</td><td colspan=3><select name ='exch'>
<option><?print $frm_row[exch]?></option>
<option>N</option>
<option>Y</option>
</select></td></tr>
<tr><td>Exchange Description </td><td colspan=3>
<textarea name='descr' cols=48><?print $frm_row[descr]?></textarea></td></tr>
<tr><td>Exchange Value</td><td colspan=1><input type=text name='exvalue' size=10 value='<?print $frm_row[exvalue]?>' style={text-align:right}>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Invoice Value <input type=text name='invalue' size=10 value='<?print $frm_row[invalue]?>' style={text-align:right}></td></tr>
<tr><td>Discount Amt.</td><td colspan=3><input type=text name='disamt' size=10 value='<?print $frm_row[disamt]?>' style={text-align:right}>
Net Amount to customer <input type=text name='netamt' size=10 value='<?print $frm_row[netamt]?>' style={text-align:right}></td></tr>

<tr><td>Other Information</td><td colspan=3><input type=text name='oinf' size=50 value='<?print $frm_row[oinf]?>'></td></tr>
<tr><td colspan=2 align=center bgcolor=green> <input type=submit value='Update' name='save'>
<input type=submit value='Cancel' onClick=window.close()></td></tr>
</table>
</form>
