<?
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;
}
$cust=str_replace('  ',' ',$cust);

$re=mysqli_query($db,"select max(formno) from orderform where brcode='$brcode'")or die(mysqli_error());
$r=mysqli_fetch_row($re);
if($r[0]<=0)
 $form_no=1;
else
 $form_no=$r[0]+1;
$dob=$doy.'-'.$dom.'-'.$dod;

$sql="insert into orderform  (formno,dt,cust,addr,phone,rname,model,config,seg,fine,exch,descr,exvalue,invalue,disamt,netamt,oinf,brcode,location,dob,op,enqno,fineamt) values('$form_no', '$dt','$cust', '$addr','$phone', '$rname', '$model','$config','$seg', '$fine','$exch','$descr', '$exvalue','$invalue', '$disamt','$netamt','$oinf', '$brcode','$loc','$dob','$op','$enqno','$fineamt')";
mysqli_query($db,$sql) or die (mysqli_error());

//$msg="Of No:".$form_no." Customer:".$cust." Config:".$config." Net:".$netamt." Rep:".$brcode;
//print "<script> window.open('sendsms.php?msg=$msg&to=91%209447779986'); window.open('sendsms.php?msg=$msg&to=91%209895211033');</script>";
}
?>
<script>
var ar1=[];
function valid()
{
var p1=document.f1.config.selectedIndex; 
var c=document.f1.cust.value;
var inv=document.f1.invalue.value;
var net=document.f1.netamt.value;

 submit="true";
// if(p1<=0)
//  {submit="false"; alert('Invalid Model Code');}
 if(c.length<=0)
  {submit="false"; alert('Invalid Customer Name');}
 if(document.f1.rname.value.length<=0)
  {submit="false"; alert('Invalid Rep. Name');}

 if(document.f1.phone.value.length<=0)
  {submit="false"; alert('Invalid Phone Number');}


 if(inv.length<=0 || isNaN(inv)||net.length<=0 ||isNaN(net))
  {submit="false"; alert('Invalid invoice');}
 if(isNaN(net)||net<=0)
  {submit="false"; alert('Invalid Net Amount');}

 if(submit=="false")
  return false;
}


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];
}
var br=[];
function cng()
{
 if(document.f1.rname.selectedIndex>0)
 {
  document.f1.loc.value=br[document.f1.rname.selectedIndex];
 }
 else
  document.f1.loc.value='';

}

function calcnet()
{
 var inv=parseFloat(document.f1.invalue.value);
 var dis=parseFloat(document.f1.disamt.value);
 if(dis>0)
 var net=(inv-dis);
 else
 net=inv;
 document.f1.netamt.value=net;
}
</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 name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">


<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td bgcolor='green' align=center> <font color=ivory><b>ORDER FORM</td></tr>
<tr><td bgcolor='ivory' align=center>
<table border=0>
<tr><td>OFNo. <td>
<?
$re=mysqli_query($db,"select max(formno) from orderform where brcode='$brcode'")or die(mysqli_error());
$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=5 value='<?print $form_no?>'> 
Enq <input type=text name='enqno' size=5>
Date dd <input type=text name='d' size=2 value='<?print date("d",time())?>'>
mm <input type=text name='m' size=2 value='<?print date("m",time())?>'>
yy <input type=text name='y' size=4 value='<?print date("Y",time())?>'>
</td></tr>
<tr><td><font color='red'> Customer Name</td><td colspan=3>
<input type=text name='cust' size=50 onKeyDown=chkey(this);></td></tr>
<tr><td>Address</td><td colspan=3><input type=text name='addr' size=50></td></tr>
<tr><td>Date of birth</td> <td>dd<input type=text name='dod' size=2>
		 mm<input type=text name='dom' size=2>
		 yy<input type=text name='doy' size=4>
</tr>
<tr><td>
Phone </td><td><input type=text name='phone' size=50></td></tr>

<tr><td><font color=red>Rep.Name</td><td colspan=3><select name='rname' onChange=cng()><option></option>
<?
 $result=mysqli_query($db,"select * from empmaster where design='SALES EXE' order by empname");
 $i=1;
 while($row=mysqli_fetch_array($result))
 {
   print "\n<option value='$row[0]'>".strtoupper($row[3])."</option>";
   print "\n  <script> br[$i]='$row[br]'; </script>";
  $i++;
 }
?>
</select>
Branch <input type=text name='loc' readonly>
</td></tr>
<tr><td>Model </td><td><select name='model'>
<?
$modres=mysqli_query($db,"select * from configmaster order by model");
while($modrow=mysqli_fetch_array($modres))
{
 print "<option>$modrow[model]</option>";
}
?>
</select>

<tr><td><font color=red> Config</td>
<td colspan=3>

 <select name='config' onChange=fun1()> 
<?
$modres=mysqli_query($db,"select * from configmaster order by model");
while($modrow=mysqli_fetch_array($modres))
{
 print "<option>$modrow[config]</option>";
}
?>


  </select>
</td>

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


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

<tr><td>Exchange (y/n)</td><td colspan=3><select name ='exch'><option>N</option><option>Y</option></select></td></tr>
<tr><td>Exchange Description </td><td colspan=3><textarea name='descr' cols=48 rows=1></textarea></td></tr>
<tr><td>Exchange Value</td><td colspan=1><input type=text name='exvalue' size=10 style={text-align:right}>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font color=red>Invoice Value <input type=text name='invalue' size=10 style={text-align:right} onChange=calcnet()></td></tr>
<tr><td>Discount Amt.</td><td colspan=3><input type=text name='disamt' size=10 style={text-align:right} onChange=calcnet()>
<font color=red>Net Amount to customer</font> &nbsp;<input type=text name='netamt' size=10 style={text-align:right}></td></tr>
<tr><td><font color=blue>Advance</td><td colspan=3><input type=text name='op'></td></tr>
<tr><td><font color=blue>Fin Amt.</td><td colspan=3><input type=text name='fineamt'></td></tr>

<tr><td>Other Information</td><td colspan=3><textarea name='oinf' cols=48 rows=2></textarea></td></tr>
<tr><td colspan=2 align=center bgcolor=green> <input type=submit value='Save' name='save'>
<input type=submit value='Cancel' onClick=document.location='../blank.html'></td></tr>
</table>
</form>
<script>
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
if(yy.indexOf("&")>-1) 
  {
    alert("& is not allowed");
    abc.value='';
  }

}
</script>



