<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
	{
		$objQuotationMgmt = new QuotationMgmt();

		$quotation_id = $_POST['quotation_id'];
		$objQuotationMgmt -> quotation_id			= $quotation_id;
		$objQuotationMgmt -> quotation_header		= $_POST['quotation_header'];
		$objQuotationMgmt -> quotation_footer		= $_POST['quotation_footer'];
		$objQuotationMgmt -> quotation_toname		= $_POST['quotation_toname'];
		$objQuotationMgmt -> quotation_toaddress	= $_POST['quotation_toaddress'];		
		$objQuotationMgmt -> quotation_referenceby 	= $_POST['quotation_reference'];
		$objQuotationMgmt -> quotation_subject	  	= $_POST['quotation_sub'];
		$objQuotationMgmt -> inquiry_id	  			= $_POST['inquiry_id'];
		$objQuotationMgmt -> quotation_date	  		= $_POST['quotation_date'];
		$objQuotationMgmt -> quotation_total        = $_POST['gross'];
		
		$objQuotationMgmt -> quotation_tax	  	= $_POST['quotation_tax'];
		$objQuotationMgmt -> quotation_cost	  			= $_POST['quotation_cost'];
		$objQuotationMgmt -> quotation_quantity	  		= $_POST['quotation_quantity'];
		$objQuotationMgmt -> quotation_total        = $_POST['quotation_total'];
			$objQuotationMgmt -> product_name    		= $_POST['product_name'];
		
		$objQuotationMgmt -> company_id	  			= $_SESSION['cCompany_id'];
		
		if($quotation_id == ""){
			$objQuotationMgmt -> add_quotationmaster();
		} else if($quotation_id != ""){
			$objQuotationMgmt -> edit_quotationmaster();
		}
	
		$griddata= stripcslashes( $_POST["griddata"]);
		$arr = array();
		$arr = json_decode($griddata,true);
		foreach($arr as $key => $value){
			if(sizeof($value)!="" || sizeof($value)!=0){		
				$objQuotationMgmt -> product_id    		= $value['product_id'];	
				$objQuotationMgmt -> product_qty   		= $value['product_qty'];
				$objQuotationMgmt -> product_rate  		= $value['product_price'];
				$objQuotationMgmt -> product_vat1  		= ($value['product_qty'] * $value['product_price'] * $value['product_vat1'])/100;
				$objQuotationMgmt -> product_vat2  		= ($value['product_qty'] * $value['product_price'] * $value['product_vat2'])/100;
				$objQuotationMgmt -> product_servicetax	= ($value['product_qty'] * $value['product_price'] * $value['product_servicetax'])/100;
				
				if($quotation_id == ""){
					$objQuotationMgmt -> add_quotationdetail();
				} else if($quotation_id != ""){
					$objQuotationMgmt -> edit_quotationdetail();
				}
				
			}
		}
	
		echo '{"success":"true"}';
	} else{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>