

	function FORM_LOAD()
	{
		POS_SALE_LIST_DGV = DataGridView("POS_SALE_LIST_DGV");

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Branch");
			
			var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_GROUP_STATUS', 2);

			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					$('#SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB').select2();
				},
				"SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB",
				true,
				2,
				GET_MAP_ARRAY 
			);
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Product");

			var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODUCT_STATUS', 2);

			JSCUS_SQL._CATEGORY._PRODUCT.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					$('#SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB').select2();
				},
				"SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB",
				true,
				2,
				GET_MAP_ARRAY 
			);
		}
	}

	function HTTP_SEARCH()
	{
		if
		(
			JSVC_VAR.VAR_ISSET(SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB) &&
			JSOC_CMB.VAR_SELECTED_INDEX(SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB) < 0 ||
			JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB)) < 0
		)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'You must select branch.', 
				'Information',
				'OK', 'WARNING',
				function(MESSAGE_RESPONSE)
				{
					SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
					SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB.focus();
				}
			);	
			return;
		}

		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_SALE_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_DATE_FROM_SALES_BY_PROD_DTP") == true &&
			JSOC_STYLE.VAR_IS_VISIBLE('SEARCH_DATE_FROM_SALES_BY_PROD_DTP') == true &&
			JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_FROM_SALES_BY_PROD_DTP")) == false
		)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_DATE_TRANSACT_FROM', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_FROM_SALES_BY_PROD_DTP"), "YYYY-MM-DD") + " 00:00:00.000000");
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_DATE_TO_SALES_BY_PROD_DTP") == true &&
			JSOC_STYLE.VAR_IS_VISIBLE('SEARCH_DATE_TO_SALES_BY_PROD_DTP') == true &&
			JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_TO_SALES_BY_PROD_DTP")) == false
		)
		{
		 	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_DATE_TRANSACT_TO', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_TO_SALES_BY_PROD_DTP"), "YYYY-MM-DD") + " 23:59:59.000000");
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_ACC_GROUP_ID', JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB")));
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_LIST_CAT_PRODUCT_ID', JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB")));
		}

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_SALE_LIST.CUS_GET_ALL
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		);
	}

	function HTTP_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// 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;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			POS_SALE_LIST_DGV.ROW.CLEAR();
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_TOTAL_SALES", "0.00");
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		// POS_SALE_LIST_DGV.POPULATE_FROM_QUERY
		// (
		// 		JSON_OBJECT, 
		// 		'',
		// 		false,
		// 		false,
		// 		1,
		// 		[2, 1]
		// );

		POS_SALE_LIST_DGV.ROW.CLEAR();
		var JSON_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");
		var CTR = 0;
		var COUNTER = 1;
		var TOTAL_SALES = 0;
		var ROW_INDEX = 1;
		var IS_INSERTED = false;
		var SUM_HOLDER = 0;
		while(CTR < JSON_COUNT)
		{
			while(POS_SALE_LIST_DGV.ROW.COUNT() >= ROW_INDEX)
			{
				if(JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_CAT_PRODUCT_ID", COUNTER)) == JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE('REC_POSSALE_LIST_CAT_PRODUCT_ID', ROW_INDEX - 1)))
				{
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_QUANTITY", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_QUANTITY", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_QUANTITY", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_AMOUNT_PRICE", ROW_INDEX - 1, JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_AMOUNT_PRICE", COUNTER)));
					SUM_HOLDER = 
					JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATABLE", ROW_INDEX - 1)) + 
					JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATEXEMPT", ROW_INDEX - 1)) + 
					JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_NONVAT", ROW_INDEX - 1)) + 
					JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_ZERORATED", ROW_INDEX - 1)) + 
					JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATOTHER", ROW_INDEX - 1)) + 
					JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT", ROW_INDEX - 1));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_SUBTOTAL", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_SUBTOTAL", COUNTER)) + JSVC_NUM.VAR_NVAL(SUM_HOLDER)));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_DISCOUNT", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_DISCOUNT", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_DISCOUNT", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATABLE", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATABLE", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATABLE", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATEXEMPT", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATEXEMPT", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATEXEMPT", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_NONVAT", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_NONVAT", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_NONVAT", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_ZERORATED", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_ZERORATED", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_ZERORATED", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATOTHER", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATOTHER", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATOTHER", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VAT", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT", ROW_INDEX - 1))));
					POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT_LESS", ROW_INDEX - 1, (JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VAT_LESS", COUNTER)) + JSVC_NUM.VAR_NVAL(POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT_LESS", ROW_INDEX - 1))));

					IS_INSERTED = true;
					break;
				}
				ROW_INDEX++;
			}

			if(IS_INSERTED === false)
			{
				var RINDEX = POS_SALE_LIST_DGV.ROW.COUNT();
				POS_SALE_LIST_DGV.ROW.INSERT_AT(RINDEX);
				POS_SALE_LIST_DGV.CELL.VALUE("ROW_COUNT", RINDEX, RINDEX + 1);
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_CAT_PRODUCT_ID", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_CAT_PRODUCT_ID", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_CAT_PRODUCT_ID_DESCRIPTION", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_CAT_PRODUCT_ID_DESCRIPTION", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_QUANTITY", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_QUANTITY", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_AMOUNT_PRICE", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_AMOUNT_PRICE", COUNTER));
				SUM_HOLDER = JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATABLE", COUNTER)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATEXEMPT", COUNTER)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_NONVAT", COUNTER)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_ZERORATED", COUNTER)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATOTHER", COUNTER)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VAT", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_SUBTOTAL", RINDEX, SUM_HOLDER);
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_DISCOUNT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_DISCOUNT", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATABLE", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATABLE", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATEXEMPT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATEXEMPT", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_NONVAT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_NONVAT", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_ZERORATED", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_ZERORATED", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VATOTHER", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VATOTHER", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VAT", COUNTER));
				POS_SALE_LIST_DGV.CELL.VALUE("REC_POSSALE_LIST_TOPAY_VAT_LESS", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSSALE_LIST_TOPAY_VAT_LESS", COUNTER));
			}
			
			IS_INSERTED = false; ROW_INDEX = 1; SUM_HOLDER = 0;
			CTR++;
			COUNTER++;
		}
		
		// For Applying CFormat
		// _______________________________________________________________________	
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_AMOUNT_PRICE");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_AMOUNT_VAT");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_QUANTITY");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_QUANTITY_PCS");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_SUBTOTAL");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_DISCOUNT");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_VATABLE");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_VATEXEMPT");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_NONVAT");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_ZERORATED");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_VATOTHER");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_VAT");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_TOPAY_VAT_LESS");
		POS_SALE_LIST_DGV.COLUMN.CFORMAT("REC_POSSALE_LIST_POINTS");
		
		JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_TOTAL_SALES", JSVC_NUM.VAR_CFORMAT(POS_SALE_LIST_DGV.COLUMN.SUM("REC_POSSALE_LIST_TOPAY_SUBTOTAL")));
		
		// Initialize
		// _______________________________________________________________________	
		var WEBTABLE_DATE = null;
		var ROW_INDEX = 0;
	
	
		// DateTime Format
		// _______________________________________________________________________	

	}

	FORM_INITIALIZE();
	FORM_LOAD();