<?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(); 

if(isset($_POST['current_project']) && isset($_POST['current_model'])){
$project			= isset($_POST['current_project']) 			? str_replace('_',' ',htmlentities(addslashes(strip_tags(trim($_POST['current_project']))))) : "";
$model				= isset($_POST['current_model']) 			? str_replace('_',' ',htmlentities(addslashes(strip_tags(trim($_POST['current_model']))))) : "";
$pricelistDate		= isset($_POST['pricelist_date']) 	? trim($_POST['pricelist_date']) : "";
$reserveDate		= isset($_POST['reservation_date']) 	? trim($_POST['reservation_date']) : "";
$broker				= isset($_POST['current_broker'])			? str_replace('_',' ',htmlentities(addslashes(strip_tags(trim($_POST['current_broker']))))) : ""; 
$agent				= isset($_POST['current_agent'])			? str_replace('_',' ',htmlentities(addslashes(strip_tags(trim($_POST['current_agent']))))) : ""; 
$first_name			= isset($_POST['reservation_first_name'])		? htmlentities(addslashes(strip_tags(trim($_POST['reservation_first_name'])))) : ""; 
$last_name			= isset($_POST['reservation_last_name'])		? htmlentities(addslashes(strip_tags(trim($_POST['reservation_last_name'])))) : ""; 
$middle_name		= isset($_POST['reservation_middle_name'])		? htmlentities(addslashes(strip_tags(trim($_POST['reservation_middle_name'])))) : ""; 
$spouse				= isset($_POST['reservation_spouse'])			? htmlentities(addslashes(strip_tags(trim($_POST['reservation_spouse'])))) : "";  


$check_pricelist_date				= isset($_POST['check_pricelist_date']) 			? trim(strip_tags($_POST['check_pricelist_date'])) : "";

$rtransfer				= isset($_POST['rtransfer']) 			? trim(strip_tags($_POST['rtransfer'])) : "";



$phase				= isset($_POST['current_phase']) 			? trim(strip_tags($_POST['current_phase'])) : "";
$block				= isset($_POST['current_block']) 			? trim(strip_tags($_POST['current_block'])) : "";
$lot				= isset($_POST['current_lot']) 				? trim(strip_tags($_POST['current_lot'])) : "";
$home_telno			= isset($_POST['reservation_home_telno'])		? trim(strip_tags($_POST['reservation_home_telno'])) : "";
$cellphone_no		= isset($_POST['reservation_cellphone_no'])		? trim(strip_tags($_POST['reservation_cellphone_no'])) : "";
$spouse_contactno	= isset($_POST['reservation_spouse_contactno'])	? trim(strip_tags($_POST['reservation_spouse_contactno'])) : "";
$spa				= isset($_POST['reservation_spa'])	? trim(strip_tags($_POST['reservation_spa'])) : "";
$spa_contactno		= isset($_POST['reservation_spa_contactno'])	? trim(strip_tags($_POST['reservation_spa_contactno'])) : "";
$spa_email			= isset($_POST['reservation_spa_email'])	? trim(strip_tags($_POST['reservation_spa_email'])) : "";
$spouse_email		= isset($_POST['reservation_spouse_email'])	? trim(strip_tags($_POST['reservation_spouse_email'])) : ""; //26MAR23
$address1			= isset($_POST['reservation_address1'])			? trim(strip_tags($_POST['reservation_address1'])) : "";
$address2			= isset($_POST['reservation_address2'])			? trim(strip_tags($_POST['reservation_address2'])) : "";
$employer_name		= isset($_POST['reservation_employer_name'])	? str_replace('_',' ',trim(strip_tags($_POST['reservation_employer_name']))) : "";
$employee_type		= isset($_POST['reservation_employee_type'])	? str_replace('_',' ',trim(strip_tags($_POST['reservation_employee_type']))) : "";
$gross_income		= isset($_POST['reservation_gross_income'])		? str_replace(',','',trim(strip_tags($_POST['reservation_gross_income']))) : "";
/*$discount_promo		= isset($_POST['discount'])	? str_replace(',','',trim(strip_tags($_POST['discount']))) : "";*/
$position			= isset($_POST['reservation_position'])			? str_replace('_',' ',trim(strip_tags($_POST['reservation_position']))) : "";
$buyer_profile		= isset($_POST['reservation_buyer_profile'])	? str_replace('_',' ',trim(strip_tags($_POST['reservation_buyer_profile']))) : "";
$income_spouse		= isset($_POST['reservation_income_of_spouse'])	? str_replace(',','',trim(strip_tags($_POST['reservation_income_of_spouse']))) : "";
$num_coborrower		= isset($_POST['coborrower_num'])				? trim(strip_tags($_POST['coborrower_num'])) : "";
$tinno				= isset($_POST['reservation_tinno'])			? trim(strip_tags($_POST['reservation_tinno'])) : "";
$office_telno		= isset($_POST['reservation_office_telno'])		? trim(strip_tags($_POST['reservation_office_telno'])) : "";
$aggregate_income	= isset($_POST['reservation_aggregate_income'])	? str_replace(',','',trim(strip_tags($_POST['reservation_aggregate_income']))) : "";
 
//CO-BORROWER DETAILS
//CO-BORROWER1
$coborrower1				= isset($_POST['reservation_coborrower1'])			? trim(strip_tags($_POST['reservation_coborrower1'])) : "";
$coborrower1_tinno			= isset($_POST['reservation_tinno_co1'])			? trim(strip_tags($_POST['reservation_tinno_co1'])) : "";
$coborrower1_office_telno	= isset($_POST['reservation_office_telno_co1'])		? trim(strip_tags($_POST['reservation_office_telno_co1'])) : "";

$coborrower1_cellphoneno	= isset($_POST['reservation_cellphoneno_co1'])		? trim(strip_tags($_POST['reservation_cellphoneno_co1'])) : "";
$coborrower1_email = isset($_POST['reservation_email_co1'])		? trim(strip_tags($_POST['reservation_email_co1'])) : "";

$coborrower1_employer		= isset($_POST['reservation_employers_name_co1'])	? trim(strip_tags($_POST['reservation_employers_name_co1'])) : "";
$coborrower1_employee_type	= isset($_POST['reservation_employee_type_co1'])	? str_replace('_',' ',trim(strip_tags($_POST['reservation_employee_type_co1']))) : "";
$coborrower1_gross_income	= isset($_POST['reservation_grossincome_co1'])		? str_replace(',','',trim(strip_tags($_POST['reservation_grossincome_co1']))) : "";
$coborrower1_position		= isset($_POST['reservation_position_co1'])			? str_replace('_',' ',trim(strip_tags($_POST['reservation_position_co1']))) : "";
$coborrower1_principal_relation		= isset($_POST['reservation_relation_to_principal_co1'])			? trim(strip_tags($_POST['reservation_relation_to_principal_co1'])) : "";
//CO-BORROWER2
$coborrower2				= isset($_POST['reservation_coborrower2'])			? trim(strip_tags($_POST['reservation_coborrower2'])) : "";
$coborrower2_tinno			= isset($_POST['reservation_tinno_co2'])			? trim(strip_tags($_POST['reservation_tinno_co2'])) : "";
$coborrower2_office_telno	= isset($_POST['reservation_office_telno_co2'])		? trim(strip_tags($_POST['reservation_office_telno_co2'])) : "";


$coborrower2_cellphoneno	= isset($_POST['reservation_cellphoneno_co2'])		? trim(strip_tags($_POST['reservation_cellphoneno_co2'])) : "";
$coborrower2_email = isset($_POST['reservation_email_co2'])		? trim(strip_tags($_POST['reservation_email_co2'])) : "";


$coborrower2_employer		= isset($_POST['reservation_employers_name_co2'])	? trim(strip_tags($_POST['reservation_employers_name_co2'])) : "";
$coborrower2_employee_type	= isset($_POST['reservation_employee_type_co2'])	? str_replace('_',' ',trim(strip_tags($_POST['reservation_employee_type_co2']))) : "";
$coborrower2_gross_income	= isset($_POST['reservation_grossincome_co2'])		? str_replace(',','',trim(strip_tags($_POST['reservation_grossincome_co2']))) : "";
$coborrower2_position		= isset($_POST['reservation_position_co2'])			? str_replace('_',' ',trim(strip_tags($_POST['reservation_position_co2']))) : "";
$coborrower2_principal_relation		= isset($_POST['reservation_relation_to_principal_co2'])			? trim(strip_tags($_POST['reservation_relation_to_principal_co2'])) : "";
//CO-BORROWER3
$coborrower3				= isset($_POST['reservation_coborrower3'])			? trim(strip_tags($_POST['reservation_coborrower3'])) : "";
$coborrower3_tinno			= isset($_POST['reservation_tinno_co3'])			? trim(strip_tags($_POST['reservation_tinno_co3'])) : "";
$coborrower3_office_telno	= isset($_POST['reservation_office_telno_co3'])		? trim(strip_tags($_POST['reservation_office_telno_co3'])) : "";

$coborrower3_cellphoneno	= isset($_POST['reservation_cellphoneno_co3'])		? trim(strip_tags($_POST['reservation_cellphoneno_co3'])) : "";
$coborrower3_email = isset($_POST['reservation_email_co3'])		? trim(strip_tags($_POST['reservation_email_co3'])) : "";


$coborrower3_employer		= isset($_POST['reservation_employers_name_co3'])	? trim(strip_tags($_POST['reservation_employers_name_co3'])) : "";
$coborrower3_employee_type	= isset($_POST['reservation_employee_type_co3'])	? str_replace('_',' ',trim(strip_tags($_POST['reservation_employee_type_co3']))) : "";
$coborrower3_gross_income	= isset($_POST['reservation_grossincome_co3'])		? str_replace(',','',trim(strip_tags($_POST['reservation_grossincome_co3']))) : "";
$coborrower3_position		= isset($_POST['reservation_position_co3'])			? str_replace('_',' ',trim(strip_tags($_POST['reservation_position_co3']))) : "";
$coborrower3_principal_relation		= isset($_POST['reservation_relation_to_principal_co3'])			? trim(strip_tags($_POST['reservation_relation_to_principal_co3'])) : "";



$construction_status		= isset($_POST['reservation_construction_status'])	? trim(strip_tags($_POST['reservation_construction_status'])) : ""; //28MAR23

$task			= isset($_POST['action'])			? trim($_POST['action']) : "";
$mainid			= isset($_POST['mainid'])			? trim($_POST['mainid']) : "";

$currentUser 	= $_SESSION['danvillee_username'];
$timeStamp		= date('Y-m-d H:i:s');
 
$detailsArr = array(); 
$detailsArr[0]['coborrower'] 			= $coborrower1;
$detailsArr[0]['tinno'] 				= $coborrower1_tinno;
$detailsArr[0]['office_telno'] 			= $coborrower1_office_telno;
$detailsArr[0]['cellphoneno'] 			= $coborrower1_cellphoneno;
$detailsArr[0]['email'] 				= $coborrower1_email;
$detailsArr[0]['employer'] 				= $coborrower1_employer;  
$detailsArr[0]['employee_type']			= $coborrower1_employee_type;
$detailsArr[0]['gross_income'] 			= str_replace(",","",$coborrower1_gross_income);
$detailsArr[0]['position'] 				= $coborrower1_position;
$detailsArr[0]['principal_relation']	= $coborrower1_principal_relation;

$detailsArr[1]['coborrower'] 			= $coborrower2;
$detailsArr[1]['tinno'] 				= $coborrower2_tinno;
$detailsArr[1]['office_telno'] 			= $coborrower2_office_telno;
$detailsArr[1]['cellphoneno'] 			= $coborrower2_cellphoneno;
$detailsArr[1]['email'] 				= $coborrower2_email;
$detailsArr[1]['employer'] 				= $coborrower2_employer;  
$detailsArr[1]['employee_type']			= $coborrower2_employee_type;
$detailsArr[1]['gross_income'] 			= str_replace(",","",$coborrower2_gross_income);
$detailsArr[1]['position'] 				= $coborrower2_position;
$detailsArr[1]['principal_relation']	= $coborrower2_principal_relation;

$detailsArr[2]['coborrower'] 			= $coborrower3;
$detailsArr[2]['tinno'] 				= $coborrower3_tinno;
$detailsArr[2]['office_telno'] 			= $coborrower3_office_telno;
$detailsArr[2]['cellphoneno'] 			= $coborrower3_cellphoneno;
$detailsArr[2]['email']		 			= $coborrower3_email;
$detailsArr[2]['employer'] 				= $coborrower3_employer;  
$detailsArr[2]['employee_type']			= $coborrower3_employee_type;
$detailsArr[2]['gross_income'] 			= str_replace(",","",$coborrower3_gross_income);
$detailsArr[2]['position'] 				= $coborrower3_position;
$detailsArr[2]['principal_relation']	= $coborrower3_principal_relation;

$outputDetails 					= $detailsArr; 
$resultDetailsArr 				= array();
$resultDetailsArr['details']  	= $outputDetails; 
$coborrowerDetails				= json_encode($resultDetailsArr);
$mainArr	= array();  
$mainArr2	= array(); 
$mainArr3	= array(); 
$mainArr4	= array(); 
$mainArr5	= array(); 
$mainArr6	= array(); 
$mainArr7	= array(); 
$mainArr8	= array(); 
$output 	= ""; 
$output2 	= ""; 
$output3 	= ""; 
$output4 	= ""; 
$output5 	= ""; 
$output6 	= ""; 
$output7 	= ""; 
$output8 	= ""; 
$mainArr['Project']				=	$project;
$mainArr['Model']				=	$model; 
$mainArr['ReservationDate'] 	=	date("Y-m-d", strtotime($reserveDate)); 
$mainArr['PricelistDate'] 		=	date("Y-m-d", strtotime($pricelistDate));  
$mainArr['Phase']				=	$phase;
$mainArr['Block']				=	$block;
$mainArr['Lot']					=	$lot;
$mainArr['LastName']			=	$last_name;
$mainArr['FirstName']			=	$first_name;
$mainArr['MiddleName']			=	$middle_name;
$mainArr['Broker']				=	$broker;
$mainArr['Agent']				=	$agent;
$mainArr['Spouse']				=	$spouse;
$mainArr['HomeTel']				=	$home_telno;
$mainArr['CellphoneNo']			=	$cellphone_no;
$mainArr['SpouseContactNo']		=	$spouse_contactno;
$mainArr['SPA']					=	$spa;
$mainArr['SPAContactNo']		=	$spa_contactno;
$mainArr['SPAEmail']			=	$spa_email;
$mainArr['SpouseEmail']			= 	$spouse_email; //26MAR23
$mainArr['ConstructionStatusUponReservation'] =	$construction_status; //28MAR23 
$mainArr['Address1']			=	$address1;
$mainArr['Address2']			=	$address2; 
$mainArr['EmployerName']		=	$employer_name;
$mainArr['EmployeeType']		=	$employee_type;
$mainArr['GrossIncome']			=	str_replace(",","",$gross_income); 
$mainArr['Position']			=	$position;
$mainArr['BuyerProfile']		=	$buyer_profile;
$mainArr['SpouseIncome']		=	str_replace(",","",$income_spouse);
$mainArr['TinNo']				=	$tinno;
$mainArr['OfficeTel']			=	$office_telno;
$mainArr['AggregateIncome']		=	str_replace(",","",$aggregate_income);
$mainArr['NoCoBorrower']		=	$num_coborrower;
$mainArr['CoBorrowerDetails']	=	$coborrowerDetails;  
$mainArr['CustomPriceDate']		=	$check_pricelist_date; 

$mainArr['EmployeeTypeBorrower1']		=	$coborrower1_employee_type; 
$mainArr['EmployeeTypeBorrower2']		=	$coborrower2_employee_type; 
$mainArr['EmployeeTypeBorrower3']		=	$coborrower3_employee_type; 




 
     
$condArr = array();
if($task=="create"):
	$mainArr['Id']				= $mecon->getNextId("Id","reservation");
	$reservationId				= $mecon->getNextId("Id","reservation"); 
	$mainArr['CreatedDate'] 	= $timeStamp;
	$mainArr['CreatedBy'] 		= $currentUser;
	$output = 	$mecon->insertSingleQuery($mainArr,"reservation"); 
	if($output==true): 
		$mainArr2['ReservationId'] 	= $reservationId;
		$mainArr2['CreatedDate'] 	= $timeStamp;
		$mainArr2['CreatedBy'] 		= $currentUser;
		$output2 = $mecon->insertSingleQuery($mainArr2,"checklist");

		$mainArr3['ReservationId'] 	= $reservationId;
		$mainArr3['CreatedDate'] 	= $timeStamp;
		$mainArr3['CreatedBy'] 		= $currentUser;
		$output3 = $mecon->insertSingleQuery($mainArr3,"monitoring_folders"); 
		
		$mainArr4['ReservationId'] 	= $reservationId;
		$mainArr4['CreatedDate'] 	= $timeStamp;
		$mainArr4['CreatedBy'] 		= $currentUser;
		$mainArr4['PaymentMode'] 	= "pag-ibig";
		$mainArr4['Financing'] 		= "pagibig"; 
		$output4 = $mecon->insertSingleQuery($mainArr4,"buyer_payment_monitoring");
		
		$mainArr5['ReservationId'] 	= $reservationId;
		$mainArr5['CreatedDate'] 	= $timeStamp;
		$mainArr5['CreatedBy'] 		= $currentUser;
		$output5 = $mecon->insertSingleQuery($mainArr5,"buyer_status_monitoring");
		
		$mainArr6['ReservationId'] 	= $reservationId;
		$mainArr6['CreatedDate'] 	= $timeStamp;
		$mainArr6['CreatedBy'] 		= $currentUser;
		$output6 = $mecon->insertSingleQuery($mainArr6,"buyer_status_folder_pagibig");

		$mainArr8['ReservationId'] 	= $reservationId;
		$mainArr8['CreatedDate'] 	= $timeStamp;
		$mainArr8['CreatedBy'] 		= $currentUser;
		$output8 = $mecon->insertSingleQuery($mainArr8,"buyer_status_folder_bank");
		
		
		$mainArr7['ReservationId'] 	= $reservationId;
		$mainArr7['CreatedDate'] 	= $timeStamp;
		$mainArr7['CreatedBy'] 		= $currentUser;
		$output7 = $mecon->insertSingleQuery($mainArr7,"buyer_house_renovation_monitoring");
		 
			//LOG TASK
			$actArr['UserType']			= "documentation_staff,documentation_supervisor";
			$actArr['Remarks']			= "Created New Reservation : [$reservationId] - $last_name , $first_name $middle_name";
			$actArr['Action']			= "create";
			$actArr['ActionType']		= "reservation";
			$actArr['TransId']			= $reservationId;
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$utility->encodeActivityLog($actArr);
		endif;	 
	
elseif($task=="edit"):


	if($rtransfer=="yes"):
		//INSERT OLD
		 $transfer_pricelist_date = isset($_POST['transfer_pricelist_date']) ? trim(strip_tags($_POST['transfer_pricelist_date'])) : "";
		 $transfer_reservation_date = isset($_POST['transfer_reservation_date']) ? trim(strip_tags($_POST['transfer_reservation_date'])) : "";
		 $transfer_reservation_last_name = isset($_POST['transfer_reservation_last_name']) ? trim(strip_tags($_POST['transfer_reservation_last_name'])) : "";
		 $transfer_reservation_first_name = isset($_POST['transfer_reservation_first_name']) ? trim(strip_tags($_POST['transfer_reservation_first_name'])) : "";
		 $transfer_reservation_middle_name = isset($_POST['transfer_reservation_middle_name']) ? trim(strip_tags($_POST['transfer_reservation_middle_name'])) : "";
		 $transfer_reservation_home_telno = isset($_POST['transfer_reservation_home_telno']) ? trim(strip_tags($_POST['transfer_reservation_home_telno'])) : "";
		 /*$transfer_discount = isset($_POST['transfer_discount']) ? trim(strip_tags($_POST['transfer_discount'])) : "";*/
		 $transfer_reservation_spouse = isset($_POST['transfer_reservation_spouse']) ? trim(strip_tags($_POST['transfer_reservation_spouse'])) : "";
		 $transfer_reservation_spouse_contactno = isset($_POST['transfer_reservation_spouse_contactno']) ? trim(strip_tags($_POST['transfer_reservation_spouse_contactno'])) : "";
		 $transfer_reservation_address1 = isset($_POST['transfer_reservation_address1']) ? trim(strip_tags($_POST['transfer_reservation_address1'])) : "";
		 $transfer_reservation_address2 = isset($_POST['transfer_reservation_address2']) ? trim(strip_tags($_POST['transfer_reservation_address2'])) : "";
		 $transfer_reservation_employer_name = isset($_POST['transfer_reservation_employer_name']) ? trim(strip_tags($_POST['transfer_reservation_employer_name'])) : "";
		 $transfer_reservation_gross_income = isset($_POST['transfer_reservation_gross_income']) ? trim(strip_tags($_POST['transfer_reservation_gross_income'])) : "";
		 $transfer_reservation_cellphone_no = isset($_POST['transfer_reservation_cellphone_no']) ? trim(strip_tags($_POST['transfer_reservation_cellphone_no'])) : "";
		 $transfer_reservation_income_of_spouse = isset($_POST['transfer_reservation_income_of_spouse']) ? trim(strip_tags($_POST['transfer_reservation_income_of_spouse'])) : "";
		 $transfer_coborrower_num = isset($_POST['transfer_coborrower_num']) ? trim(strip_tags($_POST['transfer_coborrower_num'])) : "";
		 $transfer_reservation_tinno = isset($_POST['transfer_reservation_tinno']) ? trim(strip_tags($_POST['transfer_reservation_tinno'])) : "";
		 $transfer_reservation_office_telno = isset($_POST['transfer_reservation_office_telno']) ? trim(strip_tags($_POST['transfer_reservation_office_telno'])) : "";
		 $transfer_reservation_aggregate_income = isset($_POST['transfer_reservation_aggregate_income']) ? trim(strip_tags($_POST['transfer_reservation_aggregate_income'])) : "";
		 $transfer_broker = isset($_POST['transfer_broker']) ? trim(strip_tags($_POST['transfer_broker'])) : "";
		 $transfer_agent = isset($_POST['transfer_agent']) ? trim(strip_tags($_POST['transfer_agent'])) : "";
		 $transfer_spa = isset($_POST['transfer_spa']) ? trim(strip_tags($_POST['transfer_spa'])) : "";
		 $transfer_spa_contactno = isset($_POST['transfer_spa_contactno']) ? trim(strip_tags($_POST['transfer_spa_contactno'])) : "";
		 $transfer_spa_email = isset($_POST['transfer_spa_email']) ? trim(strip_tags($_POST['transfer_spa_email'])) : "";
		 $transfer_spouse_email = isset($_POST['transfer_spouse_email']) ? trim(strip_tags($_POST['transfer_spouse_email'])) : "";//26MAR23
		 $transfer_construction_status = isset($_POST['transfer_construction_status']) ? trim(strip_tags($_POST['transfer_construction_status'])) : ""; //28MAR23    


		//SAVE OLD TRANSFER	 
		$mainArrT['Id']				= $mecon->getNextId("Id","transfer_reservation");
		$mainArrT['ReservationId']   = $mainid; 
		$mainArrT['CreatedDate'] 	= $timeStamp;
		$mainArrT['CreatedBy'] 		= $currentUser;
		$mainArrT['Project']			=	$project;  
		$mainArrT['Model']				=	 $model;
		$mainArrT['ReservationDate'] 	=	date("Y-m-d", strtotime($transfer_reservation_date)); 
		$mainArrT['PricelistDate'] 		=	date("Y-m-d", strtotime($transfer_pricelist_date));  
		$mainArrT['Phase']				=	 $phase;
		$mainArrT['Block']				=	 $block;
		$mainArrT['Lot']				=	 $lot;
		$mainArrT['LastName']			=	 $transfer_reservation_last_name;
		$mainArrT['FirstName']			=	 $transfer_reservation_first_name;
		$mainArrT['MiddleName']			=	 $transfer_reservation_middle_name;
		$mainArrT['Broker']				=	 $transfer_broker;
		$mainArrT['Agent']				=	 $transfer_agent;
		$mainArrT['Spouse']				=	 $transfer_reservation_spouse;
		$mainArrT['HomeTel']			= $transfer_reservation_home_telno;
		$mainArrT['CellphoneNo']		= $transfer_reservation_cellphone_no;
		$mainArrT['SpouseContactNo']	= $transfer_reservation_spouse_contactno;
		$mainArrT['Address1']			= $transfer_reservation_address1;
		$mainArrT['Address2']			= $transfer_reservation_address2;
		$mainArrT['SPA']				= $transfer_spa;
		$mainArrT['SPAContactNo']		= $transfer_spa_contactno;
		$mainArrT['SPAEmail']			= $transfer_spa_email;
		$mainArrT['SpouseEmail']		= $transfer_spouse_email; //26MAR23
		$mainArr['ConstructionStatusUponReservation'] =	$construction_status; //28MAR23 
		$mainArrT['EmployerName']		=  $transfer_reservation_employer_name; 
		$mainArrT['GrossIncome']		=	str_replace(",","",$transfer_reservation_gross_income); 
		$mainArrT['NoCoBorrower']		=	$transfer_coborrower_num;
		$mainArrT['SpouseIncome']		=	str_replace(",","",$transfer_reservation_income_of_spouse);
		$mainArrT['TinNo']				=  $transfer_reservation_tinno;
		$mainArrT['OfficeTel']			=  $transfer_reservation_office_telno;
		$mainArrT['AggregateIncome']		=	str_replace(",","",$transfer_reservation_aggregate_income); 
		$mecon->insertSingleQuery($mainArrT,"transfer_reservation");



		//GET TRANSFER FEE
		$mecon->query("SELECT TransferFee FROM model WHERE Status = :status AND Model = :model ORDER BY Model DESC"); 
		$mecon->bind(':status', 'active');
		$mecon->bind(':model', $model);
		$mainf = $mecon->resultset();
	  
		$mainArr['TransferredFee']		= $mainf[0]['TransferFee']; 
		$mainArr['TransferredDate'] 	= $timeStamp;
		$mainArr['TransferredBy'] 		= $currentUser;
		$mainArr['ReservationStatus'] 	= "transferred";
		$condArr['Id']					= $mainid;
		$output 						= $mecon->updateQuery($mainArr,"reservation",$condArr);
										 

				//LOG TASK
				$actArr['UserType']			= "documentation_staff,documentation_supervisor";
				$actArr['Remarks']			= "Transferred Reservation : [$mainid] -  $last_name , $first_name $middle_name";
				$actArr['TransId']			= $mainid;
				$actArr['Action']			= "transferred";
				$actArr['ActionType']		= "reservation";
				$actArr['ActionContent']	= json_encode($mainArr);
				$actArr['ActionBy'] 		= $currentUser;	
				$actArr['ActionDate']		= $timeStamp;
				$utility->encodeActivityLog($actArr);
	else:
 
	$mainArr['UpdatedDate'] 		= $timeStamp;
	$mainArr['UpdatedBy'] 			= $currentUser;
	$condArr['Id']					= $mainid;
	$output 						= $mecon->updateQuery($mainArr,"reservation",$condArr);
									   
	//LOG TASK
			$actArr['UserType']			= "documentation_staff,documentation_supervisor";
			$actArr['Remarks']			= "Updated Reservation : [$mainid] -  $last_name , $first_name $middle_name";
			$actArr['Action']			= "edit";
			$actArr['TransId']			= $mainid;
			$actArr['ActionType']		= "reservation";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$utility->encodeActivityLog($actArr); 
	endif;
endif;

$resultArr 						= array();
$resultArr['output']	  		= $output;
echo json_encode($resultArr);
}
exit();
ob_end_flush();