<?   
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, bp.TakeOut, 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, m.Financing as Financing FROM reservation r LEFT JOIN buyer_payment_monitoring m ON m.ReservationId=r.Id 
	LEFT JOIN buyer_status_folder_pagibig bp ON bp.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['danvilles_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['block']				= trim(html_entity_decode(stripslashes($main[$a]['Block']))); 
		$arr1['lot']				= trim(html_entity_decode(stripslashes($main[$a]['Lot']))); 
		$arr1['full_name']			= trim(html_entity_decode(stripslashes($main[$a]['FullName']))); 
		$arr1['model']				= trim(html_entity_decode(stripslashes($main[$a]['Model']))); 
		
		$arr1['date_rf_deposited']	= date('m/d/Y', strtotime($main[$a]['DateRFDeposited']));
		
		$arr1['reservation_date']	= (!empty($main[$a]['ReservationDate'])) ? date('m/d/Y', strtotime($main[$a]['ReservationDate'])) : date('m/d/Y', strtotime($main[$a]['ReservationDate']));
		
		$arr1['approved_equity_date']	= (!empty($main[$a]['ApprovedEquityDate'])) ? date('m/d/Y', strtotime($main[$a]['ApprovedEquityDate'])) : date('m/d/Y', strtotime($main[$a]['ApprovedEquityDate']));
		
		
		
		
		$arr1['approved_loanable']	= (!empty($main[$a]['ApprovedLoanable'])) ? number_format(trim(html_entity_decode(stripslashes($main[$a]['ApprovedLoanable']))),2) : ""; 
		
		$arr1['payment_mode']	= (!empty($main[$a]['PaymentMode'])) ? trim(html_entity_decode(stripslashes($main[$a]['PaymentMode']))) : ""; 
		
		$arr1['financing']	= (!empty($main[$a]['Financing'])) ? trim(html_entity_decode(stripslashes($main[$a]['Financing']))) : "";


		$arr1['start_of_equity']	= (!empty($main[$a]['StartOfEquity'])) ? date('m/d/Y', strtotime($main[$a]['StartOfEquity'])) : date('m/d/Y', strtotime($main[$a]['ReservationDate']." +30 days"));
		
		$arr1['tcp']				= ($main[$a]['TCP']!=0.00) ?  trim(html_entity_decode(stripslashes($main[$a]['TCP']))) : str_replace(',','',$other['contract_price']); 

		
		
		$arr1['loanable_amount']	= ($main[$a]['LoanableAmount']!=0.00) ? trim(html_entity_decode(stripslashes($main[$a]['LoanableAmount']))) : $other['loanable_amount']; 
		$arr1['net_equity']			= ($main[$a]['NetEquity']!=0.00) ? trim(html_entity_decode(stripslashes($main[$a]['NetEquity']))) :  $other['pf_net']; 
		$arr1['discount']			= ($main[$a]['Discount']!=0.00) ? trim(html_entity_decode(stripslashes($main[$a]['Discount']))) : $other['discount_amount']; //28JUL24 update from $other['discount'] to $other['discount_amount']

		$arr1['pdc_submitted']		= (!empty($main[$a]['PDCSubmitted'])) ? trim(html_entity_decode(stripslashes($main[$a]['PDCSubmitted']))) : ""; 
		 
		$arr1['payment_terms']		= ($main[$a]['TermsOfPayment']!=NULL) ? trim(html_entity_decode(stripslashes($main[$a]['TermsOfPayment']))) : $other['detail_terms'];
		 
		$arr1['lacking_pdc']		= (!empty($main[$a]['LackingPDC'])) ? trim(html_entity_decode(stripslashes($main[$a]['LackingPDC']))) : ""; 
		$arr1['monthly_equity']		= ($main[$a]['MonthlyEquity']!=0.00) ? trim(html_entity_decode(stripslashes($main[$a]['MonthlyEquity']))) : $other['pf_payable'];
		$arr1['remarks_on_equity'] 	= trim(html_entity_decode(stripslashes($main[$a]['RemarksOnEquity']))); 
		$arr1['payments_made'] 		= trim(html_entity_decode(stripslashes($main[$a]['PaymentsMade']))); 
		$arr1['takeout_amount']		= trim(html_entity_decode(stripslashes($main[$a]['TakeOutAmount']))); 
		
		$arr1['takeout_date']		= date('m/d/Y', strtotime($main[$a]['TakeOut'])); 
		$arr1['mri']				= trim(html_entity_decode(stripslashes($main[$a]['MRI']))); 
		$arr1['difference']			= trim(html_entity_decode(stripslashes($main[$a]['DifferenceApprovedVSLoanable']))); 
		$arr1['misc']				= trim(html_entity_decode(stripslashes($main[$a]['Misc']))); 
		$arr1['adjustment']				= trim(html_entity_decode(stripslashes($main[$a]['Adjustment']))); 
		$arr1['pagibig_loanable_amount']	= trim(html_entity_decode(stripslashes($main[$a]['PagibigLoanableAmount']))); 
		 
		$arr1['movein_mri']			= number_format(trim(html_entity_decode(stripslashes($main[$a]['MoveInMRI']))),2);  
		$arr1['movein_others']		= number_format(trim(html_entity_decode(stripslashes($main[$a]['MoveInOthers']))),2);  

		$arr1['refilling_fee']		= number_format(trim(html_entity_decode(stripslashes($main[$a]['RefillingFee']))),2); 
		$arr1['pagibig_upgrading']	= number_format(trim(html_entity_decode(stripslashes($main[$a]['PagibigUpgrading']))),2); 
		$arr1['pagibig_loanupdate']	= number_format(trim(html_entity_decode(stripslashes($main[$a]['PagibigLoanUpdate']))),2);
		 
		$arr1['collected_date']		= date('m/d/Y', strtotime($main[$a]['CollectedDate']));
		$arr1['deposited_date']		= date('m/d/Y', strtotime($main[$a]['DepositedDate'])); 
		$arr1['movein_amount']		= (!empty($main[$a]['MoveInAmount'])) ? trim(html_entity_decode(stripslashes($main[$a]['MoveInAmount']))) : $movein; 
		
		$arr1['lot_size']	=	$other['lot_size'];
		$arr1['floor_area']	=	$other['floor_area'];
		$arr1['phase']		=	$phase;		

		$arr1['reservationfee'] =	$other['reservationfee'];  //28JUL24 add reservation fee
		
		$arr1['pricelist_date']	= (!empty($main[$a]['PricelistDate'])) ? date('m/d/Y', strtotime($main[$a]['PricelistDate'])) : date('m/d/Y', strtotime($main[$a]['PricelistDate']));
	$arr2[] = $arr1;
}
$arr3['data'] = $arr2;
echo json_encode($arr3); 
exit();
ob_end_flush();

