
/**
 * =================================================================================
 * Print X-Reading for the current shift
 * =================================================================================
 */

var PRINT_DATA = '';
var RECORD_POS_SALE_COUNT = 0;
var READING_DATETIME = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD HH:mm:ss") + ".999999";

function X_READING(CALLBACK_METHOD)
{
	// Abort if current shift is not assigned
	// _______________________________________________________________________
	if(JSVC_STR.VAR_IS_BLANK(SHIFT_TIME_START))
	{
		alert("CONNECTION ERROR: \n" + "There is no available shift to generate reading.");
		return;		
	}
	
	
	// Initialize
	// _______________________________________________________________________
	var GET_MAP_ARRAY;
	
	var READING_DATE = JSVC_DATE.VAR_FORMAT(READING_DATETIME, "MMMM DD, YYYY");
	var READING_TIME = JSVC_DATE.VAR_FORMAT(READING_DATETIME, "hh:mm TT");
	
	var SHIFT_DATE = JSVC_DATE.VAR_FORMAT(SHIFT_TIME_START, "MMMM DD, YYYY");
	var SHIFT_TIME = JSVC_DATE.VAR_FORMAT(SHIFT_TIME_START, "hh:mm TT");

	PRINT_DATA = '';
	RECORD_POS_SALE_COUNT = 0;
		
	JSOC_DIALOG.VAR_LOADING_SPINNER(true);
	
	
	// Prepare X-Reading Header
	// _______________________________________________________________________
	PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
	PRINT_DATA += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_DESCRIPTION+'</td></tr>';
	PRINT_DATA += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ADDRESS+'</td></tr>';
	PRINT_DATA += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_CONTACT+'</td></tr>';
	PRINT_DATA += '	<tr><td style="text-align: center;">VAT Reg TIN: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_TIN+'</td></tr>';
	PRINT_DATA += '	<tr><td style="text-align: center;"><hr style="border: 1px dashed black;"></td></tr>';
	PRINT_DATA += '</table>';
	PRINT_DATA += '<br>';
							
	PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
	PRINT_DATA += '	<tr><th style="text-align: center;">X Reading Report</th></tr>';
	PRINT_DATA += '</table>';
	PRINT_DATA += '<hr style="border: 1px dashed black;">';
	
	PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
	PRINT_DATA += '	<tr><td>Read Date: '+SHIFT_DATE+' - '+READING_DATE+'</td></tr>';
	PRINT_DATA += '	<tr><td>Read Time: '+SHIFT_TIME+' - '+READING_TIME+'</td></tr>';
	PRINT_DATA += '</table>';
	PRINT_DATA += '<br>';

	PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
	PRINT_DATA += '	<tr><td>Cashier: '+JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_NAME+'</td></tr>';
	PRINT_DATA += '	<tr><td>Terminal: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_MACHINE_ID+'</td></tr>';
	PRINT_DATA += '</table>';
	PRINT_DATA += '<br>';
								
	PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
	PRINT_DATA += '	<tr><th style="text-align: center;">TOTAL SALES</th></tr>';
	PRINT_DATA += '</table>';
	PRINT_DATA += '<hr style="border: 1px dashed black;">';	
	
	
	// Populate RECORD_POS_SALES data
	// _______________________________________________________________________
	GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_SALE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_REC_POSDEVICE_ID', JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_ACC_ACCOUNT_ID', JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_DATE_TRANSACT_FROM', JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(SHIFT_TIME_START), "YYYY-MM-DD HH:mm:ss") + ".000000"); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_DATE_TRANSACT_TO', READING_DATETIME); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSSALE_STATUS', 4);
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_LIMIT', 10000);
			
	JSCUS_SQL._RECORD._POS_SALE.CUS_GET
	(
		GET_MAP_ARRAY, 
		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)
			{
				PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				PRINT_DATA += '<tr><td colspan="2">Gross Sales</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Discounts</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Less VAT</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Sales Return</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Net Sales</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="3"><br></td></tr>';
				PRINT_DATA += '<tr><td colspan="2">VATable Sales</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">VAT(12%)</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">VAT Exempt Sales</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Zero Rated Sales</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Non-VAT Sales</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="3"><br></td></tr>';	
			}
			
			// Actual Data
			// ...........................................
			else 
			{
				RECORD_POS_SALE_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");

				PRINT_DATA += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				PRINT_DATA += '<tr><td colspan="2">Gross Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_SUBTOTAL")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Discounts</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_DISCOUNT"))  + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Less VAT</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_VAT_LESS")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Sales Return</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_RTN_SUBTOTAL")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Net Sales</td><td style="text-align: right;">' + 
				JSVC_NUM.VAR_CFORMAT
				(
					JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_SUBTOTAL") - 
					(
						JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_DISCOUNT") + 
						JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_VAT_LESS") + 
						JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_RTN_SUBTOTAL")
					)
				) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="3"><br></td></tr>';
				
				PRINT_DATA += '<tr><td colspan="2">VATable Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_VATABLE")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">VAT(12%)</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_VAT")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">VAT Exempt Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_VATEXEMPT")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Zero Rated Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_ZERORATED")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Non-VAT Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_SUM(JSON_OBJECT, "REC_POSSALE_TOTAL_NONVAT")) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="3"><br></td></tr>';				
			}

			X_READING_PAYMENT(CALLBACK_METHOD);
		}
	);		
}

