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

	// ===============================================================
	// Load Reserved Orders
	// ===============================================================	

	function HTTP_LOAD_ORDER()
	{
		// Load DB data of item
		// ...........................................
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		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_REMARKS', PROPERTY_REC_TRANSACTION_REFNO);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_STATUS', 2);

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

		// 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;
					}

					if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'Orders for table number ' + PROPERTY_REC_TRANSACTION_REFNO + ' not found.',
							'Information',
							'OK', 'ERROR',
							function(){}
						);

						return;
					}
					else
					{
						
						var CTR = 1;

						while(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") >= CTR)
						{
							PROPERTY_REC_TRANSACTION_IDS[CTR] = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_ID", CTR);
							HTTP_LOAD_RESERVED_ITEMS(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_ID", CTR));
							CTR++;
						}

						//show reference number
						JSOC_ELEMENT.VAR_GET('POS_REFERENCE_DISPLAY').style.display = '';
						JSOC_ELEMENT.VAR_VALUE('POS_REFERENCE_NO', PROPERTY_REC_TRANSACTION_REFNO);

						//set customer
						PROPERTY_REC_CUSTOMER_INDEX = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_ID", 1));
						PROPERTY_REC_CUSTOMER_NAME = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_LASTNAME", 1);
						PROPERTY_REC_CUSTOMER_TIN = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_TIN", 1);
						PROPERTY_REC_CUSTOMER_ADDRESS = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_CLIENT_MIDDLENAME", 1);

						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID', PROPERTY_REC_CUSTOMER_INDEX);
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME', PROPERTY_REC_CUSTOMER_NAME);
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN', PROPERTY_REC_CUSTOMER_TIN);
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS', PROPERTY_REC_CUSTOMER_ADDRESS);
					}
				}
			};

		JSCUS_SQL._RECORD._POS_RESERVE.CUS_GET
		(
			GET_MAP_ARRAY,
			RESPONSE_HANDLER,
			true
		);
	}

	function HTTP_LOAD_RESERVED_ITEMS(POSRESERVE_ID)
	{
		// Load DB data of item
		// ...........................................
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_LIST_REC_POSRESERVE_ID', POSRESERVE_ID);

		// 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;
					}

					if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'Cannot retrieve record',
							'Information',
							'OK', 'ERROR',
							function(){}
						);

						return;
					}
					else
					{
						//ADD ITEMS TO CART
						var CTR = 1;

						while(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") >= CTR)
						{
							var COMPUTE_MAP_ARRAY = JSCUS_CALC._RECORD._SALES.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();

							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ID', JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_LIST_CAT_PRODUCT_ID", CTR)));

							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_PRICE', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_AMOUNT_PRICE", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_VAT', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_AMOUNT_VAT", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_POINT', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_AMOUNT_POINT", CTR)));

							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ALLOW_DISCOUNT', JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_ALLOW_DISCOUNT", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ALLOW_SENIOR', JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_ALLOW_SENIOR", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_PER_PIECE_QTY', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_PER_PIECE_QTY", CTR)));

							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_CAT_TAXMODEL_ID", CTR)));
							//JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_PERCENTAGE', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_TAXMODEL_PERCENTAGE", CTR)));
							//JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_AMOUNT', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_TAXMODEL_AMOUNT", CTR))); 

							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_ID', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_LIST_CAT_DISCOUNT_ID", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_PERCENTAGE', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_PERCENTAGE", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_AMOUNT', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_AMOUNT", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_VAT', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_VAT", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_HAS_POINT', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_HAS_POINT", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CHANGE_TAX_TYPE', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_CHANGE_TAX_TYPE", CTR)));
							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_CAT_TAXMODEL_ID", CTR)));


							JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'ITEM_QUANTITY', 	JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_LIST_QTY", CTR)));
							console.log(COMPUTE_MAP_ARRAY);

							//get computation
							TOTALS = JSCUS_CALC._RECORD._SALES.CUS_COMPUTE_MA(COMPUTE_MAP_ARRAY);
							console.log(TOTALS);


							//add item to cart
							var ROW_INDEX = 0;
							var RINDEX = CART_DGV.ROW.COUNT();

							CART_DGV.ROW.INSERT_AT(RINDEX);

							CART_DGV.CELL.VALUE("COUNT", RINDEX, RINDEX + 1);

							CART_DGV.CELL.VALUE("PRODUCT_LV_INDEX", RINDEX, CTR);
								
							CART_DGV.CELL.VALUE("PRODUCT_ID", RINDEX, JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_LIST_CAT_PRODUCT_ID", CTR)));
							CART_DGV.CELL.VALUE("PRODUCT_DESCRIPTION", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_LIST_CAT_PRODUCT_ID_DESCRIPTION", CTR));
							CART_DGV.CELL.VALUE("PRODUCT_VAT", RINDEX, JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_AMOUNT_VAT", CTR)));

							CART_DGV.CELL.VALUE("QTY", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "QUANTITY")));
							CART_DGV.CELL.VALUE("QTY_PCS", RINDEX, JSRC_JSON.REF_READ(TOTALS, "QUANTITY_PCS"));
								
							CART_DGV.CELL.VALUE("POINTS", RINDEX, JSRC_JSON.REF_READ(TOTALS, "POINTS"));

							CART_DGV.CELL.VALUE("DISCOUNT_ID", RINDEX, JSRC_JSON.REF_READ(TOTALS, "CAT_DISCOUNT_ID"));
							CART_DGV.CELL.VALUE("DISCOUNT_VALUE", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_DISCOUNT"));
							CART_DGV.CELL.VALUE("DISCOUNT_PERCENTAGE", RINDEX, JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_PERCENTAGE", CTR)));
							CART_DGV.CELL.VALUE("DISCOUNT_AMOUNT", RINDEX, JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_AMOUNT", CTR)));
							CART_DGV.CELL.VALUE("DISCOUNT_VAT", RINDEX, JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_VAT", CTR)));
							CART_DGV.CELL.VALUE("DISCOUNT_HAS_POINT", RINDEX, JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_HAS_POINT", CTR)));
							CART_DGV.CELL.VALUE("DISCOUNT_CHANGE_TAX_TYPE", RINDEX, JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_CHANGE_TAX_TYPE", CTR)));
							CART_DGV.CELL.VALUE("DISCOUNT_CAT_TAXMODEL_ID", RINDEX, JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_DISCOUNT_CAT_TAXMODEL_ID", CTR)));

							CART_DGV.CELL.VALUE("UOM_ID", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_CAT_UOM_ID", CTR));
							CART_DGV.CELL.VALUE("UOM_CODE", RINDEX, '');

							CART_DGV.CELL.VALUE("PRICE", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "AMOUNT_PRICE")));
							CART_DGV.CELL.VALUE("AMOUNT", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "TOPAY_SUBTOTAL")));
								
							CART_DGV.CELL.VALUE("NONVAT", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_NONVAT"));
							CART_DGV.CELL.VALUE("VAT", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT"));
							CART_DGV.CELL.VALUE("VATABLE", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATABLE"));
							CART_DGV.CELL.VALUE("VATEXEMPT", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATEXEMPT"));
							CART_DGV.CELL.VALUE("VATOTHER", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATOTHER"));
							CART_DGV.CELL.VALUE("VATLESS", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT_LESS"));
							CART_DGV.CELL.VALUE("ZERORATED", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_ZERORATED"));
							
							HTTP_CALCULATE_CART();

							CTR++;
						}

						return;
					}
				}
			};

		JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_GET_ALL
		(
			GET_MAP_ARRAY,
			RESPONSE_HANDLER,
			true
		);
	}


	// ===============================================================
	// Trims empty spaces and perform convertion for numeric fields.
	// ===============================================================
	function FIX_INPUT()
	{
		// Fix String Fields
		// ...........................................
		JSOC_INPUT_TEXT.CTL_TRIM(REC_POSSALE_CODE_TXT);
		
		
		// Fix Numeric Fields (if field type is not number.)
		// ...........................................


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

		
	// ===============================================================
	// Request Save
	// ===============================================================
	function HTTP_SAVE(CALLBACK_METHOD, TABLE_NO)
	{
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_ACC_GROUP_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ACC_GROUP_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_REC_CLIENT_ID", JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID')));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_REFERENCE_CODE", '');					

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_DATE_EXPECTED", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + '.999999');
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_REMARKS", TABLE_NO);					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_STATUS", 2);


		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;
					}

					if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
					{
						return;
					}
					else
					{
						HTTP_SAVE_LIST
						(
							JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "INSERTED_ID", "1")),
							function(IS_SUCCESS)
							{
								if(IS_SUCCESS == false)
								{
									CALLBACK_METHOD(false);
								}

								if(JSVC_STR.VAR_IS_BLANK(PROPERTY_REC_TRANSACTION_REFNO) == false)
								{
									JSOC_ELEMENT.VAR_VALUE('POS_REFERENCE_NO', '-');

									JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID', 1);
									JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME', '-');
									JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN', '');
									JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS', '');

									PROPERTY_REC_TRANSACTION_IDS = [];
									PROPERTY_REC_TRANSACTION_REFNO = '';

									PROPERTY_REC_CUSTOMER_INDEX = -1;
									PROPERTY_REC_CUSTOMER_NAME = '';
									PROPERTY_REC_CUSTOMER_TIN = '';
									PROPERTY_REC_CUSTOMER_ADDRESS = '';
								}

								CART_DGV.ROW.CLEAR();

								HTTP_CALCULATE_CART();

								JSOC_ELEMENT.VAR_VALUE('POS_REFERENCE_NO', '-');

								JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID', 1);
								JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME', '-');
								JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN', '');
								JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS', '');

								JSOC_ELEMENT.VAR_GET('DESEL_CUST_BBI').classList.add('d-none');

								//return products to default pricing scheme
								PRICE_MODEL_ID = 1;
								HTTP_SEARCH();

								JSOC_DIALOG.VAR_MESSAGE_BOX
								(
									'Successfully placed order. Tap OK to continue.',
									'Information',
									'OK', 'ERROR',
									function() {}
								);

								CALLBACK_METHOD(true);
							}
						);
					}
				}
			};

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_RESERVE.CUS_SAVE
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}


	function HTTP_SAVE_LIST(REC_POSRESERVE_ID, CALLBACK_METHOD)
	{
		var SAVE_MAP_ARRAY = [];
		var BUNDLE_MAP_ARRAY = [];

		var ROW_INDEX = 0;
		var CTR = 0;


		while(CART_DGV.ROW.COUNT() > ROW_INDEX)
		{
			SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_REC_POSRESERVE_ID", REC_POSRESERVE_ID);
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_CAT_DISCOUNT_ID", JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_ID', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_CAT_PRODUCT_ID", JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('PRODUCT_ID', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_PRICE_EXPECT", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('AMOUNT', ROW_INDEX)));	
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_PRICE_BASE", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('PRICE', ROW_INDEX)));	
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_QTY", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('QTY', ROW_INDEX)));	
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSRESERVE_LIST_STATUS", 2);

			BUNDLE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_ADD_MAPPED_ARRAY_FOR_SAVE(BUNDLE_MAP_ARRAY, SAVE_MAP_ARRAY);

			ROW_INDEX++;
		}

		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;
					}

					if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
					{
						return;
					}
					else
					{
						CALLBACK_METHOD(true);
					}
				}
			};

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_SAVE
		(
			BUNDLE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}
	
	
	// ===============================================================
	// Request Delete
	// ===============================================================
	function HTTP_DELETE(CALLBACK_METHOD, ROW_INDEX)
	{
		// 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 = CART_DGV.CELL.VALUE("QTY", ROW_INDEX) + ' ' + CART_DGV.CELL.VALUE("UOM_CODE", ROW_INDEX) + ' of ' + CART_DGV.CELL.VALUE("PRODUCT_DESCRIPTION", ROW_INDEX);
		

		CART_DGV.ROW.REMOVE_AT(ROW_INDEX);
		CART_DGV.COLUMN.ROW_COUNT_PRINT('ROW_COUNT');

		HTTP_CALCULATE_CART();

		if(CART_DGV.ROW.COUNT() <= 0)
		{
			//$('#REMOVE_DISCOUNT').addClass('d-none');

			//return products to default pricing scheme
			PRICE_MODEL_ID = 1;
			HTTP_SEARCH();
		}

		CALLBACK_METHOD(true, DELETE_ITEM_DESCRIPTION);
	}
	
	
	// ===============================================================
	// Request Void
	// ===============================================================
	function HTTP_VOID(CALLBACK_METHOD)
	{
		if(JSVC_STR.VAR_IS_BLANK(PROPERTY_REC_TRANSACTION_REFNO) == false)
		{
			JSOC_ELEMENT.VAR_VALUE('POS_REFERENCE_NO', '-');

			JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID', 1);
			JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME', '-');
			JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN', '');
			JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS', '');

			PROPERTY_REC_TRANSACTION_IDS = [];
			PROPERTY_REC_TRANSACTION_REFNO = '';

			PROPERTY_REC_CUSTOMER_INDEX = -1;
			PROPERTY_REC_CUSTOMER_NAME = '';
			PROPERTY_REC_CUSTOMER_TIN = '';
			PROPERTY_REC_CUSTOMER_ADDRESS = '';
		}

		CART_DGV.ROW.CLEAR();

		HTTP_CALCULATE_CART();

		//return products to default pricing scheme
		PRICE_MODEL_ID = 1;
		HTTP_SEARCH();

		CALLBACK_METHOD(true);
	}


	// ===============================================================
	// Add Item
	// ===============================================================
	function HTTP_ADD_ITEM(CALLBACK_METHOD)
	{
		var COMPUTE_MAP_ARRAY = [];

		var NEW_QTY = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY"));
		var CURRENT_QTY = 0;
		var QUANTITY = 0;

		var CART_INDEX = 0;

		// look for exsiting item 
		/*if(CART_DGV.ROW.COUNT() > 0) {

			var ROW_INDEX = 0;

			while(CART_DGV.ROW.COUNT() > ROW_INDEX)
			{
				if(JSVC_NUM.VAR_NVALL(PROPERTY_REC_PRODUCT_ID) == JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('PRODUCT_ID', ROW_INDEX)))
				{
					CURRENT_QTY = JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE("QTY", ROW_INDEX));
					CART_INDEX = ROW_INDEX;

					break;
				}

				ROW_INDEX++;
			}
		}*/

		QUANTITY = NEW_QTY + CURRENT_QTY;


		COMPUTE_MAP_ARRAY = JSCUS_CALC._RECORD._SALES.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ID', PROPERTY_REC_PRODUCT_ID);

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_PRICE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODBRANCH_AMOUNT_PRICE', PROPERTY_EDIT_ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_VAT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_AMOUNT_VAT', PROPERTY_EDIT_ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_POINT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_AMOUNT_POINT', PROPERTY_EDIT_ROW_INDEX)));

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ALLOW_DISCOUNT', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_ALLOW_DISCOUNT', PROPERTY_EDIT_ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ALLOW_SENIOR', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_ALLOW_SENIOR', PROPERTY_EDIT_ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_PER_PIECE_QTY', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_PER_PIECE_QTY', PROPERTY_EDIT_ROW_INDEX)));

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_CAT_TAXMODEL_ID', PROPERTY_EDIT_ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_PERCENTAGE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_TAXMODEL_AMOUNT', PROPERTY_EDIT_ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_AMOUNT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_TAXMODEL_PERCENTAGE', PROPERTY_EDIT_ROW_INDEX))); 

		//check existing discount
		/*if(CART_DGV.ROW.COUNT() > 0)
		{
			if(JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_ID', CART_INDEX)) > 1)
			{
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_ID', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_ID', CART_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_PERCENTAGE', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_PERCENTAGE', CART_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_AMOUNT', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_AMOUNT', CART_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_VAT', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_VAT', CART_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_HAS_POINT', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_HAS_POINT', CART_INDEX))); 
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CHANGE_TAX_TYPE', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CHANGE_TAX_TYPE', CART_INDEX))); 
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CAT_TAXMODEL_ID', CART_INDEX)));
			}
			else
			{
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_ID', PROPERTY_EDIT_ROW_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_PERCENTAGE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_PERCENTAGE', PROPERTY_EDIT_ROW_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_AMOUNT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_AMOUNT', PROPERTY_EDIT_ROW_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_VAT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_VAT', PROPERTY_EDIT_ROW_INDEX)));
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_HAS_POINT', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_HAS_POINT', PROPERTY_EDIT_ROW_INDEX))); 
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CHANGE_TAX_TYPE', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CHANGE_TAX_TYPE', PROPERTY_EDIT_ROW_INDEX))); 
				JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CAT_TAXMODEL_ID', PROPERTY_EDIT_ROW_INDEX)));
			}
		}*/
		//else
		//{
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_ID', PROPERTY_EDIT_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_PERCENTAGE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_PERCENTAGE', PROPERTY_EDIT_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_AMOUNT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_AMOUNT', PROPERTY_EDIT_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_VAT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_VAT', PROPERTY_EDIT_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_HAS_POINT', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_HAS_POINT', PROPERTY_EDIT_ROW_INDEX))); 
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CHANGE_TAX_TYPE', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CHANGE_TAX_TYPE', PROPERTY_EDIT_ROW_INDEX))); 
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CAT_TAXMODEL_ID', PROPERTY_EDIT_ROW_INDEX)));
		//}

				
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'ITEM_QUANTITY', 	QUANTITY);

		console.log(COMPUTE_MAP_ARRAY);

		//get computation
		TOTALS = JSCUS_CALC._RECORD._SALES.CUS_COMPUTE_MA(COMPUTE_MAP_ARRAY);
		console.log(TOTALS);

		//insert to cart
		var ROW_INDEX = 0;
		var RINDEX = CART_DGV.ROW.COUNT();

		var IS_INSERTED = false;

		/*while(CART_DGV.ROW.COUNT() > ROW_INDEX)
		{
			if(JSVC_NUM.VAR_NVALL(PROPERTY_REC_PRODUCT_ID) == JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('PRODUCT_ID', ROW_INDEX)))
			{
				//update existing item on cart
				CART_DGV.CELL.VALUE("QTY", ROW_INDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "QUANTITY")));
				CART_DGV.CELL.VALUE("QTY_PCS", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "QUANTITY_PCS"));

				CART_DGV.CELL.VALUE("POINTS", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "POINTS"));

				CART_DGV.CELL.VALUE("DISCOUNT_ID", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "CAT_DISCOUNT_ID"));
				CART_DGV.CELL.VALUE("DISCOUNT_VALUE", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_DISCOUNT"));

				//check existing discount
				if(JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(TOTALS, "CAT_DISCOUNT_ID")) > 1)
				{
					CART_DGV.CELL.VALUE("DISCOUNT_PERCENTAGE", ROW_INDEX, JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_PERCENTAGE', ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_AMOUNT", ROW_INDEX, JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_AMOUNT', ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_VAT", ROW_INDEX, JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_VAT', ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_HAS_POINT", ROW_INDEX, JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_HAS_POINT', ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_CHANGE_TAX_TYPE", ROW_INDEX, JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CHANGE_TAX_TYPE', ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_CAT_TAXMODEL_ID", ROW_INDEX, JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CAT_TAXMODEL_ID', ROW_INDEX)));
				}
				else
				{
					CART_DGV.CELL.VALUE("DISCOUNT_PERCENTAGE", ROW_INDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_PERCENTAGE', PROPERTY_EDIT_ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_AMOUNT", ROW_INDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_AMOUNT', PROPERTY_EDIT_ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_VAT", ROW_INDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_VAT', PROPERTY_EDIT_ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_HAS_POINT", ROW_INDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_HAS_POINT', PROPERTY_EDIT_ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_CHANGE_TAX_TYPE", ROW_INDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CHANGE_TAX_TYPE', PROPERTY_EDIT_ROW_INDEX)));
					CART_DGV.CELL.VALUE("DISCOUNT_CAT_TAXMODEL_ID", ROW_INDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CAT_TAXMODEL_ID', PROPERTY_EDIT_ROW_INDEX)));
				}

				CART_DGV.CELL.VALUE("UOM_ID", ROW_INDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_CAT_UOM_ID', PROPERTY_EDIT_ROW_INDEX));
				CART_DGV.CELL.VALUE("UOM_CODE", ROW_INDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_UOM_CODE', PROPERTY_EDIT_ROW_INDEX));

				CART_DGV.CELL.VALUE("PRICE", ROW_INDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "AMOUNT_PRICE")));
				CART_DGV.CELL.VALUE("AMOUNT", ROW_INDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "TOPAY_SUBTOTAL")));

				CART_DGV.CELL.VALUE("NONVAT", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_NONVAT"));
				CART_DGV.CELL.VALUE("VAT", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT"));
				CART_DGV.CELL.VALUE("VATABLE", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATABLE"));
				CART_DGV.CELL.VALUE("VATEXEMPT", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATEXEMPT"));
				CART_DGV.CELL.VALUE("VATOTHER", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATOTHER"));
				CART_DGV.CELL.VALUE("VATLESS", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT_LESS"));
				CART_DGV.CELL.VALUE("ZERORATED", ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_ZERORATED"));

				IS_INSERTED = true;
				break;
			}

			ROW_INDEX++;
		}*/

		//new item added, does not exist on cart
		//if(IS_INSERTED === false)
		//{
			var RINDEX = CART_DGV.ROW.COUNT();

			CART_DGV.ROW.INSERT_AT(RINDEX);

			CART_DGV.CELL.VALUE("COUNT", RINDEX, RINDEX + 1);

			CART_DGV.CELL.VALUE("PRODUCT_LV_INDEX", RINDEX, PROPERTY_EDIT_ROW_INDEX);
			
			CART_DGV.CELL.VALUE("PRODUCT_ID", RINDEX, PROPERTY_REC_PRODUCT_ID);
			CART_DGV.CELL.VALUE("PRODUCT_DESCRIPTION", RINDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODBRANCH_CAT_PRODUCT_ID_DESCRIPTION', PROPERTY_EDIT_ROW_INDEX));
			CART_DGV.CELL.VALUE("PRODUCT_VAT", RINDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_AMOUNT_VAT', PROPERTY_EDIT_ROW_INDEX));

			CART_DGV.CELL.VALUE("QTY", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "QUANTITY")));
			CART_DGV.CELL.VALUE("QTY_PCS", RINDEX, JSRC_JSON.REF_READ(TOTALS, "QUANTITY_PCS"));
			
			CART_DGV.CELL.VALUE("POINTS", RINDEX, JSRC_JSON.REF_READ(TOTALS, "POINTS"));

			CART_DGV.CELL.VALUE("DISCOUNT_ID", RINDEX, JSRC_JSON.REF_READ(TOTALS, "CAT_DISCOUNT_ID"));
			CART_DGV.CELL.VALUE("DISCOUNT_VALUE", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_DISCOUNT"));
			CART_DGV.CELL.VALUE("DISCOUNT_PERCENTAGE", RINDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_PERCENTAGE', PROPERTY_EDIT_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_AMOUNT", RINDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_AMOUNT', PROPERTY_EDIT_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_VAT", RINDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_VAT', PROPERTY_EDIT_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_HAS_POINT", RINDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_HAS_POINT', PROPERTY_EDIT_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_CHANGE_TAX_TYPE", RINDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CHANGE_TAX_TYPE', PROPERTY_EDIT_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_CAT_TAXMODEL_ID", RINDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CAT_TAXMODEL_ID', PROPERTY_EDIT_ROW_INDEX)));

			CART_DGV.CELL.VALUE("UOM_ID", RINDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_CAT_UOM_ID', PROPERTY_EDIT_ROW_INDEX));
			CART_DGV.CELL.VALUE("UOM_CODE", RINDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_UOM_CODE', PROPERTY_EDIT_ROW_INDEX));

			CART_DGV.CELL.VALUE("PRICE", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "AMOUNT_PRICE")));
			CART_DGV.CELL.VALUE("AMOUNT", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "TOPAY_SUBTOTAL")));
			
			CART_DGV.CELL.VALUE("NONVAT", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_NONVAT"));
			CART_DGV.CELL.VALUE("VAT", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT"));
			CART_DGV.CELL.VALUE("VATABLE", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATABLE"));
			CART_DGV.CELL.VALUE("VATEXEMPT", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATEXEMPT"));
			CART_DGV.CELL.VALUE("VATOTHER", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATOTHER"));
			CART_DGV.CELL.VALUE("VATLESS", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT_LESS"));
			CART_DGV.CELL.VALUE("ZERORATED", RINDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_ZERORATED"));
		//}

		HTTP_CALCULATE_CART(CALLBACK_METHOD);
	}


	// ===============================================================
	// Edit QTY
	// ===============================================================
	function HTTP_EDIT_QUANTITY(CALLBACK_METHOD)
	{
		var PRODUCT_LV_INDEX =  JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE("PRODUCT_LV_INDEX", PROPERTY_CART_ROW_INDEX));
		var COMPUTE_MAP_ARRAY = JSCUS_CALC._RECORD._SALES.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();


		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ID', PROPERTY_REC_PRODUCT_ID);

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_PRICE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODBRANCH_AMOUNT_PRICE', PRODUCT_LV_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_VAT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_AMOUNT_VAT', PRODUCT_LV_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_AMOUNT_POINT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_AMOUNT_POINT', PRODUCT_LV_INDEX)));

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ALLOW_DISCOUNT', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_ALLOW_DISCOUNT', PRODUCT_LV_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_ALLOW_SENIOR', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_ALLOW_SENIOR', PRODUCT_LV_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_PRODUCT_PER_PIECE_QTY', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_PER_PIECE_QTY', PRODUCT_LV_INDEX)));

		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_CAT_TAXMODEL_ID', PRODUCT_LV_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_PERCENTAGE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_TAXMODEL_AMOUNT', PRODUCT_LV_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_TAXMODEL_AMOUNT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_TAXMODEL_PERCENTAGE', PRODUCT_LV_INDEX))); 

		//check existing discount
		if(JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE("DISCOUNT_ID", PROPERTY_CART_ROW_INDEX)) > 1)
		{
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_ID', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_ID', PROPERTY_CART_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_PERCENTAGE', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_PERCENTAGE', PROPERTY_CART_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_AMOUNT', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_AMOUNT', PROPERTY_CART_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_VAT', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_VAT', PROPERTY_CART_ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_HAS_POINT', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_HAS_POINT', PROPERTY_CART_ROW_INDEX))); 
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CHANGE_TAX_TYPE', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CHANGE_TAX_TYPE', PROPERTY_CART_ROW_INDEX))); 
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CAT_TAXMODEL_ID', PROPERTY_CART_ROW_INDEX)));
		}
		else
		{
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_ID', PRODUCT_LV_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_PERCENTAGE', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_PERCENTAGE', PRODUCT_LV_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_AMOUNT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_AMOUNT', PRODUCT_LV_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_VAT', JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_VAT', PRODUCT_LV_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_HAS_POINT', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_HAS_POINT', PRODUCT_LV_INDEX))); 
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CHANGE_TAX_TYPE', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CHANGE_TAX_TYPE', PRODUCT_LV_INDEX))); 
			JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'CAT_DISCOUNT_CAT_TAXMODEL_ID', JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CAT_TAXMODEL_ID', PRODUCT_LV_INDEX)));
		}		
				
		JSVC_MAP_ARRAY.VAR_SET(COMPUTE_MAP_ARRAY, 'ITEM_QUANTITY', 	JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY")));

		console.log(COMPUTE_MAP_ARRAY);

		//get computation
		TOTALS = JSCUS_CALC._RECORD._SALES.CUS_COMPUTE_MA(COMPUTE_MAP_ARRAY);
		console.log(TOTALS);

		//update existing item on cart
		CART_DGV.CELL.VALUE("QTY", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "QUANTITY")));
		CART_DGV.CELL.VALUE("QTY_PCS", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "QUANTITY_PCS"));

		CART_DGV.CELL.VALUE("POINTS", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "POINTS"));
				
		CART_DGV.CELL.VALUE("DISCOUNT_ID", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "CAT_DISCOUNT_ID"));
		CART_DGV.CELL.VALUE("DISCOUNT_VALUE", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_DISCOUNT"));

		//check existing discount
		if(JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE("DISCOUNT_ID", PROPERTY_CART_ROW_INDEX)) > 1)
		{
			CART_DGV.CELL.VALUE("DISCOUNT_PERCENTAGE", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_PERCENTAGE', PROPERTY_CART_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_AMOUNT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_AMOUNT', PROPERTY_CART_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_VAT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_VAT', PROPERTY_CART_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_HAS_POINT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_HAS_POINT', PROPERTY_CART_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_CHANGE_TAX_TYPE", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CHANGE_TAX_TYPE', PROPERTY_CART_ROW_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_CAT_TAXMODEL_ID", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_CAT_TAXMODEL_ID', PROPERTY_CART_ROW_INDEX)));
		}
		else
		{
			CART_DGV.CELL.VALUE("DISCOUNT_PERCENTAGE", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_PERCENTAGE', PRODUCT_LV_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_AMOUNT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_AMOUNT', PRODUCT_LV_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_VAT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVAL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_VAT', PRODUCT_LV_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_HAS_POINT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_HAS_POINT', PRODUCT_LV_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_CHANGE_TAX_TYPE", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CHANGE_TAX_TYPE', PRODUCT_LV_INDEX)));
			CART_DGV.CELL.VALUE("DISCOUNT_CAT_TAXMODEL_ID", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_LV.CELL.VALUE('CAT_DISCOUNT_CAT_TAXMODEL_ID', PRODUCT_LV_INDEX)));
		}

		CART_DGV.CELL.VALUE("UOM_ID", PROPERTY_CART_ROW_INDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_PRODUCT_CAT_UOM_ID', PRODUCT_LV_INDEX));
		CART_DGV.CELL.VALUE("UOM_CODE", PROPERTY_CART_ROW_INDEX, PRODUCT_BRANCH_LV.CELL.VALUE('CAT_UOM_CODE', PRODUCT_LV_INDEX));

		CART_DGV.CELL.VALUE("PRICE", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "AMOUNT_PRICE")));
		CART_DGV.CELL.VALUE("AMOUNT", PROPERTY_CART_ROW_INDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(TOTALS, "TOPAY_SUBTOTAL")));

		CART_DGV.CELL.VALUE("NONVAT", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_NONVAT"));
		CART_DGV.CELL.VALUE("VAT", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT"));
		CART_DGV.CELL.VALUE("VATABLE", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATABLE"));
		CART_DGV.CELL.VALUE("VATEXEMPT", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATEXEMPT"));
		CART_DGV.CELL.VALUE("VATOTHER", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VATOTHER"));
		CART_DGV.CELL.VALUE("VATLESS", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_VAT_LESS"));
		CART_DGV.CELL.VALUE("ZERORATED", PROPERTY_CART_ROW_INDEX, JSRC_JSON.REF_READ(TOTALS, "TOPAY_ZERORATED"));

		HTTP_CALCULATE_CART(CALLBACK_METHOD);
	}



	// ===============================================================
	// Calculate Cart
	// ===============================================================

	function HTTP_CALCULATE_CART(CALLBACK_METHOD)
	{
		var TOTAL_ITEMS = 0;
		var TOTAL_DUE = 0;
		
		TOTAL_ITEMS = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("QTY"));
		TOTAL_DUE = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("AMOUNT"));

		JSOC_ELEMENT.VAR_VALUE("TOTAL_ITEMS", JSVC_NUM.VAR_CFORMAT(TOTAL_ITEMS));
		JSOC_ELEMENT.VAR_VALUE("TOTAL_AMOUNT", JSVC_NUM.VAR_CFORMAT(TOTAL_DUE));

		JSOC_DIALOG.VAR_MODAL("POS_QTY_MODAL", false);

		if(JSVC_VAR.VAR_ISSET(CALLBACK_METHOD))
		{
			CALLBACK_METHOD(true);
		}
	}


	// ===============================================================
	// Start Shift
	// ===============================================================
	function HTTP_START_SHIFT(CALLBACK_METHOD)
	{
		var START_TIME = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + '.999999';
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_SHIFT.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ACC_GROUP_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ACC_GROUP_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ACC_DEVICE_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID)); 
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ACC_ACCOUNT_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_TIME_BEGIN", START_TIME);

		if(JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ACC_LEVEL_ID) == 4) //cashiers only
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CASH_BEGIN", JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('SHIFT_START_AMOUNT')));
		
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_STATUS", 2);

		var RESPONSE_HANDLER =
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				if(IS_SUCCESS === false) {
					alert("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}

				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);

				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false) {
					alert("REQUEST ERROR: \n" + RESPONSE_STRING); 
					return;
				}
				else {
					var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
									
					if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false) {
						METHOD_REQUEST_FAILURE(CALLBACK_METHOD, JSON_OBJECT);
						return;
					}
					else {
						SHIFT_ID = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "INSERTED_ID", 1));
						SHIFT_TIME_START = START_TIME;

						if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_MAIN_CONTAINER"))
						{
							HTTP_SEARCH();

							PRELOAD_POS_CODE();
							PRELOAD_DISCOUNTS();
							PRELOAD_BANKS();
							PRELOAD_CARD_TYPES();
							PRELOAD_PAYMENT_TERMS();

							AUTO_UPDATE_PRODUCT_DATA();
						}

						if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DEVICE_ID_LBL")) {
							JSOC_ELEMENT.VAR_VALUE('DEVICE_ID_LBL', JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
						}

						JSOC_DIALOG.VAR_MODAL("SHIFT_START_MODAL", false);
						CALLBACK_METHOD(true);
					}
				}
			};

		JSCUS_SQL._RECORD._POS_SHIFT.CUS_SAVE
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER,
			true
		);
	}


	// ===============================================================
	// End Shift
	// ===============================================================
	function HTTP_END_SHIFT()
	{
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_SHIFT.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ACC_GROUP_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ACC_GROUP_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ACC_DEVICE_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ACC_ACCOUNT_ID", JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_ID", SHIFT_ID);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_TIME_END", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + '.999999');

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_STATUS", 1); //log out

		var RESPONSE_HANDLER =
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				if(IS_SUCCESS === false) {
					alert("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}

				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);

				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false) {
					alert("REQUEST ERROR: \n" + RESPONSE_STRING); 
					return;
				}
				else {
					var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
																
					if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false) {
						METHOD_REQUEST_FAILURE(CALLBACK_METHOD, JSON_OBJECT);
						return;
					}

					if(JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ACC_LEVEL_ID) == 4) //cashiers only
					{
						JSOC_DIALOG.VAR_MODAL("SHIFT_END_MODAL_2", false);
					}

					JSCUS_SQL._ACCOUNT._LOGIN.CUS_LOGOUT(CUS_SEND_DIALOG_TRY_DISMISS(), JSCUS_CACHE.LOGOUT_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS]);
				}
			};

		JSCUS_SQL._RECORD._POS_SHIFT.CUS_SAVE
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}