From 3aa36013035a98c0f036be70900e309d3a35be0a Mon Sep 17 00:00:00 2001 From: Qiuyi LI Date: Mon, 7 Aug 2023 17:22:48 +0200 Subject: [PATCH] Feature: Add SAV refunds (separate sheet) to invoice detail export --- .../shippingInvoice/InvoiceController.java | 30 +++-- .../business/domain/excel/SheetManager.java | 103 +++++++++--------- .../PlatformOrderShippingInvoiceService.java | 50 ++++++++- 3 files changed, 119 insertions(+), 64 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 8d02eed09..999537abf 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 @@ -55,6 +55,8 @@ public class InvoiceController { @Autowired private ISavRefundService iSavRefundService; @Autowired + private ISavRefundWithDetailService savRefundWithDetailService; + @Autowired private IExchangeRatesService iExchangeRatesService; @Autowired private IQuartzJobService quartzJobService; @@ -98,14 +100,19 @@ public class InvoiceController { String warehouseString = String.join(",", warehouses); QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap()); LambdaQueryWrapper lambdaQueryWrapper = queryWrapper.lambda(); - if(type.equals("shipping")) - lambdaQueryWrapper.in(PlatformOrder::getErpStatus, OrderStatus.Shipped.getCode()); - else if(type.equals("pre-shipping")) - lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode())); - else if(type.equals("all")) - lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode(), OrderStatus.Shipped.getCode())); - else - return Result.error("Error 404 : page not found."); + switch (type) { + case "shipping": + lambdaQueryWrapper.in(PlatformOrder::getErpStatus, OrderStatus.Shipped.getCode()); + break; + case "pre-shipping": + lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode())); + break; + case "all": + lambdaQueryWrapper.in(PlatformOrder::getErpStatus, Arrays.asList(OrderStatus.Pending.getCode(), OrderStatus.Preparing.getCode(), OrderStatus.Shipped.getCode())); + break; + default: + return Result.error("Error 404 : page not found."); + } lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber); Page page = new Page<>(pageNo, pageSize); IPage pageList; @@ -262,6 +269,7 @@ public class InvoiceController { } else { log.info("Specified shop IDs : " + param.shopIDs()); lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs()); + lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber); if(param.getErpStatuses() != null) { log.info("Specified erpStatuses : " + param.getErpStatuses()); lambdaQueryWrapper.in(PlatformOrder::getErpStatus, param.getErpStatuses()); @@ -294,6 +302,7 @@ public class InvoiceController { } else { log.info("Specified shop IDs : " + param.shopIDs()); lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs()); + lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber); lambdaQueryWrapper.inSql(PlatformOrder::getId, "SELECT id FROM platform_order po WHERE po.erp_status = '3' AND po.shipping_time between '" + param.getStart() + "' AND '" + param.getEnd() + "'" ); // on récupère les résultats de la requete List orderID = platformOrderMapper.selectList(lambdaQueryWrapper); @@ -324,8 +333,9 @@ public class InvoiceController { @GetMapping(value = "/downloadInvoiceDetail") public byte[] downloadInvoiceDetail(@RequestParam("invoiceNumber") String invoiceNumber, @RequestParam("invoiceEntity") String invoiceEntity) throws IOException { - List res = shippingInvoiceService.getInvoiceDetail(invoiceNumber); - return shippingInvoiceService.exportToExcel(res, invoiceNumber, invoiceEntity); + List factureDetails = shippingInvoiceService.getInvoiceDetail(invoiceNumber); + List refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(invoiceNumber); + return shippingInvoiceService.exportToExcel(factureDetails, refunds, invoiceNumber, invoiceEntity); } @GetMapping(value = "/breakdown/byShop") diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java index edb934c69..8cd38daca 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/excel/SheetManager.java @@ -1,6 +1,6 @@ package org.jeecg.modules.business.domain.excel; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import lombok.Data; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -12,32 +12,35 @@ import java.nio.file.Path; import java.util.Date; /** - * Provide operation that manipulate Excel sheet driven by cursor. + * Provide operation that manipulates Excel sheet driven by cursor. * The cursor's position is in the (0, 0) at the beginning. */ +@Data public class SheetManager { + private final Workbook workbook; - private final Sheet sheet; + private final Sheet detailSheet; - private int row; + private final Sheet savSheet; - private int col; + private Sheet currentSheet; + + private int currentRow; + + private int currentCol; private int max_col; - private SheetManager(Workbook workbook, Sheet sheet) { + private SheetManager(Workbook workbook, Sheet detailSheet, Sheet savSheet) { this.workbook = workbook; - this.sheet = sheet; - row = 0; - col = 0; + this.detailSheet = detailSheet; + this.savSheet = savSheet; + this.currentRow = 0; + this.currentCol = 0; max_col = 10; } - public Workbook getWorkbook() { - return workbook; - } - /** * Create a manager for the first worksheet of an empty ".xlsx" Excel file. * The created worksheet named "sheet1". @@ -45,47 +48,44 @@ public class SheetManager { * @return the sheetManager instance. */ public static SheetManager createXLSX() { - return createXLSX("sheet1"); + return createXLSX("Détails", "SAV"); } /** * Same as {@code createXLSX()}, with customer sheet name. * - * @param name the customer sheet name + * @param detailSheetName Details sheet name + * @param savSheetName SAV sheet name * @return the sheetManager object. */ - public static SheetManager createXLSX(String name) { + public static SheetManager createXLSX(String detailSheetName, String savSheetName) { Workbook workbook = new XSSFWorkbook(); - Sheet sheet = workbook.createSheet(name); - return new SheetManager(workbook, sheet); + Sheet detailSheet = workbook.createSheet(detailSheetName); + Sheet savSheet = workbook.createSheet(savSheetName); + return new SheetManager(workbook, detailSheet, savSheet); } - /** - * Create a sheet manager for a sheet of a ".xls" Excel workbook. - * - * @param path path of the workbook. - * @param sheetIndex index of the sheet, begin from 0 - * @return the sheet manager object - * @throws IOException any error while opening the workbook. - */ - public static SheetManager readXLS(Path path, int sheetIndex) throws IOException { - FileInputStream fis = new FileInputStream(path.toFile()); - Workbook workbook = new HSSFWorkbook(fis); - return new SheetManager(workbook, workbook.getSheetAt(sheetIndex)); + public void startDetailsSheet() { + this.currentSheet = detailSheet; + } + + public void startSavSheet() { + this.currentSheet = savSheet; + this.currentRow = 0; + this.currentCol = 0; } /** * Same as {@code readXLS} but for ".xlsx" Excel workbook. * * @param path path of the workbook. - * @param sheetIndex index of the sheet, begin from 0 * @return the sheet manager object * @throws IOException any error while opening the workbook. */ - public static SheetManager readXLSX(Path path, int sheetIndex) throws IOException { + public static SheetManager readXLSX(Path path) throws IOException { FileInputStream fis = new FileInputStream(path.toFile()); Workbook workbook = new XSSFWorkbook(fis); - return new SheetManager(workbook, workbook.getSheetAt(sheetIndex)); + return new SheetManager(workbook, workbook.getSheetAt(0), workbook.getSheetAt(1)); } /** @@ -96,12 +96,12 @@ public class SheetManager { * @param col col index of the location */ public void go(int row, int col) { - this.row = row; + this.currentRow = row; _moveCol(col); } public void moveRow(int row) { - this.row = row; + this.currentRow = row; } public void moveCol(int col) { @@ -109,31 +109,31 @@ public class SheetManager { } public int row() { - return row; + return currentRow; } public int col() { - return col; + return currentCol; } /** - * Move cursor to the bottom cell. + * Move the cursor to the bottom cell. */ public void nextRow() { - this.row += 1; + this.currentRow += 1; } /** - * Move cursor to the left cell. + * Move the cursor to the left cell. */ public void nextCol() { - _moveCol(this.col + 1); + _moveCol(this.currentCol + 1); } /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote, if value is null then we will change the cell to a Blank cell. + * @param value the value to be written, if value is null then we will change the cell to a Blank cell. */ public void write(String value) { cell().setCellValue(value); @@ -142,7 +142,7 @@ public class SheetManager { /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote, if value is null then we will change the cell to a Blank cell. + * @param value the value to be written, if value is null then we will change the cell to a Blank cell. */ public void write(int value) { cell().setCellValue(value); @@ -151,7 +151,7 @@ public class SheetManager { /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote, if value is null then we will change the cell to a Blank cell. + * @param value the value to be written, if value is null then we will change the cell to a Blank cell. */ public void write(BigDecimal value) { cell().setCellValue(value.doubleValue()); @@ -160,7 +160,7 @@ public class SheetManager { /** * Write a value to the cell pointed by cursor. * - * @param value the value to be wrote + * @param value the value to be written */ public void write(Date value) { cell().setCellValue(value); @@ -202,7 +202,8 @@ public class SheetManager { public void export(Path target) throws IOException { /* adjust all cols' width before export */ for (int i = 0; i < max_col; i++) { - sheet.autoSizeColumn(i); + detailSheet.autoSizeColumn(i); + savSheet.autoSizeColumn(i); } FileOutputStream fos = new FileOutputStream(target.toFile()); workbook.write(fos); @@ -211,13 +212,13 @@ public class SheetManager { private Cell cell() { - Row row = sheet.getRow(this.row); + Row row = currentSheet.getRow(this.currentRow); if (row == null) { - row = sheet.createRow(this.row); + row = currentSheet.createRow(this.currentRow); } - Cell cell = row.getCell(col); + Cell cell = row.getCell(currentCol); if (cell == null) { - cell = row.createCell(col); + cell = row.createCell(currentCol); } return cell; } @@ -226,7 +227,7 @@ public class SheetManager { if (dst > max_col) { max_col = dst + 5; } - col = dst; + currentCol = dst; } 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 18878d0ec..3e788e6b6 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 @@ -9,6 +9,7 @@ import org.jeecg.modules.business.domain.shippingInvoice.CompleteInvoice; import org.jeecg.modules.business.domain.shippingInvoice.ShippingInvoice; import org.jeecg.modules.business.domain.shippingInvoice.ShippingInvoiceFactory; import org.jeecg.modules.business.entity.PlatformOrder; +import org.jeecg.modules.business.entity.SavRefundWithDetail; import org.jeecg.modules.business.mapper.*; import org.jeecg.modules.business.vo.*; import org.jetbrains.annotations.NotNull; @@ -23,6 +24,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; @@ -85,7 +87,7 @@ public class PlatformOrderShippingInvoiceService { @Value("${jeecg.path.shippingInvoiceDetailDir}") private String INVOICE_DETAIL_DIR; - private final static String[] titles = { + private final static String[] DETAILS_TITLES = { "Boutique", "N° de Mabang", "N° de commande", @@ -107,6 +109,16 @@ public class PlatformOrderShippingInvoiceService { "TVA", "N° de facture" }; + private final static String[] SAV_TITLES = { + "Boutique", + "N° de Mabang", + "N° de commande", + "Date du remboursement", + "Montant d'achat remboursé", + "Montant de livraison remboursé", + "Montant total du remboursement", + "N° de facture" + }; public Period getValidPeriod(List shopIDs) { Date begin = platformOrderMapper.findEarliestUninvoicedPlatformOrder(shopIDs); @@ -318,9 +330,10 @@ public class PlatformOrderShippingInvoiceService { return factureDetailMapper.selectList(queryWrapper); } - public byte[] exportToExcel(List details, String invoiceNumber, String invoiceEntity) throws IOException { + public byte[] exportToExcel(List details, List refunds, String invoiceNumber, String invoiceEntity) throws IOException { SheetManager sheetManager = SheetManager.createXLSX(); - for (String title : titles) { + sheetManager.startDetailsSheet(); + for (String title : DETAILS_TITLES) { sheetManager.write(title); sheetManager.nextCol(); } @@ -370,6 +383,37 @@ public class PlatformOrderShippingInvoiceService { sheetManager.moveCol(0); sheetManager.nextRow(); } + sheetManager.startSavSheet(); + for (String title : SAV_TITLES) { + sheetManager.write(title); + sheetManager.nextCol(); + } + sheetManager.moveCol(0); + sheetManager.nextRow(); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + for (SavRefundWithDetail refund : refunds) { + sheetManager.write(refund.getShopName()); + sheetManager.nextCol(); + sheetManager.write(refund.getMabangId()); + sheetManager.nextCol(); + sheetManager.write(refund.getPlatformOrderNumber()); + sheetManager.nextCol(); + sheetManager.write(sdf.format(refund.getRefundDate())); + sheetManager.nextCol(); + sheetManager.write(refund.getPurchaseRefundAmount()); + sheetManager.nextCol(); + sheetManager.write(refund.getShippingFee() + .add(refund.getFretFee()) + .add(refund.getVat()) + .add(refund.getServiceFee())); + sheetManager.nextCol(); + sheetManager.write(refund.getTotalRefundAmount()); + sheetManager.nextCol(); + sheetManager.write(refund.getInvoiceNumber()); + sheetManager.moveCol(0); + sheetManager.nextRow(); + } Path target = Paths.get(INVOICE_DETAIL_DIR, "Détail_calcul_de_facture_" + invoiceNumber + "_(" + invoiceEntity + ").xlsx"); int i = 2;