// Populate RECORD_POS_PAYMENT data
// _______________________________________________________________________

function X_READING_PAYMENT(CALLBACK_METHOD) 
{
	var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_PAYMENT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSPAY_REC_POSDEVICE_ID', JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSPAY_ACC_ACCOUNT_ID', JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSPAY_DATE_PROCESSED_FROM', JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(SHIFT_TIME_START), "YYYY-MM-DD HH:mm:ss") + ".000000"); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSPAY_DATE_PROCESSED_TO', READING_DATETIME); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_LIMIT', 10000);

	JSCUS_SQL._RECORD._POS_PAYMENT.CUS_GET
	(
		GET_MAP_ARRAY, 
		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)
			{
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;">ACCEPTED PAYMENTS</th></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				PRINT_DATA += '<tr><td colspan="2">Cash</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Debit/Credit Cards</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Check</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Loyalty Cards</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Gift Cert./Vouchers</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Others</td><td style="text-align: right;">0.00</td></tr>';
				PRINT_DATA += '<tr><td colspan="3"><br></td></tr>';
			}
			
			// Actual Data
			// ...........................................
			else 
			{
				var CASH_SUM = 0;
				var CARD_SUM = 0;
				var CHECK_SUM = 0;
				var LOYALTY_SUM = 0;
				var VOUCHER_SUM = 0;
				var OTHERS_SUM = 0;
				
				var JSON_SUM = JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_POSPAY_AMOUNT_PAID');
				var JSON_PAYTYPE = JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_POSPAY_CAT_PAYTYPE_ID');
				var JSON_CHANGE = JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_POSPAY_CHANGE');
				var JSON_KEY = Object.keys(JSON_SUM);
				while(JSON_KEY.length > 0)
				{
					switch(JSVC_NUM.VAR_NVALL(JSON_PAYTYPE[JSON_KEY[0]])) 
					{
						case 1: CASH_SUM += JSVC_NUM.VAR_NVAL(JSON_SUM[JSON_KEY[0]]) - JSVC_NUM.VAR_NVAL(JSON_CHANGE[JSON_KEY[0]]); break;
						case 2: CARD_SUM += JSVC_NUM.VAR_NVAL(JSON_SUM[JSON_KEY[0]]); break;
						case 3: CHECK_SUM += JSVC_NUM.VAR_NVAL(JSON_SUM[JSON_KEY[0]]); break;
						case 6: LOYALTY_SUM += JSVC_NUM.VAR_NVAL(JSON_SUM[JSON_KEY[0]]); break;
						case 7: VOUCHER_SUM += JSVC_NUM.VAR_NVAL(JSON_SUM[JSON_KEY[0]]); break;
						default: OTHERS_SUM += JSVC_NUM.VAR_NVAL(JSON_SUM[JSON_KEY[0]]); break;
					}
					JSON_KEY.shift();
				}
				
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;">ACCEPTED PAYMENTS</th></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				PRINT_DATA += '<tr><td colspan="2">Cash</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(CASH_SUM) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Debit/Credit Cards</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(CARD_SUM) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Check</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(CHECK_SUM) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Loyalty Cards</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(LOYALTY_SUM) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Gift Cert./Vouchers</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(VOUCHER_SUM) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Others</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(OTHERS_SUM) + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="3"><br></td></tr>';
			}

			X_READING_CANCEL(CALLBACK_METHOD);
		}
	);
}


