<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$tbl2="partmaster";
$partcode=$_GET['key'];
if(isset($_GET['type'])=='name')
{
	
	$re=mysqli_query($db,"select * from $tbl2 where partname like '%$partcode%' limit 10 ") or die("ERR6:".mysqli_error($db));
}
else
{
	$re=mysqli_query($db,"select * from $tbl2 where partcode  like '$partcode%' order by partcode asc limit 1 ") or die("ERR6:".mysqli_error($db));
}
$json="";

while($row=mysqli_fetch_array($re))
{
    /*$query="select grp_tax from groupmaster where gname='$row[2]'";
    $rs=mysqli_query($db,$query);
    $rw=mysqli_fetch_array($rs);*/
    $query1="select lstprice from spareprmast where partcode='$row[0]'";
    $rs1=mysqli_query($db,$query1);
    $rw1=mysqli_fetch_array($rs1);
    //$query2="select curstk,curstk_dam from sparestock where itemcode='$row[0]'";
    //$rs2=mysqli_query($db,$query2);
    //$rw2=mysqli_fetch_array($rs2);
    $oldprtc=$row[0];
    //if($rw2[1]!=0)
    //{
        //$json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($rw2[0].", D:".$rw2[1]).'","rate":"'.addslashes($rw1[0]).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';
    //}
    //else
    //{
    $json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($rw2[0]).'","rate":"'.addslashes($rw1[0]).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';
    //}
}
/*
if(isset($_GET['type'])=='name')
{

	$re=mysqli_query($db,"select * from $tbl2 where brcode = '$brcode' and partname like '%$partcode%' limit 10 ") or die("ERR6:".mysqli_error($db));
}
else
{
*/
	$re=mysqli_query($db,"select * from $tbl2 where partcode  like '%$partcode%' and partcode!='$oldprtc' order by partcode asc limit 9 ") or die("ERR6:".mysqli_error($db));
//}

while($row=mysqli_fetch_array($re))
{
    //$query="select grp_tax from groupmaster where gname='$row[2]'";
    //$rs=mysqli_query($db,$query);
    //$rw=mysqli_fetch_array($rs);
    //print $query;
    $query1="select lstprice from spareprmast where partcode='$row[0]' ";
    $rs1=mysqli_query($db,$query1);
    $rw1=mysqli_fetch_array($rs1);
    
    //$query2="select curstk,curstk_dam from sparestock where itemcode='$row[0]' and brcode='$brcode'";
    //$rs2=mysqli_query($db,$query2);
    //$rw2=mysqli_fetch_array($rs2);
    //if($rw2[1]!=0)
    //{
    //$json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($rw2[0].", D:".$rw2[1]).'","rate":"'.addslashes($rw1[0]).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';
    //}
    //else
    //{
    $json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($rw2[0]).'","rate":"'.addslashes($rw1[0]).'","reduct":"'.addslashes($row[10]).'","tax":"'.addslashes($rw[0]).'"},';
    //}
}

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