<? 
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$level=$_SESSION['level'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("opendb.php");
$partcode=$_GET['key'];
$re=mysqli_query($db,"select * from sup_master where supname like '$partcode%' order by supname asc limit 30")or die(mysqli_error($db));
$json="";
while($row=mysqli_fetch_array($re))
{
    if($row['gst']=='')
    {
        $gstvl=0;  
    }
    else
    {
        $gstvl=$row['gst'];
    }
/*    
$tbl2="tcscust".$brcode.$user;
mysqli_query($db,"drop table $tbl2");
mysqli_query($db,"CREATE TABLE $tbl2 (cust varchar(200),b4amt double(10,2)default 0)");

mysqli_query($db,"insert into $tbl2 (cust,b4amt) select customer,sum(tot) from spareinvoice where customer='$row[acname]'");
mysqli_query($db,"insert into $tbl2 (cust,b4amt) select cust,sum(amt2) from veh_invoice where cessp='0' and  cust='$row[acname]'");

mysqli_query($db,"insert into $tbl2 (cust,b4amt) SELECT cname,sum(gtot) from  jobcard ,jcardparts where jobcard.jcno=jcardparts.jcno and jobcard.brcode=jcardparts.brcode and cname='$row[acname]' group by jobcard.cname order by jobcard.cname");

$re1=mysqli_query($db,"SELECT  cust,sum(b4amt) FROM $tbl2 where cust='$row[acname]'")or die(mysqli_error());

$rowb=mysqli_fetch_array($re1);
$custtot=$rowb[1];
if($custtot<='')
{
    $custtot=0;
}
*/
    $rei=mysqli_query($db,"select sum(tot)tot from sparepurchase where suplier='$row[supname]' and brcode = '$brcode' ")or die(mysqli_error());
    $inv_rowi=mysqli_fetch_row($rei);
    $custtot=$inv_rowi[0];
    

    //$sql="select msno from minput where cust='$row[code]' and brcode='$brcode'";
    //$result = mysql_query($sql);
    //$rowdt=mysql_fetch_array($result);
	 $json.= '{"orderto":"'.$row['web'].'","partname":"'.addslashes($gstvl).'","price":"'.addslashes($row['addr1']).'","supqty":"'.addslashes($row['city']).'","mrgnprc":"'.addslashes($custtot).'","custstt":"'.addslashes($row['state1']).'","shipin":"'.addslashes($row['pin1']).'","shidist":"'.addslashes($row['dist1']).'"},';
}
echo '['.trim($json,',').']';

?>