// Populate RECORD_CANCEL data			
// _______________________________________________________________________	
function X_READING_CANCEL(CALLBACK_METHOD)
{
	var GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_CANCEL.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSCANCEL_ACC_ACCOUNT_ID', JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSCANCEL_DATE_FROM', JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(SHIFT_TIME_START), "YYYY-MM-DD HH:mm:ss") + ".000000"); 
	JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_POSCANCEL_DATE_TO', READING_DATETIME); 

	JSCUS_SQL._RECORD._POS_CANCEL.CUS_GET
	(
		GET_MAP_ARRAY, 
		function(IS_SUCCESS, RESPONSE_STRING) 
		{
			// Dismiss Progress
			// ...........................................
			JSOC_DIALOG.VAR_LOADING_SPINNER(false);
			
			// 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)
			{
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;">TRANSACTIONS</th></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></tr>';
				PRINT_DATA += '<tr><td colspan="2">No. of Transactions</td><td style="text-align: right;">' + RECORD_POS_SALE_COUNT + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Cancelled Items</td><td style="text-align: right;">0</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Cancelled Trans.</td><td style="text-align: right;">0</td></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;"><hr style="border: 0; height: 1px; color: gray; background-color: gray;"></th></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;">X Reading End</th></tr>';
				PRINT_DATA += '</table>';
			}
			
			// Actual Data
			// ...........................................
			else 
			{
				var TRANSACTION_COUNT = 0;
				var ITEM_COUNT = 0;
				
				var JSON_REC_POSCANCEL_IS_FULL_DROP = JSRC_JSON.REF_READ(JSON_OBJECT, 'REC_POSCANCEL_IS_FULL_DROP');
				var JSON_KEY = Object.keys(JSON_REC_POSCANCEL_IS_FULL_DROP);
				while(JSON_KEY.length > 0)
				{
					if(JSVC_NUM.VAR_NVAL(JSON_REC_POSCANCEL_IS_FULL_DROP[JSON_KEY[0]]) == JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE) 
					{
						TRANSACTION_COUNT ++;
					}
					else
					{
						ITEM_COUNT ++;
					}
					JSON_KEY.shift();
				}
				
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;">TRANSACTIONS</th></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				PRINT_DATA += '<tr><td colspan="2">No. of Transactions</td><td style="text-align: right;">' + RECORD_POS_SALE_COUNT + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Cancelled Items</td><td style="text-align: right;">' + ITEM_COUNT + '</td></tr>';
				PRINT_DATA += '<tr><td colspan="2">Cancelled Trans.</td><td style="text-align: right;">' + TRANSACTION_COUNT + '</td></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				PRINT_DATA += '<tr><th colspan="3" style="text-align: center;">X Reading End</th></tr>';
				PRINT_DATA += '</table>';			
			}		
			

			if(JSVC_VAR.VAR_ISSET(CALLBACK_METHOD))
			{
				CALLBACK_METHOD(true);
			}

			Android.CALL('PRINT', '<html><body>' + PRINT_DATA + '</body></html>');	
		}
	);
}


/**
 * =================================================================================
 * Request EoD. (Only once per day. Returns the result of the first request, when called more than once.)
 * =================================================================================
 */
