


	

	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________	
		var DGV_ELEMENT_CHILD = null;
		var DGV_ELEMENT_CHILD_INDEX = 0;
		
		// Load DataGridVuew
		// _______________________________________________________________________	
		JOB_ORDER_TASK_DGV = DataGridView("JOB_ORDER_TASK_DGV");

		// Requires Authentication
		// _______________________________________________________________________
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);
		
		// 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();
			}
		}
	};

	function HTTP_SEARCH()
	{
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._JOB_ORDER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_DATE_POST_FROM', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("LS_DATE_FROM_DTP"), "YYYY-MM-DD") + " 00:00:00.000000");
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_DATE_POST_TO', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("LS_DATE_TO_DTP"), "YYYY-MM-DD") + " 23:59:59.999999");
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_STATUS', 2);

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._JOB_ORDER.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		);
	}

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

		//RESET DGV
		// _______________________________________________________________________
		JOB_ORDER_TASK_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)
		{
			JOB_ORDER_TASK_DGV.ROW.CLEAR();
			return;
		}

		var CALLBACK_HANDLER = 
		function(IS_SUCCESS)
		{
			// Abort on failure
			if(IS_SUCCESS == false)
			{
				return;
			}

			if(PROPERTY_COUNT >= PROPERTY_INDEX + 1)
			{
				PROPERTY_INDEX = PROPERTY_INDEX + 1;
				PROPERTY_PARENT_ID = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_ID", PROPERTY_INDEX)
				HTTP_LOAD(CALLBACK_HANDLER);
			}
			else
			{
				JOB_ORDER_TASK_DGV.COLUMN.CFORMAT("REC_JORDER_TASK_QUANTITY");
			}
		}

		PROPERTY_COUNT = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT"));
		PROPERTY_INDEX = 1;
		PROPERTY_PARENT_ID = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_ID", PROPERTY_INDEX)
		var TOTAL_SALES = 0;
		HTTP_LOAD(CALLBACK_HANDLER);
	}

	FORM_INITIALIZE();
	FORM_LOAD();