<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login') </script>";
 return;
}

include("opendb.php");

if(@$_GET['type']=='name')
{
$partname=$_GET['key'];
$re=mysqli_query($db,"select acname,brcode,code,addr1,cst,cramt from customer where  acname like '%$partname%' and brcode = '$brcode' order by acname asc limit 5");
//print "select acname,brcode,code,addr1,cst,cramt from customer where  acname like '%$partname%'  order by acname asc limit 50";
 
}
else
{
$partcode=$_GET['key'];

$sql="select acname,brcode,code,addr1,cst,cramt,state1 from customer where   acname like '$partcode%' and brcode='$brcode' order by acname asc limit 50";
//echo $sql;
$re=mysqli_query($db,"select acname,brcode,code,addr1,cst,state1 from customer where acname like '%$partcode%'  group by acname order by acname asc limit 15");

}
$json="";
while($row=mysqli_fetch_array($re))
{
//    $sql="select msno from minput where cust='$row[code]' and brcode='$brcode'";
    //$result = mysqli_query($db,$sql);
    //$rowdt=mysqli_fetch_array($result);
	 //echo $row[0];
	 
	 $json.= '{"orderto":"'.$row[0].'","partname":"'.addslashes($rowdt[0]).'","price":"'.addslashes($row['addr1']).'","supqty":"'.addslashes($row['cst']).'","mrgnprc":"'.addslashes($row['state1']).'"},';
	 
}
echo '['.trim($json,',').']';
?>