<? session_start();
 include("../opendb.php");
if($save)
{
 $dt=$y.'-'.$m.'-'.$d;

$cntres=mysqli_query($db,"select max(no) from presale where brcode='$brcode'");
$cntrow=mysqli_fetch_row($cntres);
if($cntrow[0]<=0)
 $no=1;
else
 $no=($cntrow[0]+1);
   $code=substr($na,0,3).rand(100,999); 

$sql="create table presale (no int(10),dt date,na varchar(200),addr varchar(250), ph varchar(100), segment varchar(200), prof varchar(250), stat varchar(250), fine varchar(250), area varchar(250), exec varchar(250), discuss varchar(250), accby varchar(250), brcode varchar(100),disthea varchar(50),phead varchar(50),chkd char(1),code varchar(20))";
mysqli_query($db,$sql);


$sql="insert into presale values('$no', '$dt','$na','$addr','$ph','$segment','$prof', '$stat','$fine', '$area','$exec','$discus','$accby','$brcode','$disthea','$phead','n','$code')";
mysqli_query($db,$sql) or die('Err2'.mysqli_error());
}
?>
<style>
input,select,td{background-color:ivory;font-family:'arial narrow';letter-spacing:1;font-size:12}
.mnu{margin-left:5}
th{color:white;font-family:'arial narrow'}
a{text-decoration:none}
</style>
<script>
function valid()
{
 if(document.f1.na.value.length<=0)
  {
   alert('Invalid Name');
   return false;
  }
 if(document.f1.ph.value.length<=0)
  {
   alert('Invalid Phone');
document.f1.ph.focus();
   return false;
  }
 return true;
}
</script>

<body bgcolor='ivory'>
<center>
<form action='<?print $PHP_SELF?>' name='f1' onSubmit="return valid()">
<table cellspacing=1 cellpadding=3 bgcolor='steelblue'>
<th colspan=2>Customer Details</th>
<tr><td>Date </td><td>dd<input type=text name='d' size=2 value='<?print date("d");?>'>
			mm<input type=text name='m' size=2 value='<?print date("m");?>'>
			yy<input type=text name='y' size=4 value='<?print date("Y");?>'>

<tr><td>Name</td><td><input type=text name='na' size=40></td></tr>
<tr><td>Address</td><td><textarea name='addr' cols=48 rows=4></textarea></td></tr>
<tr><td>Phone</td><td><input type=text name='ph' size=40></td></tr>
<tr><td>Segment</td><td><select name='segment'>
<?
$segres=mysqli_query($db,"select * from seg_master order by sname")or die(mysqli_error());
while($segrow=mysqli_fetch_row($segres))
{
 print "<option>$segrow[1]</option>";
}
?>
</select></td></tr>
<tr><td>Profile</td><td><input type=text name='prof' size=40></td></tr>
<tr><td>Status</td><td><input type=text name='stat' size=40></td></tr>
<tr><td>Financer</td><td><select name='fine'>
<?
$finres=mysqli_query($db,"select * from fin_master order by finname")or die(mysqli_error());
while($segrow=mysqli_fetch_row($finres))
{
 print "<option>$segrow[1]</option>";
}
?>
</select></td></tr>
<tr><td>Area/Branch</td><td><select name='area'>
<?
$brres=mysqli_query($db,"select brname from br_master where brcode='$brcode' order by brname")or die(mysqli_error());
while($segrow=mysqli_fetch_row($brres))
{
 print "<option>$segrow[0]</option>";
}
?>
</select></td></tr>
<!--
<tr><td>Executive</td><td><select name='exec'>
<option></option>
<?
$brres1=mysqli_query($db,"select repname from rep_master where branch='$brcode' order by repname")or die('err'.mysqli_error());
while($segrow=mysqli_fetch_row($brres1))
{
 print "<option>$segrow[0]</option>";
}
?>
</select></td></tr>

<tr><td>Dist Head</td><td><select name='disthea'>
<option></option>
<?
$brres13=mysqli_query($db,"select repname from coo_master where branch='$brcode' order by repname")or die('err'.mysqli_error());
while($segrow=mysqli_fetch_row($brres13))
{
 print "<option>$segrow[0]</option>";
}
?>
</select></td></tr>
-->
<tr><td>Product Head</td><td><select name='phead'>
<option></option>
<?
$brres12=mysqli_query($db,"select repname from sman_master where branch='$brcode' order by repname")or die('err'.mysqli_error());
while($segrow=mysqli_fetch_row($brres12))
{
 print "<option>$segrow[0]</option>";
}
?>
</select></td></tr>


<tr><td>Discussion</td><td><textarea name='discus' cols=48 rows=4></textarea></td></tr>
<tr><td>Accompanied by</td><td><textarea name='accby' cols=48 rows=4></textarea></td></tr>
<tr><th colspan=2><input type=submit value='Save' name='save'></th>
</table>
</form>
