<?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();  
 
  
$reserveId			= isset($_POST['mainid']) 					? trim($_POST['mainid']) : "";
$totalReleaseAmount	= isset($_POST['total_releases_amount'])	? str_replace(',','',trim($_POST['total_releases_amount'])) : "";
$netAmount			= isset($_POST['net_amount'])				? str_replace(',','',trim($_POST['net_amount'])) : "";
$ewt				= isset($_POST['ewt'])						? str_replace(',','',trim($_POST['ewt'])) : "";
$totalCommission	= isset($_POST['total_commission'])			? str_replace(',','',trim($_POST['total_commission'])) : "";
  
$currentUser 	= $_SESSION['danvilles_username'];
$timeStamp		= date('Y-m-d H:i:s');
 
$mainArr		= array(); 
$output 		= ""; 
 
$condArr = array();
 


	$existReservation = $utility->checkExistField('ReservationId','discrepancies_with_balance_alert','reservationId',$reserveId);
	if($existReservation===false){

			$mainArr['ReservationId']	 	= $reserveId; 
			$mainArr['Id']				 	= $mecon->getNextId("Id","discrepancies_with_balance_alert");  
			$mainArr['TotalReleases'] 		= $totalReleaseAmount;
			$mainArr['NetAmount'] 	 		= $netAmount;
			$mainArr['EWT'] 	 			= $ewt;
			$mainArr['TotalCommission'] 	= $totalCommission;
		 
			$mainArr['CreatedDate'] 	 = $timeStamp;
			$mainArr['CreatedBy'] 		 = $currentUser;
			$output = $mecon->insertSingleQuery($mainArr,"discrepancies_with_balance_alert");
			
			//LOG TASK 
					$actArr['UserType']			= "accounting2"; 
					$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']			= "Discrepancies Alert : [".$mainArr['ReservationId']."] - $last_name , $first_name $middle_name";
					$actArr['TransId']			= $mainArr['Id']; 
					$actArr['Action']			= "create";
					$actArr['ActionType']		= "discrepancies_with_balance_alert";
					$actArr['ActionContent']	= json_encode($mainArr);
					$actArr['ActionBy'] 		= $currentUser;	
					$actArr['ActionDate']		= $timeStamp; 
					$utility->encodeActivityLog($actArr);
		 	
 	}
		 

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