<?php
error_reporting(0); //7dec25
ob_start("ob_gzhandler");
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(); 
$task				= 	isset($_POST['action'])		? trim($_POST['action']) : "";
$mainid				= 	isset($_POST['mainid'])		? trim($_POST['mainid']) : "";
 
 
$reservationId		= 	isset($_POST['reservation_id']) 			? trim(strip_tags($_POST['reservation_id'])) : ""; 

$dateRFDeposited	= 	isset($_POST['bpm_date_rf_deposited']) 		? trim(strip_tags($_POST['bpm_date_rf_deposited'])) : ""; 
$reservation		= 	isset($_POST['bpm_reservation']) 			? trim(strip_tags($_POST['bpm_reservation'])) : ""; 

$lessCA				= 	isset($_POST['bpm_less_ca']) 				? trim(strip_tags($_POST['bpm_less_ca'])) : ""; 
$reservationLessCA	= 	isset($_POST['bpm_reservation_less_ca']) 	? trim(strip_tags($_POST['bpm_reservation_less_ca'])) : ""; 
$tcp				= 	isset($_POST['bpm_tcp']) 					? trim(strip_tags($_POST['bpm_tcp'])) : "0"; 
$lessDiscount		= 	isset($_POST['bpm_less_discount']) 			? trim(strip_tags($_POST['bpm_less_discount'])) : ""; 

$miscExpenses		= 	isset($_POST['bpm_misc_expenses']) 			? trim(strip_tags($_POST['bpm_misc_expenses'])) : ""; 
$basisCommission	= 	isset($_POST['bpm_basis_commission']) 		? trim(strip_tags($_POST['bpm_basis_commission'])) : ""; 
$rate 				= 	isset($_POST['bpm_rate']) 				?	 trim(strip_tags($_POST['bpm_rate'])) : ""; 
$commission			= 	isset($_POST['bpm_commission']) 			? trim(strip_tags($_POST['bpm_commission'])) : ""; 

$miscExpenseRate	= 	isset($_POST['bpm_misc_expense_rate']) 		? trim(strip_tags($_POST['bpm_misc_expense_rate'])) : ""; 
$withholdingTax		= 	isset($_POST['withholding_tax']) 			? trim(strip_tags($_POST['withholding_tax'])) : "";

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


$firstReleaseCheckbox		= 	isset($_POST['first_release_checkbox']) 			? trim(strip_tags($_POST['first_release_checkbox'])) : ""; 
$firstReleaseType			= 	isset($_POST['first_release_type']) 				? trim(strip_tags($_POST['first_release_type'])) : "";
$firstReleaseBrokerAmount	= 	isset($_POST['first_release_broker_amount']) 		? trim(strip_tags($_POST['first_release_broker_amount'])) : "";
$firstReleaseAgentAmount	= 	isset($_POST['first_release_agent_amount']) 		? trim(strip_tags($_POST['first_release_agent_amount'])) : ""; 
$firstReleaseBrokerCheck	= 	isset($_POST['first_release_broker_check']) 		? trim(strip_tags($_POST['first_release_broker_check'])) : ""; 
$firstReleaseAgentCheck		= 	isset($_POST['first_release_agent_check']) 			? trim(strip_tags($_POST['first_release_agent_check'])) : ""; 
$firstReleaseDate			= 	isset($_POST['first_release_date']) 				? trim(strip_tags($_POST['first_release_date'])) : ""; 

$secondReleaseCheckbox		= 	isset($_POST['second_release_checkbox']) 			? trim(strip_tags($_POST['second_release_checkbox'])) : ""; 
$secondReleaseType			= 	isset($_POST['second_release_type']) 				? trim(strip_tags($_POST['second_release_type'])) : "";
$secondReleaseBrokerAmount	= 	isset($_POST['second_release_broker_amount']) 		? trim(strip_tags($_POST['second_release_broker_amount'])) : "";
$secondReleaseAgentAmount	= 	isset($_POST['second_release_agent_amount']) 		? trim(strip_tags($_POST['second_release_agent_amount'])) : ""; 
$secondReleaseBrokerCheck	= 	isset($_POST['second_release_broker_check']) 		? trim(strip_tags($_POST['second_release_broker_check'])) : ""; 
$secondReleaseAgentCheck	= 	isset($_POST['second_release_agent_check']) 		? trim(strip_tags($_POST['second_release_agent_check'])) : ""; 
$secondReleaseDate			= 	isset($_POST['second_release_date']) 				? trim(strip_tags($_POST['second_release_date'])) : ""; 

