<?php

	// Dismiss Session
	PHPVC_SESSION::VAR_STOP();
	
	// Perform Login
    $SHORTCODE_STATUS = PHPCUS_SHORTCODE::CUS_QUICK_LOGIN();
	
	// Check Array Input
	PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();
	
	// Check already authenticated
	PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();
	// Check access rights. This may slow down server, uncomment this if you requires an extra security
	// PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_ONLY, 'record_trans_employ');

	if
	(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
			[
					'PARAM_REC_TRANSEMPLOY_ID',
					'PARAM_REC_TRANSEMPLOY_REC_TRANS_ID',
					'PARAM_REC_TRANSEMPLOY_REC_EMPLOYEE_ID',
					'PARAM_REC_TRANSEMPLOY_TASK',
					'PARAM_REC_TRANSEMPLOY_TIME_BEGIN_FROM',
					'PARAM_REC_TRANSEMPLOY_TIME_BEGIN_TO',
					'PARAM_REC_TRANSEMPLOY_TIME_END_FROM',
					'PARAM_REC_TRANSEMPLOY_TIME_END_TO',
					'PARAM_REC_TRANSEMPLOY_REMARKS',
					'PARAM_REC_TRANSEMPLOY_DAMAGE',
					'PARAM_REC_TRANSEMPLOY_STATUS',
					
					'PARAM_REC_TRANS_ID',	
					'PARAM_REC_TRANS_CAT_PRODUCT_ID',	
					'PARAM_REC_TRANS_REFERENCE_CODE',	
					'PARAM_REC_TRANS_QUANTITY_YIELD_FROM',
					'PARAM_REC_TRANS_QUANTITY_YIELD_TO',
					'PARAM_REC_TRANS_QUANTITY_POST_FROM',
					'PARAM_REC_TRANS_QUANTITY_POST_TO',
					'PARAM_REC_TRANS_QUANTITY_ACTUAL_FROM',
					'PARAM_REC_TRANS_QUANTITY_ACTUAL_TO',
					'PARAM_REC_TRANS_QUANTITY_MIX_FROM',
					'PARAM_REC_TRANS_QUANTITY_MIX_TO',
					'PARAM_REC_TRANS_COST_PPC_FROM',
					'PARAM_REC_TRANS_COST_PPC_TO',
					'PARAM_REC_TRANS_COST_TOTAL_FROM',
					'PARAM_REC_TRANS_COST_TOTAL_TO',
					'PARAM_REC_TRANS_DATE_POST_FROM',
					'PARAM_REC_TRANS_DATE_POST_TO',
					'PARAM_REC_TRANS_DATE_COMPLETE_FROM',
					'PARAM_REC_TRANS_DATE_COMPLETE_TO',
					'PARAM_REC_TRANS_DATE_SCHEDULE_FROM',
					'PARAM_REC_TRANS_DATE_SCHEDULE_TO',
					'PARAM_REC_TRANS_ACC_ACCOUNT_ID_POST',	
					'PARAM_REC_TRANS_ACC_ACCOUNT_ID_COMPLETE',	
					'PARAM_REC_TRANS_STATUS',	
					'PARAM_REC_EMPLOYEE_ID',	
					'PARAM_REC_EMPLOYEE_NAME',	
					'PARAM_REC_EMPLOYEE_STATUS',	
					'PARAM_REC_EMPLOYEE_SYSTEM_GENERATED',	
		
					'PARAM_ORDER_FIELD',
					'PARAM_ORDER_TYPE',
					'PARAM_SKIP',
					'PARAM_LIMIT'
			], True
		)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------	
			$PARAM_REC_TRANSEMPLOY_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANSEMPLOY_ID');
			$PARAM_REC_TRANSEMPLOY_REC_TRANS_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANSEMPLOY_REC_TRANS_ID');
			$PARAM_REC_TRANSEMPLOY_REC_EMPLOYEE_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANSEMPLOY_REC_EMPLOYEE_ID');
			$PARAM_REC_TRANSEMPLOY_TASK = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_TRANSEMPLOY_TASK');
			$PARAM_REC_TRANSEMPLOY_TIME_BEGIN_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANSEMPLOY_TIME_BEGIN_FROM');
			$PARAM_REC_TRANSEMPLOY_TIME_BEGIN_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANSEMPLOY_TIME_BEGIN_TO');
			$PARAM_REC_TRANSEMPLOY_TIME_END_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANSEMPLOY_TIME_END_FROM');
			$PARAM_REC_TRANSEMPLOY_TIME_END_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANSEMPLOY_TIME_END_TO');
			$PARAM_REC_TRANSEMPLOY_REMARKS = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_TRANSEMPLOY_REMARKS');
			$PARAM_REC_TRANSEMPLOY_DAMAGE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_TRANSEMPLOY_DAMAGE');
			$PARAM_REC_TRANSEMPLOY_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_TRANSEMPLOY_STATUS');
			
			$PARAM_REC_TRANS_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANS_ID');	
			$PARAM_REC_TRANS_CAT_PRODUCT_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANS_CAT_PRODUCT_ID');	
			$PARAM_REC_TRANS_REFERENCE_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_TRANS_REFERENCE_CODE');	
			$PARAM_REC_TRANS_QUANTITY_YIELD_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_YIELD_FROM');
			$PARAM_REC_TRANS_QUANTITY_YIELD_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_YIELD_TO');
			$PARAM_REC_TRANS_QUANTITY_POST_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_POST_FROM');
			$PARAM_REC_TRANS_QUANTITY_POST_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_POST_TO');
			$PARAM_REC_TRANS_QUANTITY_ACTUAL_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_ACTUAL_FROM');
			$PARAM_REC_TRANS_QUANTITY_ACTUAL_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_ACTUAL_TO');
			$PARAM_REC_TRANS_QUANTITY_MIX_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_MIX_FROM');
			$PARAM_REC_TRANS_QUANTITY_MIX_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_QUANTITY_MIX_TO');
			$PARAM_REC_TRANS_COST_PPC_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_COST_PPC_FROM');
			$PARAM_REC_TRANS_COST_PPC_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_COST_PPC_TO');
			$PARAM_REC_TRANS_COST_TOTAL_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_COST_TOTAL_FROM');
			$PARAM_REC_TRANS_COST_TOTAL_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_TRANS_COST_TOTAL_TO');
			$PARAM_REC_TRANS_DATE_POST_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANS_DATE_POST_FROM');
			$PARAM_REC_TRANS_DATE_POST_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANS_DATE_POST_TO');
			$PARAM_REC_TRANS_DATE_COMPLETE_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANS_DATE_COMPLETE_FROM');
			$PARAM_REC_TRANS_DATE_COMPLETE_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANS_DATE_COMPLETE_TO');
			$PARAM_REC_TRANS_DATE_SCHEDULE_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANS_DATE_SCHEDULE_FROM');
			$PARAM_REC_TRANS_DATE_SCHEDULE_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_TRANS_DATE_SCHEDULE_TO');
			$PARAM_REC_TRANS_ACC_ACCOUNT_ID_POST = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANS_ACC_ACCOUNT_ID_POST');	
			$PARAM_REC_TRANS_ACC_ACCOUNT_ID_COMPLETE = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANS_ACC_ACCOUNT_ID_COMPLETE');	
			$PARAM_REC_TRANS_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_TRANS_STATUS');	
			$PARAM_REC_EMPLOYEE_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_EMPLOYEE_ID');	
			$PARAM_REC_EMPLOYEE_NAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_EMPLOYEE_NAME');	
			$PARAM_REC_EMPLOYEE_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_EMPLOYEE_STATUS');	
			$PARAM_REC_EMPLOYEE_SYSTEM_GENERATED = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_EMPLOYEE_SYSTEM_GENERATED');	
			
			$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
			(
					'PARAM_ORDER_FIELD',
					[
						'REC_TRANSEMPLOY_ID', 
						'REC_TRANSEMPLOY_REC_TRANS_ID', 
						'REC_TRANSEMPLOY_REC_EMPLOYEE_ID', 
						'REC_TRANSEMPLOY_TASK', 
						'REC_TRANSEMPLOY_TIME_BEGIN', 
						'REC_TRANSEMPLOY_TIME_END', 
						'REC_TRANSEMPLOY_REMARKS', 
						'REC_TRANSEMPLOY_DAMAGE', 
						'REC_TRANSEMPLOY_STATUS'
						, 
						'REC_TRANS_ID',		
						'REC_TRANS_CAT_PRODUCT_ID',		
						'REC_TRANS_REFERENCE_CODE',		
						'REC_TRANS_QUANTITY_YIELD',		
						'REC_TRANS_QUANTITY_POST',		
						'REC_TRANS_QUANTITY_ACTUAL',		
						'REC_TRANS_QUANTITY_MIX',		
						'REC_TRANS_COST_PPC',		
						'REC_TRANS_COST_TOTAL',		
						'REC_TRANS_DATE_POST',		
						'REC_TRANS_DATE_COMPLETE',		
						'REC_TRANS_DATE_SCHEDULE',		
						'REC_TRANS_ACC_ACCOUNT_ID_POST',		
						'REC_TRANS_ACC_ACCOUNT_ID_COMPLETE',		
						'REC_TRANS_STATUS',		
						'REC_EMPLOYEE_ID',		
						'REC_EMPLOYEE_NAME',		
						'REC_EMPLOYEE_STATUS',		
						'REC_EMPLOYEE_SYSTEM_GENERATED'		
					]
			);		
			$PARAM_ORDER_TYPE = PHPCUS_PARAM::CUS_READ_SORT_TYPE('PARAM_ORDER_TYPE');
			$PARAM_SKIP	= PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_SKIP');
			$PARAM_LIMIT = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_LIMIT');
			
			// ------------------------------------------------------------------
			
			
			// Populate Map Array
			// ...........................................
			$GET_MAP_ARRAY = PHPCUS_RECORD_TRANS_EMPLOY::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_ID'] = $PARAM_REC_TRANSEMPLOY_ID;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_REC_TRANS_ID'] = $PARAM_REC_TRANSEMPLOY_REC_TRANS_ID;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_REC_EMPLOYEE_ID'] = $PARAM_REC_TRANSEMPLOY_REC_EMPLOYEE_ID;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_TASK'] = $PARAM_REC_TRANSEMPLOY_TASK;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_TIME_BEGIN_FROM'] = $PARAM_REC_TRANSEMPLOY_TIME_BEGIN_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_TIME_BEGIN_TO'] = $PARAM_REC_TRANSEMPLOY_TIME_BEGIN_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_TIME_END_FROM'] = $PARAM_REC_TRANSEMPLOY_TIME_END_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_TIME_END_TO'] = $PARAM_REC_TRANSEMPLOY_TIME_END_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_REMARKS'] = $PARAM_REC_TRANSEMPLOY_REMARKS;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_DAMAGE'] = $PARAM_REC_TRANSEMPLOY_DAMAGE;
			$GET_MAP_ARRAY['PARAM_REC_TRANSEMPLOY_STATUS'] = $PARAM_REC_TRANSEMPLOY_STATUS;
			
			$GET_MAP_ARRAY['PARAM_REC_TRANS_ID'] = $PARAM_REC_TRANS_ID;	
			$GET_MAP_ARRAY['PARAM_REC_TRANS_CAT_PRODUCT_ID'] = $PARAM_REC_TRANS_CAT_PRODUCT_ID;	
			$GET_MAP_ARRAY['PARAM_REC_TRANS_REFERENCE_CODE'] = $PARAM_REC_TRANS_REFERENCE_CODE;	
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_YIELD_FROM'] = $PARAM_REC_TRANS_QUANTITY_YIELD_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_YIELD_TO'] = $PARAM_REC_TRANS_QUANTITY_YIELD_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_POST_FROM'] = $PARAM_REC_TRANS_QUANTITY_POST_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_POST_TO'] = $PARAM_REC_TRANS_QUANTITY_POST_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_ACTUAL_FROM'] = $PARAM_REC_TRANS_QUANTITY_ACTUAL_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_ACTUAL_TO'] = $PARAM_REC_TRANS_QUANTITY_ACTUAL_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_MIX_FROM'] = $PARAM_REC_TRANS_QUANTITY_MIX_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_QUANTITY_MIX_TO'] = $PARAM_REC_TRANS_QUANTITY_MIX_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_COST_PPC_FROM'] = $PARAM_REC_TRANS_COST_PPC_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_COST_PPC_TO'] = $PARAM_REC_TRANS_COST_PPC_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_COST_TOTAL_FROM'] = $PARAM_REC_TRANS_COST_TOTAL_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_COST_TOTAL_TO'] = $PARAM_REC_TRANS_COST_TOTAL_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_DATE_POST_FROM'] = $PARAM_REC_TRANS_DATE_POST_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_DATE_POST_TO'] = $PARAM_REC_TRANS_DATE_POST_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_DATE_COMPLETE_FROM'] = $PARAM_REC_TRANS_DATE_COMPLETE_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_DATE_COMPLETE_TO'] = $PARAM_REC_TRANS_DATE_COMPLETE_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_DATE_SCHEDULE_FROM'] = $PARAM_REC_TRANS_DATE_SCHEDULE_FROM;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_DATE_SCHEDULE_TO'] = $PARAM_REC_TRANS_DATE_SCHEDULE_TO;
			$GET_MAP_ARRAY['PARAM_REC_TRANS_ACC_ACCOUNT_ID_POST'] = $PARAM_REC_TRANS_ACC_ACCOUNT_ID_POST;	
			$GET_MAP_ARRAY['PARAM_REC_TRANS_ACC_ACCOUNT_ID_COMPLETE'] = $PARAM_REC_TRANS_ACC_ACCOUNT_ID_COMPLETE;	
			$GET_MAP_ARRAY['PARAM_REC_TRANS_STATUS'] = $PARAM_REC_TRANS_STATUS;	
			$GET_MAP_ARRAY['PARAM_REC_EMPLOYEE_ID'] = $PARAM_REC_EMPLOYEE_ID;	
			$GET_MAP_ARRAY['PARAM_REC_EMPLOYEE_NAME'] = $PARAM_REC_EMPLOYEE_NAME;	
			$GET_MAP_ARRAY['PARAM_REC_EMPLOYEE_STATUS'] = $PARAM_REC_EMPLOYEE_STATUS;	
			$GET_MAP_ARRAY['PARAM_REC_EMPLOYEE_SYSTEM_GENERATED'] = $PARAM_REC_EMPLOYEE_SYSTEM_GENERATED;	
			
			$GET_MAP_ARRAY["PARAM_ORDER_FIELD"] = $PARAM_ORDER_FIELD;
			$GET_MAP_ARRAY["PARAM_ORDER_TYPE"] = $PARAM_ORDER_TYPE;
			$GET_MAP_ARRAY["PARAM_SKIP"] = $PARAM_SKIP;
			$GET_MAP_ARRAY["PARAM_LIMIT"] = $PARAM_LIMIT;
			
			
			// Execute Stored Procedure
			// ...........................................
			$DATA_SET = PHPCUS_RECORD_TRANS_EMPLOY::CUS_GET_ALL_MA($GET_MAP_ARRAY);
			
						
			// Return JSON response
			// ...........................................
			if(empty($DATA_SET) === False)
			{
				PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
			}
			else
			{
				PHPCUS_PARAM::CUS_JSON_SUCCESS('');
			}
			
		}
		Catch(Exception $ERR)
		{		
			PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
			if(isset($_SERVER['HTTP_ORIGIN']))
			{
			    PHPVC_LOG::VAR_ERROR('HTTP_ORIGIN', $_SERVER['HTTP_ORIGIN']);
			}
			if(isset($_SERVER['HTTP_HOST']))
			{
			    PHPVC_LOG::VAR_ERROR('HTTP_HOST', $_SERVER['HTTP_HOST']);
			}		
			if(isset($_SERVER['HTTP_REFERER']))
			{
			    PHPVC_LOG::VAR_ERROR('HTTP_REFERER', $_SERVER['HTTP_REFERER']);
			}
			if(isset($_SERVER['REMOTE_ADDR']))
			{
			    PHPVC_LOG::VAR_ERROR('REMOTE_ADDR', $_SERVER['REMOTE_ADDR']);
			}
			
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
		}
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}

?>