<?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']) : ""; 
$tcp				= isset($_POST['bpm_tcp']) 		? trim(strip_tags($_POST['bpm_tcp'])) : ""; 
$discount			= isset($_POST['bpm_discount']) ? trim(strip_tags($_POST['bpm_discount'])) : ""; 
//$interest			= isset($_POST['bpm_interest']) ? trim(strip_tags($_POST['bpm_interest'])) : ""; 

$downpayment		= isset($_POST['bpm_downpayment']) 	? trim(strip_tags($_POST['bpm_downpayment'])) : "";  //11AUG24


$remarks			= isset($_POST['bpm_remarks_on_equity'])	? trim(strip_tags($_POST['bpm_remarks_on_equity'])) : ""; 
$daterfdeposited	= isset($_POST['bpm_date_rf_deposited']) 	? trim(strip_tags($_POST['bpm_date_rf_deposited'])) : ""; 
$loanable_amount	= isset($_POST['bpm_loanable_amount']) 	? trim(strip_tags($_POST['bpm_loanable_amount'])) : ""; 
//$pdc_submitted		= isset($_POST['bpm_pdc_submitted']) 	? trim(strip_tags($_POST['bpm_pdc_submitted'])) : ""; 
//$lacking_pdc		= isset($_POST['bpm_lacking_pdc']) 		? trim(strip_tags($_POST['bpm_lacking_pdc'])) : ""; 
$start_of_equity	= isset($_POST['bpm_start_of_equity']) 	? trim(strip_tags($_POST['bpm_start_of_equity'])) : ""; 
$net_equity			= isset($_POST['bpm_net_equity']) 		? trim(strip_tags($_POST['bpm_net_equity'])) : ""; 
$payment_terms		= isset($_POST['bpm_terms_of_payment']) ? trim(strip_tags($_POST['bpm_terms_of_payment'])) : "0"; 
$monthly_equity		= isset($_POST['bpm_monthly_equity']) 	? trim(strip_tags($_POST['bpm_monthly_equity'])) : ""; 
//$payments_made		= isset($_POST['bpm_payments_made']) 	? trim(strip_tags($_POST['bpm_payments_made'])) : ""; 
$takeout_amount		= isset($_POST['bpm_takeout_amount']) 	? trim(strip_tags($_POST['bpm_takeout_amount'])) : ""; 
$mri				= isset($_POST['bpm_mri']) 	? trim(strip_tags($_POST['bpm_mri'])) : ""; 
$net_of_mri			= isset($_POST['bpm_net_of_mri']) 	? trim(strip_tags($_POST['bpm_net_of_mri'])) : ""; 
$adjustment			= isset($_POST['bpm_adjustment']) 	? trim(strip_tags($_POST['bpm_adjustment'])) : ""; 
$takeout_date		= isset($_POST['bpm_takeout_date']) 	? trim(strip_tags($_POST['bpm_takeout_date'])) : ""; 
$difference			= isset($_POST['bpm_difference_of_approved_vs_loanable']) 	? trim(strip_tags($_POST['bpm_difference_of_approved_vs_loanable'])) : ""; 
      
$pagibig_loanable_amount	= isset($_POST['bpm_pagibig_loanable_amount']) 	? trim(strip_tags($_POST['bpm_pagibig_loanable_amount'])) : ""; 
$movein_mri			= isset($_POST['bpm_movein_mri']) 	? trim(strip_tags($_POST['bpm_movein_mri'])) : ""; 
$others				= isset($_POST['bpm_others']) 	? trim(strip_tags($_POST['bpm_others'])) : ""; 
$refilling_fee		= isset($_POST['bpm_refilling_fee']) 	? trim(strip_tags($_POST['bpm_refilling_fee'])) : ""; 
$pagibig_upgrading	= isset($_POST['bpm_pagibig_upgrading']) 	? trim(strip_tags($_POST['bpm_pagibig_upgrading'])) : ""; 
$pagibig_loan_update = isset($_POST['bpm_pagibig_loan_update']) ? trim(strip_tags($_POST['bpm_pagibig_loan_update'])) : ""; 
$collected_date		 = isset($_POST['bpm_collected_date']) ? trim(strip_tags($_POST['bpm_collected_date'])) : ""; 
$deposited_date		 = isset($_POST['bpm_deposited_date']) ? trim(strip_tags($_POST['bpm_deposited_date'])) : ""; 
$movein_amount 		= isset($_POST['bpm_movein_amount']) ? trim(strip_tags($_POST['bpm_movein_amount'])) : ""; 

$payment_mode 		= isset($_POST['bpm_payment_mode']) ? trim($_POST['bpm_payment_mode']) : ""; 
$financing 			= isset($_POST['bpm_financing']) ? trim($_POST['bpm_financing']) : ""; 