function SAVE_EOD(REQUEST_DATE) 
{
	// Initialize
	// _______________________________________________________________________	
	var TODAY = null;	
	console.log(REQUEST_DATE);
	if(JSVC_VAR.VAR_ISSET(REQUEST_DATE))
	{
		TODAY = JSVC_DATE.VAR_TO_DATE(JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(REQUEST_DATE), "YYYY-MM-DD") + ' 23:59:59.999999');
	}
	else
	{
		TODAY = JSVC_DATE.VAR_NOW();
	}
	// Request server to do EoD
	// _______________________________________________________________________		
	var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._EOD_CSREP.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_REC_POSDEVICE_ID", JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_TIME_CLOSED", JSVC_DATE.VAR_FORMAT(TODAY, "YYYY-MM-DD HH:mm:ss") + ".999999");

	JSOC_DIALOG.VAR_LOADING_SPINNER(true);
	JSCUS_SQL._RECORD._EOD_CSREP.CUS_COMPUTE
	(
		SAVE_MAP_ARRAY, 
		function(IS_SUCCESS, HTTP_RESPONSE) 
		{
			console.log(HTTP_RESPONSE);	
			
			// Connection issue
			// ...........................................
			if(IS_SUCCESS === false) 
			{
				alert("CONNECTION ERROR: \n" + HTTP_RESPONSE);
				JSOC_DIALOG.VAR_LOADING_SPINNER(false);
				return;
			}

			// Response is not valid JSON
			// ...........................................
			var JSON_OBJECT = JSRC_JSON.REF_CREATE(HTTP_RESPONSE);
			if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false) 
			{
				alert("REQUEST ERROR: \n" + HTTP_RESPONSE); 
				JSOC_DIALOG.VAR_LOADING_SPINNER(false);
				return;
			}

			// No result
			// ...........................................
			if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
			{
				alert("REQUEST ERROR: \n" + "Unable to process request.");
				JSOC_DIALOG.VAR_LOADING_SPINNER(false);
				return;
			}
			
			// Actual Data
			// ...........................................
			else 
			{
				SAVE_EOD_ZREADING(TODAY);
				return;
			}		
		}
	);
}


/**
 * =================================================================================
 * Generates Z-Reading from existing EoD. (Only once per day. Returns the result of the first request, when called more than once.)
 * =================================================================================
 */