$thirdReleaseCheckbox		= 	isset($_POST['third_release_checkbox']) 			? trim(strip_tags($_POST['third_release_checkbox'])) : ""; 
$thirdReleaseType			= 	isset($_POST['third_release_type']) 				? trim(strip_tags($_POST['third_release_type'])) : "";
$thirdReleaseBrokerAmount	= 	isset($_POST['third_release_broker_amount']) 		? trim(strip_tags($_POST['third_release_broker_amount'])) : "";
$thirdReleaseAgentAmount	= 	isset($_POST['third_release_agent_amount']) 		? trim(strip_tags($_POST['third_release_agent_amount'])) : ""; 
$thirdReleaseBrokerCheck	= 	isset($_POST['third_release_broker_check']) 		? trim(strip_tags($_POST['third_release_broker_check'])) : ""; 
$thirdReleaseAgentCheck		= 	isset($_POST['third_release_agent_check']) 			? trim(strip_tags($_POST['third_release_agent_check'])) : ""; 
$thirdReleaseDate			= 	isset($_POST['third_release_date']) 				? trim(strip_tags($_POST['third_release_date'])) : ""; 

$fourthReleaseCheckbox		= 	isset($_POST['fourth_release_checkbox']) 			? trim(strip_tags($_POST['fourth_release_checkbox'])) : ""; 
$fourthReleaseType			= 	isset($_POST['fourth_release_type']) 				? trim(strip_tags($_POST['fourth_release_type'])) : "";
$fourthReleaseBrokerAmount	= 	isset($_POST['fourth_release_broker_amount']) 		? trim(strip_tags($_POST['fourth_release_broker_amount'])) : "";
$fourthReleaseAgentAmount	= 	isset($_POST['fourth_release_agent_amount']) 		? trim(strip_tags($_POST['fourth_release_agent_amount'])) : ""; 
$fourthReleaseBrokerCheck	= 	isset($_POST['fourth_release_broker_check']) 		? trim(strip_tags($_POST['fourth_release_broker_check'])) : ""; 
$fourthReleaseAgentCheck	= 	isset($_POST['fourth_release_agent_check']) 		? trim(strip_tags($_POST['fourth_release_agent_check'])) : ""; 
$fourthReleaseDate			= 	isset($_POST['fourth_release_date']) 				? trim(strip_tags($_POST['fourth_release_date'])) : ""; 

$fifthReleaseCheckbox		= 	isset($_POST['fifth_release_checkbox']) 			? trim(strip_tags($_POST['fifth_release_checkbox'])) : ""; 
$fifthReleaseType			= 	isset($_POST['fifth_release_type']) 				? trim(strip_tags($_POST['fifth_release_type'])) : "";
$fifthReleaseBrokerAmount	= 	isset($_POST['fifth_release_broker_amount']) 		? trim(strip_tags($_POST['fifth_release_broker_amount'])) : "";
$fifthReleaseAgentAmount	= 	isset($_POST['fifth_release_agent_amount']) 		? trim(strip_tags($_POST['fifth_release_agent_amount'])) : ""; 
$fifthReleaseBrokerCheck	= 	isset($_POST['fifth_release_broker_check']) 		? trim(strip_tags($_POST['fifth_release_broker_check'])) : ""; 
$fifthReleaseAgentCheck		= 	isset($_POST['fifth_release_agent_check']) 			? trim(strip_tags($_POST['fifth_release_agent_check'])) : ""; 
$fifthReleaseDate			= 	isset($_POST['fifth_release_date']) 				? trim(strip_tags($_POST['fifth_release_date'])) : ""; 

$sixReleaseCheckbox			= 	isset($_POST['six_release_checkbox']) 				? trim(strip_tags($_POST['six_release_checkbox'])) : ""; 
$sixReleaseType				= 	isset($_POST['six_release_type']) 					? trim(strip_tags($_POST['six_release_type'])) : "";
$sixReleaseBrokerAmount		= 	isset($_POST['six_release_broker_amount']) 			? trim(strip_tags($_POST['six_release_broker_amount'])) : "";
$sixReleaseAgentAmount		= 	isset($_POST['six_release_agent_amount']) 			? trim(strip_tags($_POST['six_release_agent_amount'])) : ""; 
$sixReleaseBrokerCheck		= 	isset($_POST['six_release_broker_check']) 			? trim(strip_tags($_POST['six_release_broker_check'])) : ""; 
$sixReleaseAgentCheck		= 	isset($_POST['six_release_agent_check']) 			? trim(strip_tags($_POST['six_release_agent_check'])) : ""; 
$sixReleaseDate				= 	isset($_POST['six_release_date']) 					? trim(strip_tags($_POST['six_release_date'])) : ""; 