$reservation_date 	= isset($_POST['bpm_reservation_date']) ? trim(strip_tags($_POST['bpm_reservation_date'])) : ""; 
$approved_equity 	= isset($_POST['bpm_approved_equity']) ? trim(strip_tags($_POST['bpm_approved_equity'])) : ""; 
$pagibig_approved_loanable_amount 	= isset($_POST['bpm_pagibig_approved_loanable_amount']) ? trim(strip_tags($_POST['bpm_pagibig_approved_loanable_amount'])) : ""; 
     
$currentUser 	= $_SESSION['danvilles_username'];
$timeStamp		= date('Y-m-d H:i:s');
//SAVING CHECKLIST DETAILS   
$mainArr	= array();
$output 	= "";
$mainArr2	= array();
$output2 	= "";
 
$mainArr['ReservationDate'] 		= date('Y-m-d', strtotime($reservation_date));
$mainArr['ApprovedEquityDate'] 		= date('Y-m-d', strtotime($approved_equity));
$mainArr['DateRFDeposited'] 		= date('Y-m-d', strtotime($daterfdeposited));
$mainArr['StartOfEquity']	 		= date('Y-m-d', strtotime($start_of_equity));
$mainArr['PaymentMode']				= $payment_mode; 
$mainArr['Financing']				= $financing; 
$mainArr['ApprovedLoanable']		= str_replace(',','',$pagibig_approved_loanable_amount); 
$mainArr['TCP']						= str_replace(',','',$tcp); 
$mainArr['LoanableAmount'] 			= str_replace(',','',$loanable_amount);
$mainArr['NetEquity']  				= str_replace(',','',$net_equity);
$mainArr['Discount'] 				= str_replace(',','',$discount);

//$mainArr['PDCDiscount'] 			= str_replace(',','',$discount); //24AUG24 disconnect from PDC Special Discount this is separate from the discount from pricelist

$mainArr['PDCDownpayment'] 			= str_replace(',','',$downpayment); //11AUG24

//$mainArr['PDCSubmitted'] 			= str_replace(',','',$pdc_submitted);
$mainArr['TermsOfPayment'] 			= str_replace(',','',$payment_terms);
//$mainArr['Interest'] 				= str_replace(',','',$interest);
//$mainArr['LackingPDC'] 				= str_replace(',','',$lacking_pdc);
$mainArr['MonthlyEquity'] 			= str_replace(',','',$monthly_equity);
$mainArr['RemarksOnEquity'] 		= str_replace(',','',$remarks);
//$mainArr['PaymentsMade'] 			= str_replace(',','',$payments_made);
$mainArr['TakeOutAmount'] 			= str_replace(',','',$takeout_amount);
$mainArr['TakeOutDate'] 			= date('Y-m-d', strtotime($takeout_date));
$mainArr['MRI'] 					= str_replace(',','',$mri);
$mainArr['DifferenceApprovedVSLoanable']	= str_replace(',','',$difference);
$mainArr['Misc']						= str_replace(',','',$net_of_mri);
$mainArr['Adjustment']					= str_replace(',','',$adjustment);
if($adjustment!=""){
$mainArr['AdjustmentDate']					= date('Y-m-d');
}
$mainArr['PagibigLoanableAmount'] 		= str_replace(',','',$pagibig_loanable_amount);
$mainArr['MoveInMRI']					= str_replace(',','',$movein_mri);
$mainArr['MoveInOthers']				= str_replace(',','',$others);
$mainArr['RefillingFee']				= str_replace(',','',$refilling_fee);
$mainArr['PagIbigUpgrading']			= str_replace(',','',$pagibig_upgrading);
$mainArr['PagIbigLoanUpdate']			= str_replace(',','',$pagibig_loan_update);
$mainArr['CollectedDate']				= date('Y-m-d', strtotime($collected_date));
$mainArr['DepositedDate']				= date('Y-m-d', strtotime($deposited_date));
$mainArr['MoveInAmount']				= str_replace(',','',$movein_amount);

$condArr = array();
if($task=="edit"):
	$mainArr['UpdatedDate'] 	= $timeStamp;
	$mainArr['UpdatedBy'] 		= $currentUser;
	$condArr['ReservationId']	= $mainid;
	$output 					= $mecon->updateQuery($mainArr,"buyer_payment_monitoring",$condArr);

	//$mainArr2['DateRFDeposited'] 		= date('Y-m-d', strtotime($daterfdeposited));
	//$output2 					= $mecon->updateQuery($mainArr2,"releases_to_broker",$condArr);

	
	
	
	//LOG TASK 
			$actArr['UserType']			= "assistant_accountant,accountant"; 
			$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 Buyer Payment Monitoring : [$mainid] - $last_name , $first_name $middle_name";
			$actArr['TransId']			= $mainid; 
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "buyer_payment_monitoring";
			$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();