<?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();
$utility	=	new utilityClass(); 
//if(isset($_POST['checklist_submission_date'])){
$task					= isset($_POST['action'])						? trim($_POST['action']) : "";
$mainid					= isset($_POST['mainid'])						? trim($_POST['mainid']) : ""; 
$submissionDate			= isset($_POST['checklist_submission_date']) 	? trim($_POST['checklist_submission_date']) : "";  
$standardReq			= isset($_POST['standard_requirements']) 		? $_POST['standard_requirements'] : ""; 
$additionalReq			= isset($_POST['additional_requirements']) 		? $_POST['additional_requirements'] : "";
$proofBillingDate		= isset($_POST['proof_of_billing_date']) 		? trim($_POST['proof_of_billing_date']) : ""; 
$barangayClearanceDate	= isset($_POST['barangay_clearance_date']) 		? trim($_POST['barangay_clearance_date']) : ""; 
$notarizedDate			= isset($_POST['notarized_date']) 				? trim($_POST['notarized_date']) : ""; 
$lastMonthDate			= isset($_POST['last_month_date']) 				? trim($_POST['last_month_date']) : "";

$standardReq1			= isset($_POST['standard_requirements1']) 		? $_POST['standard_requirements1'] 		: ""; 
$additionalReq1			= isset($_POST['additional_requirements1']) 	? $_POST['additional_requirements1'] 	: ""; 
$proofBillingDate1		= isset($_POST['proof_of_billing_date1']) 		? trim($_POST['proof_of_billing_date1']) : ""; 
$barangayClearanceDate1	= isset($_POST['barangay_clearance_date1']) 	? trim($_POST['barangay_clearance_date1']) : ""; 
$notarizedDate1			= isset($_POST['notarized_date1']) 				? trim($_POST['notarized_date1']) : ""; 
$lastMonthDate1			= isset($_POST['last_month_date1']) 			? trim($_POST['last_month_date1']) : "";

$standardReq2			= isset($_POST['standard_requirements2']) 		? $_POST['standard_requirements2'] : ""; 
$additionalReq2			= isset($_POST['additional_requirements2']) 	? $_POST['additional_requirements2'] : ""; 
$proofBillingDate2		= isset($_POST['proof_of_billing_date2']) 		? trim($_POST['proof_of_billing_date2']) : ""; 
$barangayClearanceDate2	= isset($_POST['barangay_clearance_date2']) 	? trim($_POST['barangay_clearance_date2']) : ""; 
$notarizedDate2			= isset($_POST['notarized_date2']) 				? trim($_POST['notarized_date2']) : ""; 
$lastMonthDate2			= isset($_POST['last_month_date2']) 			? trim($_POST['last_month_date2']) : "";

$standardReq3			= isset($_POST['standard_requirements3']) 		? $_POST['standard_requirements3'] : ""; 
$additionalReq3			= isset($_POST['additional_requirements3']) 	? $_POST['additional_requirements3'] : ""; 
$proofBillingDate3		= isset($_POST['proof_of_billing_date3']) 		? $_POST['proof_of_billing_date3'] : "00/00/0000"; 
$barangayClearanceDate3	= isset($_POST['barangay_clearance_date3']) 	? trim($_POST['barangay_clearance_date3']) : "00/00/0000"; 
$notarizedDate3			= isset($_POST['notarized_date3']) 				? trim($_POST['notarized_date3']) : "00/00/0000"; 
$lastMonthDate3			= isset($_POST['last_month_date3']) 				? trim($_POST['last_month_date3']) : "00/00/0000";

$thankYouDate			= isset($_POST['thank_you_date']) 				? trim($_POST['thank_you_date']) : ""; 
$thankYouLetterSent		= isset($_POST['thank_you_letter_sent']) 		? trim($_POST['thank_you_letter_sent']) : "";

$financing		= isset($_POST['checklist_financing']) 		? trim($_POST['checklist_financing']) : "";


/**********bank****************/
$bankStandardReq		= isset($_POST['bank_standard_requirements']) 		? $_POST['bank_standard_requirements'] 		: ""; 
$bankAdditionalReq		= isset($_POST['bank_additional_requirements'])		? $_POST['bank_additional_requirements'] 	: "";
$bankNotarizedDate		= isset($_POST['bank_notarized_date']) 				? trim($_POST['bank_notarized_date']) 		: "00/00/0000"; 
$bankLastMonthDate		= isset($_POST['bank_last_month_date']) 			? trim($_POST['bank_last_month_date']) 		: "00/00/0000"; 
$bankLastItrDate		= isset($_POST['bank_last_itr_date']) 				? trim($_POST['bank_last_itr_date'])		: "00/00/0000"; 
$bankOtherField			= isset($_POST['bank_other_field']) 				? trim($_POST['bank_other_field']) 			: "";