$sevenReleaseCheckbox		= 	isset($_POST['seven_release_checkbox']) 			? trim(strip_tags($_POST['seven_release_checkbox'])) : ""; 
$sevenReleaseType			= 	isset($_POST['seven_release_type']) 				? trim(strip_tags($_POST['seven_release_type'])) : "";
$sevenReleaseBrokerAmount	= 	isset($_POST['seven_release_broker_amount']) 		? trim(strip_tags($_POST['seven_release_broker_amount'])) : "";
$sevenReleaseAgentAmount	= 	isset($_POST['seven_release_agent_amount']) 		? trim(strip_tags($_POST['seven_release_agent_amount'])) : ""; 
$sevenReleaseBrokerCheck	= 	isset($_POST['seven_release_broker_check']) 		? trim(strip_tags($_POST['seven_release_broker_check'])) : ""; 
$sevenReleaseAgentCheck		= 	isset($_POST['seven_release_agent_check']) 			? trim(strip_tags($_POST['seven_release_agent_check'])) : ""; 
$sevenReleaseDate			= 	isset($_POST['seven_release_date']) 				? trim(strip_tags($_POST['seven_release_date'])) : ""; 

$eightReleaseCheckbox			= 	isset($_POST['eight_release_checkbox']) 			? trim(strip_tags($_POST['eight_release_checkbox'])) : ""; 
$eightReleaseType				= 	isset($_POST['eight_release_type']) 				? trim(strip_tags($_POST['eight_release_type'])) : "";
$eightReleaseBrokerAmount		= 	isset($_POST['eight_release_broker_amount']) 		? trim(strip_tags($_POST['eight_release_broker_amount'])) : "";
$eightReleaseAgentAmount		= 	isset($_POST['eight_release_agent_amount']) 		? trim(strip_tags($_POST['eight_release_agent_amount'])) : ""; 
$eightReleaseBrokerCheck		= 	isset($_POST['eight_release_broker_check']) 		? trim(strip_tags($_POST['eight_release_broker_check'])) : ""; 
$eightReleaseAgentCheck			= 	isset($_POST['eight_release_agent_check']) 			? trim(strip_tags($_POST['eight_release_agent_check'])) : ""; 
$eightReleaseDate				= 	isset($_POST['eight_release_date']) 				? trim(strip_tags($_POST['eight_release_date'])) : ""; 

$nineReleaseCheckbox			= 	isset($_POST['nine_release_checkbox']) 				? trim(strip_tags($_POST['nine_release_checkbox'])) : ""; 
$nineReleaseType				= 	isset($_POST['nine_release_type']) 					? trim(strip_tags($_POST['nine_release_type'])) : "";
$nineReleaseBrokerAmount		= 	isset($_POST['nine_release_broker_amount']) 		? trim(strip_tags($_POST['nine_release_broker_amount'])) : "";
$nineReleaseAgentAmount			= 	isset($_POST['nine_release_agent_amount']) 			? trim(strip_tags($_POST['nine_release_agent_amount'])) : ""; 
$nineReleaseBrokerCheck			= 	isset($_POST['nine_release_broker_check']) 			? trim(strip_tags($_POST['nine_release_broker_check'])) : ""; 
$nineReleaseAgentCheck			= 	isset($_POST['nine_release_agent_check']) 			? trim(strip_tags($_POST['nine_release_agent_check'])) : ""; 
$nineReleaseDate				= 	isset($_POST['nine_release_date']) 					? trim(strip_tags($_POST['nine_release_date'])) : ""; 