function SAVE_EOD_ZREADING(TODAY) 
{
	// Request server to do Z-Reading
	// _______________________________________________________________________		
	var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._EOD_ZREADING.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_REC_POSDEVICE_ID", JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_TIME_CLOSED",  JSVC_DATE.VAR_FORMAT(TODAY, "YYYY-MM-DD HH:mm:ss") + ".999999");

	JSCUS_SQL._RECORD._EOD_ZREADING.CUS_COMPUTE
	(
		SAVE_MAP_ARRAY, 
		function(IS_SUCCESS, RESPONSE_STRING) 
		{
			// Dismiss Progress
			// ...........................................
			JSOC_DIALOG.VAR_LOADING_SPINNER(false);
			
			// 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) 
			{
				alert("REQUEST ERROR: \n" + "Unable to process request.");
				return;
			}
			
			// Actual Data
			// ...........................................		
			else 
			{
				var RECEIPT = '';

				var READING_DATE = JSVC_DATE.VAR_FORMAT(JSON_OBJECT.REC_EODREP_ZREAD_DATE[1], "MMMM DD, YYYY");
				var READING_TIME = JSVC_DATE.VAR_FORMAT(JSON_OBJECT.REC_EODREP_ZREAD_DATE[1], "hh:mm TT");

				var READING_DATE_PRINT = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "MMMM DD, YYYY");
				var READING_TIME_PRINT = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "hh:mm TT");

	
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_DESCRIPTION+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ADDRESS+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_CONTACT+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;">VAT Reg TIN: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_TIN+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;"><hr style="border: 1px dashed black;"></td></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<br>';
						
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><th style="text-align: center;">Z Reading Report</th></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<hr style="border: 1px dashed black;">';
	
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><td>Read Date: '+READING_DATE+' - '+READING_DATE+'</td></tr>';
				RECEIPT += '	<tr><td>Covered Period: 4:00 AM ~ ' + READING_TIME + ' </td></tr>';
				RECEIPT += '	<tr><td>Print Time: ' + READING_DATE_PRINT + ' ' + READING_TIME_PRINT + '</td></tr>';
				RECEIPT += '	<tr><td>Terminal: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_MACHINE_ID+'</td></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<br>';
						
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><th style="text-align: center;">TOTAL SALES</th></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<hr style="border: 1px dashed black;">';
	
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><td colspan="2">Gross Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_SUBTOTAL[1])) + '</td></tr>';
			//	RECEIPT += '	<tr><td colspan="3">Discounts</td></tr>';
				RECEIPT += '	<tr><td></td><td>Discounts</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_DISCOUNT[1])) + '</td></tr>';
			//	RECEIPT += '	<tr><td></td><td>SC/PWD</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_DISCOUNT[1])) + '</td></tr>';
			//	RECEIPT += '	<tr><td></td><td>Other Discounts</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_DISCOUNT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Less VAT</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_VAT_LESS[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Sales Return</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_RETURN[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Net Sales</td><td style="text-align: right;">' + 
				JSVC_NUM.VAR_CFORMAT
				(
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATABLE[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATEXEMPT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_ZERORATED[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_NONVAT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VAT[1])
				) +
				'</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><td colspan="2">VATable Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATABLE[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">VAT(12%)</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VAT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">VAT Exempt Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATEXEMPT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Zero Rated Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_ZERORATED[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Non-VAT Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_NONVAT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><td colspan="2">Current Day Sales</td><td style="text-align: right;">' + 
				JSVC_NUM.VAR_CFORMAT
				(
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATABLE[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATEXEMPT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_ZERORATED[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_NONVAT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VAT[1])
				) +
				'</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Total Grand Accummulated Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVALL(JSON_OBJECT.REC_EODREP_ZREAD_AMOUNT_ACCUM[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;">ACCEPTED PAYMENTS</th></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				RECEIPT += '	<tr><td colspan="2">Cash</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_CASH[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Debit/Credit Cards</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_CARD[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Check</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_CHECK[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Loyalty Cards</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_LOYALTY[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Gift Cert./Vouchers</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_VOUCHER[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Others</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_OTHER[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;">TRANSACTIONS</th></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				RECEIPT += '	<tr><td colspan="2">Reset Counter</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVALL(JSON_OBJECT.REC_EODREP_ZREAD_AMOUNT_RESET[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Z Reading Counter</td><td style="text-align: right;">1.00</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><td colspan="2">No. of Transactions</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_TRANSACTION[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Cancelled Items</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_CANCEL_ITEM[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Cancelled Trans.</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_CANCEL_TRANSACTION[1])) + '</td></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;">Z Reading End</th></tr>';
				RECEIPT += '</table>';
				
				Android.CALL('PRINT', '<html><body>' + RECEIPT + '</body></html>');
			}
		}
	);
}/**
 * =================================================================================
 * Request EoD. (Only once per day. Returns the result of the first request, when called more than once.)
 * =================================================================================
 */
function SAVE_EOD(REQUEST_DATE) 
{
	// Initialize
	// _______________________________________________________________________	
	var TODAY = null;	
	if
	(
		JSVC_VAR.VAR_ISSET(REQUEST_DATE) &&
		JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(REQUEST_DATE), "YYYY-MM-DD") != JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD")
	)
	{
		TODAY = JSVC_DATE.VAR_TO_DATE(JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(REQUEST_DATE), "YYYY-MM-DD") + ' 23:59:59.999999');
	}
	else
	{
		TODAY = JSVC_DATE.VAR_NOW();
	}
	
	// var TODAY = JSVC_VAR.VAR_OPTIONAL(REQUEST_DATE + ' 23:59:59.999999', JSVC_DATE.VAR_NOW());	
	// var TODAY = JSVC_VAR.VAR_OPTIONAL(JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(REQUEST_DATE), "YYYY-MM-DD") + ' ' +JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "HH:mm:ss") + ".999999", JSVC_DATE.VAR_NOW());	
	
	// Request server to do EoD
	// _______________________________________________________________________		
	var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._EOD_CSREP.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_REC_POSDEVICE_ID", JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_TIME_CLOSED", JSVC_DATE.VAR_FORMAT(TODAY, "YYYY-MM-DD HH:mm:ss") + ".999999");

	JSOC_DIALOG.VAR_LOADING_SPINNER(true);
	JSCUS_SQL._RECORD._EOD_CSREP.CUS_COMPUTE
	(
		SAVE_MAP_ARRAY, 
		function(IS_SUCCESS, HTTP_RESPONSE) 
		{
			console.log(HTTP_RESPONSE);	
			
			// Connection issue
			// ...........................................
			if(IS_SUCCESS === false) 
			{
				alert("CONNECTION ERROR: \n" + HTTP_RESPONSE);
				JSOC_DIALOG.VAR_LOADING_SPINNER(false);
				return;
			}

			// Response is not valid JSON
			// ...........................................
			var JSON_OBJECT = JSRC_JSON.REF_CREATE(HTTP_RESPONSE);
			if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false) 
			{
				alert("REQUEST ERROR: \n" + HTTP_RESPONSE); 
				JSOC_DIALOG.VAR_LOADING_SPINNER(false);
				return;
			}

			// No result
			// ...........................................
			if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
			{
				alert("REQUEST ERROR: \n" + "Unable to process request.");
				JSOC_DIALOG.VAR_LOADING_SPINNER(false);
				return;
			}
			
			// Actual Data
			// ...........................................
			else 
			{
				SAVE_EOD_ZREADING(TODAY);
				return;
			}		
		}
	);
}


