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

    $partcode=$_GET['key'];
    $mname=$_GET['mname'];
    if($mname>'')
    {
        $re=mysqli_query($db,"select a.partcode,a.partname,a.tax_sales from partmaster a where model='$mname' and a.partcode like '%$partcode%' order by partcode limit 1")or die(mysqli_error($db));
    }
    else
    {
        $re=mysqli_query($db,"select a.partcode,a.partname,a.tax_sales from partmaster a where a.partcode like '%$partcode%' order by partcode limit 1")or die(mysqli_error($db));
    }
$sql="select a.partcode,a.partname,a.tax_sales from partmaster a where a.partcode like '%$partcode%' order by partcode limit 1";
//echo $sql;
$json="";
while($row=mysqli_fetch_array($re))
{
    $availqty=exqty1($row[0],$brcode,$user,$db);
    $supqty=$availqty;
    $re1=mysqli_query($db,"select lstprice from spareprmast where partcode='$row[0]' ");
    $row1=mysqli_fetch_array($re1);
    $taxqry="select tax_cgst,tax_sgst,tax_igst from taxmaster where tax='$row[tax_sales]'";
        //echo $taxqry;
        $taxres=mysqli_query($db,$taxqry);
        
        $taxrow=mysqli_fetch_array($taxres);
        $cgstvl=$taxrow[0];
        $sgstvl=$taxrow[1];
        $igstvl=$taxrow[2];
        
        $json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","rate":"'.addslashes($row1[0]).'","supqty":"'.addslashes($supqty).'","cgstrt":"'.addslashes($cgstvl).'","sgstrt":"'.addslashes($sgstvl).'","igstrt":"'.addslashes($igstvl).'"},';
        
	 //$json.= '{"partcode":"'.$row[0].'","partname":"'.addslashes($row[1]).'","stock":"'.addslashes($availqty).'","price":"'.addslashes($row1[0]).'","tax":"'.addslashes($row[2]).'"},';
}
echo '['.trim($json,',').']';
?>
