	// ===============================================================
	// Global Var
	// ===============================================================

	var PROPERTY_REC_PRODUCT_ID = -1;
	var PROPERTY_REC_PRODUCT_QTY = 0;
	var PROPERTY_REC_PRODUCT_TYPES = [];

	var PROPERTY_REC_DISCOUNT_INDEX = [];
	var PROPERTY_REC_DISCOUNT_TYPE = [];

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

	var PROPERTY_REC_CASH_AMOUNT = -1;

	var PROPERTY_REC_CARD_BANK = 1;
	var PROPERTY_REC_CARD_TYPE = -1;
	var PROPERTY_REC_CARD_NAME = '';
	var PROPERTY_REC_CARD_NUMBER = '';
	var PROPERTY_REC_CARD_REFERENCE = '';
	var PROPERTY_REC_CARD_AMOUNT = -1;

	var PROPERTY_REC_CHECK_BANK = 1;
	var PROPERTY_REC_CHECK_DATE = '1000-01-01 00:00:00.000000';
	var PROPERTY_REC_CHECK_NUMBER = '';
	var PROPERTY_REC_CHECK_REFERENCE = '';
	var PROPERTY_REC_CHECK_AMOUNT = -1;

	var PROPERTY_REC_CREDIT_TERMS = 1;
	var PROPERTY_REC_CREDIT_DATE = '1000-01-01 00:00:00.000000';
	var PROPERTY_REC_CREDIT_AMOUNT = -1;

	var PROPERTY_REC_LOYALTY_ID = 1;
	var PROPERTY_REC_LOYALTY_NUMBER = '';
	var PROPERTY_REC_LOYALTY_AMOUNT = -1;

	var PROPERTY_REC_VOUCHER_ID = 1;
	var PROPERTY_REC_VOUCHER_NUMBER = '';
	var PROPERTY_REC_VOUCHER_AMOUNT = -1;

	var PROPERTY_REC_TRANSACTION_ID = -1;
	var PROPERTY_REC_TRANSACTION_REFNO = '';

	var PROPERTY_REC_JOBORDER_INDEX = -1;
	var PROPERTY_REC_JOBORDER_ID = -1;
	var PROPERTY_REC_JOBORDER_ITEMS = [];

	var PROPERTY_REC_LOYALTYCARD_INDEX = 1;
	var PROPERTY_REC_LOYALTYCARD_NUMBER = '';
	var PROPERTY_REC_LOYALTYCARD_POINTS = -1;

	var CACHE_PRODUCTS_JSON = [];

	var ADD_QTY_BBI = null;
	var SUBTRACT_QTY_BBI = null;
	var CHANGE_QTY_BBI = null;

	var ADD_ITEM_BBI = null;
	var VOID_BBI = null;

	var OPEN_SEARCH_BBI = null;
	var CLOSE_SEARCH_BBI = null;

	var SCAN_BARCODE_CMD = null;
	var SCAN_LOYALTY_CMD = null;
	var SCAN_LOYALTYCARD_CMD = null;
	var SEARCH_CMD = null;

	var SEARCH_CUSTOMER_TXT = '';
	var SEARCH_DESC_TXT = '';

	var SAVE_BBI = null;

	var DISCOUNTS_BBI = null;
	var CUSTOMERS_BBI = null;
	var LOYALTYCARD_BBI = null;
	var PRICING_BBI = null;

	var SEL_CUST_BBI = '';
	var DESEL_CUST_BBI = '';

	var PAY_BBI = null;
	var PAYMENT_OPTIONS_BBI = null;
	var CHECKOUT_BBI = null;

	var VIEW_ACCTS_BBI = null;

	var CART_DGV = null;
	var DISCOUNT_DGV = null;
	var CUSTOMERS_DGV = null;

	var PRODUCT_BRANCH_LV = null;
	var BAGS_LV = null;

	var PRICE_MODEL_ID = 1; //default SRP


	// ===============================================================
	// Initialize Controls
	// ===============================================================     
	function FORM_INITIALIZE()
	{
		// Initialize: Ribbon Buttons [Start Shift]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_START_BBI"))
		{
    		SHIFT_START_BBI = JSOC_ELEMENT.VAR_GET("SHIFT_START_BBI"); 

    		SHIFT_START_BBI.onclick =
    			function()
    			{
    				HTTP_START_SHIFT
    				(
    					function(IS_SUCCESS) 
    					{
    						if(IS_SUCCESS == false)
    						{	
    							return;
    						}

    						alertify.success('Shift started.');
    					}
    				);
    			};
		}

		// Initialize: Ribbon Buttons [End Shift - Cash breakdown]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_END_BBI"))
		{
    		SHIFT_END_BBI = JSOC_ELEMENT.VAR_GET("SHIFT_END_BBI"); 

    		SHIFT_END_BBI.onclick =
    			function()
    			{
    				HTTP_PRINT_CASHBREAKDOWN
    				(
    					function(IS_SUCCESS) 
    					{
    						if(IS_SUCCESS == false)
    						{	
    							return;
    						}
    					}
    				);
    			};
		}

		// Initialize: Ribbon Buttons [End Shift 2]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_END_BBI_2"))
		{
    		SHIFT_END_BBI_2 = JSOC_ELEMENT.VAR_GET("SHIFT_END_BBI_2"); 

    		SHIFT_END_BBI_2.onclick =
    			function()
    			{
    				X_READING
    				(
    					function(IS_SUCCESS) 
    					{
    						if(IS_SUCCESS == true)
    						{
    							END_SHIFT();
    						}
    					}
    				);
    			};
		}

		// Initialize: Ribbon Buttons [Add Quantity]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ADD_QTY_BBI"))
		{
    		ADD_QTY_BBI = JSOC_ELEMENT.VAR_GET("ADD_QTY_BBI"); 

    		// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_QTY_MODAL"))
			{
				ADD_QTY_BBI.onclick = 
					function()
					{	
						NEW_QTY = 1;

						INPUT_QTY = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY"));
						NEW_QTY += INPUT_QTY;

						JSOC_ELEMENT.VAR_VALUE("PROD_QTY", NEW_QTY);
					}		
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}

		// Initialize: Ribbon Buttons [Subtract Quantity]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBTRACT_QTY_BBI"))
		{
    		SUBTRACT_QTY_BBI = JSOC_ELEMENT.VAR_GET("SUBTRACT_QTY_BBI"); 

    		// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_QTY_MODAL"))
			{
				SUBTRACT_QTY_BBI.onclick = 
					function()
					{	
						NEW_QTY = 1;

						INPUT_QTY = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY"));
						NEW_QTY = INPUT_QTY - NEW_QTY;

						if(NEW_QTY >= 1)
							JSOC_ELEMENT.VAR_VALUE("PROD_QTY", NEW_QTY);
					}		
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}


		// Initialize: Ribbon Buttons [Add Item]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ADD_ITEM_BBI"))
		{
    		ADD_ITEM_BBI = JSOC_ELEMENT.VAR_GET("ADD_ITEM_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_ADD_ITEM))
    		{
				// Add OnClick event
				ADD_ITEM_BBI.onclick = 
					function()
					{
						if(JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY")) > 0)
						{
							HTTP_ADD_ITEM(CALLBACK_HANDLER);
						}
						else
						{
							PROD_QTY.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
							PROD_QTY.focus();
						}
					};
    		}
		}

		// Initialize: Ribbon Buttons [Void Order]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("VOID_BBI"))
		{
    		VOID_BBI = JSOC_ELEMENT.VAR_GET("VOID_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_VOID))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				VOID_BBI.onclick = 
					function()
					{
						if(CART_DGV.ROW.COUNT() > 0)
						{
							alertify.confirm
							(
								'PeakPOS', 
								'Are you sure you want to cancel this transaction?',
								function()
								{
									HTTP_VOID
									(
										function(IS_SUCCESS)
										{
											if(IS_SUCCESS)
											{
												alertify.error('Transaction cancelled.', 'success');
											}
										}
									);	
								},
								function(){}
							).set('labels', {ok:'YES', cancel:'NO'});
						}
						
					}
    		}
		}


		// Initialize: Ribbon Buttons [Open/Show Search Bar]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("OPEN_SEARCH_BBI"))
		{
    		OPEN_SEARCH_BBI = JSOC_ELEMENT.VAR_GET("OPEN_SEARCH_BBI"); 
    		OPEN_SEARCH_BBI.onclick =
    			function()
    			{
    				$('.div-categories').addClass('d-none');
					$('.div-search').removeClass('d-none');

					$('#SEARCH_DESC_TXT').focus();
    			};
		}

		// Initialize: Ribbon Buttons [Close/Hide Search Bar]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CLOSE_SEARCH_BBI"))
		{
    		CLOSE_SEARCH_BBI = JSOC_ELEMENT.VAR_GET("CLOSE_SEARCH_BBI"); 
    		CLOSE_SEARCH_BBI.onclick =
    			function()
    			{
    				$('.div-search').addClass('d-none');
					$('.div-categories').removeClass('d-none');

					$('#SEARCH_DESC_TXT').val('');
					$('#CATEGORY_CMB').focus();
    			};
		}


		// Initialize: Ribbon Buttons [Scan Barcode]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SCAN_BARCODE_CMD"))
		{
    		SCAN_BARCODE_CMD = JSOC_ELEMENT.VAR_GET("SCAN_BARCODE_CMD"); 
    		SCAN_BARCODE_CMD.onclick = function(){Android.CALL('SCAN_BARCODE', 'SEARCH_DESC_TXT')};
		}


		// Initialize: Ribbon Buttons [Search]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD"))
		{
    		SEARCH_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CMD");
			SEARCH_CMD.onclick = function(){HTTP_SEARCH()};
		}


		// Initialize: Ribbon Buttons [Edit QTY Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("EDIT_QTY_BBI"))
		{
    		EDIT_QTY_BBI = JSOC_ELEMENT.VAR_GET("EDIT_QTY_BBI"); 

    		// Add OnClick event [Show Modal]
			EDIT_QTY_BBI.onclick = 
				function()
				{	
					if(CART_DGV.ROW.COUNT() > 0)
			    	{
			    		if($('#CART_DGV tr.table-warning').length >= 1)
						{
							if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_QTY_MODAL") == true)
							{
								// Clear Modal
								if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
								{
									JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
								}
										
								// Display Modal
								JSOC_ELEMENT.VAR_GET("ADD_ITEM_BBI").classList.add("d-none");
								JSOC_ELEMENT.VAR_GET("CHANGE_QTY_BBI").classList.remove("d-none");

								JSOC_ELEMENT.VAR_VALUE("PROD_QTY", PROPERTY_REC_PRODUCT_QTY);
								JSOC_DIALOG.VAR_MODAL("POS_QTY_MODAL", true);
								JSOC_ELEMENT.VAR_GET("POS_QTY_MODAL").style.top = '20%';
								return;
							}								
						}
						else
						{
							alertify.error('No item selected.');
						}
			    	}
			    	else
					{
						alertify.error('No items in cart.');
					}
				};
		}


		// Initialize: Ribbon Buttons [Update Item QTY]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CHANGE_QTY_BBI"))
		{
    		CHANGE_QTY_BBI = JSOC_ELEMENT.VAR_GET("CHANGE_QTY_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_EDIT_QUANTITY))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				CHANGE_QTY_BBI.onclick = 
					function()
					{
						if(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY")) > 0)
						{
							HTTP_EDIT_QUANTITY(CALLBACK_HANDLER);
						}
						else
						{
							PROD_QTY.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
							PROD_QTY.focus();
							CALLBACK_METHOD(false);
						}
					}
    		}
		}


		// Initialize: Ribbon Buttons [Discounts Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DISCOUNTS_BBI"))
		{
    		DISCOUNTS_BBI = JSOC_ELEMENT.VAR_GET("DISCOUNTS_BBI"); 

    		// Add OnClick event [Show Modal]
			DISCOUNTS_BBI.onclick = 
				function()
				{	
					if(CART_DGV.ROW.COUNT() > 0)
			    	{
			    		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_DISCOUNT_MODAL") == true)
						{
							// Clear Modal
							if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
							{
								JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
							}
										
							// Display Modal

							//remove all highlights
							for(let i = 0; DISCOUNT_DGV.ROW.COUNT() > i; i++)
							{
								DISCOUNT_DGV.ROW.ELEMENT(i).classList.remove('table-warning');
							}

							JSOC_DIALOG.VAR_MODAL("POS_DISCOUNT_MODAL", true);
							return;
						}
			    	}
			    	else
					{
						alertify.error('No items in cart.');
					}
				};
		}



		// Initialize: Ribbon Buttons [Apply Disc to Selected Item]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DISC_SEL_BBI"))
		{
    		DISC_SEL_BBI = JSOC_ELEMENT.VAR_GET("DISC_SEL_BBI"); 

    		// Prepare Save callback
			var CALLBACK_HANDLER = 
				function(IS_SUCCESS)
				{
					// Abort on failure
					if(IS_SUCCESS == false)
					{
						return;
					}
					
					// Show record saved messageBox
					//JSVC_INFO.VAR_RECORD_SAVED('');
				}
				
			// Add OnClick event
			DISC_SEL_BBI.onclick = 
				function()
				{
					if($('#CART_DGV tr.table-warning').length >= 1)
					{
						PREPARE_DISCOUNT_APPLY(PROPERTY_DISCOUNT_ROW_INDEX);			
					}
					else
					{
						JSOC_DIALOG.VAR_MODAL("POS_DISCOUNT_MODAL", false);

						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No item selected.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				}
		}


		// Initialize: Ribbon Buttons [Apply Disc to All Items]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DISC_ALL_BBI"))
		{
    		DISC_ALL_BBI = JSOC_ELEMENT.VAR_GET("DISC_ALL_BBI"); 

    		// Prepare Save callback
			var CALLBACK_HANDLER = 
				function(IS_SUCCESS)
				{
					// Abort on failure
					if(IS_SUCCESS == false)
					{
						return;
					}
					
					// Show record saved messageBox
					//JSVC_INFO.VAR_RECORD_SAVED('');
				}
				
			// Add OnClick event
			DISC_ALL_BBI.onclick = 
				function()
				{
					if(CART_DGV.ROW.COUNT() > 0)
					{
						COMPUTE_DISCOUNT_APPLY(PROPERTY_DISCOUNT_ROW_INDEX);	
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No items in cart.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				}
		}



		// Initialize: Ribbon Buttons [Customers Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTOMERS_BBI"))
		{
    		CUSTOMERS_BBI = JSOC_ELEMENT.VAR_GET("CUSTOMERS_BBI"); 

    		// Add OnClick event [Show Modal]
			CUSTOMERS_BBI.onclick = 
				function()
				{	
			    	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_CUSTOMERS_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
						}
										
						// Display Modal

						//remove all highlights
						for(let i = 0; CUSTOMERS_DGV.ROW.COUNT() > i; i++)
						{
							CUSTOMERS_DGV.ROW.ELEMENT(i).classList.remove('table-warning');
						}


						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_MODAL", true);
						HTTP_LOAD_CUSTOMERS();
						return;
					}
				};
		}

		// Initialize: Ribbon Buttons [Add New Customers Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("NEWCUSTOMER_BBI"))
		{
    		NEWCUSTOMER_BBI = JSOC_ELEMENT.VAR_GET("NEWCUSTOMER_BBI"); 

    		// Add OnClick event [Show Modal]
			NEWCUSTOMER_BBI.onclick = 
				function()
				{	
			    	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_CUSTOMERS_NEW_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

							JSOC_ELEMENT.VAR_VALUE("CUSTNEW_FNAME", '');
							JSOC_ELEMENT.VAR_VALUE("CUSTNEW_LNAME", '');
							JSOC_ELEMENT.VAR_VALUE("CUSTNEW_ADDRESS", '');
							JSOC_ELEMENT.VAR_VALUE("CUSTNEW_EMAIL", '');
							JSOC_ELEMENT.VAR_VALUE("CUSTNEW_PHONE", '');
						}
										
						// Display Modal
						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_MODAL", false);
						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_NEW_MODAL", true);
						return;
					}
				};
		}

		// Initialize: Ribbon Buttons [Save New Customer]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SAVE_CUSTOMER_BBI"))
		{
    		SAVE_CUSTOMER_BBI = JSOC_ELEMENT.VAR_GET("SAVE_CUSTOMER_BBI"); 

    		// Add OnClick event [Show Modal]
			SAVE_CUSTOMER_BBI.onclick = 
				function()
				{	
					var FLAG = [];

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTNEW_FNAME") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CUSTNEW_FNAME")) == true
					)
					{
						CUSTNEW_FNAME.classList.add('is-invalid');

						CUSTNEW_FNAME_ERROR.innerHTML = 'FIRST NAME IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CUSTNEW_FNAME.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTNEW_LNAME") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CUSTNEW_LNAME")) == true
					)
					{
						CUSTNEW_LNAME.classList.add('is-invalid');

						CUSTNEW_LNAME_ERROR.innerHTML = 'LAST NAME IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CUSTNEW_LNAME.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTNEW_ADDRESS") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CUSTNEW_ADDRESS")) == true
					)
					{
						CUSTNEW_ADDRESS.classList.add('is-invalid');

						CUSTNEW_ADDRESS_ERROR.innerHTML = 'ADDRESS IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CUSTNEW_ADDRESS.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTNEW_PHONE") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CUSTNEW_PHONE")) == true
					)
					{
						CUSTNEW_PHONE.classList.add('is-invalid');

						CUSTNEW_PHONE_ERROR.innerHTML = 'CONTACT NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CUSTNEW_PHONE.classList.remove('is-invalid');
						FLAG.push(true);
					}


					if(FLAG.includes(false) !== true)
					{
						HTTP_SAVE_CUSTOMER
						(
							function(IS_SUCCESS)
							{
								if(IS_SUCCESS == true)
								{
									JSOC_DIALOG.VAR_MESSAGE_BOX
									(
										'Record saved!',
										'Information',
										'OK', 'SUCCESS',
										function() {
											JSOC_ELEMENT.VAR_GET("CUSTOMERS_BBI").click();
										}
									);
								}

								JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_NEW_MODAL", false);
							}
						);

						return;
					}
				};
		}


		// Initialize: Ribbon Buttons [Search Customers]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CUSTOMER_CMD"))
		{
    		SEARCH_CUSTOMER_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CUSTOMER_CMD");
			SEARCH_CUSTOMER_CMD.onclick = function(){HTTP_LOAD_CUSTOMERS()};
		}


		// Initialize: Ribbon Buttons [Select Customer]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEL_CUST_BBI"))
		{
    		SEL_CUST_BBI = JSOC_ELEMENT.VAR_GET("SEL_CUST_BBI"); 
				
			// Add OnClick event
			SEL_CUST_BBI.onclick = 
				function()
				{
					if($('#CUSTOMERS_DGV tr.table-warning').length >= 1)
					{
						JSOC_ELEMENT.VAR_GET('CUSTOMER_INFO_TXT').classList.remove('d-none');

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

						$('#DESEL_CUST_BBI').removeClass('d-none');

						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_MODAL", false);
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No customer selected.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				}
		}

		// Initialize: Ribbon Buttons [Deselect Customer]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DESEL_CUST_BBI"))
		{
    		DESEL_CUST_BBI = JSOC_ELEMENT.VAR_GET("DESEL_CUST_BBI"); 
				
			// Add OnClick event
			DESEL_CUST_BBI.onclick = 
				function()
				{
					alertify.confirm
					(
						'PeakPOS', 'Are you sure you want to remove selected customer?', 
						
						function() 
						{ 
							JSOC_ELEMENT.VAR_GET('CUSTOMER_INFO_TXT').classList.add('d-none');

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

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

							$('#DESEL_CUST_BBI').addClass('d-none');
							
						},
						
						function()
						{
							
						}
				    ).set('labels', {ok:'YES', cancel:'Cancel'});
				}
		}

		// Initialize: Ribbon Buttons [View A/R]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("VIEW_ACCTS_BBI"))
		{
    		VIEW_ACCTS_BBI = JSOC_ELEMENT.VAR_GET("VIEW_ACCTS_BBI"); 
				
			// Add OnClick event
			VIEW_ACCTS_BBI.onclick = 
				function()
				{
					if($('#CUSTOMERS_DGV tr.table-warning').length >= 1)
					{
						JSOC_ELEMENT.VAR_VALUE("ACCTS_NAME", ': ' + PROPERTY_REC_CUSTOMER_NAME);
						JSOC_ELEMENT.VAR_VALUE("ACCTS_ADDRESS", ': ' + PROPERTY_REC_CUSTOMER_ADDRESS);
						JSOC_ELEMENT.VAR_VALUE("ACCTS_TIN", ': ' + PROPERTY_REC_CUSTOMER_TIN);
						
						JSOC_ELEMENT.VAR_VALUE("TOTAL_BALANCE_TXT", '');
						JSOC_ELEMENT.VAR_VALUE("TOTAL_SELECTED_TXT", '');

						POS_SALE_DGV.ROW.CLEAR();

						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_MODAL", false);
						JSOC_DIALOG.VAR_MODAL("POS_ACCTS_MODAL", true);
						
						HTTP_LOAD_CREDITS();
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No customer selected.',
							'Information',
							'OK', 'ERROR',
							function()
							{
								CALLBACK_METHOD(false);
							}
						);
					}
				}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_SALE_DGV_HEADER_SELECTED"))
		{		
			$('th#POS_SALE_DGV_HEADER_SELECTED > input').on('click', function() {
				HTTP_CALCULATE_SELECTED($('th#POS_SALE_DGV_HEADER_SELECTED > input').is(':checked'));
			});
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_ACCTS_CASH_BBI"))
		{
			PAY_ACCTS_CASH_BBI = JSOC_ELEMENT.VAR_GET("PAY_ACCTS_CASH_BBI"); 

			PAY_ACCTS_CASH_BBI.onclick =
				function()
				{
					var TO_PAY = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT'));

					if(TO_PAY > 0)
					{
						if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_ACCTS_CASH_MODAL") == true)
						{
							if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
							{
								JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
								HTTP_ACCTS_CALCULATE_CHANGE();
							}

							JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CASH_TOTAL', JSVC_NUM.VAR_CFORMAT(TO_PAY));
							JSOC_ELEMENT.VAR_VALUE('ACCTS_PAY_CASH', (Math.round(TO_PAY * 100) / 100).toFixed(2));

							JSOC_ELEMENT.VAR_GET("ACCTS_PAY_CASH").focus();

							HTTP_ACCTS_CALCULATE_CHANGE();

							JSOC_DIALOG.VAR_MODAL("POS_ACCTS_CASH_MODAL", true);
						}
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No orders selected.',
							'Information',
							'OK', 'ERROR',
							function()
							{
								CALLBACK_METHOD(false);
							}
						);
					}
				}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_CHECKOUT_CASH_BBI"))
		{
			ACCTS_CHECKOUT_CASH_BBI = JSOC_ELEMENT.VAR_GET("ACCTS_CHECKOUT_CASH_BBI");

			// Prepare Save callback
			var CALLBACK_HANDLER = 
				function(IS_SUCCESS)
				{
					if(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
						
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED("");
					}
				}

			ACCTS_CHECKOUT_CASH_BBI.onclick =
				function()
				{
					HTTP_SAVE_PAYMENT(true, CALLBACK_HANDLER);
				}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_ACCTS_CHECKS_BBI"))
		{
			PAY_ACCTS_CHECKS_BBI = JSOC_ELEMENT.VAR_GET("PAY_ACCTS_CHECKS_BBI"); 

			PAY_ACCTS_CHECKS_BBI.onclick =
				function()
				{
					var TO_PAY = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE('TOTAL_SELECTED_TXT'));

					if(TO_PAY > 0)
					{
						if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_ACCTS_CHECK_MODAL") == true)
						{
							if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
							{
								JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
								HTTP_ACCTS_CALCULATE_CHANGE(false);
							}

							JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECKOUT_CHECK_TOTAL', JSVC_NUM.VAR_CFORMAT(TO_PAY));
							JSOC_ELEMENT.VAR_VALUE('ACCTS_CHECK_AMOUNT', (Math.round(TO_PAY * 100) / 100).toFixed(2));

							JSOC_ELEMENT.VAR_GET("ACCTS_CHECK_AMOUNT").focus();

							HTTP_ACCTS_CALCULATE_CHANGE(false);

							JSOC_DIALOG.VAR_MODAL("POS_ACCTS_CHECK_MODAL", true);
						}
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No orders selected.',
							'Information',
							'OK', 'ERROR',
							function()
							{
								CALLBACK_METHOD(false);
							}
						);
					}
				}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_CHECKOUT_CHECK_BBI"))
		{
			ACCTS_CHECKOUT_CHECK_BBI = JSOC_ELEMENT.VAR_GET("ACCTS_CHECKOUT_CHECK_BBI");

			// Prepare Save callback
			var CALLBACK_HANDLER = 
				function(IS_SUCCESS)
				{
					if(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
						
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED("");
					}
				}

			ACCTS_CHECKOUT_CHECK_BBI.onclick =
				function()
				{
					var FLAG = [];

					if
					(
						JSVC_VAR.VAR_ISSET(ACCTS_CHECK_BANK) &&
						(
							JSOC_CMB.VAR_SELECTED_INDEX(ACCTS_CHECK_BANK) < 1 ||
							JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(ACCTS_CHECK_BANK)) < 1
						)
					)
					{
						ACCTS_CHECK_BANK.classList.add('is-invalid');
						ACCTS_CHECK_BANK_ERROR.innerHTML = 'BANK IS REQUIRED';

						FLAG.push(false);
					}
					else 
					{
						ACCTS_CHECK_BANK.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_CHECK_NUMBER") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("ACCTS_CHECK_NUMBER")) == true
					)
					{
						ACCTS_CHECK_NUMBER.classList.add('is-invalid');

						ACCTS_CHECK_NUMBER_ERROR.innerHTML = 'CHECK NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						ACCTS_CHECK_NUMBER.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_CHECK_DATE") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("ACCTS_CHECK_DATE")) == true
					)
					{
						ACCTS_CHECK_DATE.classList.add('is-invalid');

						ACCTS_CHECK_DATE_ERROR.innerHTML = 'CHECK DATE IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if
						(
							JSVC_DATE.VAR_TO_DATE(JSVC_DATE.VAR_END_OF_DAY(JSOC_ELEMENT.VAR_VALUE("ACCTS_CHECK_DATE")), "YYYY-MM-DD HH:mm:ss") < JSVC_DATE.VAR_TO_DATE(JSVC_DATE.VAR_END_OF_DAY(JSVC_DATE.VAR_NOW()), "YYYY-MM-DD HH:mm:ss")
						)
						{
							ACCTS_CHECK_DATE.classList.add('is-invalid');

							ACCTS_CHECK_DATE_ERROR.innerHTML = 'CHECK DATE IS OUTDATED';

							FLAG.push(false);
						}
						else
						{
							ACCTS_CHECK_DATE.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}


					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_CHECK_AMOUNT") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("ACCTS_CHECK_AMOUNT")) == true
					)
					{
						ACCTS_CHECK_AMOUNT.classList.add('is-invalid');

						ACCTS_CHECK_AMOUNT_ERROR.innerHTML = 'CHECK NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if(JSOC_ELEMENT.VAR_VALUE("ACCTS_CHECK_AMOUNT") <= 0)
						{
							ACCTS_CHECK_AMOUNT.classList.add('is-invalid');

							ACCTS_CHECK_AMOUNT_ERROR.innerHTML = 'CHECK AMOUNT MUST BE GREATER THAN ZERO';

							FLAG.push(false);
						}
						else
						{
							ACCTS_CHECK_AMOUNT.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}

					if(FLAG.includes(false) !== true)
					{
						HTTP_SAVE_PAYMENT(false, CALLBACK_HANDLER);
						return;
					}
				}
		}



		// Initialize: Ribbon Buttons [Loyalty Cards Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOYALTYCARD_BBI"))
		{
    		LOYALTYCARD_BBI = JSOC_ELEMENT.VAR_GET("LOYALTYCARD_BBI"); 

    		// Add OnClick event [Show Modal]
			LOYALTYCARD_BBI.onclick = 
				function()
				{	
			    	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_LOYALTYCARD_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
						}
										
						// Display Modal
						JSOC_DIALOG.VAR_MODAL("POS_LOYALTYCARD_MODAL", true);
						JSOC_ELEMENT.VAR_GET("POS_LOYALTYCARD_MODAL").style.top = '20%';
						return;
					}
				};
		}

		// Initialize: Ribbon Buttons [Scan Loyalty Card]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SCAN_LOYALTYCARD_CMD"))
		{
    		SCAN_LOYALTYCARD_CMD = JSOC_ELEMENT.VAR_GET("SCAN_LOYALTYCARD_CMD"); 
    		SCAN_LOYALTYCARD_CMD.onclick = function(){};
		}

		// Initialize: Ribbon Buttons [Select Loyalty Card]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEL_LOYALTYCARD_BBI"))
		{
    		SEL_LOYALTYCARD_BBI = JSOC_ELEMENT.VAR_GET("SEL_LOYALTYCARD_BBI"); 
				
			// Add OnClick event
			SEL_LOYALTYCARD_BBI.onclick = 
				function()
				{
					if(PROPERTY_REC_LOYALTYCARD_NUMBER == '') 
					{
						HTTP_VALIDATE_LOYALTYCARD
						(
							function(IS_SUCCESS) 
							{
								if(IS_SUCCESS == true)
								{
									JSOC_ELEMENT.VAR_GET('CUSTOMER_INFO_TXT').classList.remove('d-none');
									JSOC_ELEMENT.VAR_GET('LOYALTYCARD_INFO_TXT').classList.remove('d-none');

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

									JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_ID', PROPERTY_REC_LOYALTYCARD_INDEX);
									JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_NUMBER', PROPERTY_REC_LOYALTYCARD_NUMBER);
									JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_POINTS', PROPERTY_REC_LOYALTYCARD_POINTS);

									$('#DESEL_CUST_BBI').removeClass('d-none');
									$('#DESEL_LOYALTYCARD_BBI').removeClass('d-none');

									JSOC_DIALOG.VAR_MODAL("POS_LOYALTYCARD_MODAL", false);
								}
								else
								{
									JSOC_DIALOG.VAR_MESSAGE_BOX
									(
										'Loyalty Card Number not found',
										'Information',
										'OK', 'ERROR',
										function() {}
									);
								}

								
							}
						);
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'A current Loyalty Card is used.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				}
		}


		// Initialize: Ribbon Buttons [Deselect Loyalty Card]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DESEL_LOYALTYCARD_BBI"))
		{
    		DESEL_LOYALTYCARD_BBI = JSOC_ELEMENT.VAR_GET("DESEL_LOYALTYCARD_BBI"); 
				
			// Add OnClick event
			DESEL_LOYALTYCARD_BBI.onclick = 
				function()
				{
					alertify.confirm
					(
						'PeakPOS', 'Are you sure you want to remove selected loyalty card?', 
						
						function() 
						{ 
							PROPERTY_REC_CUSTOMER_INDEX = -1;
							PROPERTY_REC_CUSTOMER_NAME = '';
							PROPERTY_REC_CUSTOMER_TIN = '';
							PROPERTY_REC_CUSTOMER_ADDRESS = '';

							PROPERTY_REC_LOYALTYCARD_INDEX = -1;
							PROPERTY_REC_LOYALTYCARD_POINTS = -1;
							PROPERTY_REC_LOYALTYCARD_NUMBER = '';

							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_VALUE('POS_LOYALTYCARD_ID', 1);
							JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_POINTS', '');
							JSOC_ELEMENT.VAR_VALUE('POS_LOYALTYCARD_NUMBER', '-');

							$('#DESEL_CUST_BBI').addClass('d-none');
							$('#DESEL_LOYALTYCARD_BBI').addClass('d-none');

							JSOC_ELEMENT.VAR_GET('CUSTOMER_INFO_TXT').classList.add('d-none');
							JSOC_ELEMENT.VAR_GET('LOYALTYCARD_INFO_TXT').classList.add('d-none');							
						},
						
						function()
						{
							
						}
				    ).set('labels', {ok:'YES', cancel:'Cancel'});
				}
		}
		



		// Initialize: Ribbon Buttons [Pricing Scheme Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PRICING_BBI"))
		{
    		PRICING_BBI = JSOC_ELEMENT.VAR_GET("PRICING_BBI"); 

    		// Add OnClick event [Show Modal]
			PRICING_BBI.onclick = 
				function()
				{	
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PRICING_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
						}
											
						// Display Modal

						//remove all highlights
						for(let i = 0; PRICE_MODEL_DGV.ROW.COUNT() > i; i++)
						{
							PRICE_MODEL_DGV.ROW.ELEMENT(i).classList.remove('table-warning');
						}


						JSOC_DIALOG.VAR_MODAL("POS_PRICING_MODAL", true);
						return;
					}
				};
		}

		// Initialize: Ribbon Buttons [Select Pricing Scheme]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEL_PRICE_BBI"))
		{
    		SEL_PRICE_BBI = JSOC_ELEMENT.VAR_GET("SEL_PRICE_BBI"); 
				
			// Add OnClick event
			SEL_PRICE_BBI.onclick = 
				function()
				{
					if($('#PRICE_MODEL_DGV tr.table-warning').length >= 1)
					{
						HTTP_PRODUCT_PRICES();
						JSOC_DIALOG.VAR_MODAL("POS_PRICING_MODAL", false);
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No pricing scheme selected.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				}
		}




		// Initialize: Ribbon Buttons [PAY - show bags]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_BBI"))
		{
    		PAY_BBI = JSOC_ELEMENT.VAR_GET("PAY_BBI"); 
				
			// Add OnClick event
			PAY_BBI.onclick = 
				function()
				{
					if(CART_DGV.ROW.COUNT() > 0)
			    	{
			    		if(JSCUS_CACHE.SHOW_BAGS == true)
			    		{
			    			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_BAGS_MODAL") == true)
							{
								// Clear Modal
								if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
								{
									JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
								}

								//set all qty values to 1
								if(JSVC_NUM.VAR_NVALL(BAGS_DGV.COLUMN.SUM('BAG_QTY')) > 0)
								{
									var INDEX = 0;

									while(BAGS_DGV.ROW.COUNT() > INDEX)
									{
										BAGS_DGV.CELL.VALUE('BAG_QTY', INDEX, 0);
										INDEX++;
									}
								}
								
								JSOC_DIALOG.VAR_MODAL("POS_BAGS_MODAL", true);

								return;
							}
			    		}
			    		else
			    		{
			    			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PAYMENT_MODAL") == true)
							{
								// Clear Modal
								if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
								{
									JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

									JSOC_ELEMENT.VAR_GET('CHECKOUT_CARD_RECEIVED').classList.add('d-none');
									JSOC_ELEMENT.VAR_GET('CHECKOUT_CHECK_RECEIVED').classList.add('d-none');
									JSOC_ELEMENT.VAR_GET('CHECKOUT_LOYALTY_RECEIVED').classList.add('d-none');
									JSOC_ELEMENT.VAR_GET('CHECKOUT_CREDITS_RECEIVED').classList.add('d-none');
									JSOC_ELEMENT.VAR_GET('CHECKOUT_VOUCHER_RECEIVED').classList.add('d-none');
											
									JSOC_ELEMENT.VAR_VALUE('PAY_CARD', '');
									JSOC_ELEMENT.VAR_VALUE('PAY_CHECK', '');
									JSOC_ELEMENT.VAR_VALUE('PAY_LOYALTY', '');
									JSOC_ELEMENT.VAR_VALUE('PAY_CREDIT', '');
									JSOC_ELEMENT.VAR_VALUE('PAY_VOUCHER', '');

									HTTP_CALCULATE_CHANGE();

									$('#PAYMENT_OPTIONS').addClass('d-none');
									$('#PAYMENT_OPTIONS').removeClass('d-flex');
								}

								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('CHECKOUT_TOTAL', JSVC_NUM.VAR_CFORMAT(TOTAL_DUE));
								JSOC_ELEMENT.VAR_VALUE('PAY_CASH', (Math.round(TOTAL_DUE * 100) / 100).toFixed(2));

								PROPERTY_REC_CASH_AMOUNT = (Math.round(TOTAL_DUE * 100) / 100).toFixed(2);

								JSOC_ELEMENT.VAR_GET("PAY_CASH").focus();

								HTTP_CALCULATE_CHANGE();

								JSOC_DIALOG.VAR_MODAL("POS_PAYMENT_MODAL", true);
								JSOC_ELEMENT.VAR_GET("POS_PAYMENT_MODAL").style.top = '30%';
								return;
							}
			    		}
						
			    	}
			    	else
					{
						alertify.error('No items in cart.');
					}
				}
		}



		// Initialize: Ribbon Buttons [PAY - payments]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBMIT_BAGS_BBI"))
		{
    		SUBMIT_BAGS_BBI = JSOC_ELEMENT.VAR_GET("SUBMIT_BAGS_BBI"); 
				
			// Add OnClick event
			SUBMIT_BAGS_BBI.onclick = 
				function()
				{
					if(BAGS_DGV.COLUMN.SUM("BAG_QTY") > 0)
			    	{
			    		//add bags to cart
			    		HTTP_ADD_BAGS
			    		(
			    			function(IS_SUCCESS)
			    			{
								PAYMENT_SHOW();
			    			}
			    		);

			    		//proceed to payment
			    	}
			    	else
					{
						PAYMENT_SHOW();
					}
				}
		}



		// Initialize: Ribbon Buttons [Cash Denominations]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CASH_1000"))
		{
    		CASH_1000 = JSOC_ELEMENT.VAR_GET("CASH_1000");
			CASH_1000.onclick = 
				function()
				{
					JSOC_ELEMENT.VAR_VALUE('PAY_CASH', 1000);
					PROPERTY_REC_CASH_AMOUNT = 1000;
					HTTP_CALCULATE_CHANGE();
				};
		}

		// Initialize: Ribbon Buttons [Cash Denominations]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CASH_500"))
		{
    		CASH_500 = JSOC_ELEMENT.VAR_GET("CASH_500");
			CASH_500.onclick = 
				function()
				{
					JSOC_ELEMENT.VAR_VALUE('PAY_CASH', 500);
					PROPERTY_REC_CASH_AMOUNT = 500;
					HTTP_CALCULATE_CHANGE();
				};
		}


		// Initialize: Ribbon Buttons [Cash Denominations]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CASH_200"))
		{
    		CASH_200 = JSOC_ELEMENT.VAR_GET("CASH_200");
			CASH_200.onclick = 
				function()
				{
					JSOC_ELEMENT.VAR_VALUE('PAY_CASH', 200);
					PROPERTY_REC_CASH_AMOUNT = 200;
					HTTP_CALCULATE_CHANGE();
				};
		}


		// Initialize: Ribbon Buttons [Cash Denominations]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CASH_100"))
		{
    		CASH_100 = JSOC_ELEMENT.VAR_GET("CASH_100");
			CASH_100.onclick = 
				function()
				{
					JSOC_ELEMENT.VAR_VALUE('PAY_CASH', 100);
					PROPERTY_REC_CASH_AMOUNT = 100;
					HTTP_CALCULATE_CHANGE();
				};
		}


		// Initialize: Ribbon Buttons [Cash Denominations]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CASH_50"))
		{
    		CASH_50 = JSOC_ELEMENT.VAR_GET("CASH_50");
			CASH_50.onclick = 
				function()
				{
					JSOC_ELEMENT.VAR_VALUE('PAY_CASH', 50);
					PROPERTY_REC_CASH_AMOUNT = 50;
					HTTP_CALCULATE_CHANGE();
				};
		}


		// Initialize: Ribbon Buttons [Cash Denominations]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CASH_20"))
		{
    		CASH_20 = JSOC_ELEMENT.VAR_GET("CASH_20");
			CASH_20.onclick = 
				function()
				{
					JSOC_ELEMENT.VAR_VALUE('PAY_CASH', 20);
					PROPERTY_REC_CASH_AMOUNT = 20;
					HTTP_CALCULATE_CHANGE();
				};
		}


		// Initialize: Ribbon Buttons [Toggle Payment Options]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAYMENT_OPTIONS_BBI"))
		{
    		PAYMENT_OPTIONS = JSOC_ELEMENT.VAR_GET("PAYMENT_OPTIONS_BBI"); 
    		PAYMENT_OPTIONS.onclick =
    			function()
    			{
    				var options = $('#PAYMENT_OPTIONS');

					if(options.hasClass('d-none') === true) {
						options.removeClass('d-none');
						options.addClass('d-flex');
					}
					else {
						options.addClass('d-none');
						options.removeClass('d-flex');
					}
    			};
		}


		// Initialize: Ribbon Buttons [Checkout]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CHECKOUT_BBI"))
		{
    		CHECKOUT_BBI = JSOC_ELEMENT.VAR_GET("CHECKOUT_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_SAVE))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						if(IS_SUCCESS)
						{
							// Abort on failure
							if(IS_SUCCESS == false)
							{
								return;
							}
						
							// Show record saved messageBox
							//JSVC_INFO.VAR_RECORD_SAVED("");
						}
					}
					
	    		CHECKOUT_BBI.onclick =
	    			function()
	    			{
	    				if(JSOC_ELEMENT.VAR_VALUE("CHECKOUT_CHANGE_VALUE") < 0)
	    				{
	    					JSOC_DIALOG.VAR_MESSAGE_BOX
							(
								'Insufficient amount',
								'Information',
								'OK', 'ERROR',
								function() {}
							);
	    				}
	    				else
	    				{
	    					HTTP_SAVE(CALLBACK_HANDLER);
	    				}
	    			};
	    	}
		}



		// Initialize: Ribbon Buttons [Pay by card]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_BY_CARD_BBI"))
		{
    		PAY_BY_CARD_BBI = JSOC_ELEMENT.VAR_GET("PAY_BY_CARD_BBI"); 

    		// Add OnClick event [Show Modal]
			PAY_BY_CARD_BBI.onclick = 
				function()
				{	
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PAYBYCARD_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

							CARD_BANK.classList.remove('is-invalid');
							CARD_TYPE.classList.remove('is-invalid');
							CARD_NAME.classList.remove('is-invalid');
							CARD_NUMBER.classList.remove('is-invalid');
							CARD_AMOUNT.classList.remove('is-invalid');

							JSOC_ELEMENT.VAR_VALUE("CARD_BANK", 1);
							JSOC_ELEMENT.VAR_VALUE("CARD_TYPE", 1);
							JSOC_ELEMENT.VAR_VALUE("CARD_NAME", '');
							JSOC_ELEMENT.VAR_VALUE("CARD_NUMBER", '');
							JSOC_ELEMENT.VAR_VALUE("CARD_REFERENCE", '');
						}

						PROPERTY_REC_CARD_BANK = 1;
						PROPERTY_REC_CARD_TYPE = -1;
						PROPERTY_REC_CARD_NAME = '';
						PROPERTY_REC_CARD_NUMBER = '';
						PROPERTY_REC_CARD_REFERENCE = '';
						PROPERTY_REC_CARD_AMOUNT = -1;

						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;
										
						// Display Modal
						JSOC_ELEMENT.VAR_VALUE("CARD_AMOUNT", (Math.round(TOTAL_DUE * 100) / 100).toFixed(2));
						JSOC_DIALOG.VAR_MODAL("POS_PAYBYCARD_MODAL", true);
						JSOC_ELEMENT.VAR_GET("POS_PAYBYCARD_MODAL").style.top = '40%';
						return;
					}
				};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBMIT_CARD_BBI"))
		{
    		SUBMIT_CARD_BBI = JSOC_ELEMENT.VAR_GET("SUBMIT_CARD_BBI"); 

    		// Add OnClick event [Show Modal]
			SUBMIT_CARD_BBI.onclick = 
				function()
				{	
					var FLAG = [];

					if
					(
						JSVC_VAR.VAR_ISSET(CARD_BANK) &&
						(
							JSOC_CMB.VAR_SELECTED_INDEX(CARD_BANK) < 1 ||
							JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(CARD_BANK)) < 1
						)
					)
					{
						CARD_BANK.classList.add('is-invalid');
						CARD_BANK_ERROR.innerHTML = 'BANK IS REQUIRED';

						FLAG.push(false);
					}
					else 
					{
						CARD_BANK.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSVC_VAR.VAR_ISSET(CARD_TYPE) &&
						(
							JSOC_CMB.VAR_SELECTED_INDEX(CARD_TYPE) < 1 ||
							JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(CARD_TYPE)) < 1
						)
					)
					{
						CARD_TYPE.classList.add('is-invalid');

						CARD_TYPE_ERROR.innerHTML = 'CARD TYPE IS REQUIRED';

						FLAG.push(false);
					}
					else 
					{
						CARD_TYPE.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CARD_NAME") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CARD_NAME")) == true
					)
					{
						CARD_NAME.classList.add('is-invalid');

						CARD_NAME_ERROR.innerHTML = 'CARD HOLDER NAME IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CARD_NAME.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CARD_NUMBER") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CARD_NUMBER")) == true
					)
					{
						CARD_NUMBER.classList.add('is-invalid');

						CARD_NUMBER_ERROR.innerHTML = 'CARD NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if(JSOC_ELEMENT.VAR_TYPE_IS(CARD_NUMBER, 'input', 'number'))
						{
							if(JSOC_INPUT_TEXT.CTL_VALIDATE(CARD_NUMBER, 'Invalid Card Number', false, 4, 4) == false)
							{
								CARD_NUMBER.classList.add('is-invalid');

								CARD_NUMBER_ERROR.innerHTML = 'INVALID CARD NUMBER (MUST BE LAST 4 DIGITS ONLY)';
							
								FLAG.push(false);
							}
							else
							{
								CARD_NUMBER.classList.remove('is-invalid');
								FLAG.push(true);
							}
							
						}
						else
						{
							CARD_NUMBER.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CARD_AMOUNT") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CARD_AMOUNT")) == true
					)
					{
						CARD_AMOUNT.classList.add('is-invalid');

						CARD_AMOUNT_ERROR.innerHTML = 'CARD NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if(JSOC_ELEMENT.VAR_VALUE("CARD_AMOUNT") <= 0)
						{
							CARD_AMOUNT.classList.add('is-invalid');

							CARD_AMOUNT_ERROR.innerHTML = 'CARD AMOUNT MUST BE GREATER THAN ZERO';

							FLAG.push(false);
						}
						else
						{
							CARD_AMOUNT.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}

					if(FLAG.includes(false) !== true)
					{
						PROPERTY_REC_CARD_BANK = JSOC_ELEMENT.VAR_VALUE("CARD_BANK");
						PROPERTY_REC_CARD_TYPE = JSOC_ELEMENT.VAR_VALUE("CARD_TYPE");
						PROPERTY_REC_CARD_NAME = JSOC_ELEMENT.VAR_VALUE("CARD_NAME");
						PROPERTY_REC_CARD_NUMBER = JSOC_ELEMENT.VAR_VALUE("CARD_NUMBER");
						PROPERTY_REC_CARD_REFERENCE = JSOC_ELEMENT.VAR_VALUE("CARD_REFERENCE");
						PROPERTY_REC_CARD_AMOUNT = JSOC_ELEMENT.VAR_VALUE("CARD_AMOUNT");

						JSOC_ELEMENT.VAR_GET('CHECKOUT_CARD_RECEIVED').classList.remove('d-none');
						JSOC_ELEMENT.VAR_VALUE('PAY_CARD', JSOC_ELEMENT.VAR_VALUE("CARD_AMOUNT"));

						HTTP_CALCULATE_CHANGE();

						PAYMENT_OPTIONS.click();

						JSOC_DIALOG.VAR_MODAL("POS_PAYBYCARD_MODAL", false);
						return;
					}
				};
		}



		// Initialize: Ribbon Buttons [Pay by check]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_BY_CHECK_BBI"))
		{
    		PAY_BY_CHECK_BBI = JSOC_ELEMENT.VAR_GET("PAY_BY_CHECK_BBI"); 

    		// Add OnClick event [Show Modal]
			PAY_BY_CHECK_BBI.onclick = 
				function()
				{	
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PAYBYCHECK_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

							CHECK_BANK.classList.remove('is-invalid');
							CHECK_DATE.classList.remove('is-invalid');
							CHECK_NUMBER.classList.remove('is-invalid');
							CHECK_AMOUNT.classList.remove('is-invalid');

							JSOC_ELEMENT.VAR_VALUE("CHECK_BANK", 1);
							JSOC_ELEMENT.VAR_VALUE("CHECK_DATE", 1);
							JSOC_ELEMENT.VAR_VALUE("CHECK_NUMBER", '');
						}

						PROPERTY_REC_CHECK_BANK = 1;
						PROPERTY_REC_CHECK_DATE = -1;
						PROPERTY_REC_CHECK_NUMBER = '';
						PROPERTY_REC_CHECK_AMOUNT = -1;

						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;
										
						// Display Modal
						JSOC_ELEMENT.VAR_VALUE("CHECK_DATE", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_ADD('DAY', 0, JSVC_DATE.VAR_NOW()), "YYYY-MM-DD"));
						JSOC_ELEMENT.VAR_VALUE("CHECK_AMOUNT", (Math.round(TOTAL_DUE * 100) / 100).toFixed(2));
						JSOC_DIALOG.VAR_MODAL("POS_PAYBYCHECK_MODAL", true);
						JSOC_ELEMENT.VAR_GET("POS_PAYBYCHECK_MODAL").style.top = '35%';
						return;
					}
				};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBMIT_CHECK_BBI"))
		{
    		SUBMIT_CHECK_BBI = JSOC_ELEMENT.VAR_GET("SUBMIT_CHECK_BBI"); 

    		// Add OnClick event [Show Modal]
			SUBMIT_CHECK_BBI.onclick = 
				function()
				{	
					var FLAG = [];

					if
					(
						JSVC_VAR.VAR_ISSET(CHECK_BANK) &&
						(
							JSOC_CMB.VAR_SELECTED_INDEX(CHECK_BANK) < 1 ||
							JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(CHECK_BANK)) < 1
						)
					)
					{
						CHECK_BANK.classList.add('is-invalid');
						CHECK_BANK_ERROR.innerHTML = 'BANK IS REQUIRED';

						FLAG.push(false);
					}
					else 
					{
						CHECK_BANK.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CHECK_NUMBER") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CHECK_NUMBER")) == true
					)
					{
						CHECK_NUMBER.classList.add('is-invalid');

						CHECK_NUMBER_ERROR.innerHTML = 'CHECK NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CHECK_NUMBER.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CHECK_DATE") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CHECK_DATE")) == true
					)
					{
						CHECK_DATE.classList.add('is-invalid');

						CHECK_DATE_ERROR.innerHTML = 'CHECK DATE IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if
						(
							JSVC_DATE.VAR_TO_DATE(JSVC_DATE.VAR_END_OF_DAY(JSOC_ELEMENT.VAR_VALUE("CHECK_DATE")), "YYYY-MM-DD HH:mm:ss") < JSVC_DATE.VAR_TO_DATE(JSVC_DATE.VAR_END_OF_DAY(JSVC_DATE.VAR_NOW()), "YYYY-MM-DD HH:mm:ss")
						)
						{
							CHECK_DATE.classList.add('is-invalid');

							CHECK_DATE_ERROR.innerHTML = 'CHECK DATE IS OUTDATED';

							FLAG.push(false);
						}
						else
						{
							CHECK_DATE.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}


					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CHECK_AMOUNT") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CHECK_AMOUNT")) == true
					)
					{
						CHECK_AMOUNT.classList.add('is-invalid');

						CHECK_AMOUNT_ERROR.innerHTML = 'CHECK NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if(JSOC_ELEMENT.VAR_VALUE("CHECK_AMOUNT") <= 0)
						{
							CHECK_AMOUNT.classList.add('is-invalid');

							CHECK_AMOUNT_ERROR.innerHTML = 'CHECK AMOUNT MUST BE GREATER THAN ZERO';

							FLAG.push(false);
						}
						else
						{
							CHECK_AMOUNT.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}

					if(FLAG.includes(false) !== true)
					{
						PROPERTY_REC_CHECK_BANK = JSOC_ELEMENT.VAR_VALUE("CHECK_BANK");
						PROPERTY_REC_CHECK_DATE = JSOC_ELEMENT.VAR_VALUE("CHECK_DATE");
						PROPERTY_REC_CHECK_NUMBER = JSOC_ELEMENT.VAR_VALUE("CHECK_NUMBER");
						PROPERTY_REC_CHECK_AMOUNT = JSOC_ELEMENT.VAR_VALUE("CHECK_AMOUNT");

						JSOC_ELEMENT.VAR_GET('CHECKOUT_CHECK_RECEIVED').classList.remove('d-none');
						JSOC_ELEMENT.VAR_VALUE('PAY_CHECK', JSOC_ELEMENT.VAR_VALUE("CHECK_AMOUNT"));

						HTTP_CALCULATE_CHANGE();

						PAYMENT_OPTIONS.click();

						JSOC_DIALOG.VAR_MODAL("POS_PAYBYCHECK_MODAL", false);
						return;
					}
				};
		}




		// Initialize: Ribbon Buttons [Pay by credit sales]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_BY_CREDIT_BBI"))
		{
    		PAY_BY_CREDIT_BBI = JSOC_ELEMENT.VAR_GET("PAY_BY_CREDIT_BBI"); 

    		// Add OnClick event [Show Modal]
			PAY_BY_CREDIT_BBI.onclick = 
				function()
				{	
					if(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID')) > 1)
					{
						if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PAYBYCREDIT_MODAL") == true)
						{
							// Clear Modal
							if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
							{
								JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

								CREDIT_TERMS.classList.remove('is-invalid');
								CREDIT_DATE.classList.remove('is-invalid');
								CREDIT_AMOUNT.classList.remove('is-invalid');

								JSOC_ELEMENT.VAR_VALUE("CREDIT_DATE", '');
								JSOC_ELEMENT.VAR_VALUE("CREDIT_TERMS", '');
							}

							PROPERTY_REC_CREDIT_TERMS = 1;
							PROPERTY_REC_CREDIT_DATE = '1000-01-01 00:00:00.000000';
							PROPERTY_REC_CREDIT_AMOUNT = -1;

							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;
											
							// Display Modal
							$('#CREDIT_TERMS').val(2).trigger('change');

							JSOC_ELEMENT.VAR_VALUE("CREDIT_DATE", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_ADD('DAY', JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(CACHE_PAYMENT_TERMS_JSON, "CAT_PAYTERM_FIX_DAY_COLLECTION", JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('CREDIT_TERMS')))), JSVC_DATE.VAR_NOW()), "YYYY-MM-DD") + "T00:00");

							JSOC_ELEMENT.VAR_VALUE("CREDIT_NAME", PROPERTY_REC_CUSTOMER_NAME);
							JSOC_ELEMENT.VAR_VALUE("CREDIT_AMOUNT", (Math.round(TOTAL_DUE * 100) / 100).toFixed(2));
							//JSOC_CMB.VAR_SELECTED_INDEX('CREDIT_TERMS', 2);
							
							JSOC_DIALOG.VAR_MODAL("POS_PAYBYCREDIT_MODAL", true);
							JSOC_ELEMENT.VAR_GET("POS_PAYBYCREDIT_MODAL").style.top = '35%';
							return;
						}
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No customer account selected.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBMIT_CREDIT_BBI"))
		{
    		SUBMIT_CREDIT_BBI = JSOC_ELEMENT.VAR_GET("SUBMIT_CREDIT_BBI"); 

    		// Add OnClick event [Show Modal]
			SUBMIT_CREDIT_BBI.onclick = 
				function()
				{	
					var FLAG = [];

					if
					(
						JSVC_VAR.VAR_ISSET(CREDIT_TERMS) &&
						(
							JSOC_CMB.VAR_SELECTED_INDEX(CREDIT_TERMS) < 1 ||
							JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(CREDIT_TERMS)) < 1
						)
					)
					{
						CREDIT_TERMS.classList.add('is-invalid');
						CREDIT_TERMS.innerHTML = 'PAYMENT TERMS IS REQUIRED';

						FLAG.push(false);
					}
					else 
					{
						CREDIT_TERMS.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CREDIT_NAME") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CREDIT_NAME")) == true
					)
					{
						CREDIT_NAME.classList.add('is-invalid');

						CREDIT_NAME_ERROR.innerHTML = 'CREDIT NAME IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						CREDIT_NAME.classList.remove('is-invalid');
						FLAG.push(true);
					}


					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CREDIT_AMOUNT") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("CREDIT_AMOUNT")) == true
					)
					{
						CREDIT_AMOUNT.classList.add('is-invalid');

						CREDIT_AMOUNT_ERROR.innerHTML = 'CREDIT AMOUNT IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if(JSOC_ELEMENT.VAR_VALUE("CREDIT_AMOUNT") <= 0)
						{
							CREDIT_AMOUNT.classList.add('is-invalid');

							CREDIT_AMOUNT_ERROR.innerHTML = 'CREDIT AMOUNT MUST BE GREATER THAN ZERO';

							FLAG.push(false);
						}
						else
						{
							CREDIT_AMOUNT.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}

					if(FLAG.includes(false) !== true)
					{
						PROPERTY_REC_CREDIT_DATE = JSOC_ELEMENT.VAR_VALUE("CREDIT_DATE");
						PROPERTY_REC_CREDIT_TERMS = JSOC_ELEMENT.VAR_VALUE("CREDIT_TERMS");
						PROPERTY_REC_CREDIT_AMOUNT = JSOC_ELEMENT.VAR_VALUE("CREDIT_AMOUNT");

						JSOC_ELEMENT.VAR_GET('CHECKOUT_CREDITS_RECEIVED').classList.remove('d-none');
						JSOC_ELEMENT.VAR_VALUE('PAY_CREDIT', JSOC_ELEMENT.VAR_VALUE("CREDIT_AMOUNT"));

						HTTP_CALCULATE_CHANGE();

						PAYMENT_OPTIONS.click();

						JSOC_DIALOG.VAR_MODAL("POS_PAYBYCREDIT_MODAL", false);
						return;
					}
				};
		}



		// Initialize: Ribbon Buttons [Pay by loyalty points]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_BY_LOYALTY_BBI"))
		{
    		PAY_BY_LOYALTY_BBI = JSOC_ELEMENT.VAR_GET("PAY_BY_LOYALTY_BBI"); 

    		// Add OnClick event [Show Modal]
			PAY_BY_LOYALTY_BBI.onclick = 
				function()
				{	
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PAYBYLOYALTY_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

							LOYALTY_NUMBER.classList.remove('is-invalid');
							LOYALTY_AMOUNT.classList.remove('is-invalid');

							JSOC_ELEMENT.VAR_VALUE("LOYALTY_NUMBER", '');
						}

						PROPERTY_REC_LOYALTY_NUMBER = '';
						PROPERTY_REC_LOYALTY_AMOUNT = -1;

						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;
											
						// Display Modal
						JSOC_ELEMENT.VAR_VALUE("LOYALTY_AMOUNT", (Math.round(TOTAL_DUE * 100) / 100).toFixed(2));
						JSOC_DIALOG.VAR_MODAL("POS_PAYBYLOYALTY_MODAL", true);
						JSOC_ELEMENT.VAR_GET("POS_PAYBYLOYALTY_MODAL").style.top = '25%';
						return;
					}
				};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBMIT_LOYALTY_BBI"))
		{
    		SUBMIT_LOYALTY_BBI = JSOC_ELEMENT.VAR_GET("SUBMIT_LOYALTY_BBI"); 

    		// Add OnClick event [Show Modal]
			SUBMIT_LOYALTY_BBI.onclick = 
				function()
				{	
					var FLAG = [];

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOYALTY_NUMBER") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("LOYALTY_NUMBER")) == true
					)
					{
						LOYALTY_NUMBER.classList.add('is-invalid');

						LOYALTY_NUMBER_ERROR.innerHTML = 'LOYALTY CARD NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						LOYALTY_NUMBER.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOYALTY_AMOUNT") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("LOYALTY_AMOUNT")) == true
					)
					{
						LOYALTY_AMOUNT.classList.add('is-invalid');

						LOYALTY_AMOUNT_ERROR.innerHTML = 'REDEEM POINTS IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						if(JSOC_ELEMENT.VAR_VALUE("LOYALTY_AMOUNT") < JSOC_ELEMENT.VAR_VALUE("LOYALTY_POINTS"))
						{
							LOYALTY_AMOUNT.classList.add('is-invalid');

							LOYALTY_AMOUNT_ERROR.innerHTML = 'INSUFFICIENT POINTS';

							FLAG.push(false);
						}
						else
						{
							LOYALTY_AMOUNT.classList.remove('is-invalid');
							FLAG.push(true);
						}
					}

					if(FLAG.includes(false) !== true)
					{
						PROPERTY_REC_LOYALTY_NUMBER = JSOC_ELEMENT.VAR_VALUE("LOYALTY_NUMBER");
						PROPERTY_REC_LOYALTY_AMOUNT = JSOC_ELEMENT.VAR_VALUE("LOYALTY_AMOUNT");

						JSOC_ELEMENT.VAR_GET('CHECKOUT_LOYALTY_RECEIVED').classList.remove('d-none');
						JSOC_ELEMENT.VAR_VALUE('PAY_LOYALTY', JSOC_ELEMENT.VAR_VALUE("LOYALTY_AMOUNT"));

						HTTP_CALCULATE_CHANGE();

						PAYMENT_OPTIONS.click();

						JSOC_DIALOG.VAR_MODAL("POS_PAYBYLOYALTY_MODAL", false);
						return;
					}
				};
		}



		// Initialize: Ribbon Buttons [Pay by voucher]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_BY_VOUCHER_BBI"))
		{
    		PAY_BY_VOUCHER_BBI = JSOC_ELEMENT.VAR_GET("PAY_BY_VOUCHER_BBI"); 

    		// Add OnClick event [Show Modal]
			PAY_BY_VOUCHER_BBI.onclick = 
				function()
				{	
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_PAYBYVOUCHER_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);

							VOUCHER_NUMBER.classList.remove('is-invalid');
							VOUCHER_AMOUNT.classList.remove('is-invalid');

							JSOC_ELEMENT.VAR_VALUE("VOUCHER_NUMBER", '');
						}

						PROPERTY_REC_VOUCHER_NUMBER = '';
						PROPERTY_REC_VOUCHER_AMOUNT = -1;

						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;
											
						// Display Modal
						JSOC_ELEMENT.VAR_VALUE("VOUCHER_AMOUNT", (Math.round(TOTAL_DUE * 100) / 100).toFixed(2));
						JSOC_DIALOG.VAR_MODAL("POS_PAYBYVOUCHER_MODAL", true);
						JSOC_ELEMENT.VAR_GET("POS_PAYBYVOUCHER_MODAL").style.top = '30%';
						return;
					}
				};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBMIT_VOUCHER_BBI"))
		{
    		SUBMIT_VOUCHER_BBI = JSOC_ELEMENT.VAR_GET("SUBMIT_VOUCHER_BBI"); 

    		// Add OnClick event [Show Modal]
			SUBMIT_VOUCHER_BBI.onclick = 
				function()
				{	
					var FLAG = [];

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("VOUCHER_NUMBER") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("VOUCHER_NUMBER")) == true
					)
					{
						VOUCHER_NUMBER.classList.add('is-invalid');

						VOUCHER_NUMBER_ERROR.innerHTML = 'VOUCHER NUMBER IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						VOUCHER_NUMBER.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if
					(
						JSOC_ELEMENT.VAR_ELEMENT_EXISTS("VOUCHER_AMOUNT") == true &&
						JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("VOUCHER_AMOUNT")) == true
					)
					{
						VOUCHER_AMOUNT.classList.add('is-invalid');

						VOUCHER_AMOUNT_ERROR.innerHTML = 'VOUCHER AMOUNT IS REQUIRED';

						FLAG.push(false);
					}
					else
					{
						VOUCHER_AMOUNT.classList.remove('is-invalid');
						FLAG.push(true);
					}

					if(FLAG.includes(false) !== true)
					{
						PROPERTY_REC_VOUCHER_NUMBER = JSOC_ELEMENT.VAR_VALUE("VOUCHER_NUMBER");
						PROPERTY_REC_VOUCHER_AMOUNT = JSOC_ELEMENT.VAR_VALUE("VOUCHER_AMOUNT");

						JSOC_ELEMENT.VAR_GET('CHECKOUT_VOUCHER_RECEIVED').classList.remove('d-none');
						JSOC_ELEMENT.VAR_VALUE('PAY_VOUCHER', JSOC_ELEMENT.VAR_VALUE("VOUCHER_AMOUNT"));

						HTTP_CALCULATE_CHANGE();

						PAYMENT_OPTIONS.click();

						JSOC_DIALOG.VAR_MODAL("POS_PAYBYVOUCHER_MODAL", false);
						return;
					}
				};
		}


		// Prepare onChange event
		// ...........................................
		var ON_CHANGE_EVENT = '';


		// Initialize: Input Controls
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_START_AMOUNT"))
		{
			SHIFT_START_AMOUNT = JSOC_ELEMENT.VAR_GET("SHIFT_START_AMOUNT");
			SHIFT_START_AMOUNT.onkeydown =
				function(event) {
					if(event.which == 13 || event.keyCode == 13 || event.key === 'Enter') {
						HTTP_START_SHIFT
	    				(
	    					function(IS_SUCCESS) 
	    					{
	    						if(IS_SUCCESS == false)
	    						{	
	    							return;
	    						}

	    						alertify.success('Shift started.');
	    					}
	    				);
					}
				}
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CATEGORY_CMB"))
		{
			CATEGORY_CMB = JSOC_ELEMENT.VAR_GET("CATEGORY_CMB");      
			CATEGORY_CMB.onchange = 
				function()
				{
					//hide all
					$('div[id^="PRODUCT_BRANCH_LV_ROW_CAT_PRODUCT_ID_"]').parent().parent().each(function() {
						$(this).addClass('d-none');
					});

					//filter
					if(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("CATEGORY_CMB")) === 0) {
						//show all
						$('div[id^="PRODUCT_BRANCH_LV_ROW_CAT_PRODUCT_ID_"]').parent().parent().each(function() {
							$(this).removeClass('d-none');
						});
					}
					else {
						$('div[id^="PRODUCT_BRANCH_LV_ROW_CAT_PRODUCT_CAT_PRODTYPE_ID_LV1_"]').each(function() {
							if(JSVC_NUM.VAR_NVALL($(this).html()) == JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("CATEGORY_CMB"))) {
								$(this).parent().parent().removeClass('d-none');
							}
						});
					}
				};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAY_CASH"))
		{
			PAY_CASH = JSOC_ELEMENT.VAR_GET("PAY_CASH");      
			PAY_CASH.onchange = 
				function()
				{
					PROPERTY_REC_CASH_AMOUNT = JSVC_NUM.VAR_NVAL(JSOC_ELEMENT.VAR_VALUE("PAY_CASH"));
					HTTP_CALCULATE_CHANGE();
				};
			PAY_CASH.onkeypress = function(){PAY_CASH.onchange();};
			PAY_CASH.onpaste = function(){PAY_CASH.onchange();};
			PAY_CASH.oninput = function(){PAY_CASH.onchange();};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CREDIT_TERMS"))
		{
			CREDIT_TERMS = JSOC_ELEMENT.VAR_GET("CREDIT_TERMS");      
			CREDIT_TERMS.onchange = 
				function()
				{
					if(JSOC_ELEMENT.VAR_VALUE('CREDIT_TERMS') > 1)
					{
						//JSOC_ELEMENT.VAR_VALUE("CREDIT_DATE", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_ADD('DAY', JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('CREDIT_TERMS')), JSVC_DATE.VAR_NOW()), "YYYY-MM-DD") + "T00:00");
						JSOC_ELEMENT.VAR_VALUE("CREDIT_DATE", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_ADD('DAY', JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(CACHE_PAYMENT_TERMS_JSON, "CAT_PAYTERM_FIX_DAY_COLLECTION", JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE('CREDIT_TERMS')))), JSVC_DATE.VAR_NOW()), "YYYY-MM-DD") + "T00:00");

					}
					else
					{
						JSOC_ELEMENT.VAR_VALUE("CREDIT_DATE", JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD") + "T00:00");
					}
				};
			CREDIT_TERMS.onkeypress = function(){CREDIT_TERMS.onchange();};
			CREDIT_TERMS.onpaste = function(){CREDIT_TERMS.onchange();};
			CREDIT_TERMS.oninput = function(){CREDIT_TERMS.onchange();};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_PAY_CASH"))
		{
			ACCTS_PAY_CASH = JSOC_ELEMENT.VAR_GET("ACCTS_PAY_CASH");      
			ACCTS_PAY_CASH.onchange = 
				function()
				{
					HTTP_ACCTS_CALCULATE_CHANGE();
				};
			ACCTS_PAY_CASH.onkeypress = function(){ACCTS_PAY_CASH.onchange();};
			ACCTS_PAY_CASH.onpaste = function(){ACCTS_PAY_CASH.onchange();};
			ACCTS_PAY_CASH.oninput = function(){ACCTS_PAY_CASH.onchange();};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACCTS_CHECK_AMOUNT"))
		{
			ACCTS_CHECK_AMOUNT = JSOC_ELEMENT.VAR_GET("ACCTS_CHECK_AMOUNT");      
			ACCTS_CHECK_AMOUNT.onchange = 
				function()
				{
					HTTP_ACCTS_CALCULATE_CHANGE(false);
				};
			ACCTS_CHECK_AMOUNT.onkeypress = function(){ACCTS_CHECK_AMOUNT.onchange();};
			ACCTS_CHECK_AMOUNT.onpaste = function(){ACCTS_CHECK_AMOUNT.onchange();};
			ACCTS_CHECK_AMOUNT.oninput = function(){ACCTS_CHECK_AMOUNT.onchange();};
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SHIFT_END_MODAL"))
		{
			$('input[id^="CASHBREAKDOWN_"]').on('keyup', function (e) {
				HTTP_CALCULATE_CASH($(this).attr('id'));
			});
		}
	}