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


$partcode=$_GET['key'];


$re=mysqli_query($db,"select acname,branch,code,addr1,city,dist,stat,pin,phone1,corporate from cust_master where branch='$brcode' and acname like '$partcode%' order by acname asc limit 10");

$json="";
while($row=mysqli_fetch_array($re))
{
    if($row['stat']<='')
	{
		$custstate='KERALA';
	}
	else
	{
		$custstate=$row['stat'];
	}
    $sql="select msno from minput where cust='$row[code]' and brcode='$brcode'";
    $result = mysqli_query($db,$sql);
    $rowdt=mysqli_fetch_array($result);
	 $json.= '{"orderto":"'.$row[0].'","partname":"'.addslashes($row['addr1']).'","price":"'.addslashes($row['city']).'","supqty":"'.addslashes($row['dist']).'","mrgnprc":"'.addslashes($row['stat']).'","custstt":"'.addslashes($row['corporate']).'","shipin":"'.addslashes($row['pin']).'","shidist":"'.addslashes($row['phone1']).'"},';
}

$re=mysqli_query($db,"select * from sup_master where branch='$brcode' and supname like  '%$partcode%' order by supname asc limit 10") or die("ERR6:".mysqli_error());
    while($row=mysqli_fetch_array($re))
    {
       
    
        $json.= '{"orderto":"'.$row['supname'].'","partname":"'.addslashes($row['addr1']).'","price":"'.addslashes($row['city']).'","supqty":"'.addslashes($row['dist']).'","mrgnprc":"'.addslashes($row['stat']).'","custstt":"'.addslashes($custstate).'","shipin":"'.addslashes($row['pin']).'","shidist":"'.addslashes($row['phone1']).'"},';
    }










echo '['.trim($json,',').']';

?>