$bankStandardReq1		= isset($_POST['bank_standard_requirements1']) 		? $_POST['bank_standard_requirements1'] 	: ""; 
$bankAdditionalReq1		= isset($_POST['bank_additional_requirements1'])	? $_POST['bank_additional_requirements1'] 	: "";
$bankNotarizedDate1		= isset($_POST['bank_notarized_date1']) 			? trim($_POST['bank_notarized_date1']) 		: "00/00/0000"; 
$bankLastMonthDate1		= isset($_POST['bank_last_month_date1']) 			? trim($_POST['bank_last_month_date1']) 	: "00/00/0000"; 
$bankLastItrDate1		= isset($_POST['bank_last_itr_date1']) 				? trim($_POST['bank_last_itr_date1']) 		: "00/00/0000"; 
$bankOtherField1		= isset($_POST['bank_other_field1']) 				? trim($_POST['bank_other_field1']) 		: "";

$bankStandardReq2		= isset($_POST['bank_standard_requirements2']) 		? $_POST['bank_standard_requirements2'] 	: ""; 
$bankAdditionalReq2		= isset($_POST['bank_additional_requirements2'])	? $_POST['bank_additional_requirements2'] 	: "";
$bankNotarizedDate2		= isset($_POST['bank_notarized_date2']) 			? trim($_POST['bank_notarized_date2']) 		: "00/00/0000"; 
$bankLastMonthDate2		= isset($_POST['bank_last_month_date2']) 			? trim($_POST['bank_last_month_date2']) 	: "00/00/0000"; 
$bankLastItrDate2		= isset($_POST['bank_last_itr_date2']) 				? trim($_POST['bank_last_itr_date2']) 		: "00/00/0000"; 
$bankOtherField2		= isset($_POST['bank_other_field2']) 				? trim($_POST['bank_other_field2']) 		: "";

$bankStandardReq3		= isset($_POST['bank_standard_requirements3']) 		? $_POST['bank_standard_requirements3'] 	: ""; 
$bankAdditionalReq3		= isset($_POST['bank_additional_requirements3'])	? $_POST['bank_additional_requirements3'] 	: "";
$bankNotarizedDate3		= isset($_POST['bank_notarized_date3']) 			? trim($_POST['bank_notarized_date3']) 		: "00/00/0000"; 
$bankLastMonthDate3		= isset($_POST['bank_last_month_date3']) 			? trim($_POST['bank_last_month_date3']) 	: "00/00/0000"; 
$bankLastItrDate3		= isset($_POST['bank_last_itr_date3']) 				? trim($_POST['bank_last_itr_date3']) 		: "00/00/0000"; 
$bankOtherField3		= isset($_POST['bank_other_field3']) 				? trim($_POST['bank_other_field3']) 		: "";
    

/**********bank****************/


$currentUser 	= $_SESSION['danvilles_username'];
$timeStamp		= date('Y-m-d H:i:s');
//SAVING CHECKLIST DETAILS 
$mainArr	= array();
$output 	= ""; 

$mainArr['SubmissionDate'] 								= date("Y-m-d", strtotime($submissionDate)); 
$mainArr['ThankYouLetterSentDate']						= date("Y-m-d", strtotime($thankYouDate));
$mainArr['IsThankYouLetterSent']						= $thankYouLetterSent; 