$tenReleaseCheckbox				= 	isset($_POST['ten_release_checkbox']) 				? trim(strip_tags($_POST['ten_release_checkbox'])) : ""; 
$tenReleaseType					= 	isset($_POST['ten_release_type']) 					? trim(strip_tags($_POST['ten_release_type'])) : "";
$tenReleaseBrokerAmount			= 	isset($_POST['ten_release_broker_amount']) 			? trim(strip_tags($_POST['ten_release_broker_amount'])) : "";
$tenReleaseAgentAmount			= 	isset($_POST['ten_release_agent_amount']) 			? trim(strip_tags($_POST['ten_release_agent_amount'])) : ""; 
$tenReleaseBrokerCheck			= 	isset($_POST['ten_release_broker_check']) 			? trim(strip_tags($_POST['ten_release_broker_check'])) : ""; 
$tenReleaseAgentCheck			= 	isset($_POST['ten_release_agent_check']) 			? trim(strip_tags($_POST['ten_release_agent_check'])) : ""; 
$tenReleaseDate					= 	isset($_POST['ten_release_date']) 					? trim(strip_tags($_POST['ten_release_date'])) : ""; 

$elevenReleaseCheckbox			= 	isset($_POST['eleven_release_checkbox']) 				? trim(strip_tags($_POST['eleven_release_checkbox'])) : ""; 
$elevenReleaseType				= 	isset($_POST['eleven_release_type']) 					? trim(strip_tags($_POST['eleven_release_type'])) : "";
$elevenReleaseBrokerAmount		= 	isset($_POST['eleven_release_broker_amount']) 			? trim(strip_tags($_POST['eleven_release_broker_amount'])) : "";
$elevenReleaseAgentAmount		= 	isset($_POST['eleven_release_agent_amount']) 			? trim(strip_tags($_POST['eleven_release_agent_amount'])) : ""; 
$elevenReleaseBrokerCheck		= 	isset($_POST['eleven_release_broker_check']) 			? trim(strip_tags($_POST['eleven_release_broker_check'])) : ""; 
$elevenReleaseAgentCheck		= 	isset($_POST['eleven_release_agent_check']) 			? trim(strip_tags($_POST['eleven_release_agent_check'])) : ""; 
$elevenReleaseDate				= 	isset($_POST['eleven_release_date']) 					? trim(strip_tags($_POST['eleven_release_date'])) : ""; 

$twelveReleaseCheckbox			= 	isset($_POST['twelve_release_checkbox']) 				? trim(strip_tags($_POST['twelve_release_checkbox'])) : ""; 
$twelveReleaseType				= 	isset($_POST['twelve_release_type']) 					? trim(strip_tags($_POST['twelve_release_type'])) : "";
$twelveReleaseBrokerAmount		= 	isset($_POST['twelve_release_broker_amount']) 			? trim(strip_tags($_POST['twelve_release_broker_amount'])) : "";
$twelveReleaseAgentAmount		= 	isset($_POST['twelve_release_agent_amount']) 			? trim(strip_tags($_POST['twelve_release_agent_amount'])) : ""; 
$twelveReleaseBrokerCheck		= 	isset($_POST['twelve_release_broker_check']) 			? trim(strip_tags($_POST['twelve_release_broker_check'])) : ""; 
$twelveReleaseAgentCheck		= 	isset($_POST['twelve_release_agent_check']) 			? trim(strip_tags($_POST['twelve_release_agent_check'])) : ""; 
$twelveReleaseDate				= 	isset($_POST['twelve_release_date']) 					? trim(strip_tags($_POST['twelve_release_date'])) : ""; 

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

$subtotalReleaseBrokerAmount	= 	isset($_POST['subtotal_release_broker_amount'])    ? trim(strip_tags($_POST['subtotal_release_broker_amount'])) : ""; 
$subtotalReleaseAgentAmount		= 	isset($_POST['subtotal_release_agent_amount'])     ? trim(strip_tags($_POST['subtotal_release_agent_amount'])) : ""; 


$addCashAdvance				= 	isset($_POST['add_cash_advance'])  			? trim(strip_tags($_POST['add_cash_advance'])) : ""; 
$totalReleaseAmount			= 	isset($_POST['total_releases_amount'])  	? trim(strip_tags($_POST['total_releases_amount'])) : ""; 


$fullTick					= 	isset($_POST['fulltick'])  	? trim($_POST['fulltick']) : ""; 
$FullCheckbox				= 	($fullTick=="yes") 	? 'yes' : 'no'; 


