<?php
error_reporting(0); //7dec25
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.EmployeeType as EmployeeType, r.NoCoBorrower as NoCoBorrower, r.CoBorrowerDetails as CoBorrowerDetails, c.SubmissionDate as SubmissionDate, c.BuyerStandardReqDetails, c.AdditionalReqDetails, c.IsThankYouLetterSent, c.ThankYouLetterSentDate, c.CoBorrower1StandardReqDetails, c.CoBorrower1AdditionalReqDetails, c.CoBorrower2StandardReqDetails, c.CoBorrower2AdditionalReqDetails, c.CoBorrower3StandardReqDetails, c.CoBorrower3AdditionalReqDetails, c.BillingDate, c.BarangayDate, c.NotarizedDate, c.PaySlipDate, c.ITRDate,c.OtherField,c.Co1ITRDate,c.Co1OtherField,c.Co2ITRDate,c.Co2OtherField,c.Co3ITRDate,c.Co3OtherField, c.Co1BillingDate, c.Co1BarangayDate, c.Co1NotarizedDate, c.Co1PaySlipDate, c.Co2BillingDate, c.Co2BarangayDate, c.Co2NotarizedDate, c.Co2PaySlipDate, c.Co3BillingDate, c.Co3BarangayDate, c.Co3NotarizedDate, c.Co3PaySlipDate,r.Model as Model, r.Project as Project, r.PricelistDate as PricelistDate, r.Phase as Phase, r.Block as Block, r.Lot as Lot, bpm.Financing as Financing, r.Spouse as Spouse FROM reservation r 
	LEFT JOIN checklist c ON c.ReservationId=r.Id
	LEFT JOIN buyer_payment_monitoring bpm ON bpm.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(); 
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);		
		$lot_size	=	$other['lot_size'];
		$floor_area	=	$other['floor_area']; 
		$loanable_amount	=	$other['loanable_amount']; 
		 
		
		$arr1['id']					= $main[$a]['Id']; 
		$arr1['standard_req']		= $main[$a]['BuyerStandardReqDetails']; 
		$arr1['financing']			= strtoupper($main[$a]['Financing']); 

		$arr1['spouse']				= strtoupper($main[$a]['Spouse']); 

		
		$arr1['additional_req']		= $main[$a]['AdditionalReqDetails']; 
		$arr1['coborrower1_standard_req']		= $main[$a]['CoBorrower1StandardReqDetails']; 
		$arr1['coborrower1_additional_req']		= $main[$a]['CoBorrower1AdditionalReqDetails']; 
		$arr1['coborrower2_standard_req']		= $main[$a]['CoBorrower2StandardReqDetails']; 
		$arr1['coborrower2_additional_req']		= $main[$a]['CoBorrower2AdditionalReqDetails']; 
		$arr1['coborrower3_standard_req']		= $main[$a]['CoBorrower3StandardReqDetails']; 
		$arr1['coborrower3_additional_req']		= $main[$a]['CoBorrower3AdditionalReqDetails']; 
		
		$arr1['employee_type']		= trim(html_entity_decode(stripslashes($main[$a]['EmployeeType']))); 
		$arr1['full_name']			= trim(html_entity_decode(stripslashes($main[$a]['FullName']))); 
		$arr1['num_borrower']		= trim(html_entity_decode(stripslashes($main[$a]['NoCoBorrower'])));
		$arr1['details']			= trim(html_entity_decode(stripslashes($main[$a]['CoBorrowerDetails'])));
		$arr1['thank_you_sent']		= trim(html_entity_decode(stripslashes($main[$a]['IsThankYouLetterSent'])));
		$arr1['thank_you_date']		= date("m/d/Y", strtotime($main[$a]['ThankYouLetterSentDate']));
		$arr1['submission_date']	= date("m/d/Y", strtotime($main[$a]['SubmissionDate']));
		$arr1['billing_date']		= date("m/d/Y", strtotime($main[$a]['BillingDate']));
		$arr1['barangay_date']		= date("m/d/Y", strtotime($main[$a]['BarangayDate']));
		$arr1['notarized_date']		= date("m/d/Y", strtotime($main[$a]['NotarizedDate']));
		$arr1['payslip_date']		= date("m/d/Y", strtotime($main[$a]['PaySlipDate']));

		$arr1['itr_date']			= date("m/d/Y", strtotime($main[$a]['ITRDate']));
		$arr1['other_field']		= date("m/d/Y", strtotime($main[$a]['OtherField']));
		
		$arr1['billing_date1']		= date("m/d/Y", strtotime($main[$a]['Co1BillingDate']));
		$arr1['barangay_date1']		= date("m/d/Y", strtotime($main[$a]['Co1BarangayDate']));
		$arr1['notarized_date1']	= date("m/d/Y", strtotime($main[$a]['Co1NotarizedDate']));
		$arr1['payslip_date1']		= date("m/d/Y", strtotime($main[$a]['Co1PaySlipDate']));
		
		$arr1['itr_date1']			= date("m/d/Y", strtotime($main[$a]['Co1ITRDate']));
		$arr1['other_field1']		= date("m/d/Y", strtotime($main[$a]['Co1OtherField']));
		
		$arr1['billing_date2']		= date("m/d/Y", strtotime($main[$a]['Co2BillingDate']));
		$arr1['barangay_date2']		= date("m/d/Y", strtotime($main[$a]['Co2BarangayDate']));
		$arr1['notarized_date2']	= date("m/d/Y", strtotime($main[$a]['Co2NotarizedDate']));
		$arr1['payslip_date2']		= date("m/d/Y", strtotime($main[$a]['Co2PaySlipDate']));

		$arr1['itr_date2']			= date("m/d/Y", strtotime($main[$a]['Co2ITRDate']));
		$arr1['other_field2']		= date("m/d/Y", strtotime($main[$a]['Co2OtherField']));
		
		$arr1['billing_date3']		= date("m/d/Y", strtotime($main[$a]['Co3BillingDate']));
		$arr1['barangay_date3']		= date("m/d/Y", strtotime($main[$a]['Co3BarangayDate']));
		$arr1['notarized_date3']	= date("m/d/Y", strtotime($main[$a]['Co3NotarizedDate']));
		$arr1['payslip_date3']		= date("m/d/Y", strtotime($main[$a]['Co3PaySlipDate']));

		$arr1['itr_date3']			= date("m/d/Y", strtotime($main[$a]['Co3ITRDate']));
		$arr1['other_field3']		= date("m/d/Y", strtotime($main[$a]['Co3OtherField']));
		  
		$arr1['lot_size']				= $lot_size;
		$arr1['floor_area']				= $floor_area; 
		$arr1['loanable_amount']		= $loanable_amount; 
		$arr1['phase']					= $main[$a]['Phase']; 
		$arr1['block']					= $main[$a]['Block']; 
		$arr1['lot']					= $main[$a]['Lot']; 
	$arr2[] = $arr1;
}
$arr3['data'] = $arr2;
echo json_encode($arr3); 
exit();
ob_end_flush();