<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
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?>'>
<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>
<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 "\n<option value='$reprow[0]'>$reprow[1]</option>";
 }
?>
</select></td><td>
<input type=submit value='Search' name='sea'>
</td></tr>
</table>
</form>
<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' >

</td></tr>


</table>



<font color=green size=4><b><u>Collections at branches to be cleared</b></u>
<?
$exe=$_REQUEST['exe'];
$seafno=$_REQUEST['seafno'];
$seaname=$_REQUEST['seaname'];
if(strlen($exe)>0)
{
$sql="select a.date,a.amount,b.cust,b.location,a.formno,a.code,a.type,b.mofno,b.addr from advcollection a,orderform b  where a.formno=b.formno and  b.rname='$exe' and a.brcode='$brcode' and b.brcode='$brcode' and a.clearing='n' order by a.date,b.location";
}
else if(strlen($seafno)>0)
{
$sql="select a.date,a.amount,b.cust,b.location,a.formno,a.code,a.type,b.mofno,b.addr from advcollection a,orderform b  where a.formno=b.formno and  a.formno='$seafno' and  a.brcode='$brcode' and b.brcode='$brcode' and a.clearing='n' order by a.date,b.location";
}
else if(strlen($seaname)>0)
{
$sql="select a.date,a.amount,b.cust,b.location,a.formno,a.code,a.type,b.mofno,b.addr from advcollection a,orderform b  where a.formno=b.formno and  b.cust like'%$seaname%' and  a.brcode='$brcode' and b.brcode='$brcode' and a.clearing='n' order by a.date,b.location";
}
else
$sql="select a.date,a.amount,b.cust,b.location,a.formno,a.code,a.type,b.mofno,b.addr from advcollection a,orderform b  where a.formno=b.formno and  a.brcode='$brcode' and b.brcode='$brcode' and a.clearing='n' order by a.date,b.location";

 $result=mysqli_query($db,$sql)or die(mysqli_error());
print "<table border=1> \n<th>SL. <th>O  F  No.<th>Manual Order Form<th>Date <th>Amount <th> Type <th>Customer<th>Branch<th>Clear";
$i=1;
while($row=mysqli_fetch_array($result))
{
 print "\n<form action='veh/clr_adv.php' method='POST'>
 <input type=hidden name='fno' value='$row[formno]'>";
 print "<input type=hidden name='amt' value='$row[amount]'>";
 print "<input type=hidden name='name' value='$row[cust]'>";
 print "<input type=hidden name='addr' value='$row[addr]'>";
 print "<input type=hidden name='ptype' value='$row[type]'>";
 print "<input type=hidden name='code' value='$row[code]'>";


 print "\n<tr><td>".$i++."</td><td>$row[4]</td><td>$row[7]</td><td>".datetohtml($row[0])."</td><td>$row[1]</td>";
 print "<td>$row[6]</td><td>$row[2]</td><td>$row[3]</td>";
 print "\n<td align=center><input type=submit value='Clear'></td></form>";

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

 
