From 0a131321147aae268793c1628dae397355329f7e Mon Sep 17 00:00:00 2001 From: rivo Date: Sun, 1 Dec 2024 14:51:44 +0800 Subject: [PATCH] FEAT:fixing date format download report' --- .../app/service/impl/AnalyticsServiceImpl.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pos/app/service/impl/AnalyticsServiceImpl.java b/src/main/java/com/pos/app/service/impl/AnalyticsServiceImpl.java index c4f3303..f556b3f 100644 --- a/src/main/java/com/pos/app/service/impl/AnalyticsServiceImpl.java +++ b/src/main/java/com/pos/app/service/impl/AnalyticsServiceImpl.java @@ -22,6 +22,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -122,14 +123,26 @@ public Page getReportSales(Pageable pageable, Date startDate, Date endDate) { public ResponseEntity downloadReport() { List orderProductPage = orderProductRepository.getSalesReport(); try { - String[] headers = {"Product Name", "Product ID", "order ID", "qty", "price per qty", "total price", "total transaction", "tax", "date"}; + String[] headers = {"Product ID", "Product name", "order ID", "qty", "price per qty", "total price", "total transaction", "tax", "date"}; String[][] data = new String[orderProductPage.size()][headers.length]; int index = 0; for (Object[] obj : orderProductPage) { String[] objData = new String[obj.length]; for (int i = 0; i < obj.length; i++) { - objData[i] = obj[i] != null ? obj[i].toString() : ""; + + if (obj[i] instanceof Long) { // Check if the object is a Long (Unix time) + long unixTime = (Long) obj[i]; + Date date = new Date(unixTime); + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + String formattedDate = formatter.format(date); + + objData[i] = formattedDate; + } else { + objData[i] = obj[i] != null ? obj[i].toString() : ""; + } + } data[index] = objData; index++;