<? 
session_start();
$brcode= $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<link href="../css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>



<body bgcolor='ivory'>
<form action='<?print $PHP_SELF?>' method='POST'>
<table border=1 >
<tr><td align=center>Form No. <input type=text name='seafno' size=5> customer Name <input type=text name='seaname'></td><td>Rep.
<select name='exe'><option></option>
<?
 $r=mysqli_query($db,"select * from rep_master where branch='$brcode'  order by repname")or die(mysqli_error());
 while($reprow=mysqli_fetch_row($r))
 {
  print "<option value='$reprow[0]'>$reprow[1]</option>";
 }
?>
</select></td><td>
<input type=submit value='Search' name='sea'>
</td></tr>
</table>

<br>



		<link type="text/css" href="../css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="../js/jquery-ui-1.8.16.custom.min.js"></script>
			<script type="text/javascript">
			$(function(){
					$("#partcode").autocomplete({
						source: function( request, response ) {
							//alert($(this).attr("id"));
						$.ajax({
							url: "../search.php",
							dataType: "json",
							data: "key="+$("#partcode").val(),
							success: function( data ) {
								response( $.map( data, function( item ) {
									return {
										label: item.id+' | '+  item.value     ,
										value: item.id,
										name:item.value

									}
								}));
							}
						});
					}
					
				,
					minLength: 2,
					select: function( event, ui ) {

					$("#partname").val(ui.item.name);
					/*log( ui.item ?
					"Selected: " + ui.item.label :
					"Nothing selected, input was " + this.value);
					*/
					 }
					
					});
		
			});
		</script>



<body bgcolor='ivory'>

<table>
<tr>
<td>CustomerName</td><td>



<input name='partcode' type="text" value="" id='partcode' >
<input name='partname' type="text" value="" id='partname' >
<input name='rate' type="text" value="" id='rate' >
<input type=submit value='Edit Customer' name='sea1' >
</form>
</td>
</tr>


</table>


<?
$sql="select * from orderform where brcode='$brcode' and sale_invno='-' order by formno desc limit 100";
if($save)
{

}

if($sea1)
{
$sql="select * from cust_master where branch='$brcode' and acname = '$partcode' order by acname";
$result=mysqli_query($db,$sql)or die(mysqli_error());
$row=mysqli_fetch_row($result);

print "<script> window.open('editcust_mast.php?code=$row[0]'); </script>";


}

if(isset($_POST['sea']))
{ print '<font color=blue> Search Result: </font>';
 if(strlen($seafno)>0)
  $sql="select * from orderform where brcode='$brcode' and formno='$seafno' and sale_invno='-' order by formno desc";
 else if(strlen($seaname)>0)
  $sql="select * from orderform where brcode='$brcode' and cust like '%$seaname%' and sale_invno='-' order by formno desc";
 else if(strlen($exe)>0)
  $sql="select * from orderform where brcode='$brcode' and rname= '$exe' and sale_invno='-' order by formno desc";

}
else
 print "<font color=blue>Printing last 100 order forms</font>";

$re=mysqli_query($db,$sql) or die(mysqli_error());
if(mysqli_num_rows($re)<=0)
{
 print "<font color=red>Record does not exist</font>";
 return;
}


print "<table border=1> <th>Form No <th>Manual OrderForm No<th>Date <th>Customer <th>Phone<th>Executive <th>Model <th>Config";
print "<th>Net Amt <th>Info<th>Edit";
while($row=mysqli_fetch_array($re))
{
$sql="select * from rep_master where branch='$brcode' and code= '$row[rname]'";
$re1=mysqli_query($db,$sql) or die(mysqli_error());
$rep=mysqli_fetch_row($re1);

 print "\n<tr><td align=center>";
if($row[stat]=='In-Active')
 print "<font color=red size=3><b> * </b></font>";
print "$row[formno]</td><td>$row[mofno]</td><td>".implode('-', array_reverse(explode('-', $row['dt'])))."</td><td>".strtoupper($row['cust'])."</td><td>$row[phone]</td><td>$rep[1]</td><td>$row[model]</td><td>$row[config]</td><td align=right>$row[netamt]</td><td>$row[oinf]</td><td>";
if($level>=4||$user=='manju') 
 print "<a href='editoform.php?code=$row[formno]'>[Edit]</a></td>";
else
 print "&nbsp;</td>";

if($level>=4) 
 print "<td><a href='cust-mastnew.php?code=$row[formno]'>[Create]</a></td>";
else
 print "&nbsp;</td>";

print "</tr>";
}
?>
</table>