$fullAmount					= 	isset($_POST['full_amount'])  				? trim(strip_tags($_POST['full_amount'])) : ""; 
$fullNet					= 	isset($_POST['full_net'])  					? trim(strip_tags($_POST['full_net'])) : ""; 
$fullCheck					= 	isset($_POST['full_check'])  				? trim(strip_tags($_POST['full_check'])) : ""; 
$FullDate					= 	isset($_POST['full_date']) 					? trim(strip_tags($_POST['full_date'])) : ""; 
$totalAmount				= 	isset($_POST['total_amount'])  				? trim(strip_tags($_POST['total_amount'])) : ""; 
$totalWHT					= 	isset($_POST['total_wht'])  				? trim(strip_tags($_POST['total_wht'])) : ""; 
$releasesStatus				= 	isset($_POST['releases_status'])  			? trim(strip_tags($_POST['releases_status'])) : ""; 
$releasesRemarks			= 	isset($_POST['releases_remarks'])  			? trim(strip_tags($_POST['releases_remarks'])) : ""; 
 
$currentUser 	= $_SESSION['danvilles_username'];
$timeStamp		= date('Y-m-d H:i:s');
//SAVING CHECKLIST DETAILS   
$mainArr	= array();
$output 	= "";

$mainArr['DateRFDeposited'] 		= date('Y-m-d', strtotime($dateRFDeposited));

$mainArr['ReservationId']			= $reservationId; 
$mainArr['Reservation']				= str_replace(',','',$reservation); 
$mainArr['LessCA']					= str_replace(',','',$lessCA); 
$mainArr['ReservationLessCA'] 		= str_replace(',','',$reservationLessCA);
$mainArr['TCP'] 					= str_replace(',','',$tcp);
$mainArr['LessDiscount'] 			= str_replace(',','',$lessDiscount);
$mainArr['MiscExpenses'] 			= str_replace(',','',$miscExpenses);
$mainArr['MiscExpensesRate'] 		= str_replace(',','',$miscExpenseRate);
$mainArr['BasisCommission'] 		= str_replace(',','',$basisCommission);
$mainArr['Rate'] 					= str_replace(',','',$rate);
$mainArr['Commission'] 				= str_replace(',','',$commission);
$mainArr['WHT'] 					= str_replace(',','',$withholdingTax); 


$mainArr['FirstReleaseCheckbox'] 		= $firstReleaseCheckbox;
$mainArr['FirstReleaseBrokerAmount']	= str_replace(',','',$firstReleaseBrokerAmount);
$mainArr['FirstReleaseAgentAmount'] 	= str_replace(',','',$firstReleaseAgentAmount); 
$mainArr['FirstReleaseBrokerCheck'] 	= str_replace(',','',$firstReleaseBrokerCheck);
$mainArr['FirstReleaseAgentCheck'] 		= str_replace(',','',$firstReleaseAgentCheck);
$mainArr['FirstReleaseDate'] 		= date('Y-m-d', strtotime($firstReleaseDate));

$mainArr['SecondReleaseCheckbox'] 		= $secondReleaseCheckbox; 
$mainArr['SecondReleaseBrokerAmount']	= str_replace(',','',$secondReleaseBrokerAmount);
$mainArr['SecondReleaseAgentAmount'] 	= str_replace(',','',$secondReleaseAgentAmount); 
$mainArr['SecondReleaseBrokerCheck'] 	= str_replace(',','',$secondReleaseBrokerCheck);
$mainArr['SecondReleaseAgentCheck'] 	= str_replace(',','',$secondReleaseAgentCheck);
$mainArr['SecondReleaseDate'] 			= date('Y-m-d', strtotime($secondReleaseDate)); 
  
$mainArr['ThirdReleaseCheckbox'] 		= $thirdReleaseCheckbox;
$mainArr['ThirdReleaseBrokerAmount']	= str_replace(',','',$thirdReleaseBrokerAmount);
$mainArr['ThirdReleaseAgentAmount'] 	= str_replace(',','',$thirdReleaseAgentAmount); 
$mainArr['ThirdReleaseBrokerCheck'] 	= str_replace(',','',$thirdReleaseBrokerCheck);
$mainArr['ThirdReleaseAgentCheck'] 		= str_replace(',','',$thirdReleaseAgentCheck);
$mainArr['ThirdReleaseDate']			= date('Y-m-d', strtotime($thirdReleaseDate));

