<?php
	require "../commonincludefiles.php";
	$condition="";
	$product_ids= Escape($_POST['product_ids']);
	$quotation_id = Escape($_POST['quotation_id']);
	
	if($product_ids !="") {
		
		$objQuotationMgmt = new QuotationMgmt();  
		
		if($_POST["formMode"] == "add") {
			$condition .= " AND pm.product_id in(".$product_ids.")";
			$result = $objQuotationMgmt->product_getAllRecords_ADD(0,0,$condition,$order_field,$order_type) ;
		}
		else if($_POST["formMode"] == "edit") {
			$condition .= " AND pm.product_id in(".$_POST["product_ids"].") AND qm.quotation_id = '".$quotation_id."' ";
			$result = $objQuotationMgmt->product_getAllRecords_EDIT(0,0,$condition,$order_field,$order_type) ;
		}
		
		$num = dbRows($result);
		$i = 0;   
		if(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["grouping"]  		  = "test";
				$temparray["product_id"]  		  = $row["product_id"];
				$temparray["product_name"]   	  = $row["product_name"];
				$temparray["product_measurement"] = $row["product_measurement"];
				$temparray["product_price"]  	  = $row["product_price"];
				
				if($_POST["formMode"] == "add") {
					$temparray["product_qty"]  	  = 1;
				}
				else if($_POST["formMode"] == "edit") {
					$temparray["product_qty"]  	  = $row["product_qty"];
				}
				
				$temparray["product_description"] = $row["product_description"];
				$temparray["product_vat1"] 		  = $row["product_vat1"];
				$temparray["product_vat2"]        = $row["product_vat2"];
				$temparray["product_servicetax"]  = $row["product_servicetax"];
				$griddata[$i] = $temparray;   
				$i++;
			}		
			echo '{"total":"'.$num.'","griddata":'.json_encode($griddata).'}';				
		} 
	}
?>