/**
 * =================================================================================
 * Generates Z-Reading from existing EoD. (Only once per day. Returns the result of the first request, when called more than once.)
 * =================================================================================
 */
function SAVE_EOD_ZREADING(TODAY) 
{
	// Request server to do Z-Reading
	// _______________________________________________________________________		
	var SAVE_MAP_ARRAY = JSCUS_SQL._RECORD._EOD_ZREADING.CUS_PREPARE_MAPPED_ARRAY_FOR_COMPUTE();
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_REC_POSDEVICE_ID", JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
	JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_REC_EODREP_TIME_CLOSED",  JSVC_DATE.VAR_FORMAT(TODAY, "YYYY-MM-DD HH:mm:ss") + ".999999");

	JSCUS_SQL._RECORD._EOD_ZREADING.CUS_COMPUTE
	(
		SAVE_MAP_ARRAY, 
		function(IS_SUCCESS, RESPONSE_STRING) 
		{
			// Dismiss Progress
			// ...........................................
			JSOC_DIALOG.VAR_LOADING_SPINNER(false);
			
			// 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) 
			{
				alert("REQUEST ERROR: \n" + "Unable to process request.");
				return;
			}
			
			// Actual Data
			// ...........................................		
			else 
			{
				var RECEIPT = '';

				var READING_DATE = JSVC_DATE.VAR_FORMAT(JSON_OBJECT.REC_EODREP_ZREAD_DATE[1], "MMMM DD, YYYY");
				var READING_TIME = JSVC_DATE.VAR_FORMAT(JSON_OBJECT.REC_EODREP_ZREAD_DATE[1], "hh:mm TT");

				var READING_DATE_PRINT = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "MMMM DD, YYYY");
				var READING_TIME_PRINT = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "hh:mm TT");
	
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_DESCRIPTION+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ADDRESS+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;">'+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_CONTACT+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;">VAT Reg TIN: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_TIN+'</td></tr>';
				RECEIPT += '	<tr><td style="text-align: center;"><hr style="border: 1px dashed black;"></td></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<br>';
						
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><th style="text-align: center;">Z Reading Report</th></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<hr style="border: 1px dashed black;">';
	
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><td>Read Date: '+READING_DATE+' - '+READING_DATE+'</td></tr>';
				// RECEIPT += '	<tr><td>Covered Period: 4:00 AM ~ ' + READING_TIME + ' </td></tr>';
				RECEIPT += '	<tr><td>Print Time: ' + READING_DATE_PRINT + ' ' + READING_TIME_PRINT + '</td></tr>';
				RECEIPT += '	<tr><td>Terminal: '+JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_MACHINE_ID+'</td></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<br>';
						
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><th style="text-align: center;">TOTAL SALES</th></tr>';
				RECEIPT += '</table>';
				RECEIPT += '<hr style="border: 1px dashed black;">';
	
				RECEIPT += '<table border="0" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 0 !important;">';
				RECEIPT += '	<tr><td colspan="2">Gross Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_SUBTOTAL[1])) + '</td></tr>';
			//	RECEIPT += '	<tr><td colspan="3">Discounts</td></tr>';
				RECEIPT += '	<tr><td></td><td>Discounts</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_DISCOUNT[1])) + '</td></tr>';
			//	RECEIPT += '	<tr><td></td><td>SC/PWD</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_DISCOUNT[1])) + '</td></tr>';
			//	RECEIPT += '	<tr><td></td><td>Other Discounts</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_DISCOUNT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Less VAT</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_SALE_VAT_LESS[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Sales Return</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_RETURN[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Net Sales</td><td style="text-align: right;">' + 
				JSVC_NUM.VAR_CFORMAT
				(
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATABLE[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATEXEMPT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_ZERORATED[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_NONVAT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VAT[1])
				) +
				'</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><td colspan="2">VATable Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATABLE[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">VAT(12%)</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VAT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">VAT Exempt Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATEXEMPT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Zero Rated Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_ZERORATED[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Non-VAT Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_NONVAT[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><td colspan="2">Current Day Sales</td><td style="text-align: right;">' + 
				JSVC_NUM.VAR_CFORMAT
				(
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATABLE[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VATEXEMPT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_ZERORATED[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_NONVAT[1]) +
					JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_VAT[1])
				) +
				'</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Total Grand Accummulated Sales</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVALL(JSON_OBJECT.REC_EODREP_ZREAD_AMOUNT_ACCUM[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;">ACCEPTED PAYMENTS</th></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				RECEIPT += '	<tr><td colspan="2">Cash</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_CASH[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Debit/Credit Cards</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_CARD[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Check</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_CHECK[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Loyalty Cards</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_LOYALTY[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Gift Cert./Vouchers</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_VOUCHER[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Others</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_PAID_OTHER[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;">TRANSACTIONS</th></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				RECEIPT += '	<tr><td colspan="2">Reset Counter</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVALL(JSON_OBJECT.REC_EODREP_ZREAD_AMOUNT_RESET[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Z Reading Counter</td><td style="text-align: right;">1.00</td></tr>';
				RECEIPT += '	<tr><td colspan="3"><br></td></tr>';
				RECEIPT += '	<tr><td colspan="2">No. of Transactions</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_ZREAD_SALE_TRANSACTION[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Cancelled Items</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_CANCEL_ITEM[1])) + '</td></tr>';
				RECEIPT += '	<tr><td colspan="2">Cancelled Trans.</td><td style="text-align: right;">' + JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSON_OBJECT.REC_EODREP_CANCEL_TRANSACTION[1])) + '</td></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;"><hr style="border: 1px dashed black;"></th></tr>';
				RECEIPT += '	<tr><th colspan="3" style="text-align: center;">Z Reading End</th></tr>';
				RECEIPT += '</table>';
				
				Android.CALL('PRINT', '<html><body>' + RECEIPT + '</body></html>');

				console.log(RECEIPT);
			}
		}
	);
}

