Skip to content

Commit

Permalink
FEAT:fixing date format download report'
Browse files Browse the repository at this point in the history
  • Loading branch information
rivopelu committed Dec 1, 2024
1 parent 812dd0b commit 0a13132
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/com/pos/app/service/impl/AnalyticsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,14 +123,26 @@ public Page getReportSales(Pageable pageable, Date startDate, Date endDate) {
public ResponseEntity<byte[]> downloadReport() {
List<Object[]> 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++;
Expand Down

0 comments on commit 0a13132

Please sign in to comment.