<?   
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();
$main		=	array();
$main2		=	array();
$arr3		=	array();
$main3		=	array();
$main4		=	array();
$mainId		=	(isset($_POST['mainid']))	?	$_POST['mainid']	:	"";
$mecon->query("SELECT u.Id as Id, u.Block as Block, u.Lot as Lot, u.Status as Status, pl.TaxDecLandProcessed as TaxDecLandProcessed
	, pl.TaxDecLandReleased as TaxDecLandReleased, pl.TaxDecBuildingProcessed as TaxDecBuildingProcessed, pl.TaxDecBuildingReleased as TaxDecBuildingReleased, pl.TaxReceiptLandProcessed as TaxReceiptLandProcessed, pl.TaxReceiptLandReleased as TaxReceiptLandReleased 
    , pl.TaxReceiptBuildingProcessed as TaxReceiptBuildingProcessed, pl.TaxReceiptBuildingReleased as TaxReceiptBuildingReleased, pl.BuildingPermitProcessed as BuildingPermitProcessed, pl.BuildingPermitReleased as BuildingPermitReleased, pl.ElectricalPermitProcessed as ElectricalPermitProcessed, pl.ElectricalPermitReleased as ElectricalPermitReleased, pl.SanitaryPermitProcessed as SanitaryPermitProcessed, pl.SanitaryPermitReleased as SanitaryPermitReleased, pl.OccupancyPermitProcessed as OccupancyPermitProcessed
    , pl.OccupancyPermitReleased as OccupancyPermitReleased	FROM units u LEFT JOIN permits_and_licenses pl ON pl.Id=u.Id WHERE u.Status = :status AND u.Id = :id ORDER BY 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++){ 
		$arr1['id']							=	$main[$a]['Id'];
		$arr1['block']						= 	trim(stripslashes(html_entity_decode($main[$a]['Block']))); 
		$arr1['lot']						=	trim(stripslashes(html_entity_decode($main[$a]['Lot']))); 
		$arr1['tax_dec_land_processed']		=	(($main[$a]['TaxDecLandProcessed']=='1970-01-01') || ($main[$a]['TaxDecLandProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxDecLandProcessed']));
		$arr1['tax_dec_land_released']		=	(($main[$a]['TaxDecLandReleased']=='1970-01-01') || ($main[$a]['TaxDecLandReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxDecLandReleased']));
		$arr1['tax_dec_building_processed']	=	(($main[$a]['TaxDecBuildingProcessed']=='1970-01-01') || ($main[$a]['TaxDecBuildingProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxDecBuildingProcessed']));

		$arr1['tax_dec_building_released']	=	(($main[$a]['TaxDecBuildingReleased']=='1970-01-01') || ($main[$a]['TaxDecBuildingReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxDecBuildingReleased']));
 
		$arr1['tax_receipt_land_processed']	=	(($main[$a]['TaxReceiptLandProcessed']=='1970-01-01') || ($main[$a]['TaxReceiptLandProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxReceiptLandProcessed']));

		$arr1['tax_receipt_land_released']	=	(($main[$a]['TaxReceiptLandReleased']=='1970-01-01') || ($main[$a]['TaxReceiptLandReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxReceiptLandReleased']));

$arr1['tax_receipt_building_processed']	=	(($main[$a]['TaxReceiptBuildingProcessed']=='1970-01-01') || ($main[$a]['TaxReceiptBuildingProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxReceiptBuildingProcessed']));

$arr1['tax_receipt_building_released']	=	(($main[$a]['TaxReceiptBuildingReleased']=='1970-01-01') || ($main[$a]['TaxReceiptBuildingReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['TaxReceiptBuildingReleased']));

$arr1['building_permit_processed']	=	(($main[$a]['BuildingPermitProcessed']=='1970-01-01') || ($main[$a]['BuildingPermitProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['BuildingPermitProcessed']));

$arr1['building_permit_released']	=	(($main[$a]['BuildingPermitReleased']=='1970-01-01') || ($main[$a]['BuildingPermitReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['BuildingPermitReleased']));

$arr1['electrical_permit_processed']	=	(($main[$a]['ElectricalPermitProcessed']=='1970-01-01') || ($main[$a]['ElectricalPermitProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['ElectricalPermitProcessed']));

$arr1['electrical_permit_released']	=	(($main[$a]['ElectricalPermitReleased']=='1970-01-01') || ($main[$a]['ElectricalPermitReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['ElectricalPermitReleased']));

$arr1['sanitary_permit_processed']	=	(($main[$a]['SanitaryPermitProcessed']=='1970-01-01') || ($main[$a]['SanitaryPermitProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['SanitaryPermitProcessed']));

$arr1['sanitary_permit_released']	=	(($main[$a]['SanitaryPermitReleased']=='1970-01-01') || ($main[$a]['SanitaryPermitReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['SanitaryPermitReleased']));

$arr1['occupancy_permit_processed']	=	(($main[$a]['OccupancyPermitProcessed']=='1970-01-01') || ($main[$a]['OccupancyPermitProcessed']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['OccupancyPermitProcessed']));

$arr1['occupancy_permit_released']	=	(($main[$a]['OccupancyPermitReleased']=='1970-01-01') || ($main[$a]['OccupancyPermitReleased']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['OccupancyPermitReleased']));
    




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