$mainArr['FourthReleaseCheckbox'] 		= $fourthReleaseCheckbox;
$mainArr['FourthReleaseBrokerAmount']	= str_replace(',','',$fourthReleaseBrokerAmount);
$mainArr['FourthReleaseAgentAmount'] 	= str_replace(',','',$fourthReleaseAgentAmount); 
$mainArr['FourthReleaseBrokerCheck'] 	= str_replace(',','',$fourthReleaseBrokerCheck);
$mainArr['FourthReleaseAgentCheck'] 	= str_replace(',','',$fourthReleaseAgentCheck);
$mainArr['FourthReleaseDate']			= date('Y-m-d', strtotime($fourthReleaseDate));

$mainArr['FifthReleaseCheckbox'] 		= $fifthReleaseCheckbox;
$mainArr['FifthReleaseBrokerAmount']	= str_replace(',','',$fifthReleaseBrokerAmount);
$mainArr['FifthReleaseAgentAmount'] 	= str_replace(',','',$fifthReleaseAgentAmount); 
$mainArr['FifthReleaseBrokerCheck'] 	= str_replace(',','',$fifthReleaseBrokerCheck);
$mainArr['FifthReleaseAgentCheck'] 		= str_replace(',','',$fifthReleaseAgentCheck);
$mainArr['FifthReleaseDate']			= date('Y-m-d', strtotime($fifthReleaseDate));

$mainArr['SixReleaseCheckbox'] 			= $sixReleaseCheckbox;
$mainArr['SixReleaseBrokerAmount']		= str_replace(',','',$sixReleaseBrokerAmount);
$mainArr['SixReleaseAgentAmount'] 		= str_replace(',','',$sixReleaseAgentAmount); 
$mainArr['SixReleaseBrokerCheck'] 		= str_replace(',','',$sixReleaseBrokerCheck);
$mainArr['SixReleaseAgentCheck'] 		= str_replace(',','',$sixReleaseAgentCheck);
$mainArr['SixReleaseDate']				= date('Y-m-d', strtotime($sixReleaseDate));

$mainArr['SevenReleaseCheckbox'] 		= $sevenReleaseCheckbox;
$mainArr['SevenReleaseBrokerAmount']	= str_replace(',','',$sevenReleaseBrokerAmount);
$mainArr['SevenReleaseAgentAmount'] 	= str_replace(',','',$sevenReleaseAgentAmount); 
$mainArr['SevenReleaseBrokerCheck'] 	= str_replace(',','',$sevenReleaseBrokerCheck);
$mainArr['SevenReleaseAgentCheck'] 		= str_replace(',','',$sevenReleaseAgentCheck);
$mainArr['SevenReleaseDate']			= date('Y-m-d', strtotime($sevenReleaseDate));

$mainArr['EightReleaseCheckbox'] 		= $eightReleaseCheckbox;
$mainArr['EightReleaseBrokerAmount']	= str_replace(',','',$eightReleaseBrokerAmount);
$mainArr['EightReleaseAgentAmount'] 	= str_replace(',','',$eightReleaseAgentAmount); 
$mainArr['EightReleaseBrokerCheck'] 	= str_replace(',','',$eightReleaseBrokerCheck);
$mainArr['EightReleaseAgentCheck'] 		= str_replace(',','',$eightReleaseAgentCheck);
$mainArr['EightReleaseDate']			= date('Y-m-d', strtotime($eightReleaseDate));

$mainArr['NineReleaseCheckbox'] 		= $nineReleaseCheckbox;
$mainArr['NineReleaseBrokerAmount']		= str_replace(',','',$nineReleaseBrokerAmount);
$mainArr['NineReleaseAgentAmount'] 		= str_replace(',','',$nineReleaseAgentAmount); 
$mainArr['NineReleaseBrokerCheck'] 		= str_replace(',','',$nineReleaseBrokerCheck);
$mainArr['NineReleaseAgentCheck'] 		= str_replace(',','',$nineReleaseAgentCheck);
$mainArr['NineReleaseDate']				= date('Y-m-d', strtotime($nineReleaseDate));

$mainArr['TenReleaseCheckbox'] 			= $tenReleaseCheckbox;
$mainArr['TenReleaseBrokerAmount']		= str_replace(',','',$tenReleaseBrokerAmount);
$mainArr['TenReleaseAgentAmount'] 		= str_replace(',','',$tenReleaseAgentAmount); 
$mainArr['TenReleaseBrokerCheck'] 		= str_replace(',','',$tenReleaseBrokerCheck);
$mainArr['TenReleaseAgentCheck'] 		= str_replace(',','',$tenReleaseAgentCheck);
$mainArr['TenReleaseDate']				= date('Y-m-d', strtotime($tenReleaseDate));


