<?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();
$mainId		= isset($_POST['mainid']) ? trim(strip_tags($_POST['mainid'])) : "";
$ttype		= isset($_POST['types']) ? trim(strip_tags($_POST['types'])) : "";
$transTable	= isset($_POST['transaction']) ? trim(strip_tags($_POST['transaction'])) : "";
$currentUser 	= $_SESSION['danvillee_username'];
$timeStamp		= date('Y-m-d H:i:s');
$output 	= "";  
$condArr 	= array();
$actArr 	= array();

$mainId2 = $mainId;


if($ttype=="buyer_profile"){
$condArr['ReferenceType']					= "buyer_profile";
}else if($ttype=="employee_type"){
$condArr['ReferenceType']					= "employee_type";
}else if($ttype=="position"){
$condArr['ReferenceType']					= "position";
}


//ACTIVITY LOG 
if($transTable=="promo"){
$promo = $utility->getFieldId("Promo","Id",$mainId2,"promo");
$actArr['UserType']			= "accountant,assistant_accountant";
$actArr['Remarks']			= "Deleted Promo : [$mainId2] - $promo";
$actArr['TransId']			= $mainId2;
}else if($transTable=="pricelist"){
$pricelist = $utility->getFieldId("PricelistDate","Id",$mainId2,"pricelist");
$actArr['UserType']			= "accountant,assistant_accountant";
$actArr['Remarks']			= "Deleted Pricelist : [$mainId2] - $pricelist";
$actArr['TransId']			= $mainId2;
}else if($transTable=="reservation"){
$first_name = $utility->getFieldId("FirstName","Id",$mainId2,"reservation");
$last_name = $utility->getFieldId("LastName","Id",$mainId2,"reservation");
$middle_name = $utility->getFieldId("MiddleName","Id",$mainId2,"reservation");
$actArr['UserType']			= "documentation_staff,documentation_supervisor";
$actArr['Remarks']			= "Deleted Reservation : [$mainId2] - $last_name , $first_name $middle_name";
$actArr['TransId']			= $mainId2;
}else if($transTable=="broker"){
$broker = $utility->getFieldId("Broker","Id",$mainId2,"broker");
$actArr['UserType']			= "documentation_staff,documentation_supervisor";
$actArr['Remarks']			= "Deleted Broker : [$mainId2] - $broker";
$actArr['TransId']			= $mainId2;
}else if($transTable=="reference" && $ttype=="employee_type"){
$employee_type = $utility->getFieldId("ReferenceValue","Id",$mainId2,"reference");
$actArr['UserType']			= "documentation_staff,documentation_supervisor";
$actArr['Remarks']			= "Deleted Employee Type : [$mainId2] - $employee_type";
$actArr['TransId']			= $mainId2;
}else if($transTable=="reference" && $ttype=="position"){
$position = $utility->getFieldId("ReferenceValue","Id",$mainId2,"reference");
$actArr['UserType']			= "documentation_staff,documentation_supervisor";
$actArr['Remarks']			= "Deleted Position : [$mainId2] - $position";
$actArr['TransId']			= $mainId2;
}else if($transTable=="reference" && $ttype=="buyer_profile"){
$buyer_profile = $utility->getFieldId("ReferenceValue","Id",$mainId2,"reference");
$actArr['UserType']			= "documentation_staff,documentation_supervisor";
$actArr['Remarks']			= "Deleted Buyer Profile : [$mainId2] - $buyer_profile";
$actArr['TransId']			= $mainId2;
}else if($transTable=="agent"){
$agent = $utility->getFieldId("Agent","Id",$mainId2,"agent");
$actArr['UserType']			= "documentation_staff,documentation_supervisor";
$actArr['Remarks']			= "Deleted Agent : [$mainId2] - $agent";
$actArr['TransId']			= $mainId2;
}else if($transTable=="users"){
$username = $utility->getFieldId("Username","Id",$mainId2,"user");
$actArr['UserType']			= "admin";
$actArr['Remarks']			= "Deleted User : [$mainId2] - $username";
$actArr['TransId']			= $mainId2;
}else if($transTable=="buyer_cheque_monitoring"){
$chequeDate = $utility->getFieldId("ChequeDate","Id",$mainId2,"buyer_cheque_monitoring");
$chequeNo	= $utility->getFieldId("ChequeNo","Id",$mainId2,"buyer_cheque_monitoring");
$reserveId	= $utility->getFieldId("ReservationId","Id",$mainId2,"buyer_cheque_monitoring");
$actArr['UserType']			= "accountant,assistant_accountant";
$actArr['Remarks']			= "Deleted Postdated Checks Received for Equity : [$mainId2] - $chequeDate : $chequeNo ( $reserveId )";
$actArr['TransId']			= $mainId2;
}else if($transTable=="buyer_cheque_monitoring_past_due"){
$chequeDate = $utility->getFieldId("ChequeDate","Id",$mainId2,"buyer_cheque_monitoring_past_due");
$chequeNo	= $utility->getFieldId("ChequeNo","Id",$mainId2,"buyer_cheque_monitoring_past_due");
$reserveId	= $utility->getFieldId("ReservationId","Id",$mainId2,"buyer_cheque_monitoring_past_due");
$actArr['UserType']			= "accountant,assistant_accountant";
$actArr['Remarks']			= "Deleted Postdated Checks Received for Equity : [$mainId2] - $chequeDate : $chequeNo ( $reserveId )";
$actArr['TransId']			= $mainId2;
}

$condArr['Id']					= $mainId;
$output = $mecon->deleteQuery($transTable,$condArr);
$resultArr 						= array();
$resultArr['output']	  		= $output;  

if($output==true){
$actArr['Action']			= "delete";
$actArr['ActionType']		= $transTable;
$actArr['ActionContent']	= json_encode(array());
$actArr['ActionBy'] 		= $currentUser;	
$actArr['ActionDate']		= $timeStamp;
$utility->encodeActivityLog($actArr);
}
echo json_encode($resultArr);
exit();
ob_end_flush();