// NOTE: [This JS must loaded as last item]


	// ===============================================================
	// Initialize Form
	// ===============================================================
	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________	
		var DGV_ELEMENT_CHILD = null;
		var DGV_ELEMENT_CHILD_INDEX = 0;
		
		
		// Load DataGridVuew
		// _______________________________________________________________________	
		POS_RESERVE_DGV = DataGridView("POS_RESERVE_DGV");
		PRODUCT_BRANCH_DGV = DataGridView("PRODUCT_BRANCH_DGV");
		JOB_ORDER_TASK_DELIVER_DGV = DataGridView("JOB_ORDER_TASK_DELIVER_DGV");
		JOB_ORDER_TASK_RETURN_DGV = DataGridView("JOB_ORDER_TASK_RETURN_DGV");

		//POS_RESERVE_DGV.SETTING_ALLOW_USER_TO_ADD_ROWS = true;
		//POS_RESERVE_DGV.SETTING_EDITABLE = true;

		PRODUCT_BRANCH_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// Delete Button
				// ...........................................
				if(PRODUCT_BRANCH_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_CMD")
				{
					if(JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_DGV.CELL.VALUE('REC_POSRESERVE_LIST_ID', ROW_INDEX)) > 0)
					{
						HTTP_DELETE
						(
							function(IS_SUCCESS){ }, 
							ROW_INDEX
						);
					}
					else
						PRODUCT_BRANCH_DGV.ROW.REMOVE_AT(ROW_INDEX);
				}
			}
		);

		POS_RESERVE_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_NEW_MODAL") == true && POS_RESERVE_DGV.COLUMN.NAME(COL_INDEX) == "CHILD_CMD")
				{

					if(JSVC_NUM.VAR_NVALL(POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS', ROW_INDEX)) != 1)
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'Only pending reservation can be edit.', 
							'Information',
							'OK', 'WARNING',
							function(){ }
						);	
						return;			
					}

					if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE2))
					{
						JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE2);
					}
					
					// Replace Modal Data
					PROPERTY_REC_POSRESERVE_ID = POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_ID', ROW_INDEX);
					PROPERTY_EDIT_ROW_INDEX = ROW_INDEX;

					//JSOC_CMB.VAR_SELECTED_VALUE("REC_POSRESERVE_ACC_GROUP_ID_CMB", JSVC_NUM.VAR_NVALL(POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_ACC_GROUP_ID', ROW_INDEX)));
					JSOC_CMB.VAR_SELECTED_VALUE("REC_POSRESERVE_REC_CLIENT_ID_CMB", JSVC_NUM.VAR_NVALL(POS_RESERVE_DGV.CELL.VALUE('REC_CLIENT_ID', ROW_INDEX)));
					JSOC_CMB.VAR_SELECTED_VALUE("REC_POSRESERVE_LONG_A_CMB", JSVC_NUM.VAR_NVALL(POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_LONG_A', ROW_INDEX)));
					
					//HTTP_SEARCH_PRODUCT();
					JSOC_CMB.VAR_SELECTED_INDEX("REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB", 9999);

					JSOC_ELEMENT.VAR_VALUE("REC_POSRESERVE_REMARKS_TXT", POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_REMARKS', ROW_INDEX));

					JSOC_DIALOG.VAR_MODAL("POS_RESERVE_NEW_MODAL", true);
					HTTP_LOAD2();
					return;
				}
			}
		); 

		JOB_ORDER_DGV.ON_CLICK
		(
			function(COL_INDEX, ROW_INDEX)
			{
				// If dialog supported
				// ...........................................
				if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("JOB_ORDER_MODAL") == true)
				{
					// Clear Modal
					
					// Display Modal
					PROPERTY_PARENT_ID = JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_LONG_A', ROW_INDEX);
					PROPERTY_REC_JORDER_ID = JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_ID', ROW_INDEX);
					PROPERTY_REC_JORDER_CODE = JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_REFERENCE_NUMBER', ROW_INDEX);
					PROPERTY_EDIT_ROW_INDEX = ROW_INDEX;
					
					if
					(
						JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS', ROW_INDEX)) == 2 &&
						JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_FOR_COMPLETION', ROW_INDEX)) == 1
					)
					{
						$("#SAVE_BBI").show();
						$("#COMPLETION_BBI").show();
						$("#CANCEL_BBI").show();
					}
					else
					{
						$("#SAVE_BBI").hide();
						$("#COMPLETION_BBI").hide();
						$("#CANCEL_BBI").hide();
					}

					JSOC_DIALOG.VAR_MODAL("JOB_ORDER_MODAL", true);

					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_CODE_LBL", PROPERTY_REC_JORDER_CODE);
					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_REC_CLIENT_LBL", ': ' + JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_NAME', ROW_INDEX));
					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_REC_CONTACT_LBL", ': ' + JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_CONTACT', ROW_INDEX));
					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_REC_ADDRESS_LBL", ': ' + JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_ADDRESS', ROW_INDEX));

					if(JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_DECIMAL_A', ROW_INDEX)) == 2)
						JSOC_ELEMENT.VAR_VALUE("REC_JORDER_DECIMAL_A_LBL", ': Cash');
					else if (JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_DECIMAL_A', ROW_INDEX)) == 3)
						JSOC_ELEMENT.VAR_VALUE("REC_JORDER_DECIMAL_A_LBL", ': Credit');
					else
						JSOC_ELEMENT.VAR_VALUE("REC_JORDER_DECIMAL_A_LBL", ':');

					JSOC_ELEMENT.VAR_VALUE("TOTAL_AMOUNT", JSVC_NUM.VAR_CFORMAT(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_AMOUNT', ROW_INDEX)));
					
					HTTP_LOAD();
					return;
				}
			}
		);   

		
		// Show Progress
		// _______________________________________________________________________	
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		
		// Requires Authentication
		// _______________________________________________________________________	
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);	
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_REC_CLIENT_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_POSRESERVE_REC_CLIENT_ID_CMB", FLAG_BIGINT_NULL.toString(), "-");
			// To use custom populate

			var GET_MAP_ARRAY = JSCUS_SQL._RECORD._CLIENT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_CLIENT_STATUS', 2);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'REC_CLIENT_FIRSTNAME');
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_TYPE', 'ASC');
			
			JSCUS_SQL._RECORD._CLIENT.CUS_GET
			(
				GET_MAP_ARRAY,
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					if(IS_SUCCESS === false)
					{
						console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
						return;
					}
					
					// Validate JSON Response
					// _______________________________________________________________________
					var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
					CUS_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
					if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
					{
						console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
						return;
					}
					
					// JSON Empty (Clears the DataGrodView)
					// _______________________________________________________________________
					if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
					{
						return;
					}

					var JSON_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");
					var CTR = 0;
					var COUNTER = 1;
					var TOTAL_SALES = 0;

					while(CTR < JSON_COUNT)
					{
						JSOC_CMB.VAR_ADD
						(
							"REC_POSRESERVE_REC_CLIENT_ID_CMB",
							JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_ID", COUNTER),
							JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_FIRSTNAME", COUNTER) + " " + JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_LASTNAME", COUNTER)
						);
						CTR++;
						COUNTER++;
					}

					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_POSRESERVE_REC_CLIENT_ID_CMB", 0);
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_NEW_MODAL") == true)
					{
						INPUT_INSTANCE2 = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("POS_RESERVE_NEW_MODAL");
					}
					
					HTTP_POPULATE_RESULT();		
				},
				true
			);
		}


		if (true)
		{
			var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._STORAGE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_STORAGE_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ACC_GROUP_ID));
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_STORAGE_IS_STORE', 2);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_STORAGE_STATUS', 2);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'CAT_STORAGE_ID');
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_TYPE', 'DESC');
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_LIMIT', 1);

			JSCUS_SQL._CATEGORY._STORAGE.CUS_GET
			(
				GET_MAP_ARRAY,
				function(IS_SUCCESS, HTTP_RESPONSE)
				{
					// Handle Error
					// ...........................................
					if(IS_SUCCESS === false)
					{
						METHOD_UNABLE_TO_SEND_REQUEST(CALLBACK_METHOD);	
						return;
					}
					
					// Catch JSON Error
					// ...........................................
					else if(JSRC_JSON.REF_IS_JSTRING(HTTP_RESPONSE) == false)
					{
						METHOD_SERVER_ISSUE(CALLBACK_METHOD, HTTP_RESPONSE);
						return;			
					}
						
					// Read Response
					// ...........................................
					else
					{
						// Load Response
						var JSON_OBJECT = JSRC_JSON.REF_CREATE(HTTP_RESPONSE);
						if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
						{
							METHOD_REQUEST_FAILURE(CALLBACK_METHOD, JSON_OBJECT);
							return;
						}
						else
						{
							PROPERTY_REC_STORAGE_ID = JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_STORAGE_ID", 1);
							HTTP_POPULATE_RESULT();
						}
					}
				},
				true
			);
		}

		
		// Get Modal Instance (Add Modal Adjustment before this line)
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTOMER_MODAL") == true)
		{
			INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("CUSTOMER_MODAL");
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_NEW_MODAL") == true)
		{
			INPUT_INSTANCE2 = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("POS_RESERVE_NEW_MODAL");
		}
		
		// Add Search Events for the SEARCH_DESCRIPTION_TXT - TextInput
		// _______________________________________________________________________		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD"))
		{
			var SEARCH_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CMD");
			SEARCH_CMD.onkeydown = 
				function() 
				{ 
					return function(e) 
					{
						if
						(
							(
								e.which == 13 || 
								e.keyCode == 13 || 
								e.key === "Enter"
							) &&
							JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD")
						)
						{
							HTTP_SEARCH();
						}
					};
				}();;		
		}
		
		
		// Load Parent Data (if Exists)
		// _______________________________________________________________________	
		HTTP_PARENT_LOAD();
		
		
		// Pre-Load Items (uncomment if no foreign key pre-fetch)
		// _______________________________________________________________________	
		if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
		{
			HTTP_SEARCH();
		}
		
		// Disable Dialogs
		// _______________________________________________________________________	
		CUS_SEND_DIALOG_TRY_DISMISS();
	};
	
	
	// ===============================================================
	// Populate Foreign Keys
	// ===============================================================
	function HTTP_POPULATE_RESULT(IS_SUCCESS, HTTP_RESPONSE)
	{
		// Disable Dialogs
		CUS_SEND_DIALOG_TRY_DISMISS();
			
		// Handle Error
		if(IS_SUCCESS === false)
		{
			alert("Unable to populate lists.");
		}
		else
		{
			PRELOAD_POSDEVICE(function() {
				HTTP_PRODUCT_LOAD();
				HTTP_RES_SEARCH();
				HTTP_JO_SEARCH();

			});
		}
	};

	function HTTP_PRODUCT_LOAD()
	{
		var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ACC_GROUP_ID));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_STATUS', 2);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_CAT_PRICEMDL_ID', 1);

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'CAT_PRODUCT_DESCRIPTION');
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_TYPE', 'ASC');

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_GET
		(
			GET_MAP_ARRAY,
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				CUS_SEND_DIALOG_TRY_DISMISS();
				
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// Validate JSON Response
				// _______________________________________________________________________
				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				PROD_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
				{
					console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// JSON Empty (Clears the DataGrodView)
				// _______________________________________________________________________
				if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
				{
					return;
				}

				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					'REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB',
					JSON_OBJECT,
					'CAT_PRODUCT_ID',
					'CAT_PRODUCT_DESCRIPTION', 
					false,
					false
				)
			},
			true
		);
	}

	function HTTP_ADD_PRODUCT()
	{
		if(JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB)) <= 0)
		 	return;

		var RINDEX = PRODUCT_BRANCH_DGV.ROW.COUNT();
		PRODUCT_BRANCH_DGV.ROW.INSERT_AT(RINDEX);
		PRODUCT_BRANCH_DGV.CELL.VALUE("REC_POSRESERVE_LIST_ID", RINDEX, 0);
		PRODUCT_BRANCH_DGV.CELL.VALUE("REC_POSRESERVE_LIST_CAT_PRODUCT_ID", RINDEX, JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB)));
		PRODUCT_BRANCH_DGV.CELL.VALUE("REC_POSRESERVE_LIST_CAT_PRODUCT_ID_DESCRIPTION", RINDEX, JSOC_CMB.VAR_SELECTED_TEXT(REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB));
		PRODUCT_BRANCH_DGV.CELL.VALUE("REC_POSRESERVE_LIST_QTY", RINDEX, 1);
		PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODUCT_CAT_UOM_ID_DESCRIPTION", RINDEX, "");
		PRODUCT_BRANCH_DGV.CELL.VALUE("REC_POSRESERVE_LIST_STATUS", RINDEX, 1);

		var ROW_INDEX = 1;
		var CTR = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(PROD_HOLDER, "JSON_COUNT"));
		while(ROW_INDEX <= CTR)
		{
			if
			(
				JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB)) ==
				JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(PROD_HOLDER, "CAT_PRODBRANCH_CAT_PRODUCT_ID", COUNTER))
			)
			{
				PRODUCT_BRANCH_DGV.CELL.VALUE("REC_POSRESERVE_LIST_PRICE_BASE", RINDEX, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(PROD_HOLDER, "CAT_PRODBRANCH_AMOUNT_PRICE", ROW_INDEX))));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODUCT_CAT_UOM_ID_DESCRIPTION", RINDEX, JSRC_JSON.REF_READ(PROD_HOLDER, "CAT_PRODUCT_CAT_UOM_ID_DESCRIPTION", ROW_INDEX));

				return;
			}

			ROW_INDEX++;
		}
	}

	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_RES_SEARCH()
	{
		//GET RESERVATION MOTHER
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ACC_GROUP_ID));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_STATUS', 1);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'REC_POSRESERVE_ID'); 
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_TYPE', 'DESC'); 

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_RESERVE.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_RES_SEARCH_CALLBACK,
			true
		); 
	};
	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_RES_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		RES_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			POS_RESERVE_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		POS_RESERVE_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				false,
				1,
				[2, 1]
		);
		
		
		// For Applying CFormat
		// _______________________________________________________________________	
		// POS_RESERVE_DGV.COLUMN.CFORMAT("REC_POSRESERVE_AMOUNT");
		
		
		// Initialize
		// _______________________________________________________________________	
		var WEBTABLE_DATE = null;
		var ROW_INDEX = 0;
		var CURRENT_CELL_VALUE = null;
		var STATUS; 

		while(POS_RESERVE_DGV.ROW.COUNT() > ROW_INDEX)
		{		
			STATUS = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_STATUS", ROW_INDEX + 1));

			if (STATUS == 1)
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Pending');
			else if (STATUS == 2)
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Approved');
			else if (STATUS == 3)
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Cancelled');
			else
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Completed');

			POS_RESERVE_DGV.CELL.VALUE
			(
				'REC_CLIENT_NAME',
				ROW_INDEX,
				POS_RESERVE_DGV.CELL.VALUE('REC_CLIENT_FIRSTNAME', ROW_INDEX) +
				' ' +
				POS_RESERVE_DGV.CELL.VALUE('REC_CLIENT_LASTNAME', ROW_INDEX)
			);

			ROW_INDEX ++;
		}
	
		// DateTime Format
		// _______________________________________________________________________	
		if(POS_RESERVE_DGV.COLUMN.IS_EXISTS("REC_POSRESERVE_DATE_RECORDED"))
		{
			WEBTABLE_DATE = null;
			ROW_INDEX = 0;
			while(POS_RESERVE_DGV.ROW.COUNT() > ROW_INDEX)
			{
				// Read Current Value
				// ...........................................
				 WEBTABLE_DATE = JSVC_DATE.VAR_TO_DATE
					 (
							POS_RESERVE_DGV.CELL.VALUE
							(
									"REC_POSRESERVE_DATE_RECORDED", 
									ROW_INDEX
							)
					 );
				
				// Apply CFormat, and DateFormat
				// ...........................................
				if(JSVC_VAR.VAR_ISSET(WEBTABLE_DATE))
				{
					POS_RESERVE_DGV.CELL.VALUE
					(
							"REC_POSRESERVE_DATE_RECORDED", ROW_INDEX, 
							JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "MMM DD, YYYY hh:mm TT")
					);	

					POS_RESERVE_DGV.CELL.VALUE
					(
							"REC_POSRESERVE_DATE_RECORDED_RAW", ROW_INDEX, 
							JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "YYYY-MM-DD HH:mm:ss") + '.999999'
					);	
				}			
				
				// To next loop
				// ...........................................	
				ROW_INDEX ++;
			}			
		}
	};

	// ===============================================================
	// Request Search - PART.B
	// ===============================================================
	function HTTP_JO_SEARCH()
	{
		//GET JO MOTHER
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._JOB_ORDER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_STATUS', 2); // LHT LNG NG APPROVE
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_USER_ASSIGN', JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID));

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._JOB_ORDER.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		);
	};
	
	// ===============================================================
	// Request Search - PART.B
	// ===============================================================
	function HTTP_JO_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();

		//RESET DGV
		// _______________________________________________________________________
		JOB_ORDER_DGV.ROW.CLEAR();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			alert("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		JO_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			alert("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			JOB_ORDER_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		JOB_ORDER_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				false,
				1,
				[2, 1]
		);

		var ROW_INDEX = 0;
		var WEBTABLE_DATE = null;
		var CURRENT_CELL_VALUE = null;

		while(JOB_ORDER_DGV.ROW.COUNT() > ROW_INDEX)
		{
			// Get Value
			// ...........................................
			CURRENT_CELL_VALUE = JOB_ORDER_DGV.CELL.VALUE
				(
					"REC_JORDER_DATE_COMPLETE", 
					ROW_INDEX
				);
			
			// Read Current Value
			// ...........................................
			if(JSVC_STR.VAR_IS_BLANK(CURRENT_CELL_VALUE) == false)
			{
				WEBTABLE_DATE = JSVC_DATE.VAR_TO_DATE(CURRENT_CELL_VALUE);			
			}
			else
			{
				WEBTABLE_DATE = null;
			}			
			
			// Apply CFormat, and DateFormat
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(WEBTABLE_DATE))
			{
				JOB_ORDER_DGV.CELL.VALUE
				(
						"REC_JORDER_DATE_COMPLETE", ROW_INDEX, 
						JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "MMM DD, YYYY hh:mm TT")
				);				
			}
			
			
			if(JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_LONG_B', ROW_INDEX)) == 1)
				JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS_TEXT', ROW_INDEX, 'Collected');
			else if(JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS', ROW_INDEX)) == 2)
				JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS_TEXT', ROW_INDEX, 'Approve');
			else if(JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS', ROW_INDEX)) == 3)
				JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS_TEXT', ROW_INDEX, 'Cancelled');
			else if(JSVC_NUM.VAR_NVALL(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS', ROW_INDEX)) == 4)
				JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_STATUS_TEXT', ROW_INDEX, 'Delivered');
			
			JOB_ORDER_DGV.CELL.VALUE
			(
				'REC_CLIENT_NAME',
				ROW_INDEX,
				JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_FIRSTNAME', ROW_INDEX) +
				' ' +
				JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_LASTNAME', ROW_INDEX)
			);

			ROW_INDEX++;
		}
	};

	// ===============================================================
	// Request Search - PART.C
	// ===============================================================
	function HTTP_RES_SEARCH()
	{
		//GET RESERVATION MOTHER
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
		//RECORD_POS_RESERVE_LIST_GET_ALL
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ACC_GROUP_ID));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_STATUS', 1);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'REC_POSRESERVE_ID'); 
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_TYPE', 'DESC'); 

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_RESERVE.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_RES_SEARCH_CALLBACK,
			true
		); 
	};
	
	// ===============================================================
	// Request Search - PART.C
	// ===============================================================
	function HTTP_RES_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		RES_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			POS_RESERVE_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		POS_RESERVE_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				false,
				1,
				[2, 1]
		);
		
		
		// For Applying CFormat
		// _______________________________________________________________________	
		// POS_RESERVE_DGV.COLUMN.CFORMAT("REC_POSRESERVE_AMOUNT");
		
		
		// Initialize
		// _______________________________________________________________________	
		var WEBTABLE_DATE = null;
		var ROW_INDEX = 0;
		var CURRENT_CELL_VALUE = null;
		var STATUS; 

		while(POS_RESERVE_DGV.ROW.COUNT() > ROW_INDEX)
		{		
			STATUS = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_STATUS", ROW_INDEX + 1));

			if (STATUS == 1)
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Pending');
			else if (STATUS == 2)
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Approved');
			else if (STATUS == 3)
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Cancelled');
			else
				POS_RESERVE_DGV.CELL.VALUE('REC_POSRESERVE_STATUS_DESCRIPTION', ROW_INDEX, 'Completed');

			POS_RESERVE_DGV.CELL.VALUE
			(
				'REC_CLIENT_NAME',
				ROW_INDEX,
				POS_RESERVE_DGV.CELL.VALUE('REC_CLIENT_FIRSTNAME', ROW_INDEX) +
				' ' +
				POS_RESERVE_DGV.CELL.VALUE('REC_CLIENT_LASTNAME', ROW_INDEX)
			);

			ROW_INDEX ++;
		}
	
		// DateTime Format
		// _______________________________________________________________________	
		if(POS_RESERVE_DGV.COLUMN.IS_EXISTS("REC_POSRESERVE_DATE_RECORDED"))
		{
			WEBTABLE_DATE = null;
			ROW_INDEX = 0;
			while(POS_RESERVE_DGV.ROW.COUNT() > ROW_INDEX)
			{
				// Read Current Value
				// ...........................................
				 WEBTABLE_DATE = JSVC_DATE.VAR_TO_DATE
					 (
							POS_RESERVE_DGV.CELL.VALUE
							(
									"REC_POSRESERVE_DATE_RECORDED", 
									ROW_INDEX
							)
					 );
				
				// Apply CFormat, and DateFormat
				// ...........................................
				if(JSVC_VAR.VAR_ISSET(WEBTABLE_DATE))
				{
					POS_RESERVE_DGV.CELL.VALUE
					(
							"REC_POSRESERVE_DATE_RECORDED", ROW_INDEX, 
							JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "MMM DD, YYYY hh:mm TT")
					);	

					POS_RESERVE_DGV.CELL.VALUE
					(
							"REC_POSRESERVE_DATE_RECORDED_RAW", ROW_INDEX, 
							JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "YYYY-MM-DD HH:mm:ss") + '.999999'
					);	
				}			
				
				// To next loop
				// ...........................................	
				ROW_INDEX ++;
			}			
		}
	};


	//GET RES & JO LINE DEPENDE SA LOOP

	//
	//RECORD_JOB_ORDER_TASK_GET_ALL

	//INSERT IN TABLE NLNG


	// ===============================================================
	// Begin Processing the Page
	// ===============================================================
	FORM_INITIALIZE();
	FORM_LOAD();