

	function FORM_LOAD()
	{
		TRANSFLOW_SMRY_DGV = DataGridView("TRANSFLOW_SMRY_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();
					HTTP_LOAD_BRANCH_PRODUCTS(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("SEARCH_SALES_BY_PROD_ACC_GROUP_ID_CMB")));
				},
				"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();

			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._EOD_PRODUCT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		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_EODPROD_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_EODPROD_CAT_PRODUCT_ID', JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB")));
		}
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_EODPROD_DATE_REPORT_FROM', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_FROM_SALES_BY_PROD_DTP"), "YYYY-MM-DD") + " 00:00:00.000000");
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_EODPROD_DATE_REPORT_TO', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("SEARCH_DATE_TO_SALES_BY_PROD_DTP"), "YYYY-MM-DD") + " 23:59:59.999999");

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_SKIP', SKIP);

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._EOD_PRODUCT.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_LOAD_EOD_CALLBACK,
			true
		);
	}

	function HTTP_LOAD_EOD_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();

		//RESET DGV
		// _______________________________________________________________________
		if (SKIP == 0)
			TRANSFLOW_SMRY_DGV.ROW.CLEAR();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			alert("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)
		{
			alert("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			if (SKIP == 0)
				TRANSFLOW_SMRY_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		var JSON_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");
		var COUNTER = 1;
		while(COUNTER <= JSON_COUNT)
		{
			var R_INDEX = 1; var IS_INSERTED = 0;
			while(TRANSFLOW_SMRY_DGV.ROW.COUNT() >= R_INDEX)
			{
				if
				(
					JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_CAT_PRODUCT_ID", R_INDEX-1)) ==
					JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_CAT_PRODUCT_ID", COUNTER))
				)
				{
					IS_INSERTED = 1;
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_SF_SOLD_ITEM", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_SF_SOLD_ITEM", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_SF_SOLD_ITEM", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_SENIOR_20P", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_SENIOR_20P", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_SENIOR_20P", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_SENIOR_5P", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_SENIOR_5P", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_SENIOR_5P", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_PWD_20P", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_PWD_20P", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_PWD_20P", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_PWD_5P", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_PWD_5P", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_PWD_5P", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_GOV_5P", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_GOV_5P", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_GOV_5P", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSA_AMOUNT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSA_AMOUNT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSA_AMOUNT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSB_AMOUNT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSB_AMOUNT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSB_AMOUNT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSC_AMOUNT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSC_AMOUNT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSC_AMOUNT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSD_AMOUNT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSD_AMOUNT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSD_AMOUNT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSE_AMOUNT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSE_AMOUNT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSE_AMOUNT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_OTHER", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_OTHER", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_OTHER", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATABLE", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATABLE", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VATABLE", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATEXEMPT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATEXEMPT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VATEXEMPT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_NONVAT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_NONVAT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_NONVAT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_ZERORATED", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_ZERORATED", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_ZERORATED", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATOTHER", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATOTHER", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VATOTHER", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VAT", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VAT", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VAT", COUNTER)));
					TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VAT_LESS", R_INDEX-1, JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VAT_LESS", R_INDEX-1)) + JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VAT_LESS", COUNTER)));
					break;
				}
				R_INDEX++;
			}

			if(IS_INSERTED == 0)
			{
				var RINDEX = TRANSFLOW_SMRY_DGV.ROW.COUNT();
				TRANSFLOW_SMRY_DGV.ROW.INSERT_AT(RINDEX);
				TRANSFLOW_SMRY_DGV.CELL.VALUE("ROW_COUNT", RINDEX, RINDEX + 1);
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_CAT_PRODUCT_ID", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_CAT_PRODUCT_ID", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_CAT_PRODUCT_DESCRIPTION", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_CAT_PRODUCT_DESCRIPTION", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_UOM", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_UOM", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_AMOUNT_PRICE", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_AMOUNT_PRICE", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_SF_SOLD_ITEM", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_SF_SOLD_ITEM", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_SENIOR_20P", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_SENIOR_20P", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_SENIOR_5P", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_SENIOR_5P", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_PWD_20P", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_PWD_20P", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_PWD_5P", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_PWD_5P", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_GOV_5P", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_GOV_5P", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSA_AMOUNT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSA_AMOUNT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSB_AMOUNT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSB_AMOUNT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSC_AMOUNT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSC_AMOUNT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSD_AMOUNT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSD_AMOUNT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_CUSE_AMOUNT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_CUSE_AMOUNT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_DC_OTHER", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_DC_OTHER", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATABLE", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VATABLE", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATEXEMPT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VATEXEMPT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_NONVAT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_NONVAT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_ZERORATED", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_ZERORATED", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VATOTHER", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VATOTHER", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VAT", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VAT", COUNTER));
				TRANSFLOW_SMRY_DGV.CELL.VALUE("REC_EODPROD_TOTAL_VAT_LESS", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_EODPROD_TOTAL_VAT_LESS", COUNTER));
			}
			
			COUNTER++;
		}

		if (JSON_COUNT == 1000)
		{
			SKIP = SKIP + 1000;
			HTTP_SEARCH();
		}
		else
		{
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_VATABLE");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_VATEXEMPT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_NONVAT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_ZERORATED");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_VATOTHER");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_VAT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_TOTAL_VAT_LESS");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_SF_SOLD_ITEM");
			
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_DC_CUSA_AMOUNT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_DC_CUSB_AMOUNT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_DC_CUSC_AMOUNT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_DC_CUSD_AMOUNT");
			TRANSFLOW_SMRY_DGV.COLUMN.CFORMAT("REC_EODPROD_DC_CUSE_AMOUNT");

			var ROW_INDEX = 0;
            
            var DC_CUSA = 0;
            var DC_CUSB = 0;
            var DC_CUSC = 0;
            var DC_CUSD = 0;
            var DC_CUSE = 0;
            
			while(TRANSFLOW_SMRY_DGV.ROW.COUNT() > ROW_INDEX)
			{
				if (JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_AMOUNT_PRICE', ROW_INDEX)) > 0)
				{
					DC_CUSA += (JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSA_AMOUNT', ROW_INDEX)) / JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_AMOUNT_PRICE', ROW_INDEX)));
			    	DC_CUSB += (JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSB_AMOUNT', ROW_INDEX)) / JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_AMOUNT_PRICE', ROW_INDEX)));
			   	 	DC_CUSC += (JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSC_AMOUNT', ROW_INDEX)) / JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_AMOUNT_PRICE', ROW_INDEX)));
			   	 	DC_CUSD += (JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSD_AMOUNT', ROW_INDEX)) / JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_AMOUNT_PRICE', ROW_INDEX)));
			   	 	DC_CUSE += (JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSE_AMOUNT', ROW_INDEX)) / JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_AMOUNT_PRICE', ROW_INDEX)));
				}
			    
				TRANSFLOW_SMRY_DGV.CELL.VALUE('TOTAL_SALES', ROW_INDEX,
					JSVC_NUM.VAR_CFORMAT(
						JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('TOTAL_SALES', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_TOTAL_VATABLE', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_TOTAL_VATEXEMPT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_TOTAL_NONVAT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_TOTAL_ZERORATED', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_TOTAL_VATOTHER', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_TOTAL_VAT', ROW_INDEX))
					));


				TRANSFLOW_SMRY_DGV.CELL.VALUE('TOTAL_DISCOUNT', ROW_INDEX,
					JSVC_NUM.VAR_CFORMAT(
						JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('TOTAL_DISCOUNT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_SENIOR_20P', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_SENIOR_5P', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_PWD_20P', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_PWD_5P', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_GOV_5P', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSA_AMOUNT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSB_AMOUNT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSC_AMOUNT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSD_AMOUNT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_CUSE_AMOUNT', ROW_INDEX)) +
			    		JSVC_NUM.VAR_NVAL(TRANSFLOW_SMRY_DGV.CELL.VALUE('REC_EODPROD_DC_OTHER', ROW_INDEX))
					));

				ROW_INDEX++;
			}
			
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_TOTAL_SALES", JSVC_NUM.VAR_CFORMAT(TRANSFLOW_SMRY_DGV.COLUMN.SUM("TOTAL_SALES")));
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_TOTAL_DISCOUNT", JSVC_NUM.VAR_CFORMAT(TRANSFLOW_SMRY_DGV.COLUMN.SUM("TOTAL_DISCOUNT")));
			
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_DC_CUSA", JSVC_NUM.VAR_CFORMAT(DC_CUSA));
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_DC_CUSB", JSVC_NUM.VAR_CFORMAT(DC_CUSB));
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_DC_CUSC", JSVC_NUM.VAR_CFORMAT(DC_CUSC));
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_DC_CUSD", JSVC_NUM.VAR_CFORMAT(DC_CUSD));
			JSOC_ELEMENT.VAR_VALUE("SALES_BY_PRODUCT_DC_CUSE", JSVC_NUM.VAR_CFORMAT(DC_CUSE));
		}
	}

	function HTTP_LOAD_BRANCH_PRODUCTS(BRANCH_ID)
	{
		//show all products
		if(BRANCH_ID < 0)
		{
			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 
			);
		}

		//show per branch products
		else
		{
			var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_ACC_GROUP_ID', BRANCH_ID);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_CAT_PRICEMDL_ID', 1);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_STATUS', 2);

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

			var RESPONSE_HANDLER =
				function(IS_SUCCESS, RESPONSE_STRING)
				{				
					// Connection issue
					// ...........................................
					if(IS_SUCCESS === false) 
					{
						alert("CONNECTION ERROR: \n" + RESPONSE_STRING);
						return;
					}
			
					// Response is not valid JSON
					// ...........................................
					var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
					if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
					{
						alert("REQUEST ERROR: \n" + RESPONSE_STRING); 
						return;
					}
			
					// No result
					// ...........................................
					if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
					{
						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");
						return; 
					}
			
					// Populate discounts
					// ...........................................
					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");

					JSOC_CMB.VAR_ADD_FROM_JSON
					(
						'SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB',
						JSON_OBJECT,
						'CAT_PRODUCT_ID',
						'CAT_PRODUCT_DESCRIPTION', 
						true,
						false
					)

					$('#SEARCH_SALES_BY_PROD_CAT_PRODUCT_ID_CMB').select2();
				};
			
			JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_GET
			(
				GET_MAP_ARRAY, 
				RESPONSE_HANDLER, 
				true
			); 
		}
	}

	FORM_INITIALIZE();
	FORM_LOAD();