<?php
include_once 'db_functions.php';     
$db = new DB_Functions();  
////// initialize array
$a = array();     
$b = array();
////// get request parameter
$rtc = $_REQUEST['retailerCode'];//// mandatory
$pdc = $_REQUEST['productCode'];///// optional
////// get stock on the basis of retailer or product code(optional)
$res_stock = $db->stockList($rtc,$pdc);
///// if query is executed
if($res_stock != false){ 
	////// fetch stock data
	while($row_stock = mysql_fetch_assoc($res_stock)){	   
		$b["retailercode"] = $row_stock["asc_code"];
		//// retailer name
		$res_loc = $db->getLocationDetail($row_stock["asc_code"]);
		$row_loc = mysql_fetch_array($res_loc);
		$b["retailername"] = $row_loc["name"];
		$b["retailercity"] = $row_loc["city"];
		$b["retailerstate"] = $row_loc["state"];
		//// product details
		$b["prodcode"] = $row_stock["partcode"];
		$res_prod = $db->productDetail($row_stock["partcode"]);
		$row_prod = mysql_fetch_array($res_prod);
		$b["pname"] = $row_prod["productname"];
		$b["pcode"] = $row_prod["productcode"];
		$b["pcolor"] = $row_prod["productcolor"];
		$b["pcat"] = $row_prod["productcat"];
		$b["pbrand"] = $row_prod["brand"];
		$b["pfeature"] = $row_prod["feature_type"];
		$b["okqty"] = $row_stock["okqty"];
		$b["damageqty"] = $row_stock["broken"];
		$b["missingqty"] = $row_stock["missing"];
		$b["uom"] = $row_stock["uom"];	
		array_push($a,$b);
	}	
	echo json_encode($a);
}
?>