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


	function EXPORT_INVOICE_HEADER()
	{
		return "\"*InvoiceNo\",\"*Customer\",\"*InvoiceDate\",\"*DueDate\",\"Terms\"," +
		"\"Location\",\"Memo\",\"Item(Product/Service)\",\"ItemDescription\",\"ItemQuantity\",\"ItemRate\"," +
		"\"*ItemAmount\",\"*ItemTaxCode\",\"ItemTaxAmount\",\"Service Date\"" + "\r\n";
	};
	
	
	/**
	  *  CALLBACK_METHOD (RESULT_STRING, IS_SUCCESS)
      *
	  */
	function EXPORT_RESERVATION_LINE(REC_POSRESERVE_ID, CALLBACK_METHOD)
	{
		// Initialize
		// _______________________________________________________________________
		var RESULT_STRING = '';
		var GET_MAP_ARRAY = GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_ID', REC_POSRESERVE_ID);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_LIMIT', 1);
		
		
		// Enclose CSV String
		// _______________________________________________________________________
		var TO_CSV_DATA = function(CURRENT_DATA, NEW_LINE = false)
		{
			// Handle Date input
			// ...........................................
			if(JSVC_VAR.VAR_IS_DATE(CURRENT_DATA))
			{
				CURRENT_DATA = JSVC_DATE.VAR_FORMAT(CURRENT_DATA, "DD/MM/YYYY");
			}
			
			// Enclose String
			// ...........................................
			CURRENT_DATA = "\"" + CURRENT_DATA + "\"";
			
			// Manage end of line
			// ...........................................
			if(NEW_LINE == true)
			{
				CURRENT_DATA = CURRENT_DATA + '\r\n';
			}
			else
			{
				CURRENT_DATA = CURRENT_DATA + ",";
			}
			
			// Return result
			// ...........................................
			return CURRENT_DATA;
		};
	
		
		// Generate CSV Script
		// _______________________________________________________________________
		var GENERATE_CSV = function(PARENT_JSON, IS_SUCCESS, RESPONSE_STRING)
		{
			// Validate
			// ...........................................
			if(IS_SUCCESS === false)
			{
				console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
				CALLBACK_METHOD("", false);
				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);
				CALLBACK_METHOD("", false);
				return;
			}
			
			// JSON Empty (Clears the DataGrodView)
			// ...........................................
			if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
			{
				CALLBACK_METHOD("", true);
				return;
			}
			
			// Generate CSV
			// ...........................................
			var JSON_COUNT = JSRC_JSON.REF_READ_NVALL(JSON_OBJECT, "JSON_COUNT");
			var JSON_INDEX = 1;
			
			while(JSON_COUNT >= JSON_INDEX)
			{
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_CODE", JSON_INDEX), false);
				RESULT_STRING += TO_CSV_DATA
				(
					JSRC_JSON.REF_READ(PARENT_JSON, "REC_CLIENT_FIRSTNAME", 1) + " " +
					JSRC_JSON.REF_READ(PARENT_JSON, "REC_CLIENT_LASTNAME", 1), 
					false
				); // Customer
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ_TO_DATE(JSON_OBJECT, "REC_POSRESERVE_DATE_RECORDED", JSON_INDEX), false);
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ_TO_DATE(JSON_OBJECT, "REC_POSRESERVE_DATE_EXPECTED", JSON_INDEX), false);
				RESULT_STRING += TO_CSV_DATA("", false); // Terms
				// RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ(PARENT_JSON, "REC_CLIENT_ADDRESS", 1), false); // Location
				// RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ(PARENT_JSON, "ACC_GROUP_DESCRIPTION", 1), false); // Location
				RESULT_STRING += TO_CSV_DATA("", false); // Location
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_POSRESERVE_REMARKS", JSON_INDEX), false);
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODUCT_DESCRIPTION", JSON_INDEX), false); 
				RESULT_STRING += TO_CSV_DATA("", false); // Item Description
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ_NVAL(JSON_OBJECT, "REC_POSRESERVE_LIST_QTY", JSON_INDEX), false); 
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ_NVAL(JSON_OBJECT, "REC_POSRESERVE_LIST_PRICE_BASE", JSON_INDEX), false); 
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ_NVAL(JSON_OBJECT, "REC_POSRESERVE_LIST_PRICE_EXPECT", JSON_INDEX), false);
				RESULT_STRING += TO_CSV_DATA("12% S", false); // Tax Rate
				RESULT_STRING += TO_CSV_DATA
				(
					JSRC_JSON.REF_READ_NVAL(JSON_OBJECT, "REC_POSRESERVE_LIST_PRICE_EXPECT", JSON_INDEX) - 
					(
						JSRC_JSON.REF_READ_NVAL(JSON_OBJECT, "REC_POSRESERVE_LIST_PRICE_EXPECT", JSON_INDEX) / 1.12
					), 
					false
				); // Tax Amount
				RESULT_STRING += TO_CSV_DATA(JSRC_JSON.REF_READ_TO_DATE(JSON_OBJECT, "REC_POSRESERVE_DATE_EXPECTED", JSON_INDEX), true);
				JSON_INDEX ++;
			}
			
			
			// Return Result
			// ...........................................
			CALLBACK_METHOD(RESULT_STRING, true);
		};
		
		
		// Retrieve Parent Data
		// _______________________________________________________________________
		var HANDLE_PARENT = function(IS_SUCCESS, RESPONSE_STRING)
		{
			// Validate
			// ...........................................
			if(IS_SUCCESS === false)
			{
				console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
				CALLBACK_METHOD("", false);
				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);
				CALLBACK_METHOD("", false);
				return;
			}
			
			// JSON Empty (Clears the DataGrodView)
			// ...........................................
			if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
			{
				console.error("REQUEST ERROR: \n" + 'Reservation not exists ID: ' + REC_POSRESERVE_ID);
				CALLBACK_METHOD("", false);
				return;
			}			
			
			// Prepare Request
			// ...........................................
			GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSRESERVE_LIST_REC_POSRESERVE_ID', REC_POSRESERVE_ID);
			
			// Call Child Request
			// ...........................................
			JSCUS_SQL._RECORD._POS_RESERVE_LIST.CUS_GET
			(
				GET_MAP_ARRAY,
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					GENERATE_CSV(JSON_OBJECT, IS_SUCCESS, RESPONSE_STRING);
				},
				false
			); 				
		};
			
			
		// Call Request
		// _______________________________________________________________________
		JSCUS_SQL._RECORD._POS_RESERVE.CUS_GET
		(
			GET_MAP_ARRAY,
			HANDLE_PARENT,
			false
		); 		
		
		
	};