$mainArr['ElevenReleaseCheckbox'] 			= $elevenReleaseCheckbox;
$mainArr['ElevenReleaseBrokerAmount']		= str_replace(',','',$elevenReleaseBrokerAmount);
$mainArr['ElevenReleaseAgentAmount'] 		= str_replace(',','',$elevenReleaseAgentAmount); 
$mainArr['ElevenReleaseBrokerCheck'] 		= str_replace(',','',$elevenReleaseBrokerCheck);
$mainArr['ElevenReleaseAgentCheck'] 		= str_replace(',','',$elevenReleaseAgentCheck);
$mainArr['ElevenReleaseDate']				= date('Y-m-d', strtotime($elevenReleaseDate));

$mainArr['TwelveReleaseCheckbox'] 			= $twelveReleaseCheckbox;
$mainArr['TwelveReleaseBrokerAmount']		= str_replace(',','',$twelveReleaseBrokerAmount);
$mainArr['TwelveReleaseAgentAmount'] 		= str_replace(',','',$twelveReleaseAgentAmount); 
$mainArr['TwelveReleaseBrokerCheck'] 		= str_replace(',','',$twelveReleaseBrokerCheck);
$mainArr['TwelveReleaseAgentCheck'] 		= str_replace(',','',$twelveReleaseAgentCheck);
$mainArr['TwelveReleaseDate']				= date('Y-m-d', strtotime($twelveReleaseDate));



$mainArr['BrokerAgentAmount'] 		= str_replace(',','',$subtotalReleaseAmount);
 
$mainArr['BrokerAmount']		= str_replace(',','',$subtotalReleaseBrokerAmount);
$mainArr['AgentAmount']			= str_replace(',','',$subtotalReleaseAgentAmount);
$mainArr['AddCashAdvance']		= str_replace(',','',$addCashAdvance);
$mainArr['TotalReleaseAmount']	= str_replace(',','',$totalReleaseAmount);

$mainArr['FullDate'] 			= date('Y-m-d', strtotime($FullDate));
$mainArr['FullCheckbox'] 		= $fullTick;

$mainArr['FullTick'] 			= $fullTick;

$mainArr['FullAmount'] 			= str_replace(',','',$fullAmount);
$mainArr['FullNet'] 			= str_replace(',','',$fullNet);
$mainArr['FullCheck'] 			= str_replace(',','',$fullCheck);
  
$mainArr['TotalAmount'] 		= str_replace(',','',$totalAmount);
$mainArr['TotalWHT'] 			= str_replace(',','',$totalWHT);
  
$mainArr['ReleasesStatus'] 		= str_replace(',','',$releasesStatus);
$mainArr['ReleasesRemarks'] 	= str_replace(',','',$releasesRemarks);
 
$mainArr['NetSellingPrice']			= str_replace(',','',$netSellingPrice); 
  
$condArr = array();
//if($task=="edit"):

	/**********************/

	$existReservation = $utility->checkExistField('ReservationId','releases_to_broker_for_wht','reservationId',$reservationId);
	if($existReservation===false){
		//insert

			$mainArr['CreatedDate'] 	= $timeStamp;
			$mainArr['CreatedBy'] 		= $currentUser; 
			$output 					= $mecon->insertSingleQuery($mainArr,"releases_to_broker_for_wht"); 

	}else{
		//reservation exist update record
			$mainArr['UpdatedDate'] 	= $timeStamp;
			$mainArr['UpdatedBy'] 		= $currentUser;
			$condArr['ReservationId']	= $mainid;
			$output 					= $mecon->updateQuery($mainArr,"releases_to_broker_for_wht",$condArr);


	//update partial table
			$mainArrr = array(); 
			$condArrr = array();
			$mainArrr['PartialStatus'] 	= $releasesStatus; 
			$condArrr['ReservationId']	= $mainid;
			$output3 					= $mecon->updateQuery($mainArrr,"partial_commission_releases",$condArrr);
 
	} 
	/***********************/





	
	
	//LOG TASK 
			$actArr['UserType']			= "accounting2"; 
			$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 Releases to Broker for WHT : [$mainid] - $last_name , $first_name $middle_name";
			$actArr['TransId']			= $mainid; 
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "releases_to_broker_for_wht";
			$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();