<?php
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, rb.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, m.Financing as Financing FROM reservation r LEFT JOIN buyer_payment_monitoring m ON m.ReservationId=r.Id 
	LEFT JOIN releases_to_broker rb ON rb.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['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'])) ? trim(html_entity_decode(stripslashes($main[$a]['ApprovedLoanable']))) : ""; 
		
		$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']				= (!empty($main[$a]['TCP'])) ?  trim(html_entity_decode(stripslashes($main[$a]['TCP']))) : $other['contract_price']; 
		
		$arr1['loanable_amount']	= (!empty($main[$a]['LoanableAmount'])) ? trim(html_entity_decode(stripslashes($main[$a]['LoanableAmount']))) : $other['loanable_amount']; 
		$arr1['net_equity']			= (!empty($main[$a]['NetEquity'])) ? trim(html_entity_decode(stripslashes($main[$a]['NetEquity']))) :  $other['pf_net']; 
		$arr1['discount']			= (!empty($main[$a]['Discount'])) ? trim(html_entity_decode(stripslashes($main[$a]['Discount']))) : $other['discount'];
		$arr1['pdc_submitted']		= (!empty($main[$a]['PDCSubmitted'])) ? trim(html_entity_decode(stripslashes($main[$a]['PDCSubmitted']))) : ""; 
		 
		$arr1['payment_terms']		= (!empty($main[$a]['TermsOfPayment'])) ? 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']		= (!empty($main[$a]['MonthlyEquity'])) ? 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]['TakeOutDate'])); 
		$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']			= trim(html_entity_decode(stripslashes($main[$a]['MoveInMRI']))); 
		$arr1['movein_others']		= trim(html_entity_decode(stripslashes($main[$a]['MoveInOthers']))); 
		$arr1['refilling_fee']		= trim(html_entity_decode(stripslashes($main[$a]['RefillingFee']))); 
		$arr1['pagibig_upgrading']	= trim(html_entity_decode(stripslashes($main[$a]['PagibigUpgrading']))); 
		$arr1['pagibig_loanupdate']	= trim(html_entity_decode(stripslashes($main[$a]['PagibigLoanUpdate']))); 
		$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['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();

