diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java index 8d00bfb1d..b7d50b9be 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/CompleteInvoice.java @@ -1,11 +1,11 @@ package org.jeecg.modules.business.domain.shippingInvoice; -import org.jeecg.modules.business.domain.invoice.InvoiceStyleFactory; import org.jeecg.modules.business.domain.invoice.Row; import org.jeecg.modules.business.domain.purchase.invoice.PurchaseInvoiceEntry; import org.jeecg.modules.business.entity.Client; import org.jeecg.modules.business.entity.PlatformOrder; import org.jeecg.modules.business.entity.PlatformOrderContent; +import org.jeecg.modules.business.entity.SavRefundWithDetail; import org.jeecg.modules.business.vo.PromotionDetail; import java.math.BigDecimal; @@ -22,11 +22,11 @@ public class CompleteInvoice extends ShippingInvoice { private final List promotions; - public CompleteInvoice(Client targetClient, String code, - String subject, + public CompleteInvoice(Client targetClient, String code, String subject, Map> ordersToContent, - List purchaseInvoiceEntries, List promotions, BigDecimal exchangeRate) { - super(targetClient, code, subject, ordersToContent, null, exchangeRate); + List savRefunds, List purchaseInvoiceEntries, + List promotions, BigDecimal exchangeRate) { + super(targetClient, code, subject, ordersToContent, savRefunds, exchangeRate); this.purchaseInvoiceEntries = purchaseInvoiceEntries; this.promotions = promotions; } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java index 08c81e0d8..08565a398 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/shippingInvoice/ShippingInvoiceFactory.java @@ -109,17 +109,18 @@ public class ShippingInvoiceFactory { * * * @param customerId the customer id - * @param ordersIds the list of order IDs + * @param orderIds the list of order IDs * @return the generated invoice * @throws UserException if package used by the invoice can not or find more than 1 logistic * channel price, this exception will be thrown. */ @Transactional - public ShippingInvoice createShippingInvoice(String customerId, List ordersIds, String type, String start, String end) throws UserException { - log.info("Creating an invoice with arguments:\n client ID: {}, order IDs: {}]", customerId, ordersIds); + public ShippingInvoice createShippingInvoice(String customerId, List orderIds, String type, String start, String end) throws UserException { + log.info("Creating an invoice with arguments:\n client ID: {}, order IDs: {}]", customerId, orderIds); // find orders and their contents of the invoice - Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(ordersIds); + Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(orderIds); Set platformOrders = uninvoicedOrderToContent.keySet(); + List savRefunds = savRefundWithDetailService.findUnprocessedRefundsByClient(customerId); List shopIds = platformOrders.stream() .map(PlatformOrder::getShopId) .distinct() @@ -134,7 +135,7 @@ public class ShippingInvoiceFactory { subject = String.format("Shipping fees, order time from %s to %s", start, end); else throw new UserException("Couldn't create shipping invoice of unknown type."); - return createInvoice(customerId, shopIds, uninvoicedOrderToContent, null, subject, true); + return createInvoice(customerId, shopIds, uninvoicedOrderToContent, savRefunds, subject, true); } /** @@ -152,18 +153,19 @@ public class ShippingInvoiceFactory { * * @param username current username * @param customerId the customer id - * @param ordersIds the list of order IDs + * @param orderIds the list of order IDs * @param shippingMethod "post" = postShipping, "pre" = preShipping, "all" = all shipping methods * @return the generated invoice * @throws UserException if package used by the invoice can not or find more than 1 logistic * channel price, this exception will be thrown. */ @Transactional - public CompleteInvoice createCompleteShippingInvoice(String username, String customerId, List ordersIds, String shippingMethod, String start, String end) throws UserException { - log.info("Creating a complete invoice for \n client ID: {}, order IDs: {}]", customerId, ordersIds); + public CompleteInvoice createCompleteShippingInvoice(String username, String customerId, List orderIds, String shippingMethod, String start, String end) throws UserException { + log.info("Creating a complete invoice for \n client ID: {}, order IDs: {}]", customerId, orderIds); // find orders and their contents of the invoice - Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(ordersIds); + Map> uninvoicedOrderToContent = platformOrderService.fetchOrderData(orderIds); Set platformOrders = uninvoicedOrderToContent.keySet(); + List savRefunds = savRefundWithDetailService.findUnprocessedRefundsByClient(customerId); List shopIds = platformOrders.stream() .map(PlatformOrder::getShopId) .distinct() @@ -180,7 +182,7 @@ public class ShippingInvoiceFactory { subject = String.format("Purchase and Shipping fees, order time from %s to %s", start, end); else throw new UserException("Couldn't create complete invoice for unknown shipping method"); - return createInvoice(username, customerId, shopIds, uninvoicedOrderToContent, subject); + return createInvoice(username, customerId, shopIds, uninvoicedOrderToContent, savRefunds, subject); } @@ -200,6 +202,7 @@ public class ShippingInvoiceFactory { * @param username Current username * @param customerId Customer ID * @param shopIds Shop IDs + * @param savRefunds List of SAV refunds * @param subject Invoice subject * @return the generated invoice * @throws UserException if package used by the invoice can not or find more than 1 logistic @@ -208,7 +211,7 @@ public class ShippingInvoiceFactory { @Transactional public CompleteInvoice createInvoice(String username, String customerId, List shopIds, Map> orderAndContent, - String subject) throws UserException { + List savRefunds, String subject) throws UserException { Client client = clientMapper.selectById(customerId); log.info("User {} is creating a complete invoice for customer {}", username, client.getInternalCode()); @@ -243,10 +246,13 @@ public class ShippingInvoiceFactory { List purchaseOrderSkuList = purchaseOrderContentMapper.selectInvoiceDataByID(purchaseID); List promotionDetails = skuPromotionHistoryMapper.selectPromotionByPurchase(purchaseID); + if (savRefunds != null) { + updateSavRefundsInDb(savRefunds, invoiceCode); + } updateOrdersAndContentsInDb(orderAndContent); - return new CompleteInvoice(client, invoiceCode, subject, orderAndContent, + return new CompleteInvoice(client, invoiceCode, subject, orderAndContent, savRefunds, purchaseOrderSkuList, promotionDetails, eurToUsd); }