if($financing=="BANK" || $financing=="bank"){
	$mainArr['BuyerStandardReqDetails']						= json_encode($bankStandardReq);
	$mainArr['CoBorrower1StandardReqDetails']				= json_encode($bankStandardReq1);
	$mainArr['CoBorrower2StandardReqDetails']				= json_encode($bankStandardReq2);
	$mainArr['CoBorrower3StandardReqDetails']				= json_encode($bankStandardReq3); 
	$mainArr['AdditionalReqDetails']						= json_encode($bankAdditionalReq); 
	$mainArr['CoBorrower1AdditionalReqDetails']				= json_encode($bankAdditionalReq1); 
	$mainArr['CoBorrower2AdditionalReqDetails']				= json_encode($bankAdditionalReq2); 
	$mainArr['CoBorrower3AdditionalReqDetails']				= json_encode($bankAdditionalReq3); 


	  
	$mainArr['NotarizedDate']		= date("Y-m-d", strtotime($bankNotarizedDate));
	$mainArr['PaySlipDate']			= date("Y-m-d", strtotime($bankLastMonthDate)); 
	$mainArr['ITRDate']				= date("Y-m-d", strtotime($bankLastItrDate));
	$mainArr['OtherField']			= date("Y-m-d", strtotime($bankOtherField));
   	
	$mainArr['Co1NotarizedDate']	= date("Y-m-d", strtotime($bankNotarizedDate1));	
	$mainArr['Co1PaySlipDate']		= date("Y-m-d", strtotime($bankLastMonthDate1));
	$mainArr['Co1ITRDate']			= date("Y-m-d", strtotime($bankLastItrDate1));	
	$mainArr['Co1OtherField']		= date("Y-m-d", strtotime($bankOtherField1));
	
	$mainArr['Co2NotarizedDate']	= date("Y-m-d", strtotime($bankNotarizedDate2));	
	$mainArr['Co2PaySlipDate']		= date("Y-m-d", strtotime($bankLastMonthDate2));
	$mainArr['Co2ITRDate']			= date("Y-m-d", strtotime($bankLastItrDate2));	
	$mainArr['Co2OtherField']		= date("Y-m-d", strtotime($bankOtherField2));
	
	$mainArr['Co3NotarizedDate']	= date("Y-m-d", strtotime($bankNotarizedDate3));	
	$mainArr['Co3PaySlipDate']		= date("Y-m-d", strtotime($bankLastMonthDate3));
	$mainArr['Co3ITRDate']			= date("Y-m-d", strtotime($bankLastItrDate3));	
	$mainArr['Co3OtherField']		= date("Y-m-d", strtotime($bankOtherField3));
	
}else{  
	$mainArr['BuyerStandardReqDetails']						= json_encode($standardReq);
	$mainArr['CoBorrower1StandardReqDetails']				= json_encode($standardReq1);
	$mainArr['CoBorrower2StandardReqDetails']				= json_encode($standardReq2);
	$mainArr['CoBorrower3StandardReqDetails']				= json_encode($standardReq3); 
	$mainArr['AdditionalReqDetails']						= json_encode($additionalReq); 
	$mainArr['CoBorrower1AdditionalReqDetails']				= json_encode($additionalReq1); 
	$mainArr['CoBorrower2AdditionalReqDetails']				= json_encode($additionalReq2); 
	$mainArr['CoBorrower3AdditionalReqDetails']				= json_encode($additionalReq3); 


	$mainArr['BillingDate']			= date("Y-m-d", strtotime($proofBillingDate));
	$mainArr['BarangayDate']		= date("Y-m-d", strtotime($barangayClearanceDate));
	$mainArr['NotarizedDate']		= date("Y-m-d", strtotime($notarizedDate));
	$mainArr['PaySlipDate']			= date("Y-m-d", strtotime($lastMonthDate));
	$mainArr['Co1BillingDate']		= date("Y-m-d", strtotime($proofBillingDate1));
	$mainArr['Co1BarangayDate']		= date("Y-m-d", strtotime($barangayClearanceDate1));
	$mainArr['Co1NotarizedDate']	= date("Y-m-d", strtotime($notarizedDate1));	
	$mainArr['Co1PaySlipDate']		= date("Y-m-d", strtotime($lastMonthDate1));
	$mainArr['Co2BillingDate']		= date("Y-m-d", strtotime($proofBillingDate2));
	$mainArr['Co2BarangayDate']		= date("Y-m-d", strtotime($barangayClearanceDate2));
	$mainArr['Co2NotarizedDate']	= date("Y-m-d", strtotime($notarizedDate2));	
	$mainArr['Co2PaySlipDate']		= date("Y-m-d", strtotime($lastMonthDate2));
	$mainArr['Co3BillingDate']		= date("Y-m-d", strtotime($proofBillingDate3));
	$mainArr['Co3BarangayDate']		= date("Y-m-d", strtotime($barangayClearanceDate3));
	$mainArr['Co3NotarizedDate']	= date("Y-m-d", strtotime($notarizedDate3));	
	$mainArr['Co3PaySlipDate']		= date("Y-m-d", strtotime($lastMonthDate3));
	   
}
 

  
$condArr = array();
if($task=="edit"):
	$mainArr['UpdatedDate'] 	= $timeStamp;
	$mainArr['UpdatedBy'] 		= $currentUser;
	$condArr['ReservationId']	= $mainid;
	$output 					= $mecon->updateQuery($mainArr,"checklist",$condArr);
	
	//LOG TASK
			$actArr['UserType']			= "documentation_staff,documentation_supervisor";
			$first_name = $utility->getFieldId("FirstName","Id",$mainid,"reservation");
			$last_name = $utility->getFieldId("LastName","Id",$mainid,"reservation");
			$middle_name = $utility->getFieldId("MiddleName","Id",$mainid,"reservation");
			$actArr['Remarks']			= "Updated Checklist : [$mainid] - $last_name , $first_name $middle_name";
			$actArr['TransId']			= $mainid;
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "checklist_of_requirements";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$utility->encodeActivityLog($actArr);
			
endif;

$resultArr 						= array();
$resultArr['output']	  		= $output;

echo json_encode($resultArr);
//}
exit();
ob_end_flush();