<?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();
$utility	=	new utilityClass();   
$retArr		= isset($_POST['return_select_pdc']) ? $_POST['return_select_pdc'] : "";
$task			= isset($_POST['action'])			? trim($_POST['action']) : "edit";
$reserveId		= isset($_POST['mainrid'])			? trim($_POST['mainrid']) : "";
//$mainid			= isset($_POST['mainid'])			? trim($_POST['mainid']) : "";

$currentUser 	= $_SESSION['castalia_username'];
$timeStamp		= date('Y-m-d H:i:s');
 
$mainArr	= array(); 
$mainArr2	= array(); 
$output 	= "";   
$boom = "";
for($a=0; $a<count($retArr); $a++){
	//UPDATE
	$mainArr['ReservationId']		=	$reserveId; 
	$mainArr['ChequeProcessDate'] 	=	date("Y-m-d"); 
	$mainArr['ChequeStatus']		=	"Returned";
	$mainArr['ReturnRemarks']		=	"Closed Account";
		  
	$condArr = array();
	$outArr = array();
	if($task=="edit"):
		$mainArr['UpdatedDate'] 		= $timeStamp;
		$mainArr['UpdatedBy'] 			= $currentUser;
		$mainid = $retArr[$a];
		$condArr['ChequeNo']			= $mainid;
		$condArr['ReservationId']		= $reserveId;
		$outArr[] = $mecon->updateQuery($mainArr,"buyer_cheque_monitoring_past_due",$condArr); 
		
		//LOG TASK 
				$actArr['UserType']			= "assistant_accountant,accountant"; 
				$first_name 	= $utility->getFieldId("FirstName","Id",$reserveId,"reservation");
				$last_name 		= $utility->getFieldId("LastName","Id",$reserveId,"reservation");
				$middle_name 	= $utility->getFieldId("MiddleName","Id",$reserveId,"reservation");
				$actArr['Remarks']			= "Update Postdated Check Status Cheque #: [".$mainid."] - $last_name , $first_name $middle_name";
				$actArr['TransId']			= $utility->getFieldId("Id","ReservationId",$reserveId,"buyer_cheque_monitoring_past_due");
				$actArr['Action']			= "edit";
				$actArr['ActionType']		= "buyer_cheque_monitoring_past_due";
				$actArr['ActionContent']	= json_encode($mainArr);
				$actArr['ActionBy'] 		= $currentUser;	
				$actArr['ActionDate']		= $timeStamp; 
				$utility->encodeActivityLog($actArr);
	endif;
}
 
if (in_array(true, $outArr)) {
   $output = true;
}else{
	$output = false;
}
$resultArr 						= array();
$resultArr['output']	  		= $output; 
echo json_encode($resultArr); 
exit();
ob_end_flush();