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


if(isset($_POST['company'])){
 
$company	= isset($_POST['company'])	? str_replace('_',' ',htmlentities(addslashes(strip_tags(trim($_POST['company']))))) : "";     
$category	= isset($_POST['category'])	? strip_tags(trim($_POST['category'])) : "";    
$tin_no		= isset($_POST['tin_no'])	? $_POST['tin_no'] : "";    
 
$task		= isset($_POST['action'])	? trim($_POST['action']) : "";
$mainid		= isset($_POST['mainid'])	? trim($_POST['mainid']) : "";

$currentUser 	= $_SESSION['danvilles_username'];
$timeStamp		= date('Y-m-d H:i:s');
$mainArr		= array();
$output 		= "";
 
$mainArr['CompanyName']		=	$company; 
$mainArr['Type']			=	$category;  
$mainArr['TIN']				=	$tin_no;   
 
$condArr = array();
if($task=="create"):
		
	$Id	 						= $mecon->getNextId("Id","tin"); 
	$mainArr['Id']				= $Id;
	$mainArr['CreatedDate'] 	= $timeStamp;
	$mainArr['CreatedBy'] 		= $currentUser;
	$output						= $mecon->insertSingleQuery($mainArr,"tin"); 	 
	
			//LOG TASK 
			$actArr['UserType']			= "accountant";
			$actArr['Remarks']			= "Created New Tin of Supplier : $company";
			$actArr['Action']			= "create";
			$actArr['ActionType']		= "tin";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$actArr['TransId']			= $Id;
			$utility->encodeActivityLog($actArr);

elseif($task=="edit"):
	$mainArr['UpdatedDate'] 		= $timeStamp;
	$mainArr['UpdatedBy'] 			= $currentUser;
	$condArr['Id']					= $mainid;
	$output 						= $mecon->updateQuery($mainArr,"tin",$condArr); 
	
	//LOG TASK 
			$actArr['UserType']			= "accountant";
			$actArr['Remarks']			= "Updated Tin of Supplier : $company";
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "tin";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$actArr['TransId']			= $mainid;
			$utility->encodeActivityLog($actArr);
endif; 
$resultArr 						= array();
$resultArr['output']	  		= $output;
echo json_encode($resultArr);
}
exit();
ob_end_flush();