<?   
error_reporting(0);
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
session_start();
session_cache_limiter('private');
$cache_limiter 	= session_cache_limiter();
session_cache_expire(60);
$cache_expire 	= session_cache_expire(); 
date_default_timezone_set('Asia/Manila'); 
$CURRENT_DATE 	= date('Y-m-d H:i:s');
include_once('../config/minho.php');
include_once('../config/autoloadClass.php');
$autoload	=	new autoloadClass();
$mecon		=	new condbClass();
$formClass		=	new formClass();
$main		=	array();
$main2		=	array();
$arr3		=	array();
$main3		=	array();
$main4		=	array();
$mainId		=	(isset($_POST['mainid'])) ? $_POST['mainid'] : ""; 
 
$mecon->query("SELECT r.Id as Id, CONCAT(r.LastName,', ',r.FirstName,' ',r.MiddleName) as FullName, r.Phase as Phase, r.Block as Block, r.Lot as Lot, m.DateRFDeposited, m.StartOfEquity, m.TCP, m.LoanableAmount, m.NetEquity, m.Discount, m.PDCSubmitted, m.TermsOfPayment, m.Interest, m.LackingPDC, m.MonthlyEquity, m.RemarksOnEquity, m.PaymentsMade, m.TakeOutAmount, m.TakeOutDate, m.MRI, m.DifferenceApprovedVSLoanable, m.Misc, m.PagibigLoanableAmount, m.MoveInMRI, m.MoveInOthers, m.RefillingFee, m.PagibigUpgrading, m.PagibigLoanUpdate, m.CollectedDate, m.Adjustment, m.DepositedDate, m.MoveInAmount, r.ReservationDate, r.Model, r.Project, m.PaymentMode as PaymentMode, m.ApprovedLoanable as ApprovedLoanable, m.ApprovedEquityDate as ApprovedEquityDate, r.PricelistDate as PricelistDate FROM reservation r LEFT JOIN buyer_payment_monitoring m ON m.ReservationId=r.Id WHERE r.Status = :status AND r.Id = :id ORDER BY r.Id DESC"); 
$mecon->bind(':status', 'active');
$mecon->bind(':id', $mainId);
$main = $mecon->resultset(); 
$counter = count($main); 
$arr1 = array();
$arr2 = array();
$arr3 = array(); 
$other = array(); 
$userType	=	$_SESSION['danvillee_user_type'];
for($a=0; $a<$counter; $a++){ 
		$models						= $main[$a]['Model']; 
		$project					= $main[$a]['Project']; 
		$pricedate					= $main[$a]['PricelistDate']; 
		$phase						= $main[$a]['Phase']; 
		$block						= $main[$a]['Block']; 
		$lot						= $main[$a]['Lot']; 
		$other = $formClass->getOtherDetails($pricedate,$models,$project,$phase,$block,$lot);		
		/**********************/
		
 
		
		//GET MOVEIN FEE
		$mecon->query("SELECT MoveInFee FROM model WHERE Status = :status AND Model = :model ORDER BY Model DESC");
		$mecon->bind(':status', 'active');
		$mecon->bind(':model', $models);
		$mainf	= $mecon->resultset();
		$movein	= $mainf[$a]['MoveInFee'];

		$arr1['id']					= $main[$a]['Id'];
		$arr1['tcp']				= str_replace(',','',$other['contract_price']);
		$arr1['loanable_amount']	= str_replace(',','',$other['loanable_amount']);
		$arr1['net_equity']			= str_replace(',','',$other['pf_net']);
		$arr1['discount']			= str_replace(',','',$other['discount']);
		$arr1['payment_terms']		= $other['detail_terms']; 
		$arr1['monthly_equity']		= str_replace(',','',$other['pf_payable']);
	$arr2[] = $arr1;
}
$arr3['data'] = $arr2;
echo json_encode($arr3); 
exit();
ob_end_flush();

