<?php 
require "../commonincludefiles.php";

if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
{	

	$objQuotationMgmt = new QuotationMgmt();
	
	$action = $_REQUEST['action'];
	
	$arr = array();
	
	if($action == "reference"){
		$result = $objQuotationMgmt->getDistinctReferenceBy();
		$total = dbRows($result);
		$i=0;
		$refbyData = array("count" => $total, "rows" => array());
		if(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["quotation_referenceby"]  = $row["quotation_referenceby"];
				$refbyData["rows"][$i] = $temparray;   
				$i++;
			}										
		}
		echo json_encode($refbyData);	
	}else if($action == "subject"){
		$result = $objQuotationMgmt->getDistinctSubject();
		$total = dbRows($result);
		$i=0;
		$subjectData = array("count" => $total, "rows" => array());
		if(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["quotation_subject"]  = $row["quotation_subject"];
				$subjectData["rows"][$i] = $temparray;   
				$i++;
			}										
		}
		echo json_encode($subjectData);	
	}
	else if($action == "product"){
		$result = $objQuotationMgmt->getDistinctproduct();
		$total = dbRows($result);
		$i=0;
		$subjectData = array("count" => $total, "rows" => array());
		if(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["product_subject"]  = $row["product_name"];
				$productData["rows"][$i] = $temparray;   
				$i++;
			}										
		}
		echo json_encode($productData);	
	}

}
?>