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


	// ===============================================================
	// Initialize Form
	// ===============================================================
	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________	
		var DGV_ELEMENT_CHILD = null;
		var DGV_ELEMENT_CHILD_INDEX = 0;
		
		
		// Load DataGridVuew
		// _______________________________________________________________________	
		JSTOOL_CUSTOMIZE.DGVREORDER.APPLY("INVOICE_DGV");
		INVOICE_DGV = DataGridView("INVOICE_DGV");
		//INVOICE_DGV.SETTING_ALLOW_USER_TO_ADD_ROWS = true;
		//INVOICE_DGV.SETTING_EDITABLE = true;
	

		// Auto Compute
		// _______________________________________________________________________	
		var AUTO_CALC = JSTOOL_CUSTOMIZE.DGVCALC.APPLY(INVOICE_DGV);
		var AUTO_COMPUTE_BLOCKS = AUTO_CALC[0];
			
		/*
			// Sample Code
			AUTO_COMPUTE_BLOCKS.push
			(
				[
					'COLUMN_A', 					// Target Column
					'`COLUMN_1` + `COLUMN_2`',		// Math
					true							// Apply CFormat
				]
			);
		*/
		// INVOICE_DGV.COLUMN.AUTO_COMPUTE_CREATE(AUTO_COMPUTE_BLOCKS);
		
		
		// Auto Total
		// _______________________________________________________________________	
		var AUTO_TOTAL_COLUMNS = AUTO_CALC[1];
		var AUTO_TOTAL_COPY_TO_ELEMENT = AUTO_CALC[2];
		
		/*
			AUTO_TOTAL_COLUMNS.push('COLUMN_A');					// Column to Auto Total
			AUTO_TOTAL_COPY_TO_ELEMENT.push(["COL_ID", "ELEM_ID"]);	// Source Column, Element ID where total is copied to
		*/
		AUTO_TOTAL_COLUMNS.push('REC_INVOICELIST_QUANTITY');
		AUTO_TOTAL_COLUMNS.push('REC_INVOICELIST_SALES');
		AUTO_TOTAL_COLUMNS.push('REC_INVOICELIST_DISCOUNT');	
		AUTO_TOTAL_COLUMNS.push('REC_INVOICERTN_QUANTITY');
		AUTO_TOTAL_COLUMNS.push('REC_INVOICERTN_SALES');
				
		INVOICE_DGV.COLUMN.TOTAL_CREATE
		(
			AUTO_TOTAL_COLUMNS,
			'CAT_PRODUCT_DESCRIPTION',									// Column, where you want to display the caption `Total:`.
			AUTO_TOTAL_COPY_TO_ELEMENT
		);		

		
		
		// DGV OnClick Event
		// _______________________________________________________________________		
		INVOICE_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				GROUP_SHOW_HIDE(ROW_INDEX);
			}
		);   


		// DGV OnChange Event
		// _______________________________________________________________________	
		INVOICE_DGV.ON_CHANGE
		(			
			function(COL_INDEX, ROW_INDEX)
			{

			}
		);

		
		// Show Progress
		// _______________________________________________________________________	
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		
		// Requires Authentication
		// _______________________________________________________________________	
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);			


		
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_ACC_GROUP_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_INVOICE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(), "-");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_INVOICE_ACC_GROUP_ID_CMB", 0);
					
					// Clone to DGV Cell if ComboBox Exists
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_DGV_ROW_REC_INVOICE_ACC_GROUP_ID") == true)
					{
						DGV_ELEMENT_CHILD = JSOC_ELEMENT.VAR_SUB_ELEMENTS("INVOICE_DGV_ROW_REC_INVOICE_ACC_GROUP_ID");
						DGV_ELEMENT_CHILD_INDEX = 0;
						while(DGV_ELEMENT_CHILD.length > DGV_ELEMENT_CHILD_INDEX)
						{
							if
							(
								DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].tagName == "SELECT" &&
								JSVC_STR.VAR_IS_BLANK(DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].id.toString())
							)
							{
								JSOC_ELEMENT.VAR_INNER_HTML
								(
									DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX], 
									JSOC_ELEMENT.VAR_INNER_HTML("REC_INVOICE_ACC_GROUP_ID_CMB")
								);
							}	
							DGV_ELEMENT_CHILD_INDEX ++;
						}
					}
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Group");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("REC_INVOICE_ACC_GROUP_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB", 0);
						$('.BSSP_SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB').selectpicker('refresh');
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("INVOICE_MODAL");
					}
					
					// Forward populate complete event.
					$('.BSSP_REC_INVOICE_ACC_GROUP_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();		
				},
				"REC_INVOICE_ACC_GROUP_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB") == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_ACC_GROUP_ID_CMB") == false
		)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Group");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB", 0);
					
					// Forward populate complete event.		
					$('.BSSP_SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();
				},		
				"SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_REC_EMPLOYEE_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_INVOICE_REC_EMPLOYEE_ID_CMB", FLAG_BIGINT_NULL.toString(), "-");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._RECORD._EMPLOYEE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._RECORD._EMPLOYEE.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_INVOICE_REC_EMPLOYEE_ID_CMB", 0);
					
					// Clone to DGV Cell if ComboBox Exists
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_DGV_ROW_REC_INVOICE_REC_EMPLOYEE_ID") == true)
					{
						DGV_ELEMENT_CHILD = JSOC_ELEMENT.VAR_SUB_ELEMENTS("INVOICE_DGV_ROW_REC_INVOICE_REC_EMPLOYEE_ID");
						DGV_ELEMENT_CHILD_INDEX = 0;
						while(DGV_ELEMENT_CHILD.length > DGV_ELEMENT_CHILD_INDEX)
						{
							if
							(
								DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].tagName == "SELECT" &&
								JSVC_STR.VAR_IS_BLANK(DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].id.toString())
							)
							{
								JSOC_ELEMENT.VAR_INNER_HTML
								(
									DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX], 
									JSOC_ELEMENT.VAR_INNER_HTML("REC_INVOICE_REC_EMPLOYEE_ID_CMB")
								);
							}	
							DGV_ELEMENT_CHILD_INDEX ++;
						}
					}
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Employee");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("REC_INVOICE_REC_EMPLOYEE_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB", 0);
						$('.BSSP_SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB').selectpicker('refresh');
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("INVOICE_MODAL");
					}
					
					// Forward populate complete event.
					$('.BSSP_REC_INVOICE_REC_EMPLOYEE_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();		
				},
				"REC_INVOICE_REC_EMPLOYEE_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB") == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_REC_EMPLOYEE_ID_CMB") == false
		)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Employee");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._RECORD._EMPLOYEE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._RECORD._EMPLOYEE.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB", 0);
					
					// Forward populate complete event.		
					$('.BSSP_SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();
				},		
				"SEARCH_REC_INVOICE_REC_EMPLOYEE_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_ACC_ACCOUNT_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_INVOICE_ACC_ACCOUNT_ID_CMB", FLAG_BIGINT_NULL.toString(), "-");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._MEMBER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._ACCOUNT._MEMBER.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_INVOICE_ACC_ACCOUNT_ID_CMB", 0);
					
					// Clone to DGV Cell if ComboBox Exists
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_DGV_ROW_REC_INVOICE_ACC_ACCOUNT_ID") == true)
					{
						DGV_ELEMENT_CHILD = JSOC_ELEMENT.VAR_SUB_ELEMENTS("INVOICE_DGV_ROW_REC_INVOICE_ACC_ACCOUNT_ID");
						DGV_ELEMENT_CHILD_INDEX = 0;
						while(DGV_ELEMENT_CHILD.length > DGV_ELEMENT_CHILD_INDEX)
						{
							if
							(
								DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].tagName == "SELECT" &&
								JSVC_STR.VAR_IS_BLANK(DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].id.toString())
							)
							{
								JSOC_ELEMENT.VAR_INNER_HTML
								(
									DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX], 
									JSOC_ELEMENT.VAR_INNER_HTML("REC_INVOICE_ACC_ACCOUNT_ID_CMB")
								);
							}	
							DGV_ELEMENT_CHILD_INDEX ++;
						}
					}
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Member");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("REC_INVOICE_ACC_ACCOUNT_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB", 0);
						$('.BSSP_SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB').selectpicker('refresh');
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("INVOICE_MODAL");
					}
					
					// Forward populate complete event.
					$('.BSSP_REC_INVOICE_ACC_ACCOUNT_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();		
				},
				"REC_INVOICE_ACC_ACCOUNT_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB") == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_ACC_ACCOUNT_ID_CMB") == false
		)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Member");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._MEMBER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._ACCOUNT._MEMBER.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB", 0);
					
					// Forward populate complete event.		
					$('.BSSP_SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB').selectpicker('refresh');
					HTTP_POPULATE_RESULT();
				},		
				"SEARCH_REC_INVOICE_ACC_ACCOUNT_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		
		// Status		
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_STATUS_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_INVOICE_STATUS_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_STATUS_CMB", "0","Any Status");
			JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_STATUS_CMB", "1","Inactive");
			JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_STATUS_CMB", "2","Active");
			// JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_STATUS_CMB", "3","Closed");
			// JSOC_CMB.VAR_ADD("SEARCH_REC_INVOICE_STATUS_CMB", "4","Completed");
			JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_REC_INVOICE_STATUS_CMB", "2");
		}			
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVOICE_STATUS_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("REC_INVOICE_STATUS_CMB");
			JSOC_CMB.VAR_ADD("REC_INVOICE_STATUS_CMB", "1","Inactive");
			JSOC_CMB.VAR_ADD("REC_INVOICE_STATUS_CMB", "2","Active");
			// JSOC_CMB.VAR_ADD("REC_INVOICE_STATUS_CMB", "3","Closed");
			// JSOC_CMB.VAR_ADD("REC_INVOICE_STATUS_CMB", "4","Completed");
			JSOC_CMB.VAR_SELECTED_VALUE("REC_INVOICE_STATUS_CMB", "2");
		}
		
		
		
		// Get Modal Instance (Add Modal Adjustment before this line)
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVOICE_MODAL") == true)
		{
			INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("INVOICE_MODAL");
		}
		
		// Add Search Events for the SEARCH_DESCRIPTION_TXT - TextInput
		// _______________________________________________________________________		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_INVOICE_CODE_TXT"))
		{
			var SEARCH_REC_INVOICE_CODE_TXT = JSOC_ELEMENT.VAR_GET("SEARCH_REC_INVOICE_CODE_TXT");
			SEARCH_REC_INVOICE_CODE_TXT.onkeydown = 
				function() 
				{ 
					return function(e) 
					{
						if
						(
							(
								e.which == 13 || 
								e.keyCode == 13 || 
								e.key === "Enter"
							) &&
							JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD")
						)
						{
							HTTP_SEARCH();
						}
					};
				}();
		}
		
		
		// Load Parent Data (if Exists)
		// _______________________________________________________________________	
		
		
		// Pre-Load Items (uncomment if no foreign key pre-fetch)
		// _______________________________________________________________________	
		if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
		{
			HTTP_SEARCH();
		}
		
		
		// Disable Dialogs
		// _______________________________________________________________________	
		CUS_SEND_DIALOG_TRY_DISMISS();
	};
	
	
	// ===============================================================
	// Populate Foreign Keys
	// ===============================================================
	function HTTP_POPULATE_RESULT(IS_SUCCESS, HTTP_RESPONSE)
	{
		// Disable Dialogs
		CUS_SEND_DIALOG_TRY_DISMISS();
			
		// Handle Error
		if(IS_SUCCESS === false)
		{
			alert("Unable to populate lists.");
		}
		else
		{
			// Disable Dialogs
			if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
			{
				HTTP_SEARCH();
			}
		}
	};

	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_SEARCH()
	{
		// Actual Function
		// _______________________________________________________________________
		GET_MAP_ARRAY = JSCUS_SQL._RECORD._INVOICE.CUS_PREPARE_MAPPED_ARRAY_FOR_SALES_REPORT();	
		// if(JSVC_VAR.VAR_ISSET("PROPERTY_PARENT_ID"))
		// {
		//	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_PARENT_ID', PROPERTY_PARENT_ID);
		// }  // Parent ID Sample
		
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_INVOICE_ACC_GROUP_ID_CMB', 'PARAM_REC_INVOICE_ACC_GROUP_ID'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_INVOICE_DATE_DELIVERY_FROM_DTP', 'PARAM_REC_INVOICE_DATE_DELIVERY_FROM'
		);
		JSCUS_SQL._ADD_FROM
		(
			GET_MAP_ARRAY, 'SEARCH_REC_INVOICE_DATE_DELIVERY_TO_DTP', 'PARAM_REC_INVOICE_DATE_DELIVERY_TO'
		);			
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'ACC_GROUP_DESCRIPTION');	
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		

		// REGULAR Search Mode
		// _______________________________________________________________________	
		JSCUS_SQL._RECORD._INVOICE.CUS_SALES_REPORT
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		); 						
	};
	
	
	// ===============================================================
	// Request Search - PART.B
	// ===============================================================
	function HTTP_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING, KEEP_DGV_ITEMS = false)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Back to DGV Top
		// _______________________________________________________________________	
		if(LOAD_PAGING_IGNORE_NEXT_REQUEST == true)
		{
			JSOC_ELEMENT.VAR_GET("INVOICE_DGV").scrollIntoView
			(
				{
			  		behavior: 'auto', 
			  		block: 'start'
				}
			);		
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			INVOICE_DGV.ROW.CLEAR();
			if(INVOICE_DGV.COLUMN.TOTAL_IS_READY())
			{
				INVOICE_DGV.COLUMN.TOTAL_REFRESH();
			}
			return;
		}
		
		// Populate DGV
		// _______________________________________________________________________
		INVOICE_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				KEEP_DGV_ITEMS,
				false,
				1,
				[2, 1]
		);
		
		
		// For Applying CFormat
		// _______________________________________________________________________	
		// INVOICE_DGV.COLUMN.CFORMAT("REC_INVOICE_LINE_TOTAL");
		
		
		// Initialize
		// _______________________________________________________________________	
		var WEBTABLE_DATE = null;
		var CURRENT_CELL_VALUE = null;
		var ROW_INDEX = 0;

		
		// Color Coding (Uncomment to use)
		// _______________________________________________________________________	
		//INVOICE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#1cc88a"; // Safe
		//INVOICE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#5a5c69"; // Neutral
		//INVOICE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#f6c23e"; // Caution
		//INVOICE_DGV.CELL.ELEMENT("COLUMN_NAME", ROW_INDEX).style.color = "#e74a3b"; // Warning


		// Auto-total tool
		// _______________________________________________________________________	
		if(INVOICE_DGV.COLUMN.TOTAL_IS_READY())
		{
			INVOICE_DGV.COLUMN.TOTAL_REFRESH();
		}
		
		JSRC_THREAD.REF_POST_DELAYED
		(
			function()
			{
				GROUP_SALES();
			},
			500
		);
	};
	
				
	// ===============================================================
	// Begin Processing the Page
	// ===============================================================
	FORM_INITIALIZE();
	FORM_LOAD();