	// ===============================================================
	// Load Parent Information Flags
	// ===============================================================	
	function HTTP_PARENT_LOAD()
	{
	}
	

	// ===============================================================
	// EditHandler Flags
	// ===============================================================	
	
	function HTTP_LOAD(CALLBACK_FUNCTION)
	{
		// Escape if new item
		// ...........................................
		if(JSRC_FLAG.IS_NULL_BIGINT(PROPERTY_REC_PORDER_LIST_ID, 1, 1))
		{
			return;
		}
		
		
		// Load DB data of item
		// ...........................................
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._PO_ORDER_LIST.CUS_GET_THEN_POPULATE_FORM
		(
			function()
			{
				CUS_SEND_DIALOG_TRY_DISMISS();
				
				/*
				JSOC_IMAGE.VAR_SRC_WITH_PROGRESS
				(
					'QR_IMAGE_IMG', 
					'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEAAAAALAAAAAABAAEAAAI=', 
					JSCUS_CACHE.SERVER_URL + '/System/image/qrcode?PARAM_QRCODE=' + JSOC_ELEMENT.VAR_VALUE("REC_PORDER_LIST_ID") + '&PARAM_SIZE=10', 
					JSCUS_CACHE.SERVER_URL + '/res/lib/dlg/noimage.png'
				);
				*/
				
				if(JSVC_VAR.VAR_ISSET(CALLBACK_FUNCTION))
				{
					CALLBACK_FUNCTION();
				}
			},
			
			"PO_ORDER_LIST_MODAL", 
			FLAG_TINYINT_NULL, 
			PROPERTY_REC_PORDER_LIST_ID
		);
		
		
		// Clear Changes due to loading
		// ...........................................
		
		
	}


	// ===============================================================
	// Trims empty spaces and perform convertion for numeric fields.
	// ===============================================================
	function FIX_INPUT()
	{
		// Fix String Fields
		// ...........................................
		
		
		// Fix Numeric Fields (if field type is not number.)
		// ...........................................
			if(JSOC_ELEMENT.VAR_TYPE_IS(REC_PORDER_LIST_COST_TXT, 'input', 'number'))
			{
				JSOC_INPUT_TEXT.CTL_NVAL(REC_PORDER_LIST_COST_TXT);
			}
			else
			{
				JSOC_INPUT_TEXT.CTL_CFORMAT(REC_PORDER_LIST_COST_TXT);
			}			
			if(JSOC_ELEMENT.VAR_TYPE_IS(REC_PORDER_LIST_QUANTITY_EXPECT_TXT, 'input', 'number'))
			{
				JSOC_INPUT_TEXT.CTL_NVAL(REC_PORDER_LIST_QUANTITY_EXPECT_TXT);
			}
			else
			{
				JSOC_INPUT_TEXT.CTL_CFORMAT(REC_PORDER_LIST_QUANTITY_EXPECT_TXT);
			}			


		// Fix Password Fields
		// ...........................................
	}

		
	// ===============================================================
	// Request Save
	// ===============================================================
	function HTTP_SAVE(CALLBACK_METHOD, R_INDEX)
	{
		// Save item [Prepare]
		// _______________________________________________________________________
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._PO_ORDER_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_ID", JSVC_NUM.VAR_NVALL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_ID', R_INDEX))); //LINE ID				
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_REC_PORDER_ID", PROPERTY_PARENT_ID); //MOTHER ID
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_CAT_PRODUCT_ID", JSVC_NUM.VAR_NVALL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_CAT_PRODUCT_ID', R_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_COST", JSVC_NUM.VAR_NVAL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_COST', R_INDEX)));	
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_QUANTITY_EXPECT", JSVC_NUM.VAR_NVAL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_QUANTITY_APPROVE', R_INDEX)));	
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_STATUS", 4); //ALWAYS 4
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PARAM_REC_PORDER_LIST_ID_FILE_FP"))
		{
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_LIST_ID_FILE", PARAM_REC_PORDER_LIST_ID_FILE_FP);
		}
		
		
		// Declare Post Request Handler
		// _______________________________________________________________________
		var RESPONSE_HANDLER = 			
			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;			
				}
				else
				{
					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
					{
						// Retrieve Inserted ID
						if(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_ID', R_INDEX) <=0)
							PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_ID', R_INDEX, JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "INSERTED_ID", "1")));

						PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_QUANTITY_EXPECT', R_INDEX, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_QUANTITY_APPROVE', R_INDEX))));
						var REC_PORDER_LIST_QUANTITY_EXPECT = JSVC_NUM.VAR_NVAL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_QUANTITY_APPROVE', R_INDEX));
						var REC_PORDER_LIST_QUANTITY_RECEIVE = JSVC_NUM.VAR_NVAL(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_QUANTITY_RECEIVE', R_INDEX));
						PO_ORDER_LIST_DGV.CELL.VALUE
						(
							'REC_PORDER_DESCRIPANCY',
							R_INDEX, 
							JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(REC_PORDER_LIST_QUANTITY_EXPECT - REC_PORDER_LIST_QUANTITY_RECEIVE))
						);
						CALLBACK_METHOD(true);
					}
				}
			};
			
			
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._PO_ORDER_LIST.CUS_SAVE 
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
		
	}

	function HTTP_PO_CANCEL(CALLBACK_METHOD)
	{
		// Save item [Prepare]
		// _______________________________________________________________________
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._PO_ORDER.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_ID", PROPERTY_PARENT_ID);				
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_STATUS", 3); //CANCELLED
		
		// Declare Post Request Handler
		// _______________________________________________________________________
		var RESPONSE_HANDLER = 			
			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
					{	
						CALLBACK_METHOD(true);
					}
				}
			};
			
			
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._PO_ORDER.CUS_SAVE 
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}

	function HTTP_APPROVE(CALLBACK_METHOD)
	{
		// Save item [Prepare]
		// _______________________________________________________________________
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._PO_ORDER.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_ID", PROPERTY_PARENT_ID);				
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_ACC_GROUP_ID", JSVC_NUM.VAR_NVALL(PROPERTY_PARENT_BRANCH_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_DATE_EXPECT", JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("PAGE_DATE_EXPECT_LBL"), "YYYY-MM-DD") + '23:59:59.999999');
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_REMARKS", JSOC_ELEMENT.VAR_VALUE("PAGE_REMARKS_LBL"));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_PORDER_STATUS", 2); //ALWAYS APPROVE
		
		
		// Declare Post Request Handler
		// _______________________________________________________________________
		var RESPONSE_HANDLER = 			
			function(IS_SUCCESS, HTTP_RESPONSE)
			{
				CUS_SEND_DIALOG_TRY_DISMISS();

				// 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
					{	
						CALLBACK_METHOD(true);
					}
				}
			};
			
			
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._PO_ORDER.CUS_SAVE 
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}

	function DGV_ADD_PRODUCT(CALLBACK_METHOD)
	{
		FIX_INPUT();

		if(EDIT_HANDLER.REF_IS_MODIFIED == false)
		{
			JSVC_INFO.VAR_NOTHING_TO_LOAD(function(){CALLBACK_METHOD(false);})	
			return;		
		}
		if
		(
			JSVC_VAR.VAR_ISSET(REC_PORDER_LIST_CAT_PRODUCT_ID_CMB) &&
			(
				JSOC_CMB.VAR_SELECTED_INDEX(REC_PORDER_LIST_CAT_PRODUCT_ID_CMB) < 0 ||
				JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(REC_PORDER_LIST_CAT_PRODUCT_ID_CMB)) < 0
			)
		)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'Product is required.', 
				'Information',
				'OK', 'WARNING',
				function(MESSAGE_RESPONSE)
				{
					REC_PORDER_LIST_CAT_PRODUCT_ID_CMB.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
					REC_PORDER_LIST_CAT_PRODUCT_ID_CMB.focus();
					CALLBACK_METHOD(false);
				}
			);	
			return;			
		}
		if(JSOC_INPUT_TEXT.CTL_NVAL(REC_PORDER_LIST_QUANTITY_EXPECT_TXT) <= 0)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'Field Expecting Quantity cannot be less than 1.', 
				'Information',
				'OK', 'WARNING',
				function(MESSAGE_RESPONSE)
				{
					REC_PORDER_LIST_QUANTITY_EXPECT_TXT.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
					REC_PORDER_LIST_QUANTITY_EXPECT_TXT.focus();
					CALLBACK_METHOD(false);
				}
			);	
			return;			
		}

		var RINDEX = PO_ORDER_LIST_DGV.ROW.COUNT();
		PO_ORDER_LIST_DGV.ROW.INSERT_AT(RINDEX);

		PO_ORDER_LIST_DGV.CELL.VALUE("ROW_COUNT", RINDEX, RINDEX + 1);
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_ID", RINDEX, 0);
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_CAT_PRODUCT_ID", RINDEX, JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(REC_PORDER_LIST_CAT_PRODUCT_ID_CMB)));
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_CAT_PRODUCT_ID_DESCRIPTION", RINDEX, JSOC_CMB.VAR_SELECTED_TEXT(REC_PORDER_LIST_CAT_PRODUCT_ID_CMB));
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_COST", RINDEX, 1);
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_QUANTITY_EXPECT", RINDEX, JSOC_INPUT_TEXT.CTL_NVAL(REC_PORDER_LIST_QUANTITY_EXPECT_TXT));
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_QUANTITY_APPROVE", RINDEX, JSOC_INPUT_TEXT.CTL_NVAL(REC_PORDER_LIST_QUANTITY_EXPECT_TXT));
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_QUANTITY_RECEIVE", RINDEX, "0.00");
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_DESCRIPANCY", RINDEX, JSOC_INPUT_TEXT.CTL_NVAL(REC_PORDER_LIST_QUANTITY_EXPECT_TXT));
		PO_ORDER_LIST_DGV.CELL.VALUE("REC_PORDER_LIST_STATUS", RINDEX, 2)

		PO_ORDER_LIST_DGV.COLUMN.CFORMAT("REC_PORDER_LIST_QUANTITY_EXPECT");
		PO_ORDER_LIST_DGV.COLUMN.CFORMAT("REC_PORDER_QUANTITY_APPROVE");
		PO_ORDER_LIST_DGV.COLUMN.CFORMAT("REC_PORDER_DESCRIPANCY");

		//CLEAR MODAL AFTER ADD
		if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
		{
		 	JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
		}
		EDIT_HANDLER.REF_IS_MODIFIED = false;
	}
	
	// ===============================================================
	// Request Delete
	// ===============================================================
	function HTTP_DELETE(CALLBACK_METHOD, ROW_INDEX)
	{
		// Escape if Disabled
		// _______________________________________________________________________
		if(JSVC_VAR.VAR_ISSET(DELETE_BBI) && DELETE_BBI.Enabled == false)
		{
			CALLBACK_METHOD(false);
			return;
		}

		// Escape if nothing selected
		// _______________________________________________________________________
		if(ROW_INDEX < 0)
		{
			JSVC_ERROR.VAR_ARGUMENT_EXCEPTION_NOTHING_SELECTED(true);
			CALLBACK_METHOD(false);
			return;
		}
		
		// Initialize
		// _______________________________________________________________________
		var DELETE_ITEM_DESCRIPTION = PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_ID', ROW_INDEX);
		
		
		
		// Declare Post Request Handler
		// _______________________________________________________________________
		var RESPONSE_HANDLER = function
		(
			IS_SUCCESS, 
			HTTP_RESPONSE
		)
		{
			// Disable Dialogs
			// ...........................................
			CUS_SEND_DIALOG_TRY_DISMISS();
				
				
			// 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;
				}
				
				// Post Delete Action
				else
				{
					PO_ORDER_LIST_DGV.ROW.REMOVE_AT(ROW_INDEX);
					PO_ORDER_LIST_DGV.COLUMN.ROW_COUNT_PRINT('ROW_COUNT');
					JSVC_INFO.VAR_RECORD_DELETED
					(
						DELETE_ITEM_DESCRIPTION, 
						function()
						{
							CALLBACK_METHOD(true);
						}
					);		
				}
			}
		};
		
		
		// Request User Verification for Delete
		// _______________________________________________________________________
		JSVC_INFO.VAR_VERIFY_DELETE
		(
			DELETE_ITEM_DESCRIPTION,
			function(VERIFY_RESULT) 
			{
				// Abort if rejected by user.
				// ...........................................
				if(VERIFY_RESULT != JSOC_DIALOG.MSGBOX_YES)
				{

					CALLBACK_METHOD(false);
					return;
				}
				
				
				//Delete Item
				// ...........................................
				JSOC_DIALOG.VAR_LOADING_SPINNER(true);
				JSCUS_SQL._RECORD._PO_ORDER_LIST.CUS_DELETE
				(
					PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_ID', ROW_INDEX),
					RESPONSE_HANDLER
				)
			}
		);
	}
	
	
	// ===============================================================
	// Request Void
	// ===============================================================
	function HTTP_VOID(CALLBACK_METHOD, ROW_INDEX)
	{
		
		// Escape if Disabled
		// _______________________________________________________________________
		if
		(
			JSVC_VAR.VAR_ISSET(PO_ORDER_LIST_DGV.CELL.ELEMENT('REC_PORDER_LIST_STATUS', ROW_INDEX)) && 
			PO_ORDER_LIST_DGV.CELL.ELEMENT('REC_PORDER_LIST_STATUS', ROW_INDEX).Enabled == false
		)
		{
			CALLBACK_METHOD(false);
			return;
		}

		// Escape if nothing selected
		// _______________________________________________________________________
		if(ROW_INDEX < 0)
		{
			JSVC_ERROR.VAR_ARGUMENT_EXCEPTION_NOTHING_SELECTED(true);
			CALLBACK_METHOD(false);
			return;
		}
		
		// Abort if already Voided (Status = 3)
		// _______________________________________________________________________
		if(PO_ORDER_LIST_DGV.CELL.VALUE('REC_PORDER_LIST_STATUS', ROW_INDEX) == 3)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'This item is already Voided', 
				'Information',
				'OK', 'INFO',
				null
			);		
			return;
		}		
		
		// Notify User to Void	
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_MESSAGE_BOX
		(
			'Do you want to void the selected item?', 
			'Information',
			'YESNO', 'QUESTION',
			function(VERIFY_RESULT)
			{
				if(VERIFY_RESULT == JSOC_DIALOG.MSGBOX_YES)
				{
					PROPERTY_REC_VOUCHER_ID = PO_ORDER_LIST_DGV.CELL.VALUE('5359', ROW_INDEX);
					PROPERTY_EDIT_ROW_INDEX = ROW_INDEX;
					HTTP_LOAD
					(
						function()
						{
							JSOC_CMB.VAR_SELECTED_VALUE(REC_PORDER_LIST_STATUS_CMB, 3);
							JSOC_DIALOG.VAR_MODAL("PO_ORDER_LIST_MODAL", true);
							EDIT_HANDLER.REF_IS_MODIFIED = true;				
						}
					);
				}
			}
		);
		
	}