From 20f3cb015161ca9881e9a5478ae65c1bad0b969e Mon Sep 17 00:00:00 2001 From: Gauthier LO Date: Fri, 21 Feb 2025 17:17:25 +0100 Subject: [PATCH] hotfix: invoice excel and pdf for USD complete invoice --- .../shippingInvoice/InvoiceController.java | 2 +- .../domain/invoice/AbstractInvoice.java | 23 ++++++++----------- .../service/IPurchaseOrderService.java | 2 +- .../PlatformOrderShippingInvoiceService.java | 13 +++++++++-- .../purchase/PurchaseOrderServiceImpl.java | 9 ++++---- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java index 58e41234d..b39cc3bf9 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java @@ -1262,7 +1262,7 @@ public class InvoiceController { } catch (IOException e) { log.error(e.getMessage()); return Result.error("Sorry, server error, please try later"); - } catch (URISyntaxException e) { + } catch (Exception e) { throw new RuntimeException(e); } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/invoice/AbstractInvoice.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/invoice/AbstractInvoice.java index c7bca5ba8..d78f39c75 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/invoice/AbstractInvoice.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/invoice/AbstractInvoice.java @@ -195,11 +195,13 @@ public abstract class AbstractInvoice { } } else {// on dépasse forcément le format A4 d'un PDF - if(((TOTAL_ROW - 44) % 63) < 13) { + if(((TOTAL_ROW - 44) % 63) < 16) { + int dataSizeAfterFirstPage = data.size() - 44; + int shift = (int) Math.ceil((double) (dataSizeAfterFirstPage) / 63) * 63; // we shift the footer to the next page // Not enough space for footer - sheet.shiftRows(startRow, fileLastRow, TOTAL_ROW - LAST_ROW + ((TOTAL_ROW-44)%63), true, false); - imgShift = TOTAL_ROW-44 + ((TOTAL_ROW-44)%63) -1; - TOTAL_ROW += ((TOTAL_ROW-44)%63) + 1; + sheet.shiftRows(startRow, fileLastRow, shift + 20, true, false); // why 20 ? no idea, it just works + imgShift = shift + 16; // 16 is the number of lines of footer + TOTAL_ROW = 63 + shift; // we just yeet the total row to next page footerRow = TOTAL_ROW+1; situation = 4; } @@ -256,7 +258,7 @@ public abstract class AbstractInvoice { for (int i = 0; i < data.size(); i++) { lineNum = i + FIRST_ROW; rowValue = data.get(i); - log.info("Writing line {} with data {}", lineNum, rowValue); +// log.info("Writing line {} with data {}", lineNum, rowValue); configCell("C", lineNum, String.format("%06d", i + 1), factory.leftSideStyle()); configCell("D", lineNum, rowValue.getCol1(), factory.leftSideStyle()); configCell("E", lineNum, rowValue.getCol2(), factory.rightSideDecimalStyle()); @@ -342,15 +344,8 @@ public abstract class AbstractInvoice { if (targetClient.getCurrency().equals("USD")) { org.apache.poi.ss.usermodel.Row dollarRow; - String formula; - if ((((LAST_ROW + additionalRowNum - 44) % 63) < 13) && ((LAST_ROW + additionalRowNum - 44) % 63) > 0) { - dollarRow = sheet.getRow(TOTAL_ROW + 2); - formula = "H"+ (TOTAL_ROW + 2) +" *" + exchangeRate; - } - else { - dollarRow = sheet.getRow(data.size() >= 44 ? TOTAL_ROW + 3 : TOTAL_ROW + 2); - formula = "H" + (data.size() >= 44 ? TOTAL_ROW + 3 : TOTAL_ROW + 2) + " *" + exchangeRate; - } + dollarRow = sheet.getRow(TOTAL_ROW + 2); + String formula = "H"+ (TOTAL_ROW + 2) +" *" + exchangeRate; Cell dollarCell = dollarRow.createCell(7); // column H CellStyle cellStyle = factory.getWorkbook().createCellStyle(); DataFormat format = factory.getWorkbook().createDataFormat(); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IPurchaseOrderService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IPurchaseOrderService.java index fe08f6179..3409dbd67 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IPurchaseOrderService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IPurchaseOrderService.java @@ -107,7 +107,7 @@ public interface IPurchaseOrderService extends IService { * @throws IOException IO error while reading the file. */ InvoiceMetaData makeInvoice(String purchaseID) throws IOException, URISyntaxException, UserException; - InvoiceMetaData makeInvoiceTest(int nbOfLines) throws IOException, URISyntaxException, UserException; + InvoiceMetaData makeInvoiceTest(int nbOfLines) throws Exception; byte[] getInvoiceByte(String invoiceCode) throws IOException; diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java index 1ee5ab4cd..0c061ed31 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/PlatformOrderShippingInvoiceService.java @@ -988,6 +988,7 @@ public class PlatformOrderShippingInvoiceService { public InvoiceMetaData makeCompleteInvoiceTest(int nbOfLines) throws Exception { // Creates invoice by factory Client client = clientService.getClientBySku("TEST"); + client.setCurrency("USD"); Map> ordersToContent = new HashMap<>(); List savRefunds = new ArrayList<>(); List extraFees = new ArrayList<>(); @@ -1025,8 +1026,11 @@ public class PlatformOrderShippingInvoiceService { CompleteInvoice invoice = new CompleteInvoice(client, invoiceCode, "Test subject", ordersToContent, savRefunds, extraFees, purchaseInvoiceEntries, promotionDetails, exchangeRate); Path src; -// src = Paths.get(COMPLETE_INVOICE_TEMPLATE_US); - src = Paths.get(COMPLETE_INVOICE_TEMPLATE_EU); + if(client.getCurrency().equals("USD")) { + src = Paths.get(COMPLETE_INVOICE_TEMPLATE_US); + } else { + src = Paths.get(COMPLETE_INVOICE_TEMPLATE_EU); + } // Writes invoice content to a new excel file String filename = "Complete invoice N°" + invoice.code() + " (" + invoice.client().getInvoiceEntity() + ") _" + nbOfLines + ".xlsx"; @@ -1060,6 +1064,7 @@ public class PlatformOrderShippingInvoiceService { int maxRow = cells.getMaxDataRow(); PageSetup pageSetup = sheet.getPageSetup(); // Setting the number of pages to which the length of the worksheet will + System.out.println("maxRow : " + maxRow); if(maxRow < 63) { // be spanned pageSetup.setFitToPagesTall(1); @@ -1067,6 +1072,10 @@ public class PlatformOrderShippingInvoiceService { // Setting the number of pages to which the width of the worksheet will be spanned pageSetup.setFitToPagesWide(1); } + else { + pageSetup.setFitToPagesTall((int) Math.ceil((double) maxRow /63)); + pageSetup.setFitToPagesWide(1); + } // On enregistre le document au format PDF workbook.save(pdfFilePath, saveOptions); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/purchase/PurchaseOrderServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/purchase/PurchaseOrderServiceImpl.java index ed64067dc..c952dadd4 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/purchase/PurchaseOrderServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/purchase/PurchaseOrderServiceImpl.java @@ -60,9 +60,7 @@ public class PurchaseOrderServiceImpl extends ServiceImpl purchaseOrderSkuList = new ArrayList<>(); // -5 because we have at least 5 lines of promotions @@ -570,7 +568,7 @@ public class PurchaseOrderServiceImpl extends ServiceImpl