<?   
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, bpm.TakeOutDate, r.PricelistDate as PricelistDate, r.Model as Model, r.Project as Project, m.PermitToConstructNo as PermitToConstructNo, m.ConstructionBondPaid as ConstructionBondPaid,  m.RefundDate as RefundDate, m.FullRefundOrWithViolation as FullRefundOrWithViolation, m.Penalty as Penalty, m.Remarks as Remarks, m.Amount as Amount,
	m.ConstructionBondPaidAmount as ConstructionBondPaidAmount, m.Remarks2 as Remarks2,
	m.PaymentDetails as PaymentDetails, m.CheckReleaseDetails as CheckReleaseDetails 
	FROM reservation r 
	LEFT JOIN buyer_house_renovation_monitoring m ON m.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(); 
$userType	=	$_SESSION['castalia_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']; 
		 

		$arr1['id']						= $main[$a]['Id']; 
		$arr1['full_name']				= trim(html_entity_decode(stripslashes($main[$a]['FullName']))); 
		$arr1['take_out_date']			= date('m/d/Y', strtotime($main[$a]['TakeOutDate']));
		$arr1['phase']					= $main[$a]['Phase']; 
		$arr1['block']					= $main[$a]['Block']; 
		$arr1['lot']					= $main[$a]['Lot'];  
		 
		$arr1['PermitToConstructNo']		= trim(html_entity_decode(stripslashes($main[$a]['PermitToConstructNo']))); 
		$arr1['ConstructionBondPaid']		= date('m/d/Y', strtotime($main[$a]['ConstructionBondPaid']));
		$arr1['RefundDate']					= date('m/d/Y', strtotime($main[$a]['RefundDate'])); 
		$arr1['FullRefundOrWithViolation'] 	= $main[$a]['FullRefundOrWithViolation'];  
		$arr1['Penalty']					= $main[$a]['Penalty'];  
		$arr1['Remarks']					= $main[$a]['Remarks'];  
		$arr1['Amount']						= $main[$a]['Amount'];  
		
		$arr1['ConstructionBondPaidAmount'] = $main[$a]['ConstructionBondPaidAmount'];  
		$arr1['Remarks2']					= $main[$a]['Remarks2'];  
		$arr1['PaymentDetails']				= $main[$a]['PaymentDetails'];  
		$arr1['CheckReleaseDetails']		= $main[$a]['CheckReleaseDetails'];  
 
	$arr2[] = $arr1;
}
$arr3['data'] = $arr2;
echo json_encode($arr3); 
exit();
ob_end_flush();
