<?php

	// 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
	PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_ONLY, 'record_job_order');
	
	if
	(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
			[
					'PARAM_REC_JORDER_ID',
					'PARAM_REC_JORDER_ACC_GROUP_ID',
					'PARAM_REC_JORDER_REC_CLIENT_ID',
					'PARAM_REC_JORDER_REFERENCE_NUMBER',
					'PARAM_REC_JORDER_DESCRIPTION',
					'PARAM_REC_JORDER_AMOUNT_FROM',
					'PARAM_REC_JORDER_AMOUNT_TO',
					'PARAM_REC_JORDER_REMARKS',
					'PARAM_REC_JORDER_REMARKS_ASSIGN',
					'PARAM_REC_JORDER_FOR_COMPLETION',
					'PARAM_REC_JORDER_DATE_POST_FROM',
					'PARAM_REC_JORDER_DATE_POST_TO',
					'PARAM_REC_JORDER_DATE_ASSIGN_FROM',
					'PARAM_REC_JORDER_DATE_ASSIGN_TO',
					'PARAM_REC_JORDER_DATE_COMPLETE_FROM',
					'PARAM_REC_JORDER_DATE_COMPLETE_TO',
					'PARAM_REC_JORDER_USER_POST',
					'PARAM_REC_JORDER_USER_ASSIGN',
					'PARAM_REC_JORDER_USER_REVIEW',
					'PARAM_REC_JORDER_LONG_A_FROM',
					'PARAM_REC_JORDER_LONG_A_TO',
					'PARAM_REC_JORDER_LONG_B_FROM',
					'PARAM_REC_JORDER_LONG_B_TO',
					'PARAM_REC_JORDER_DECIMAL_A_FROM',
					'PARAM_REC_JORDER_DECIMAL_A_TO',
					'PARAM_REC_JORDER_DECIMAL_B_FROM',
					'PARAM_REC_JORDER_DECIMAL_B_TO',
					'PARAM_REC_JORDER_VARCHAR_A',
					'PARAM_REC_JORDER_VARCHAR_B',
					'PARAM_REC_JORDER_DATETIME_A_FROM',
					'PARAM_REC_JORDER_DATETIME_A_TO',
					'PARAM_REC_JORDER_DATETIME_B_FROM',
					'PARAM_REC_JORDER_DATETIME_B_TO',
					'PARAM_REC_JORDER_STATUS',
					
					'PARAM_ORDER_FIELD',
					'PARAM_ORDER_TYPE',
					'PARAM_SKIP',
					'PARAM_LIMIT'
			], True
		)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------	
			$PARAM_REC_JORDER_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_ID');
			$PARAM_REC_JORDER_ACC_GROUP_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_ACC_GROUP_ID');
			$PARAM_REC_JORDER_REC_CLIENT_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_REC_CLIENT_ID');
			$PARAM_REC_JORDER_REFERENCE_NUMBER = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_JORDER_REFERENCE_NUMBER');
			$PARAM_REC_JORDER_DESCRIPTION = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_JORDER_DESCRIPTION');
			$PARAM_REC_JORDER_AMOUNT_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_JORDER_AMOUNT_FROM');
			$PARAM_REC_JORDER_AMOUNT_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_JORDER_AMOUNT_TO');
			$PARAM_REC_JORDER_REMARKS = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_JORDER_REMARKS');
			$PARAM_REC_JORDER_REMARKS_ASSIGN = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_JORDER_REMARKS_ASSIGN');
			$PARAM_REC_JORDER_FOR_COMPLETION = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_JORDER_FOR_COMPLETION');
			$PARAM_REC_JORDER_DATE_POST_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATE_POST_FROM');
			$PARAM_REC_JORDER_DATE_POST_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATE_POST_TO');
			$PARAM_REC_JORDER_DATE_ASSIGN_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATE_ASSIGN_FROM');
			$PARAM_REC_JORDER_DATE_ASSIGN_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATE_ASSIGN_TO');
			$PARAM_REC_JORDER_DATE_COMPLETE_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATE_COMPLETE_FROM');
			$PARAM_REC_JORDER_DATE_COMPLETE_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATE_COMPLETE_TO');
			$PARAM_REC_JORDER_USER_POST = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_USER_POST');
			$PARAM_REC_JORDER_USER_ASSIGN = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_USER_ASSIGN');
			$PARAM_REC_JORDER_USER_REVIEW = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_USER_REVIEW');
			$PARAM_REC_JORDER_LONG_A_FROM = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_LONG_A_FROM');
			$PARAM_REC_JORDER_LONG_A_TO = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_LONG_A_TO');
			$PARAM_REC_JORDER_LONG_B_FROM = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_LONG_B_FROM');
			$PARAM_REC_JORDER_LONG_B_TO = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_JORDER_LONG_B_TO');
			$PARAM_REC_JORDER_DECIMAL_A_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_JORDER_DECIMAL_A_FROM');
			$PARAM_REC_JORDER_DECIMAL_A_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_JORDER_DECIMAL_A_TO');
			$PARAM_REC_JORDER_DECIMAL_B_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_JORDER_DECIMAL_B_FROM');
			$PARAM_REC_JORDER_DECIMAL_B_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_JORDER_DECIMAL_B_TO');
			$PARAM_REC_JORDER_VARCHAR_A = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_JORDER_VARCHAR_A');
			$PARAM_REC_JORDER_VARCHAR_B = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_JORDER_VARCHAR_B');
			$PARAM_REC_JORDER_DATETIME_A_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATETIME_A_FROM');
			$PARAM_REC_JORDER_DATETIME_A_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATETIME_A_TO');
			$PARAM_REC_JORDER_DATETIME_B_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATETIME_B_FROM');
			$PARAM_REC_JORDER_DATETIME_B_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_JORDER_DATETIME_B_TO');
			$PARAM_REC_JORDER_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_JORDER_STATUS');
			
			$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
			(
					'PARAM_ORDER_FIELD',
					[
						'REC_JORDER_ID', 
						'REC_JORDER_ACC_GROUP_ID', 
						'REC_JORDER_REC_CLIENT_ID', 
						'REC_JORDER_REFERENCE_NUMBER', 
						'REC_JORDER_DESCRIPTION', 
						'REC_JORDER_AMOUNT', 
						'REC_JORDER_REMARKS', 
						'REC_JORDER_REMARKS_ASSIGN', 
						'REC_JORDER_FOR_COMPLETION', 
						'REC_JORDER_DATE_POST', 
						'REC_JORDER_DATE_ASSIGN', 
						'REC_JORDER_DATE_COMPLETE', 
						'REC_JORDER_USER_POST', 
						'REC_JORDER_USER_ASSIGN', 
						'REC_JORDER_USER_REVIEW', 
						'REC_JORDER_LONG_A', 
						'REC_JORDER_LONG_B', 
						'REC_JORDER_DECIMAL_A', 
						'REC_JORDER_DECIMAL_B', 
						'REC_JORDER_VARCHAR_A', 
						'REC_JORDER_VARCHAR_B', 
						'REC_JORDER_DATETIME_A', 
						'REC_JORDER_DATETIME_B', 
						'REC_JORDER_STATUS'
						, 
						'ACC_GROUP_ID',		
						'ACC_GROUP_DESCRIPTION',		
						'ACC_GROUP_STATUS',		
						'ACC_GROUP_SYSTEM_GENERATED',		
						'REC_CLIENT_ID',		
						'REC_CLIENT_CODE',		
						'REC_CLIENT_LASTNAME',		
						'REC_CLIENT_FIRSTNAME',		
						'REC_CLIENT_MIDDLENAME',		
						'REC_CLIENT_CAT_SUFFIX_ID',		
						'REC_CLIENT_SYS_GENDER_ID',		
						'REC_CLIENT_CONTACT',		
						'REC_CLIENT_EMAIL',		
						'REC_CLIENT_CAT_COMPANY_ID',		
						'REC_CLIENT_SENIOR_CODE',		
						'REC_CLIENT_PWD_CODE',		
						'REC_CLIENT_TIN',		
						'REC_CLIENT_DATE_ISSUED',		
						'REC_CLIENT_ADDRESS',		
						'REC_CLIENT_REMARKS',		
						'REC_CLIENT_STATUS',		
						'REC_CLIENT_SYSTEM_GENERATED',		
						'REC_JORDER_USER_POST_ACC_ACCOUNT_ID', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_SERVER_ID', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_ACC_LEVEL_ID', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_ACC_GROUP_ID', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_ADD_RESOURCE_ID', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_USERNAME', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_PASSWORD', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_AUTH_CODE', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_FIRST_NAME', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_MIDDLE_NAME', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_LAST_NAME', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_POSITION', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_SYS_GENDER_ID', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_STATUS', 
						'REC_JORDER_USER_POST_ACC_ACCOUNT_SYSTEM_GENERATED', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_ID', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_SERVER_ID', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_ACC_LEVEL_ID', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_ACC_GROUP_ID', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_ADD_RESOURCE_ID', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_USERNAME', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_PASSWORD', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_AUTH_CODE', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_FIRST_NAME', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_MIDDLE_NAME', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_LAST_NAME', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_POSITION', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_SYS_GENDER_ID', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_STATUS', 
						'REC_JORDER_USER_ASSIGN_ACC_ACCOUNT_SYSTEM_GENERATED', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_ID', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_SERVER_ID', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_ACC_LEVEL_ID', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_ACC_GROUP_ID', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_ADD_RESOURCE_ID', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_USERNAME', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_PASSWORD', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_AUTH_CODE', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_FIRST_NAME', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_MIDDLE_NAME', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_LAST_NAME', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_POSITION', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_SYS_GENDER_ID', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_STATUS', 
						'REC_JORDER_USER_REVIEW_ACC_ACCOUNT_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_JOB_ORDER::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			
			$GET_MAP_ARRAY['PARAM_REC_JORDER_ID'] = $PARAM_REC_JORDER_ID;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_ACC_GROUP_ID'] = $PARAM_REC_JORDER_ACC_GROUP_ID;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_REC_CLIENT_ID'] = $PARAM_REC_JORDER_REC_CLIENT_ID;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_REFERENCE_NUMBER'] = $PARAM_REC_JORDER_REFERENCE_NUMBER;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DESCRIPTION'] = $PARAM_REC_JORDER_DESCRIPTION;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_AMOUNT_FROM'] = $PARAM_REC_JORDER_AMOUNT_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_AMOUNT_TO'] = $PARAM_REC_JORDER_AMOUNT_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_REMARKS'] = $PARAM_REC_JORDER_REMARKS;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_REMARKS_ASSIGN'] = $PARAM_REC_JORDER_REMARKS_ASSIGN;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_FOR_COMPLETION'] = $PARAM_REC_JORDER_FOR_COMPLETION;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATE_POST_FROM'] = $PARAM_REC_JORDER_DATE_POST_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATE_POST_TO'] = $PARAM_REC_JORDER_DATE_POST_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATE_ASSIGN_FROM'] = $PARAM_REC_JORDER_DATE_ASSIGN_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATE_ASSIGN_TO'] = $PARAM_REC_JORDER_DATE_ASSIGN_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATE_COMPLETE_FROM'] = $PARAM_REC_JORDER_DATE_COMPLETE_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATE_COMPLETE_TO'] = $PARAM_REC_JORDER_DATE_COMPLETE_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_USER_POST'] = $PARAM_REC_JORDER_USER_POST;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_USER_ASSIGN'] = $PARAM_REC_JORDER_USER_ASSIGN;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_USER_REVIEW'] = $PARAM_REC_JORDER_USER_REVIEW;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_LONG_A_FROM'] = $PARAM_REC_JORDER_LONG_A_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_LONG_A_TO'] = $PARAM_REC_JORDER_LONG_A_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_LONG_B_FROM'] = $PARAM_REC_JORDER_LONG_B_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_LONG_B_TO'] = $PARAM_REC_JORDER_LONG_B_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DECIMAL_A_FROM'] = $PARAM_REC_JORDER_DECIMAL_A_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DECIMAL_A_TO'] = $PARAM_REC_JORDER_DECIMAL_A_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DECIMAL_B_FROM'] = $PARAM_REC_JORDER_DECIMAL_B_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DECIMAL_B_TO'] = $PARAM_REC_JORDER_DECIMAL_B_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_VARCHAR_A'] = $PARAM_REC_JORDER_VARCHAR_A;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_VARCHAR_B'] = $PARAM_REC_JORDER_VARCHAR_B;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATETIME_A_FROM'] = $PARAM_REC_JORDER_DATETIME_A_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATETIME_A_TO'] = $PARAM_REC_JORDER_DATETIME_A_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATETIME_B_FROM'] = $PARAM_REC_JORDER_DATETIME_B_FROM;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_DATETIME_B_TO'] = $PARAM_REC_JORDER_DATETIME_B_TO;
			$GET_MAP_ARRAY['PARAM_REC_JORDER_STATUS'] = $PARAM_REC_JORDER_STATUS;
			
			$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_JOB_ORDER::CUS_GET_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');
	}

?>