<?php 
include_once 'db_functions.php'; 
$db = new DB_Functions(); 
$json = $_POST["saleJSON"];
if (get_magic_quotes_gpc()){ 
	$json = stripslashes($json); 
}
//Decode JSON into an Array 
$data = json_decode($json); 
//Util arrays to create response JSON 
$a=array();
$b=array();
for($i=0; $i<count($data) ; $i++) {
	//Store User into MySQL DB 
	$res = $db-> getSaleReport($data[$i]->userid,$data[$i]->fromdate,$data[$i]->todate);
	if($res){
		$row = mysql_fetch_assoc($res);
		$res_prod = $db->productDetail($row["prod_code"]);
    	$row_prod = mysql_fetch_array($res_prod);
		$b["prod_name"] = $row_prod["productname"];
		$b["prod_code"] = $row["prod_code"];
		$b["orderqty"] = $row["req_qty"];
		$b["billqty"] = $row["qty"];
	}else{
		$b["error"] = "Something went wrong";
	}	
	//Based on inserttion, create JSON response     
	array_push($a,$b);
}
echo json_encode($a); 
?>