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

	// ===============================================================
	// Load Accounts Receivable
	// ===============================================================	

	function HTTP_LOAD_CREDITS()
	{
		// Load DB data of item
		// ...........................................
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_SALE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_REC_CLIENT_ID', PROPERTY_REC_CUSTOMER_INDEX);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_STATUS', 2);

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'REC_POSSALE_DATE_TRANSACT');
		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)
					{
						POS_SALE_DGV.ROW.CLEAR();

						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No records found.',
							'Information',
							'OK', 'ERROR',
							function(){}
						);

						return;
					}
					else
					{
						POS_SALE_DGV.POPULATE_FROM_QUERY
						(
							JSON_OBJECT, 
							'',
							false,
							false,
							1,
							[2, 1]
						);

						if(POS_SALE_DGV.COLUMN.IS_EXISTS("REC_POSSALE_DATE_TRANSACT"))
						{
							WEBTABLE_DATE = null;
							ROW_INDEX = 0;
							while(POS_SALE_DGV.ROW.COUNT() > ROW_INDEX)
							{
								// Read Current Value
								// ...........................................
								 WEBTABLE_DATE = JSVC_DATE.VAR_TO_DATE
									 (
											POS_SALE_DGV.CELL.VALUE
											(
													"REC_POSSALE_DATE_TRANSACT", 
													ROW_INDEX
											)
									 );
								
								// Apply CFormat, and DateFormat
								// ...........................................
								if(JSVC_VAR.VAR_ISSET(WEBTABLE_DATE))
								{
									POS_SALE_DGV.CELL.VALUE
									(
											"REC_POSSALE_DATE_TRANSACT", ROW_INDEX, 
											JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "MMM DD, YYYY")
									);				
								}			
								
								// To next loop
								// ...........................................	
								ROW_INDEX ++;
							}			
						}

						if(POS_SALE_DGV.COLUMN.IS_EXISTS("REC_POSSALE_DATE_DUE"))
						{
							WEBTABLE_DATE = null;
							ROW_INDEX = 0;
							while(POS_SALE_DGV.ROW.COUNT() > ROW_INDEX)
							{
								// Read Current Value
								// ...........................................
								 WEBTABLE_DATE = JSVC_DATE.VAR_TO_DATE
									 (
											POS_SALE_DGV.CELL.VALUE
											(
													"REC_POSSALE_DATE_DUE", 
													ROW_INDEX
											)
									 );
								
								// Apply CFormat, and DateFormat
								// ...........................................
								if(JSVC_VAR.VAR_ISSET(WEBTABLE_DATE))
								{
									POS_SALE_DGV.CELL.VALUE
									(
											"REC_POSSALE_DATE_DUE", ROW_INDEX, 
											JSVC_DATE.VAR_FORMAT(WEBTABLE_DATE, "MMM DD, YYYY")
									);				
								}			
								
								// To next loop
								// ...........................................	
								ROW_INDEX ++;
							}			
						}

						if(POS_SALE_DGV.COLUMN.IS_EXISTS("REC_POSSALE_DUE"))
						{
							ROW_INDEX = 0;

							while(POS_SALE_DGV.ROW.COUNT() > ROW_INDEX)
							{
								// Read Current Value
								// ...........................................
								TOTAL_PAID = JSVC_NUM.VAR_NVAL(POS_SALE_DGV.CELL.VALUE('REC_POSSALE_TOTAL_PAID', ROW_INDEX));
								TOTAL_DUE = JSVC_NUM.VAR_NVAL(POS_SALE_DGV.CELL.VALUE('REC_POSSALE_TOTAL_SUBTOTAL', ROW_INDEX));

								BALANCE = TOTAL_DUE - TOTAL_PAID;

								POS_SALE_DGV.CELL.VALUE('REC_POSSALE_DUE', ROW_INDEX, JSVC_NUM.VAR_CFORMAT(BALANCE));
								
								// To next loop
								// ...........................................	
								ROW_INDEX ++;
							}			
						}

						JSOC_ELEMENT.VAR_VALUE('TOTAL_BALANCE_TXT', JSVC_NUM.VAR_CFORMAT(POS_SALE_DGV.COLUMN.SUM('REC_POSSALE_DUE')));
						JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT', JSVC_NUM.VAR_CFORMAT(0));

						$('th#POS_SALE_DGV_HEADER_SELECTED > input').click();
					}
				}
			};


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

	// ===============================================================
	// 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)
	{
		var SAVE_MAP_ARRAY1 = [];
		var SAVE_MAP_ARRAY2 = [];

		var ORDER_ARRAY = [];
		var PAYMENT_ARRAY = [];
		var FINAL_SAVE_MAP_ARRAY = [];
		
		var ACCOUNT_ID = JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID);

		var TRANSACTION_NO = JSOC_ELEMENT.VAR_VALUE('POS_TRANSACTION_NO');
		var TRANSACTION_DATE = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + '.999999';

		var CUSTOMER_ID = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID'));
		var CUSTOMER_NAME = JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME');
		var CUSTOMER_TIN = JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN');
		var CUSTOMER_ADDRESS = JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS');

		var LOYALTY_NUMBER = JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_NUMBER');
		var LOYALTY_POINTS = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_POINTS'));
		var LOYALTY_POINTS_EARNED = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('TOTAL_POINTS'));
		var LOYALTY_TOTAL_POINTS = LOYALTY_POINTS + LOYALTY_POINTS_EARNED;
		
		var VOUCHER_ID = 1;

		var PAYMENT_TYPES = ['CASH', 'CARD', 'CHECK', 'BANK', 'CREDIT', 'LOYALTY', 'VOUCHER'];
		var PAYMENT_TYPE_ID = 0;

		var AMOUNT_CHANGE = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('CHECKOUT_CHANGE_VALUE'));
		
		var RECEIPT = '';

		var ROW_INDEX = 0;
		var CTR = 0;

		//cart
		while(CART_DGV.ROW.COUNT() > ROW_INDEX)
		{
			SAVE_MAP_ARRAY1 = JSCUS_SQL._RECORD._POS_SALE_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_PURCHASE();

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_REC_CLIENT_ID", CUSTOMER_ID);
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_REC_LOYALTY_ID", PROPERTY_REC_LOYALTYCARD_INDEX);

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_CODE", TRANSACTION_NO);

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_DATE_DUE", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(PROPERTY_REC_CREDIT_DATE), "YYYY-MM-DD HH:mm:ss") + '.999999');
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_REMARKS", '');

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_ACC_ACCOUNT_ID", ACCOUNT_ID);
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_DATE_TRANSACT", TRANSACTION_DATE);

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_STATUS", 2);

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_CAT_PRODUCT_ID", JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('PRODUCT_ID', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_CAT_UOM_ID", JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('UOM_ID', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_AMOUNT_PRICE", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('PRICE', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_AMOUNT_VAT", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('PRODUCT_VAT', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_QUANTITY", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('QTY', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_QUANTITY_PCS", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('QTY_PCS', ROW_INDEX)));

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_CAT_DISCOUNT_ID", JSVC_NUM.VAR_NVALL(CART_DGV.CELL.VALUE('DISCOUNT_ID', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_SUBTOTAL", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('AMOUNT', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_DISCOUNT", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('DISCOUNT_VALUE', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_VATABLE", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('VATABLE', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_VATEXEMPT", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('VATEXEMPT', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_NONVAT", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('NONVAT', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_ZERORATED", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('ZERORATED', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_VATOTHER", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('VATOTHER', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_VAT", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('VAT', ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_TOPAY_VAT_LESS", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('VATLESS', ROW_INDEX)));	
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY1, "PARAM_REC_POSSALE_LIST_POINTS", JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE('POINTS', ROW_INDEX))); 

			ORDER_ARRAY.push(SAVE_MAP_ARRAY1);

			ROW_INDEX++;
		}

		//payment
		$.each(PAYMENT_TYPES, function(KEY, VALUE) {
			var AMOUNT_PAID = 0;

			var PAYMENT_NAME = '';
			var PAYMENT_NUMBER = '';
			var PAYMENT_BANK = 1;
			var PAYMENT_CARD = 1;
			var PAYMENT_DATE = '1000-01-01 00:00:00.000000';
			var PAYMENT_REMARKS = '';

			var IS_INITIAL_PAY = 2;

			switch(VALUE) 
			{
				case 'CASH':
					PAYMENT_TYPE_ID = 1;
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CASH'));
					break;
				case 'CARD':
					PAYMENT_TYPE_ID = 2;
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CARD'));

					PAYMENT_NAME = PROPERTY_REC_CARD_NAME;
					PAYMENT_NUMBER = PROPERTY_REC_CARD_NUMBER;
					PAYMENT_BANK = JSVC_NUM.VAR_NVALL(PROPERTY_REC_CARD_BANK);
					PAYMENT_CARD = JSVC_NUM.VAR_NVALL(PROPERTY_REC_CARD_TYPE);
					PAYMENT_REMARKS = PROPERTY_REC_CARD_REFERENCE;
					break;
				case 'CHECK':
					PAYMENT_TYPE_ID = 3;
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CHECK'));

					PAYMENT_NUMBER = PROPERTY_REC_CHECK_NUMBER;
					PAYMENT_BANK = JSVC_NUM.VAR_NVALL(PROPERTY_REC_CHECK_BANK);
					PAYMENT_DATE = PROPERTY_REC_CHECK_DATE;
					PAYMENT_REMARKS = PROPERTY_REC_CHECK_REFERENCE;
					break;
				case 'CREDIT':
					//PAYMENT_TYPE_ID = 5;
					//AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CREDIT'));

					//PAYMENT_NAME = PROPERTY_REC_CUSTOMER_NAME;
					//IS_INITIAL_PAY = 1;
					break;
				case 'LOYALTY':
					PAYMENT_TYPE_ID = 6;
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_LOYALTY'));

					PAYMENT_NUMBER = PROPERTY_REC_LOYALTY_NUMBER;
					break;
				case 'VOUCHER':
					PAYMENT_TYPE_ID = 7;
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_VOUCHER'));

					PAYMENT_NUMBER = PROPERTY_REC_VOUCHER_NUMBER;
					break;
			}

			if(AMOUNT_PAID !== 0)
			{
				SAVE_MAP_ARRAY2 = JSCUS_SQL._RECORD._POS_SALE_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_PURCHASE();

				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_CHANGE", AMOUNT_CHANGE);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_CAT_PAYTYPE_ID", PAYMENT_TYPE_ID);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_AMOUNT_PAID", AMOUNT_PAID);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_NUMBER", PAYMENT_NUMBER);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_PAYEE", PAYMENT_NAME); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_CAT_BANK_ID", PAYMENT_BANK); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_CAT_CARDTYPE_ID", PAYMENT_CARD);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_REC_LOYALTY_ID", PROPERTY_REC_LOYALTY_ID);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_REC_VOUCHER_ID", VOUCHER_ID);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_CHECK_DATE", PAYMENT_DATE);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_REMARKS", PAYMENT_REMARKS);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_ACC_ACCOUNT_ID", ACCOUNT_ID); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_DATE_PROCESSED", TRANSACTION_DATE);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSPAY_IS_INITIAL_PAY", IS_INITIAL_PAY);

				PAYMENT_ARRAY.push(SAVE_MAP_ARRAY2);
			}
		});


		//COMPARE SIZE
		var ARRAY_INDEX = 0;

		if(ORDER_ARRAY.length >= PAYMENT_ARRAY.length)
		{
			while(PAYMENT_ARRAY.length > ARRAY_INDEX)
			{
				SAVE_MAP_ARRAY = ORDER_ARRAY[ARRAY_INDEX];
				SAVE_MAP_ARRAY2 = PAYMENT_ARRAY[ARRAY_INDEX];
							
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CHANGE", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_CHANGE"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CAT_PAYTYPE_ID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_CAT_PAYTYPE_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_AMOUNT_PAID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_AMOUNT_PAID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_NUMBER", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_NUMBER"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_PAYEE", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_PAYEE"]); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CAT_BANK_ID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_CAT_BANK_ID"]); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CAT_CARDTYPE_ID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_CAT_CARDTYPE_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REC_LOYALTY_ID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_REC_LOYALTY_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REC_VOUCHER_ID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_REC_VOUCHER_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CHECK_DATE", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_CHECK_DATE"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REMARKS", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_REMARKS"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_ACC_ACCOUNT_ID", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_ACC_ACCOUNT_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_DATE_PROCESSED", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_DATE_PROCESSED"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_IS_INITIAL_PAY", SAVE_MAP_ARRAY2["PARAM_REC_POSPAY_IS_INITIAL_PAY"]);
							
				ORDER_ARRAY[ARRAY_INDEX] = SAVE_MAP_ARRAY;
				ARRAY_INDEX++;
			}

			FINAL_SAVE_MAP_ARRAY = ORDER_ARRAY;
		}
		else
		{
			while(ORDER_ARRAY.length > ARRAY_INDEX)
			{
				SAVE_MAP_ARRAY = ORDER_ARRAY[ARRAY_INDEX];
				SAVE_MAP_ARRAY2 = PAYMENT_ARRAY[ARRAY_INDEX];
							
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_REC_CLIENT_ID", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_REC_CLIENT_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_REC_LOYALTY_ID", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_REC_LOYALTY_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_CODE", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_CODE"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_DATE_DUE", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_DATE_DUE"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_REMARKS", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_REMARKS"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_ACC_ACCOUNT_ID", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_ACC_ACCOUNT_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_DATE_TRANSACT", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_DATE_TRANSACT"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_STATUS", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_STATUS"]); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_CAT_PRODUCT_ID", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_CAT_PRODUCT_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_CAT_UOM_ID", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_CAT_UOM_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_AMOUNT_PRICE", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_AMOUNT_PRICE"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_AMOUNT_VAT", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_AMOUNT_VAT"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_QUANTITY", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_QUANTITY"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_QUANTITY_PCS", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_QUANTITY_PCS"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_CAT_DISCOUNT_ID", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_CAT_DISCOUNT_ID"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_SUBTOTAL", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_SUBTOTAL"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_DISCOUNT", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_DISCOUNT"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_VATABLE", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_VATABLE"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_VATEXEMPT", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_VATEXEMPT"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_NONVAT", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_NONVAT"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_ZERORATED", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_ZERORATED"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_VATOTHER", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_VATOTHER"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_VAT", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_VAT"]);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_TOPAY_VAT_LESS", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_TOPAY_VAT_LESS"]);	
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY2, "PARAM_REC_POSSALE_LIST_POINTS", SAVE_MAP_ARRAY["PARAM_REC_POSSALE_LIST_POINTS"]);
							
				PAYMENT_ARRAY[ARRAY_INDEX] = SAVE_MAP_ARRAY2;	
				ARRAY_INDEX++;
			}

			FINAL_SAVE_MAP_ARRAY = PAYMENT_ARRAY;
		}


		var CTR;

		if(getValue('CTR') === null)
		{
			createItem('CTR', 1);
			CTR = 1;
		}
		else
			CTR = getValue('CTR');

		var GROUP_CODE = new Date();

		GROUP_CODE = JSVC_DATE.VAR_FORMAT(GROUP_CODE, "MMM DD, YYYY HH:mm:ss");
		ARRAY_INDEX = 0;

		while(FINAL_SAVE_MAP_ARRAY.length > ARRAY_INDEX)
		{
			while (CTR != 0)
			{
				if(getValue('LSTS' + CTR) === null)
				{
					createItem('LSTS' + CTR, 0);
					createItem('GCODE' + CTR, GROUP_CODE);
					createItem('FINAL_SAVE_MAP_ARRAY' + CTR, JSVC_MAP_ARRAY.VAR_TO_STRING(FINAL_SAVE_MAP_ARRAY[ARRAY_INDEX]));
					createItem('TOTAL', CTR);

					ARRAY_INDEX++;
					CTR++;

					break;
				}
				else
				{
					CTR++;
				}
			}
		}

		//update status of reservations
		if(JSVC_ARR.VAR_EMPTY(PROPERTY_REC_TRANSACTION_IDS) == false)
		{
			var INDEX = 0;

			while(PROPERTY_REC_TRANSACTION_IDS.length > ARRAY_INDEX)
			{
				createItem('RESERVE_ID_' + INDEX, PROPERTY_REC_TRANSACTION_IDS[INDEX]);
				INDEX++;
			}

			createItem('RESERVE_IDS_TOTAL', PROPERTY_REC_TRANSACTION_IDS.length);
		}

		console.log(FINAL_SAVE_MAP_ARRAY);

		JSOC_DIALOG.VAR_MODAL("POS_PAYMENT_MODAL", false);
		JSOC_DIALOG.VAR_LOADING_SPINNER(false);


		//RECEIPT
		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
			RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_DESCRIPTION+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ADDRESS+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_CONTACT+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">VAT Reg TIN: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_TIN+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;"><hr style="border: 1px dashed black;"></td></tr>';
		RECEIPT += '</table>';

		RECEIPT += '<table border="0" style="width: 100%; font-size: 10px; margin-bottom: 0 !important;">';
			RECEIPT += '<tr><td style="text-align: right;"> OR NO. '+ TRANSACTION_NO+'</td></tr>';
			RECEIPT += '<tr><td>DATE: '+JSVC_DATE.VAR_FORMAT(TRANSACTION_DATE, "MMM DD, YYYY hh:mm TT")+'</td></tr>';
			RECEIPT += '<tr><td>CASHIER: '+JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_NAME+'</td></tr>';
			RECEIPT += '<tr><td>CUSTOMER: '+CUSTOMER_NAME+'</td></tr>';
			RECEIPT += '<tr><td>TIN: '+CUSTOMER_TIN+'</td></tr>';
			RECEIPT += '<tr><td>ADDRESS: '+CUSTOMER_ADDRESS+'</td></tr>';
		RECEIPT += '</table>';

		RECEIPT += '<br>';

		RECEIPT += '<table border="0" style="width: 100%; font-size: 11px; margin-bottom: 0 !important;">';
			RECEIPT += '<tr>';
				RECEIPT += '<td>ITEM</td>';
				RECEIPT += '<td style="text-align: right;">QTY</td>';
				RECEIPT += '<td style="text-align: right;">PRICE</td>';
				RECEIPT += '<td style="text-align: right;">SUB-TOTAL</td>';
			RECEIPT += '</tr>';
			RECEIPT += '<tr><td colspan="4"><hr style="border: 1px dashed black;"></td></tr>';
		RECEIPT += '</table>';

		ROW_INDEX = 0;

		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
			while(CART_DGV.ROW.COUNT() > ROW_INDEX)
			{
				RECEIPT += '<tr>';
					RECEIPT += '<td style="vertical-align: top;"><small>'+CART_DGV.CELL.VALUE('PRODUCT_DESCRIPTION', ROW_INDEX)+'</small></td>';
				RECEIPT += '</tr>';
				RECEIPT += '<tr>';
					RECEIPT += '<td colspan="3" style="vertical-align: top;"><small>'+CART_DGV.CELL.VALUE('QTY', ROW_INDEX)+' '+CART_DGV.CELL.VALUE('UOM_CODE', ROW_INDEX)+' X '+CART_DGV.CELL.VALUE('PRICE', ROW_INDEX)+'</small></td>';
					RECEIPT += '<td style="text-align: right; vertical-align: top;"><small>'+CART_DGV.CELL.VALUE('AMOUNT', ROW_INDEX)+'</small></td>';
				RECEIPT += '</tr>';

				ROW_INDEX++;
			}
		RECEIPT += '</table>';

		RECEIPT += '<hr style="border: 1px dashed black;">';

		RECEIPT += '<table border="0" style="width: 100%; font-size: 10px;">';
			RECEIPT += '<thead>';
				RECEIPT += '<tr><td>SUB-TOTAL</td><td style="text-align: right;">'+JSOC_ELEMENT.VAR_VALUE('TOTAL_SUBTOTAL')+'</td></tr>';

				if(CART_DGV.COLUMN.SUM("DISCOUNT_VALUE") > 0) {
					RECEIPT += '<tr><td style="padding-left: 10px;">LESS DISCOUNT</td><td style="text-align: right;">'+JSOC_ELEMENT.VAR_VALUE('TOTAL_DISCOUNT')+'</td></tr>';
				}
				RECEIPT += '<tr><td></td><td style="text-align: right;"><hr style="border: 1px dashed black;"></td></tr>';
				RECEIPT += '<tr><td>AMOUNT DUE</td><td style="text-align: right;">'+JSOC_ELEMENT.VAR_VALUE('TOTAL_AMOUNT')+'</td></tr>';

				if(PROPERTY_REC_CASH_AMOUNT > -1) {
					RECEIPT += '<tr><td style="padding-left: 10px;">CASH</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(PROPERTY_REC_CASH_AMOUNT)+'</td></tr>';
				}

				if(PROPERTY_REC_CARD_AMOUNT > -1) {
					RECEIPT += '<tr><td style="padding-left: 10px;">C/D: ****-****-****-'+PROPERTY_REC_CARD_NUMBER+'</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(PROPERTY_REC_CARD_AMOUNT)+'</td></tr>';
				}

				if(PROPERTY_REC_CHECK_AMOUNT > -1) {
					RECEIPT += '<tr><td style="padding-left: 10px;">CHECK: '+PROPERTY_REC_CHECK_NUMBER+'</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(PROPERTY_REC_CHECK_AMOUNT)+'</td></tr>';
				}

				if(PROPERTY_REC_LOYALTY_AMOUNT > -1) {
					RECEIPT += '<tr><td style="padding-left: 10px;">LOYALTY CARD: '+PROPERTY_REC_LOYALTY_NUMBER+'</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(PROPERTY_REC_LOYALTY_AMOUNT)+'</td></tr>';
				}

				if(PROPERTY_REC_VOUCHER_AMOUNT > -1) {
					RECEIPT += '<tr><td style="padding-left: 10px;">GIFT CERT./VOUCHER: '+PROPERTY_REC_VOUCHER_NUMBER+'</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(PROPERTY_REC_VOUCHER_AMOUNT)+'</td></tr>';
				}

				RECEIPT += '<tr><td></td><td style="text-align: right;"><hr style="border: 1px dashed black;"></td></tr>';
				RECEIPT += '<tr><td>CHANGE</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(AMOUNT_CHANGE)+'</td></tr>';


				// if charged to account
				if(PROPERTY_REC_CREDIT_AMOUNT > -1)
				{
					RECEIPT += '<tr><td> </td><td> </td></tr>';
					RECEIPT += '<tr><td> </td><td> </td></tr>';
					RECEIPT += '<tr><td>ITEMS:</td><td style="text-align: right;">'+JSOC_ELEMENT.VAR_VALUE('TOTAL_ITEMS')+'</td></tr>';
					RECEIPT += '<tr><td> </td><td> </td></tr>';
					RECEIPT += '<tr><td colspan="2" style="text-align: center;">_______________________________</td></tr>';
					RECEIPT += '<tr><td colspan="2" style="text-align: center;"><small>SIGNATURE OVER PRINTED NAME</small></td></tr>';
					RECEIPT += '<tr><td colspan="2" style="text-align: center;">RECEIVED THE ABOVE GOODS COMPLETE AND IN GOOD CONDITION</td></tr>';
				}

			RECEIPT += '</thead>';
		RECEIPT += '</table>'

		RECEIPT += '<br>';

		RECEIPT += '<table border="0" style="width: 100%; font-size: 10px;">';
			RECEIPT += '<tr><td>VAT Sales</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(CART_DGV.COLUMN.SUM("VATABLE"))+'</td></tr>';
			RECEIPT += '<tr><td>VAT(12%)</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(CART_DGV.COLUMN.SUM("VAT"))+'</td></tr>';
			RECEIPT += '<tr><td>VAT Exempt Sales</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(CART_DGV.COLUMN.SUM("VATEXEMPT"))+'</td></tr>';
			RECEIPT += '<tr><td>Non-VAT</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(CART_DGV.COLUMN.SUM("NONVAT"))+'</td></tr>';
			RECEIPT += '<tr><td>Zero Rated Sales</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(CART_DGV.COLUMN.SUM("ZERORATED"))+'</td></tr>';
		RECEIPT += '</table>';

		RECEIPT += '<br>';
		
		if(PROPERTY_REC_LOYALTYCARD_INDEX > 1)
		{
			RECEIPT += '<table border="0" style="width: 100%; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '<tr><td>LOYALTY CARD: '+LOYALTY_NUMBER+'</td></tr>';
				RECEIPT += '<tr><td>POINTS EARNED: '+JSVC_NUM.VAR_CFORMAT(LOYALTY_POINTS_EARNED)+'</td></tr>';
				RECEIPT += '<tr><td>TOTAL POINTS: '+JSVC_NUM.VAR_CFORMAT(LOYALTY_TOTAL_POINTS)+'</td></tr>';
			RECEIPT += '</table>';

			RECEIPT += '<br>';
		}

		RECEIPT += '<hr style="border: 1px dashed black;">';

		RECEIPT += '<table border="0" style="width: 100%; font-size: 10px;">';
			RECEIPT += '<tr><td style="text-align: center;">POS SOFTWARE PROVIDER</td></tr>';
			RECEIPT += '<tr><td> </td></tr>';
			RECEIPT += '<tr><td> </td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">DSA SOFTWARE SOLUTIONS</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">Diamond Township Bldg., Cotabato City</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">Contact No.: 09661452163 / 064-557-4005</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">TIN: 278-081-323</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">ACCR. No.: 1072780813232016010482</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">ACCR. DATE: 12/06/2019</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">PERMIT No.: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_PERMIT_NUMBER+'</td></tr>';
		RECEIPT += '</table>';

		//not charge to account
		if(PAYMENT_TYPE_ID !== 5) {
			RECEIPT += '<br>';

			RECEIPT += '<table border="0" style="width: 100%; font-size: 10px;">';
				RECEIPT += '<tr><td style="text-align: center;">This invoice/RECEIPT shall be valid for five years from the date of permit to use.</td></tr>';
				RECEIPT += '<tr><td></td></tr>';
				RECEIPT += '<tr><td></td></tr>';
				RECEIPT += '<tr><td style="text-align: center;">*THIS SERVES AS AN OFFICIAL RECEIPT*</td></tr>';
				RECEIPT += '<tr><td style="text-align: center;">***THANK YOU! COME AGAIN!***</td></tr>';
			RECEIPT += '</table>';
		}

		if(JSVC_STR.VAR_IS_BLANK(PROPERTY_REC_TRANSACTION_REFNO) == false)
		{
			JSOC_ELEMENT.VAR_GET('POS_REFERENCE_DISPLAY').style.display = 'none';
			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 = '';
		}

		alertify.confirm
		(
			'PeakPOS', 'Print RECEIPT?', 
			function() 
			{ 
				Android.CALL('PRINT', '<html><body>' + RECEIPT + '</body></html>');
				HTTP_COMPLETE_TRANSACTION();
				CALLBACK_METHOD(true);
			}, 
			function() 
			{
				HTTP_COMPLETE_TRANSACTION();
				CALLBACK_METHOD(true);
			}
		).set('closable', false, 'labels', {ok:'YES', cancel:'NO'});
	}

	function HTTP_COMPLETE_TRANSACTION()
	{		
		LAST_POS_CODE+=1;
					
		CART_DGV.ROW.CLEAR();
		JSOC_ELEMENT.VAR_GET('REMOVE_DISCOUNT').classList.add('d-none');

		HTTP_CALCULATE_CART();

		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');

		//update transaction number
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_TRANSACTION_NO")) {
			JSOC_ELEMENT.VAR_VALUE('POS_TRANSACTION_NO', LAST_POS_CODE.toString().padStart(9, 0));
		}

		JSOC_DIALOG.VAR_MESSAGE_BOX
		(
			'Transaction complete. Tap OK to continue.',
			'Information',
			'OK', 'ERROR',
			function() {
				//return products to default pricing scheme
				if(PRICE_MODEL_ID > 1) {
					PRICE_MODEL_ID = 1;
					JSOC_ELEMENT.VAR_VALUE("PRICE_MODEL_TXT", 'SRP');
					HTTP_SEARCH();
				}
			}
		);
	}

	// Save customer accounts payments
	function HTTP_SAVE_PAYMENT(IS_CASH = true, CALLBACK_METHOD)
	{
		var SAVE_MAP_ARRAY = [];
		var BUNDLE_MAP_ARRAY = [];

		var PROCESS_DATE = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + '.999999';
		
		var ACCOUNT_ID = JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID);

		var CUSTOMER_ID = JSVC_NUM.VAR_NVALL(PROPERTY_REC_CUSTOMER_INDEX);
		var CUSTOMER_NAME = PROPERTY_REC_CUSTOMER_NAME;
		var CUSTOMER_TIN = PROPERTY_REC_CUSTOMER_TIN;
		var CUSTOMER_ADDRESS = PROPERTY_REC_CUSTOMER_ADDRESS;

		var LOYALTY_ID = 1;
		var VOUCHER_ID = 1;

		var AMOUNT_CHANGE = 0
		var AMOUNT_PAID = 0

		var TOTAL_PAID = 0;
		var TOTAL_CHANGE = 0;

		var IS_INITIAL_PAY = 1;
		var STATUS = 4;
		
		var RECEIPT = '';

		var TOTAL_SELECTED = 0;
		var INDEX = 0;

		while(POS_SALE_DGV.ROW.COUNT() > INDEX)
		{
			AMOUNT_PAID = 0;

			if(POS_SALE_DGV.CELL.VALUE('SELECTED', INDEX) == true)
			{
				//cash payment
				if(IS_CASH == true) {
					PAYMENT_TYPE_ID = 1;
					PAYMENT_NUMBER = '';
					PAYMENT_NAME = '';
					PAYMENT_BANK = 1;
					PAYMENT_DATE = '1000-01-01 00:00:00.000000';

					AMOUNT_CHANGE = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CASH_CHANGE_VALUE')) / JSVC_NUM.VAR_NVALL(POS_SALE_DGV.COLUMN.SUM('SELECTED'));
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_PAY_CASH')) / JSVC_NUM.VAR_NVALL(POS_SALE_DGV.COLUMN.SUM('SELECTED'));

					if(JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_PAY_CASH')) == JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT')))
					{
						AMOUNT_PAID = JSVC_NUM.VAR_NVALL(POS_SALE_DGV.COLUMN.SUM('REC_POSSALE_DUE'));
					}

					if(AMOUNT_CHANGE <= 0) {
						IS_INITIAL_PAY = 2;
						STATUS = 2;
					}
				}

				//check payment
				else {
					PAYMENT_TYPE_ID = 3;
					PAYMENT_NUMBER = JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECK_NUMBER');
					PAYMENT_NAME = '';
					PAYMENT_BANK = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECK_BANK'));
					PAYMENT_DATE = JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECK_DATE'), "YYYY-MM-DD HH:mm:ss") + '.999999';

					AMOUNT_CHANGE = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CHECK_CHANGE_VALUE')) / JSVC_NUM.VAR_NVALL(POS_SALE_DGV.COLUMN.SUM('SELECTED'));
					AMOUNT_PAID = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECK_AMOUNT')) / JSVC_NUM.VAR_NVALL(POS_SALE_DGV.COLUMN.SUM('SELECTED'));

					if(JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_PAY_CASH')) == JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT')))
					{
						AMOUNT_PAID = JSVC_NUM.VAR_NVALL(POS_SALE_DGV.COLUMN.SUM('REC_POSSALE_DUE'));
					}

					if(AMOUNT_CHANGE <= 0) {
						IS_INITIAL_PAY = 2;
						STATUS = 2;
					}
				}

				TOTAL_PAID += AMOUNT_PAID;
				TOTAL_CHANGE += AMOUNT_CHANGE;

				SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_PAYMENT.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();

				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REC_POSSALE_ID", POS_SALE_DGV.CELL.VALUE('REC_POSSALE_ID', INDEX));

				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CHANGE", AMOUNT_CHANGE);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CAT_PAYTYPE_ID", PAYMENT_TYPE_ID);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_AMOUNT_PAID", AMOUNT_PAID);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_NUMBER", PAYMENT_NUMBER);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_PAYEE", PAYMENT_NAME); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CAT_BANK_ID", PAYMENT_BANK); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CAT_CARDTYPE_ID", 1);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REC_LOYALTY_ID", 1);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REC_VOUCHER_ID", 1);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_CHECK_DATE", PAYMENT_DATE);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_REMARKS", '');
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_ACC_ACCOUNT_ID", ACCOUNT_ID); 
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_DATE_PROCESSED",PROCESS_DATE);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_IS_INITIAL_PAY", IS_INITIAL_PAY);
				JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSPAY_STATUS", STATUS);

				BUNDLE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_PAYMENT.CUS_ADD_MAPPED_ARRAY_FOR_SAVE(BUNDLE_MAP_ARRAY, SAVE_MAP_ARRAY);
			}

			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
					{
						//RECEIPT
						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
							RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_DESCRIPTION+'</td></tr>';
							RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ADDRESS+'</td></tr>';
							RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_CONTACT+'</td></tr>';
							RECEIPT += '<tr><td style="text-align: center;">VAT Reg TIN: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_TIN+'</td></tr>';
							RECEIPT += '<tr><td style="text-align: center;"><hr style="border: 1px dashed black;"></td></tr>';
						RECEIPT += '</table>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
							RECEIPT += '<tr><td>DATE: '+JSVC_DATE.VAR_FORMAT(PROCESS_DATE, "MMM DD, YYYY hh:mm TT")+'</td></tr>';
							RECEIPT += '<tr><td>CASHIER: '+JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_NAME+'</td></tr>';
							RECEIPT += '<tr><td>CUSTOMER: '+CUSTOMER_NAME+'</td></tr>';
							RECEIPT += '<tr><td>TIN: '+CUSTOMER_TIN+'</td></tr>';
							RECEIPT += '<tr><td>ADDRESS: '+CUSTOMER_ADDRESS+'</td></tr>';
						RECEIPT += '</table>';

						RECEIPT += '<br>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 0 !important;">';
							RECEIPT += '<tr>';
								RECEIPT += '<td>Particulars</td>';
								RECEIPT += '<td style="text-align: right;">Amount</td>';
							RECEIPT += '</tr>';
							RECEIPT += '<tr><td colspan="2"><hr style="border: 1px dashed black;"></td></tr>';
						RECEIPT += '</table>';

						ROW_INDEX = 1;

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 0 !important;">';
							while(POS_SALE_DGV.ROW.COUNT() > ROW_INDEX)
							{
								if(POS_SALE_DGV.CELL.VALUE('SELECTED', ROW_INDEX) == true)
								{
									RECEIPT += '<tr>';
										RECEIPT += '<td style="vertical-align: top;">'+POS_SALE_DGV.CELL.VALUE('REC_POSSALE_CODE', ROW_INDEX)+'</td>';
										RECEIPT += '<td style="text-align: right; vertical-align: top;">'+POS_SALE_DGV.CELL.VALUE('REC_POSSALE_DUE', ROW_INDEX)+'</td>';
									RECEIPT += '</tr>';
								}

								ROW_INDEX++;
							}
						RECEIPT += '</table>';

						RECEIPT += '<hr style="border: 1px dashed black;">';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
							RECEIPT += '<thead>';
								RECEIPT += '<tr><td>Balance</td><td style="text-align: right;">'+JSOC_ELEMENT.VAR_VALUE('TOTAL_BALANCE_TXT')+'</td></tr>';
							RECEIPT += '</thead>';
						RECEIPT += '</table>';

						RECEIPT += '<br>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
							RECEIPT += '<thead>';	
								if(IS_CASH == true) 
								{
									RECEIPT += '<tr><td>PAYMENT:</td><td style="text-align: right; margin-bottom: 1px solid #000;">'+JSVC_NUM.VAR_CFORMAT(TOTAL_PAID)+'</td></tr>';
								}
								else 
								{
									RECEIPT += '<tr><td>PAYMENT: CHK#'+PAYMENT_NUMBER+'</td><td style="text-align: right; margin-bottom: 1px solid #000;">'+JSVC_NUM.VAR_CFORMAT(TOTAL_PAID)+'</td></tr>';
								}

								RECEIPT += '<tr><td></td><td style="text-align: right;"><hr style="border: 1px dashed black;"></td></tr>';
								RECEIPT += '<tr><td>CHANGE</td><td style="text-align: right;">'+JSVC_NUM.VAR_CFORMAT(TOTAL_CHANGE)+'</td></tr>';
							RECEIPT += '</thead>';
						RECEIPT += '</table>'


						RECEIPT += '<br>';

						RECEIPT += '<hr style="border: 1px dashed black;">';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
							RECEIPT += '<tr><td style="text-align: center;">POS SOFTWARE PROVIDER</td></tr>';
						RECEIPT += '</table>';

						RECEIPT += '<br>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
							RECEIPT += '<tr><td>DSA SOFTWARE SOLUTIONS</td></tr>';
							RECEIPT += '<tr><td>Diamond Township Bldg., Cotabato City</td></tr>';
							RECEIPT += '<tr><td>Contact #: 09661452163 / 064-557-4005</td></tr>';
							RECEIPT += '<tr><td>TIN: 278-081-323</td></tr>';
							RECEIPT += '<tr><td>ACCR. #: 1072780813232016010482</td></tr>';
							RECEIPT += '<tr><td>ACCR. DATE: 12/06/2019</td></tr>';
							RECEIPT += '<tr><td>PERMIT #: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_PERMIT_NUMBER+'</td></tr>';
						RECEIPT += '</table>';

						RECEIPT += '<br><br>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
								RECEIPT += '<tr><td style="text-align: center;">This invoice/RECEIPT shall be valid for five years from the date of permit to use.</td></tr>';
						RECEIPT += '</table>';

						RECEIPT += '<br><br>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
								RECEIPT += '<tr><td style="text-align: center;">*THIS SERVES AS AN OFFICIAL RECEIPT*</td></tr>';
						RECEIPT += '</table>';

						RECEIPT += '<br><br>';

						RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
								RECEIPT += '<tr><td style="text-align: center;">***THANK YOU! COME AGAIN!***</td></tr>';
						RECEIPT += '</table>';


						if(IS_CASH == true)
						{
							JSOC_DIALOG.VAR_MODAL("POS_ACCTS_CASH_MODAL", false);
						}
						else
						{
							JSOC_DIALOG.VAR_MODAL("POS_ACCTS_CHECK_MODAL", false);
						}

						JSOC_DIALOG.VAR_MODAL("POS_ACCTS_MODAL", false);

						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'Print RECEIPT?',
							'PeakPOS',
							'YES NO', 'SUCCESS',
							function(RESPONSE) {
								if(RESPONSE == 2) {
									Android.CALL('PRINT', '<html><body>' + RECEIPT + '</body></html>');
									HTTP_LOAD_CREDITS();
								}
								else
								{
									HTTP_LOAD_CREDITS();
								}
							}
						);
					}
				}
			};
		
		
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_PAYMENT.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);
		

		// Actual Function
		// _______________________________________________________________________
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._POS_CANCEL.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, 'PARAM_REC_POSCANCEL_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_POSCANCEL_ACC_ACCOUNT_ID', JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID));

		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, 'PARAM_REC_POSCANCEL_IS_FULL_DROP', 1); 
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, 'PARAM_REC_POSCANCEL_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_POSCANCEL_QUANTITY', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE("QTY", ROW_INDEX)));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSCANCEL_DATE", 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_POSCANCEL_STATUS", 2);
		
		
		// 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
					{
						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);
					}
				}
			};
		
		
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_CANCEL.CUS_SAVE
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}
	
	
	// ===============================================================
	// Request Void
	// ===============================================================
	function HTTP_VOID(CALLBACK_METHOD)
	{
		var SAVE_MAP_ARRAY = [];
		var BUNDLE_MAP_ARRAY = [];

		var ROW_INDEX = 1;

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

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, 'PARAM_REC_POSCANCEL_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_POSCANCEL_ACC_ACCOUNT_ID', JSVC_NUM.VAR_NVALL(JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID));

			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, 'PARAM_REC_POSCANCEL_IS_FULL_DROP', 2); 
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, 'PARAM_REC_POSCANCEL_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_POSCANCEL_QUANTITY', JSVC_NUM.VAR_NVAL(CART_DGV.CELL.VALUE("QTY", ROW_INDEX)));
			JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_POSCANCEL_DATE", 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_POSCANCEL_STATUS", 2);

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

			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
					{
						if(JSVC_STR.VAR_IS_BLANK(PROPERTY_REC_TRANSACTION_REFNO) == false)
						{
							JSOC_ELEMENT.VAR_GET('POS_REFERENCE_DISPLAY').style.display = 'none';
							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();
						$('#REMOVE_DISCOUNT').addClass('d-none');

						HTTP_CALCULATE_CART();

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

						CALLBACK_METHOD(true);
					}
				}
			};
		
		
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_CANCEL.CUS_SAVE
		(
			BUNDLE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	}


	// ===============================================================
	// 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_POINTS = 0;
		var TOTAL_ITEMS = 0;
		var TOTAL_AMOUNT = 0;
		var TOTAL_DISCOUNT = 0;
		var TOTAL_DUE = 0;
		
		TOTAL_POINTS = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("POINTS"));
		TOTAL_ITEMS = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("QTY"));
		TOTAL_SUBTOTAL = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("AMOUNT"));
		TOTAL_DISCOUNT = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("DISCOUNT_VALUE"));
		TOTAL_DUE = TOTAL_SUBTOTAL - TOTAL_DISCOUNT;

		JSOC_ELEMENT.VAR_VALUE("TOTAL_POINTS", JSVC_NUM.VAR_CFORMAT(TOTAL_POINTS));
		JSOC_ELEMENT.VAR_VALUE("TOTAL_ITEMS", JSVC_NUM.VAR_CFORMAT(TOTAL_ITEMS));
		JSOC_ELEMENT.VAR_VALUE("TOTAL_SUBTOTAL", JSVC_NUM.VAR_CFORMAT(TOTAL_SUBTOTAL));
		JSOC_ELEMENT.VAR_VALUE("TOTAL_DISCOUNT", JSVC_NUM.VAR_CFORMAT(TOTAL_DISCOUNT));
		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);
		}
	}


	// ===============================================================
	// Calculate Change
	// ===============================================================

	function HTTP_CALCULATE_CHANGE(DUE, CALLBACK_METHOD)
	{
		var TOTAL_ITEMS = 0;
		var TOTAL_AMOUNT = 0;
		var TOTAL_DISCOUNT = 0;
		var TOTAL_DUE = 0;
		
		var TOTAL_CASH = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CASH'));
		var TOTAL_CARD = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CARD'));
		var TOTAL_CHECK = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CHECK'));
		var TOTAL_LOYALTY = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_LOYALTY'));
		var TOTAL_CREDIT = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_CREDIT'));
		var TOTAL_VOUCHER = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('PAY_VOUCHER'));

		var CHANGE = 0;

		TOTAL_ITEMS = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("QTY"));
		TOTAL_SUBTOTAL = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("AMOUNT"));
		TOTAL_DISCOUNT = JSVC_NUM.VAR_NVAL(CART_DGV.COLUMN.SUM("DISCOUNT_VALUE"));
		TOTAL_DUE = TOTAL_SUBTOTAL - TOTAL_DISCOUNT;
	
		CHANGE = (TOTAL_CASH + TOTAL_CARD + TOTAL_CHECK + TOTAL_LOYALTY + TOTAL_CREDIT + TOTAL_VOUCHER) - TOTAL_DUE;

		JSOC_ELEMENT.VAR_VALUE('CHECKOUT_CHANGE_VALUE', CHANGE);
		JSOC_ELEMENT.VAR_VALUE('CHECKOUT_CHANGE', JSVC_NUM.VAR_CFORMAT(CHANGE));

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



	// ===============================================================
	// Calculate Payments - A/R
	// ===============================================================

	function HTTP_CALCULATE_SELECTED(COL_HEADER_SELECT = null)
	{
		var TOTAL_SELECTED = 0;
		var INDEX = 0;

		while(POS_SALE_DGV.ROW.COUNT() > INDEX)
		{
			if(COL_HEADER_SELECT !== null)
			{
				if(COL_HEADER_SELECT == true)
					TOTAL_SELECTED += JSVC_NUM.VAR_NVAL(POS_SALE_DGV.CELL.VALUE('REC_POSSALE_DUE', INDEX));
				else
					TOTAL_SELECTED += 0;
			}
			else
			{
				if(POS_SALE_DGV.CELL.VALUE('SELECTED', INDEX) == true)
					TOTAL_SELECTED += JSVC_NUM.VAR_NVAL(POS_SALE_DGV.CELL.VALUE('REC_POSSALE_DUE', INDEX));
			}

			INDEX ++;
		}

		JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT', JSVC_NUM.VAR_CFORMAT(TOTAL_SELECTED));
	}


	// ===============================================================
	// Calculate Change - A/R Payments
	// ===============================================================

	function HTTP_ACCTS_CALCULATE_CHANGE(IS_CASH = true)
	{
		var TOTAL_DUE = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT'));
		var CHANGE = 0;
	
		if(IS_CASH == true)
		{
			PAYMENT = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_PAY_CASH'));
			CHANGE = PAYMENT - TOTAL_DUE;

			JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CASH_CHANGE_VALUE', CHANGE);
			JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CASH_CHANGE', JSVC_NUM.VAR_CFORMAT(CHANGE));
		}
		else
		{
			PAYMENT = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECK_AMOUNT'));
			CHANGE = PAYMENT - TOTAL_DUE;

			JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CHECK_CHANGE_VALUE', CHANGE);
			JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CHECK_CHANGE', JSVC_NUM.VAR_CFORMAT(CHANGE));
		}
	}



	// ===============================================================
	// 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);
		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 cents = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_CENTS"]').val());
		var ones = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_1"]').val());
		var fives = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_5"]').val());
		var tens = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_10"]').val());
		var twenties = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_20"]').val());
		var fifties = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_50"]').val());
		var hundreds = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_100"]').val());
		var twohundreds = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_200"]').val());
		var fivehundreds = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_500"]').val());
		var thousands = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_1000"]').val());
		var check_qty = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_CHECKS_QTY"]').val());
		var check_amt = JSVC_NUM.VAR_NVAL($('#CASH_BREAKDOWN_MODAL input[id="CASHBREAKDOWN_CHECKS"]').val());

		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_TO_DATE(JSOC_ELEMENT.VAR_VALUE('SHIFT_END_END_TIME')), "YYYY-MM-DD HH:mm:ss"));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_1KS", thousands);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_500S", fivehundreds);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_200S", twohundreds);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_100S", hundreds);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_50S", fifties);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_20S", twenties);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_10S", tens);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_5S", fives);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_1S", ones);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_CENTS", cents);			
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_CHECK_COUNT", check_qty);			
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_SHIFT_CREDIT_CHECK_AMOUNT", check_amt);	

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

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


	// ===============================================================
	// Calculate Cash Breakdown
	// ===============================================================
	function HTTP_CALCULATE_CASH(id)
	{
		var input = $('#SHIFT_END_MODAL input[id="'+id+'"]');
		var output = $('#SHIFT_END_MODAL input[id="'+id+'_TOTAL"]');

		var amount = JSVC_NUM.VAR_NVAL(id.replace('CASHBREAKDOWN_', ''));
		var multiplier = JSVC_NUM.VAR_NVAL(input.val());

		var TOTAL = 0;

		if(id === 'CASHBREAKDOWN_CENTS')
			TOTAL = multiplier * 0.01;
		else if(id === 'CASHBREAKDOWN_CHECKS')
			TOTAL = multiplier;
		else
			TOTAL = amount * multiplier;

		output.val(TOTAL);
		output.next().html(JSVC_NUM.VAR_FORMAT(TOTAL, 2));

		HTTP_CALCULATE_TOTAL_CASH();
	}

	function HTTP_CALCULATE_TOTAL_CASH() 
	{
		var output = $('#SHIFT_END_MODAL #CASHBREAKDOWN_TOTAL');
		var amounts = [1000, 500, 200, 100, 50, 20, 10, 5, 1, 'CENTS', 'CHECKS'];

		var TOTAL = 0;
		var value = 0;
		
		$.each(amounts, function(i, item) {
			value = JSVC_NUM.VAR_NVAL($('input[id="CASHBREAKDOWN_'+item+'_TOTAL"]').val());
			TOTAL += value;
		});

		//send to end shift modal
		SHIFT_TIME_END_AMOUNT = TOTAL;
		output.html(JSVC_NUM.VAR_CFORMAT(TOTAL));
	}


	// ===============================================================
	// Print Cash Breakdown
	// ===============================================================
	function HTTP_PRINT_CASHBREAKDOWN(CALLBACK_METHOD)
	{
		var RECEIPT = '';

		var REPORT_DATE = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + '.999999';;

		var DENOMINATIONS = [1000, 500, 200, 100, 50, 20, 10, 5, 1, 'CENTS', 'CHECKS'];
		var SUBTOTAL = 0;

		var TOTAL = 0;
		var QTY = 0;

		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
			RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_DESCRIPTION+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ADDRESS+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_CONTACT+'</td></tr>';
			RECEIPT += '<tr><td style="text-align: center;">VAT Reg TIN: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_TIN+'</td></tr>';
		RECEIPT += '</table>';

		RECEIPT += '<br>';
		
		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
			RECEIPT += '<tr><td style="text-align: center;">CASH BREAKDOWN</td></tr>';
		RECEIPT += '</table>';

		RECEIPT += '<hr style="border: 1px dashed black;">';

		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
			RECEIPT += '<tr><td>DATE AND TIME: '+JSVC_DATE.VAR_FORMAT(REPORT_DATE, "MMM DD, YYYY hh:mm TT")+'</td></tr>';
			RECEIPT += '<tr><td>CASHIER: '+JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_NAME+'</td></tr>';
			RECEIPT += '<tr><td>TERMINAL ID: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_MACHINE_ID+'</td></tr>';
		RECEIPT += '</table>';

		RECEIPT += '<hr style="border: 1px dashed black;">';
		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 0 !important;">';

		$.each(DENOMINATIONS, function(i, item) {
			TOTAL = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('CASHBREAKDOWN_'+item+'_TOTAL'));
			QTY = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('CASHBREAKDOWN_'+item));

			if(item === 'CENTS') {
				RECEIPT += '<tr>';
					RECEIPT += '<td colspan="3" style="text-align: left; vertical-align: middle; width: 60%;">'+item+'</td>';
					RECEIPT += '<td style="text-align: center; vertical-align: middle; width: 20%;">=</td>'
					RECEIPT += '<td width="20%" style="text-align: right; vertical-align: middle;">'+JSVC_NUM.VAR_CFORMAT(TOTAL)+'</td>';
				RECEIPT += '</tr>';
			}
			else if(item === 'CHECKS') {
				RECEIPT += '<tr>';
					RECEIPT += '<td style="text-left: right; vertical-align: middle; width: 20%;">'+item+'</td>';
					RECEIPT += '<td style="text-align: center; vertical-align: middle; width: 20%;"><small>QTY: '+JSOC_ELEMENT.VAR_VALUE('CASHBREAKDOWN_CHECKS_QTY')+'</small></td>';
					RECEIPT += '<td width="20%" style="text-align: right; vertical-align: middle;">'+JSVC_NUM.VAR_CFORMAT(QTY)+'</td>';
					RECEIPT += '<td style="text-align: center; vertical-align: middle; width: 10%;">=</td>'
					RECEIPT += '<td style="text-align: right; vertical-align: middle; width: 20%;">'+JSVC_NUM.VAR_CFORMAT(TOTAL)+'</td>';
				RECEIPT += '</tr>';
			}
			else {
				RECEIPT += '<tr>';
					RECEIPT += '<td style="text-align: right; vertical-align: middle; width: 20%;">'+JSVC_NUM.VAR_CFORMAT(item)+'</td>';
					RECEIPT += '<td style="text-align: center; vertical-align: middle; width: 20%;">x</td>';
					RECEIPT += '<td style="text-align: right; vertical-align: middle; width: 20%;">'+JSVC_NUM.VAR_CFORMAT(QTY)+'</td>';
					RECEIPT += '<td style="text-align: center; vertical-align: middle; width: 20%;">=</td>'
					RECEIPT += '<td style="text-align: right; vertical-align: middle; width: 20%;">'+JSVC_NUM.VAR_CFORMAT(TOTAL)+'</td>';
				RECEIPT += '</tr>';
			}

			SUBTOTAL += TOTAL;
		});

		RECEIPT += '</table>';

		RECEIPT += '<hr style="border: 1px dashed black;">';

		RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
			RECEIPT += '<thead>';
				RECEIPT += '<tr><td style="width: 60%">TOTAL: </td><td style="width: 40%; text-align: right;">'+JSVC_NUM.VAR_CFORMAT(SUBTOTAL)+'</td></tr>';
			RECEIPT += '</thead>';
		RECEIPT += '</table>';

		JSOC_DIALOG.VAR_MODAL("SHIFT_END_MODAL", false);
		JSOC_DIALOG.VAR_LOADING_SPINNER(false);

		alertify.confirm
		(
			'PeakPOS', 'Print Cash Breakdown Report?', 
			function() 
			{ 
				Android.CALL('PRINT', '<html><body>' + RECEIPT + '</body></html>');

				if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_END_MODAL_2") == true)
				{
					// Clear Modal
					if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
					{
						JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
					}
												
					// Display Modal
					JSOC_ELEMENT.VAR_VALUE('SHIFT_END_NAME', JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_NAME);
					JSOC_ELEMENT.VAR_VALUE('SHIFT_END_START_TIME', JSVC_DATE.VAR_FORMAT(SHIFT_TIME_START, "MMM DD, YYYY hh:mm TT"));
					JSOC_ELEMENT.VAR_VALUE('SHIFT_END_END_TIME', JSVC_DATE.VAR_FORMAT(REPORT_DATE, "MMM DD, YYYY hh:mm TT"));
					JSOC_DIALOG.VAR_MODAL("SHIFT_END_MODAL_2", true);
					return;
				}

				CALLBACK_METHOD(true);
			}, 
			function() 
			{ 
				if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_END_MODAL_2") == true)
				{
					// Clear Modal
					if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
					{
						JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
					}
												
					// Display Modal
					JSOC_ELEMENT.VAR_VALUE('SHIFT_END_NAME', JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_NAME);
					JSOC_ELEMENT.VAR_VALUE('SHIFT_END_START_TIME', JSVC_DATE.VAR_FORMAT(SHIFT_TIME_START, "MMM DD, YYYY hh:mm TT"));
					JSOC_ELEMENT.VAR_VALUE('SHIFT_END_END_TIME', JSVC_DATE.VAR_FORMAT(REPORT_DATE, "MMM DD, YYYY hh:mm TT"));
					JSOC_DIALOG.VAR_MODAL("SHIFT_END_MODAL_2", true);
					return;
				}

				CALLBACK_METHOD(true);
			}
		).set('closable', false, 'labels', {ok:'YES', cancel:'NO'});
	}


	// ===============================================================
	// Validate Loyalty Card
	// ===============================================================
	function HTTP_VALIDATE_LOYALTYCARD(CALLBACK_METHOD) 
	{
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._LOYALTY.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_LOYALTY_CODE', JSOC_ELEMENT.VAR_VALUE("LOYALTYCARD_NUMBER"));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_LOYALTY_STATUS', 2);

		// 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)
					{
						CALLBACK_METHOD(false);
						return;
					}
					else
					{
						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_FIRSTNAME', 1);
						PROPERTY_REC_CUSTOMER_TIN = '';
						PROPERTY_REC_CUSTOMER_ADDRESS = JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_CLIENT_MIDDLENAME', 1);

						PROPERTY_REC_LOYALTYCARD_INDEX = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_LOYALTY_ID', 1));
						PROPERTY_REC_LOYALTYCARD_POINTS = JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_LOYALTY_BALANCE', 1));
						PROPERTY_REC_LOYALTYCARD_NUMBER = JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_LOYALTY_CODE', 1);
						
						CALLBACK_METHOD(true);
						
						return;
					}
				}
			};

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


	// ===============================================================
	// Add Customer
	// ===============================================================
	function HTTP_SAVE_CUSTOMER(CALLBACK_METHOD)
	{
		// Fix String Fields
		// ...........................................
		JSOC_INPUT_TEXT.CTL_TRIM(CUSTNEW_FNAME);
		JSOC_INPUT_TEXT.CTL_TRIM(CUSTNEW_LNAME);

		// Save item [Prepare]
		// _______________________________________________________________________
		var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._CLIENT.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();		
			
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_LASTNAME", JSOC_ELEMENT.VAR_VALUE(CUSTNEW_LNAME));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_FIRSTNAME", JSOC_ELEMENT.VAR_VALUE(CUSTNEW_FNAME));	
		//JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_MIDDLENAME", JSOC_ELEMENT.VAR_VALUE(REC_CLIENT_MIDDLENAME_TXT));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_CAT_SUFFIX_ID", 1);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_SYS_GENDER_ID", JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(CUSTNEW_GENDER)));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_CONTACT", JSOC_ELEMENT.VAR_VALUE(CUSTNEW_PHONE));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_EMAIL", JSOC_ELEMENT.VAR_VALUE(CUSTNEW_EMAIL));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_CAT_COMPANY_ID", 1);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_CAT_PRICEMDL_ID", 1); //SRP
		//JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_SENIOR_CODE", JSOC_ELEMENT.VAR_VALUE(REC_CLIENT_SENIOR_CODE_TXT));
		//JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_PWD_CODE", JSOC_ELEMENT.VAR_VALUE(REC_CLIENT_PWD_CODE_TXT));
		//JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_TIN", JSOC_ELEMENT.VAR_VALUE(REC_CLIENT_TIN_TXT));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_DATE_ISSUED", 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_CLIENT_ADDRESS", JSOC_ELEMENT.VAR_VALUE(CUSTNEW_ADDRESS));
		//JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_REMARKS", JSOC_ELEMENT.VAR_VALUE(REC_CLIENT_REMARKS_TXT));
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_CLIENT_STATUS", 2);

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