// Required: common.js

// SYSTEM_EMPLOYMENT_STATUS GET
JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS = function(){};

	/** 
	 * SP_GET Cache of ParameterSet (Array) 
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY = null;

	
	/** 
	 * =======================================================================================================
	 * Perform SQL GET request to the table SYSTEM_EMPLOYMENT_STATUS. Returns DataSet.
	 *
	 * @param VAR_PARAMETER_ARRAY String() Array with Request ParameterSet.
	 * @param CALLBACK_ADDRESS(bool, String) A callback method when the server response is received.
	 *
	 * @param SQL_KEEP_PARAMETER_TO_CACHE bool (Optional) If TRUE save to cache, for easier paging request.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET = function
	(
		VAR_PARAMETER_ARRAY,
		CALLBACK_ADDRESS,
		SQL_KEEP_PARAMETER_TO_CACHE
	)
	{
		CALLBACK_ADDRESS
		(
			true,
			'{"SYS_EMPLOYSTATUS_ID":{"1":"2","2":"4","3":"7","4":"5","5":"3","6":"6","7":"1"},"SYS_EMPLOYSTATUS_CODE":{"1":"E","2":"N","3":"X","4":"R","5":"S","6":"ST","7":"U"},"SYS_EMPLOYSTATUS_DESCRIPTION":{"1":"Employed","2":"Non-Working","3":"Others","4":"Retired","5":"Self-Employed","6":"Student","7":"Unemployed"},"SYS_EMPLOYSTATUS_REMARKS":{"1":"","2":"Housewives, Disabled, etc.","3":"","4":"","5":"","6":"","7":""},"SYS_EMPLOYSTATUS_STATUS":{"1":"2","2":"2","3":"2","4":"2","5":"2","6":"2","7":"2"},"RECORD_COUNT":{"1":"7","2":"7","3":"7","4":"7","5":"7","6":"7","7":"7"},"PROCESS_TIME":"0","IS_SUCCESS":"TRUE","JSON_COUNT":"7"}'
		);
	}

	/** 
	 * =======================================================================================================
	 * Populate SP-GET request request parameters with default value.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_PREPARE_MAPPED_ARRAY_FOR_GET = function()
	{
		// Initialize
		var RESULT_MAPARRAY = [];

		// Populate default fields
		RESULT_MAPARRAY["PARAM_SYS_EMPLOYSTATUS_ID"] = FLAG_BIGINT_NULL;
		RESULT_MAPARRAY["PARAM_SYS_EMPLOYSTATUS_CODE"] = FLAG_NVARCHAR_NULL;
		RESULT_MAPARRAY["PARAM_SYS_EMPLOYSTATUS_DESCRIPTION"] = FLAG_NVARCHAR_NULL;
		RESULT_MAPARRAY["PARAM_SYS_EMPLOYSTATUS_REMARKS"] = FLAG_NVARCHAR_NULL;
		RESULT_MAPARRAY["PARAM_SYS_EMPLOYSTATUS_STATUS"] = FLAG_TINYINT_NULL;
		
		// Paging Parameters
		RESULT_MAPARRAY["PARAM_ORDER_FIELD"] = "SYS_EMPLOYSTATUS_DESCRIPTION";
		RESULT_MAPARRAY["PARAM_ORDER_TYPE"] = "ASC";
		RESULT_MAPARRAY["PARAM_SKIP"] = 0;
		RESULT_MAPARRAY["PARAM_LIMIT"] = JSCUS_CACHE.SITE_SHOW_RESULT_PER_PAGE_PLAIN_TEXT;

		// Return prepared MapArray
		return RESULT_MAPARRAY;
	}
	
	
	/** 
	 * =======================================================================================================
	 * Reload current page in query, stored at SQL cache.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE = function
	(
		CALLBACK_ADDRESS
	)
	{
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET
		(
			JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY,
			CALLBACK_ADDRESS
		);
	}
	
	/**
	 * =======================================================================================================
	 * Resets a value within the SQL cache to NULLs.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE_CLEAR = function()
	{
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY = null;
	}
				
	/** 
	 * =======================================================================================================
	 * Load First page in query, stored at SQL cache.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE_MOVE_FIRST = function
	(
		CALLBACK_ADDRESS
	)
	{
		// Adjust Paging
		// ...........................................
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"] = 0;

		// Return ParameterSet
		// ...........................................
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE(CALLBACK_ADDRESS);
	}


	/**
     * =======================================================================================================
	 * <summary>Load Previous page in query, stored at SQL cache.</summary>
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE_MOVE_PREV = function
	(
		CALLBACK_ADDRESS
	)
	{
		// Initialize
		// ...........................................
		var PARAM_SKIP = JSVC_NUM.VAR_NVALL(JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"]);
		var PARAM_LIMIT = JSVC_NUM.VAR_NVALL(JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_LIMIT"]);

		// Adjust Paging
		// ...........................................
		if(PARAM_SKIP > PARAM_LIMIT)
		{
			JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"] = PARAM_SKIP - PARAM_LIMIT;
		}
		else
		{
			JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"] = 0;
		}

		// Request Query
		// ...........................................
		if(JSVC_NUM.VAR_NVALL(JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"]) != PARAM_SKIP)
		{
			JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE(CALLBACK_ADDRESS);
			return true;
		}
		else
		{
			return false;	
		}		
	}


	/**
	 * =======================================================================================================
	 * Load Next page in query, stored at SQL cache.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE_MOVE_NEXT = function
	(
		CALLBACK_ADDRESS
	)
	{
		// Initialize
		// ...........................................
		var PARAM_SKIP = JSVC_NUM.VAR_NVALL(JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"]);
		var PARAM_LIMIT = JSVC_NUM.VAR_NVALL(JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_LIMIT"]);

		// Adjust Paging
		// ...........................................
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.PROPERTY_CACHED_QUERY["PARAM_SKIP"] = PARAM_SKIP + PARAM_LIMIT;

		// Request Query
		// ...........................................
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_CACHE(CALLBACK_ADDRESS);
	}
	
	// =======================================================================================================
	
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_CALLBACK_ADDRESS = [];
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_CONTROL_VAR = [];
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_KEEP_RECORD = [];
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_RECORD_STATUS = [];
	
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_PARAM_SYS_EMPLOYSTATUS_ID = [];
	
	/**
	 * =======================================================================================================
	 * Perform SQL GET requests to the table SYSTEM_EMPLOYMENT_STATUS, and populate Form/ComboBox/DataGridViewComboBoxColumn with the request result.
	 * Form/ComboBox/DataGridViewComboBoxColumn to Populate.
	 *
	 * @param Method CALLBACK_ADDRESS A Method to be called on Completion.
	 * @param Control CONTROL_VAR A Control to Populate.
	 * @param Boolean KEEP_RECORD If TRUE keeps the current items when populating ComboBox/ListBox.
	 * @param Byte RECORD_STATUS For Filtering a status of retrieving query.
	 *
	 * @return JSON String used to populate the control. (At Callback Address)
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE = function
	(
		CALLBACK_ADDRESS,
		
		CONTROL_VAR, 
		KEEP_RECORD,
		RECORD_STATUS,
		
		PARAM_SYS_EMPLOYSTATUS_ID,
		MAPPED_ARRAY_PARAMS
	)
	{	
		// Parameter Validation
		// _______________________________________________________________________
		JSVC_AV.VAR_VALIDATE_NULL(CALLBACK_ADDRESS, "CALLBACK_ADDRESS")
		JSVC_AV.VAR_VALIDATE_NULL(CONTROL_VAR, "CONTROL_VAR")
		JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(KEEP_RECORD, 'KEEP_RECORD', 'BOOLEAN');
		JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(RECORD_STATUS, 'RECORD_STATUS', 'NUMERIC');
		JSVC_AV.VAR_VALIDATE_ARGUMENT_TYPE(PARAM_SYS_EMPLOYSTATUS_ID, 'PARAM_SYS_EMPLOYSTATUS_ID', 'NUMERIC');
		
		// Handle Optionals
		// _______________________________________________________________________
		PARAM_SYS_EMPLOYSTATUS_ID = JSVC_VAR.VAR_OPTIONAL(PARAM_SYS_EMPLOYSTATUS_ID, FLAG_BIGINT_NULL);
		
		// Initialize
		// _______________________________________________________________________
		if(JSVC_VAR.VAR_ISSET(MAPPED_ARRAY_PARAMS) == false)
		{
			MAPPED_ARRAY_PARAMS = JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			MAPPED_ARRAY_PARAMS["PARAM_SYS_EMPLOYSTATUS_ID"] = PARAM_SYS_EMPLOYSTATUS_ID;
			MAPPED_ARRAY_PARAMS["PARAM_SYS_EMPLOYSTATUS_STATUS"] = RECORD_STATUS;		
		}		
	
		// Push to Cache
		// _______________________________________________________________________
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_CALLBACK_ADDRESS.push(CALLBACK_ADDRESS);
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_CONTROL_VAR.push(CONTROL_VAR);
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_KEEP_RECORD.push(KEEP_RECORD);
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_RECORD_STATUS.push(RECORD_STATUS);
	
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_PARAM_SYS_EMPLOYSTATUS_ID.push(PARAM_SYS_EMPLOYSTATUS_ID);
			
		// Request Query
		// _______________________________________________________________________
		JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET
		(
			MAPPED_ARRAY_PARAMS, 
			JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_ON_RESPONSE, 
			false
		);
		
	}
	
	/**
	 * Continuation on CUS_GET_THEN_POPULATE_EXECUTE(). Handles response from server.
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_ON_RESPONSE = function
	(
		IS_SUCCESS, 
		RESPONSE_STRING
	)
	{
		// Request failure (connection)
		// ...........................................
		if(IS_SUCCESS != true)
		{
			return null;
		}

		// Catch JSON Error
		// ...........................................
		else if(JSRC_JSON.REF_IS_JSTRING(RESPONSE_STRING) == false)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'Server error - please contact the system administrator : <br />' + RESPONSE_STRING,
				'Information',
				'OK', 'ERROR',
				null
			);	
			return;			
		}
				
		// Initialize
		// ...........................................		
		var CALLBACK_ADDRESS = JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_CALLBACK_ADDRESS.shift();
		var CONTROL_VAR = JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_CONTROL_VAR.shift(); 
		var KEEP_RECORD = JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_KEEP_RECORD.shift();
		var RECORD_STATUS = JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_RECORD_STATUS.shift();
		
		var PARAM_SYS_EMPLOYSTATUS_ID = JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE_CACHE_PARAM_SYS_EMPLOYSTATUS_ID.shift();
	
		// Populate DataGridViewComboBoxColumn
		// ...........................................
		if
		(
			JSVC_VAR.VAR_ISSET(CONTROL_VAR.TYPEOF) &&
			CONTROL_VAR.TYPEOF() == "DataGridView"
		)
		{
			CONTROL_VAR.POPULATE_FROM_QUERY 
			(
				RESPONSE_STRING,
				null,
				KEEP_RECORD,
				false,
				1,
				["2", "1"]
			);
			return null;
		}
								
		// Populate ComboBox Multiples
		// ...........................................
		if(JSVC_VAR.VAR_IS_ARRAY(CONTROL_VAR) && JSOC_ELEMENT.VAR_IS_SELECT(CONTROL_VAR[0]))
		{
			var ARRAY_INDEX = 0;
			while(CONTROL_VAR.length > ARRAY_INDEX)
			{
				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					CONTROL_VAR[ARRAY_INDEX],  RESPONSE_STRING,
					"SYS_EMPLOYSTATUS_ID",
					"SYS_EMPLOYSTATUS_DESCRIPTION",
					KEEP_RECORD, false
				);				
				ARRAY_INDEX ++;
			}
			CALLBACK_ADDRESS(true, RESPONSE_STRING);
			return null;
		}

		// Populate ComboBox Single
		// ...........................................
		if(JSOC_ELEMENT.VAR_IS_SELECT(CONTROL_VAR))
		{
			JSOC_CMB.VAR_ADD_FROM_JSON
				(
					CONTROL_VAR,  RESPONSE_STRING,
					"SYS_EMPLOYSTATUS_ID",
					"SYS_EMPLOYSTATUS_DESCRIPTION",
					KEEP_RECORD, false
				);		
			CALLBACK_ADDRESS(true, RESPONSE_STRING);
			return null;
		}
							
		// Populate Form
		// ...........................................
		if(JSOC_ELEMENT.VAR_IS_PANEL(CONTROL_VAR))
		{
			JSOC_WINDOW.VAR_POPULATE_FROM_QUERY(CONTROL_VAR,  RESPONSE_STRING, ["2", "1"]);
			CALLBACK_ADDRESS(true, RESPONSE_STRING);
			return null;
		}
		
		// Return Result
		// ...........................................
		CALLBACK_ADDRESS(true, RESPONSE_STRING);
		return null;
	}

	/**
	 * =======================================================================================================
	 * Perform SQL GET requests to the table SYSTEM_EMPLOYMENT_STATUS, and populate Form with the request result. Combobox items should be pre-populated.
	 * @param FORM_VAR Parent-Element of the sub-elements to Populate.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_FORM = function
	(
		CALLBACK_ADDRESS,
		
		FORM_VAR, 
		RECORD_STATUS,
		
		PARAM_SYS_EMPLOYSTATUS_ID,
		MAPPED_ARRAY_PARAMS
		
	)
	{
		return JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE
		(
			CALLBACK_ADDRESS,
			
			FORM_VAR, 
			false, 
			RECORD_STATUS, 
			
			PARAM_SYS_EMPLOYSTATUS_ID,
			MAPPED_ARRAY_PARAMS
		);
	}
		
		
	
	/**
	 * =======================================================================================================
	 * Perform SQL GET requests to the table SYSTEM_EMPLOYMENT_STATUS, and populate ComboBox with the request result.
	 * @param COMBOBOX_VAR ComboBox to Populate.
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_COMBOBOX = function 
	(
		CALLBACK_ADDRESS,
		
		COMBOBOX_VAR,
		KEEP_RECORD,	
		RECORD_STATUS,
		
		MAPPED_ARRAY_PARAMS
	)
	{
		return JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE 
			(
				CALLBACK_ADDRESS,
				
				COMBOBOX_VAR,
				KEEP_RECORD,
				RECORD_STATUS,
				
				FLAG_BIGINT_NULL,
				MAPPED_ARRAY_PARAMS
			);
	}
				
	/** 
	 * =======================================================================================================
	 * <summary>Perform SQL GET requests to the table SYSTEM_EMPLOYMENT_STATUS, and populate DataGridViewComboBoxColumn with the request result.</summary>
	 * <param name="COMBOBOX_VAR">DataGridViewComboBoxColumn to Populate.</param>
	 * =======================================================================================================
	 */
	JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_DGV = function
	(
		CALLBACK_ADDRESS,
		
		DGV_VAR, 
		KEEP_RECORD,
		RECORD_STATUS,
		
		MAPPED_ARRAY_PARAMS
	)
	{
		return JSCUS_SQL._SYSTEM._EMPLOYMENT_STATUS.CUS_GET_THEN_POPULATE_EXECUTE
			(
				CALLBACK_ADDRESS,
				
				DGV_VAR, 
				KEEP_RECORD,
				RECORD_STATUS,
				
				FLAG_BIGINT_NULL,
				MAPPED_ARRAY_PARAMS
			);		
	}
	// =======================================================================================================
	