<?
session_start();
$brcode = $_SESSION['brcode'];
$user = $_SESSION['user'];
if(strlen($brcode)<=0)
{
 	print "<script> alert('Session timed out'); parent.document.location='../index.php'; </script>";
	return;
}
include("../opendb.php");
include("../test.php");
//include("../util/exqty.php");
//include("../util/exqty_23102018.php");
$marginprc=$_GET['marginprc'];

    $partcode=$_GET['key'];
    $mname=$_GET['mname'];
    
        $re=mysqli_query($db,"select a.partcode,a.partname,a.tax_sales from partmaster a where a.partcode like '$partcode%' order by partcode limit 15");
    

//$sql="select a.partcode,a.partname,a.tax_sales from partmaster a where a.partcode like '$partcode%' order by partcode limit 15";
//echo $sql;
$json="";
while($row=mysqli_fetch_array($re))
{
    //$availqty=exqty1($row[0],$brcode,$user);
   
    $re1=mysqli_query($db,"select lstprice,mrp from spareprmast where partcode='$row[0]' order by effectfrom desc limit 1");
    $row1=mysqli_fetch_array($re1);
    $unitprice=$row1[0];
	if($marginprc>0)
	{
		$unitprice=$unitprice+($unitprice*$marginprc/100);
		$unitprice=round($unitprice,2);
	}
	$re12=mysqli_query($db,"select location from spareopstock where itemcode='$row[0]' and brcode='$brcode'  limit 1");
	$sql="select location from spareopstock where itemcode='$row[0]'  limit 1";
	//echo $sql;
    $row12=mysqli_fetch_row($re12);
    $locat = trim($row12[0]);
   
    //echo $locat;
	$json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($availqty).'","price":"'.addslashes($unitprice).'","tax":"'.addslashes($row[2]).'","locat":"'.addslashes($locat).'","mrp":"'.addslashes($row1[1]).'"},';

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