<?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, r.ReservationDate, m.HouseAcceptance, m.Reinspection, m.Inspection, m.HomeownerOrientation, m.Conducted, m.BuyerOrientationDate, pm.TakeOutDate, m.PermitToOccupy, m.PermitToOccupyNumber, m.PTOStatus, m.LetterSent, r.PricelistDate as PricelistDate, r.Model as Model, r.Project as Project FROM reservation r LEFT JOIN buyer_status_monitoring m ON m.ReservationId=r.Id LEFT JOIN buyer_payment_monitoring pm ON pm.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(); 
$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);		
		$lot_size	=	$other['lot_size'];
		$floor_area	=	$other['floor_area'];

		$arr1['id']						= $main[$a]['Id']; 
		$arr1['full_name']				= trim(html_entity_decode(stripslashes($main[$a]['FullName']))); 
		$arr1['reservation_date']		= date('m/d/Y', strtotime($main[$a]['ReservationDate']));
		$arr1['orientation_date']		= date('m/d/Y', strtotime($main[$a]['BuyerOrientationDate']));
		$arr1['conducted']				= trim(html_entity_decode(stripslashes($main[$a]['Conducted']))); 
		$arr1['pagibig_takeout_date']	= date('m/d/Y', strtotime($main[$a]['TakeOutDate']));
		$arr1['homeowner_orientation']	= date('m/d/Y', strtotime($main[$a]['HomeownerOrientation']));
		$arr1['inspection']				= date('m/d/Y', strtotime($main[$a]['Inspection']));
		$arr1['reinspection']			= date('m/d/Y', strtotime($main[$a]['Reinspection']));
		$arr1['house_acceptance']		= date('m/d/Y', strtotime($main[$a]['HouseAcceptance'])); 
		$arr1['permit_to_occupy']		= date('m/d/Y', strtotime($main[$a]['PermitToOccupy'])); 
		$arr1['letter_sent']			= date('m/d/Y', strtotime($main[$a]['LetterSent'])); 
		$arr1['lot_size']				= $lot_size;
		$arr1['floor_area']				= $floor_area; 
		$arr1['phase']					= $main[$a]['Phase']; 
		$arr1['block']					= $main[$a]['Block']; 
		$arr1['lot']					= $main[$a]['Lot']; 
		$arr1['permit_to_occupy_number']	= $main[$a]['PermitToOccupyNumber']; 
		$arr1['pto_status']				= $main[$a]['PTOStatus']; 


	$arr2[] = $arr1;
}
$arr3['data'] = $arr2;
echo json_encode($arr3); 
exit();
ob_end_flush();