Merge pull request #176 from LQYBill/feat/complete-invoice-detail-download

download complete invoice details including purchase fee
pull/8547/head
Qiuyi LI 2025-06-30 15:21:11 +02:00 committed by GitHub
commit 172fdb3115
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,49 @@
CREATE OR REPLACE VIEW detail_de_facture_avec_frais_achat AS
SELECT
s.name AS `Boutique`,
po.platform_order_id AS `N° de Mabang`,
po.platform_order_number AS `N° de commande`,
po.tracking_number AS `N° de suivi`,
po.order_time AS `Date de commande`,
po.shipping_time AS `Date d'expédition`,
po.recipient AS `Nom de client`,
po.country AS `Pays`,
po.postcode AS `Code postal`,
JSON_ARRAYAGG(sku.erp_code) AS `SKU`,
JSON_ARRAYAGG(sku.en_name) AS `Nom produits`,
JSON_ARRAYAGG(poc.quantity) AS `Quantité`,
-- Calculate purchase fees, using the price from sku_price if purchase_fee is 0
COALESCE(SUM(
CASE
WHEN poc.purchase_fee = 0 THEN poc.quantity * COALESCE(
(
SELECT sp.price
FROM sku_price sp
WHERE sp.sku_id = poc.sku_id
AND sp.date <= po.order_time
ORDER BY sp.date DESC
LIMIT 1
), 0
)
ELSE poc.purchase_fee
END
), 0) AS `Frais d'achat`,
po.fret_fee AS `Frais de FRET`,
SUM(poc.shipping_fee) AS `Frais de livraison`,
(po.order_service_fee + SUM(poc.service_fee)) AS `Frais de service`,
(po.picking_fee + SUM(poc.picking_fee)) AS `Frais de préparation`,
po.packaging_material_fee AS `Frais de matériel d'emballage`,
COALESCE(po.insurance_fee, 0.00) AS `Frais d'assurance produits`,
SUM(poc.vat) AS `TVA`,
po.shipping_invoice_number AS `N° de facture`
FROM platform_order po
JOIN shop s ON po.shop_id = s.id
RIGHT JOIN platform_order_content poc ON po.id = poc.platform_order_id
JOIN sku ON poc.sku_id = sku.id
WHERE po.order_time > '2025-01-01'
AND shipping_invoice_number IS NOT NULL
AND poc.erp_status <> 5
GROUP BY po.id, s.name, po.order_time
ORDER BY s.name, po.order_time;

View File

@ -659,6 +659,15 @@ public class InvoiceController {
return shippingInvoiceService.exportToExcel(invoiceDetails, Collections.emptyList(), Collections.emptyList(), period, client.getInvoiceEntity(), client.getInternalCode());
}
@GetMapping(value = "/downloadCompleteInvoiceDetail")
public byte[] downloadCompleteInvoiceDetail(@RequestParam("invoiceNumber") String invoiceNumber, @RequestParam("invoiceEntity") String invoiceEntity, @RequestParam("internalCode") String internalCode) throws IOException {
List<FactureDetail> factureDetails = shippingInvoiceService.getInvoiceDetailWithPurchaseFee(invoiceNumber);
List<SavRefundWithDetail> refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(invoiceNumber);
List<ExtraFeeResult> extraFees = extraFeeService.findByInvoiceNumber(invoiceNumber);
String fileNameInfo = invoiceNumber + "_complete";
return shippingInvoiceService.exportToExcel(factureDetails, refunds, extraFees, fileNameInfo, invoiceEntity, internalCode);
}
/**
* Only downloads the inventory of skus that are in the invoice
* Whereas downloadInventory downloads the inventory of a list of skus for the client

View File

@ -10,5 +10,7 @@ import java.util.List;
@Repository
public interface FactureDetailMapper extends BaseMapper<FactureDetail> {
List<FactureDetail> getInvoiceDetailWithPurchaseFee(@Param("invoiceNumber") String invoiceNumber);
List<FactureDetail> selectByShopsAndPeriod(@Param("shopIds") List<String> shopIds, @Param("start") String startDate, @Param("end") String endDate, @Param("type") String type);
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.business.mapper.FactureDetailMapper">
<select id="getInvoiceDetailWithPurchaseFee" resultType="org.jeecg.modules.business.vo.FactureDetail">
SELECT * FROM detail_de_facture_avec_frais_achat
WHERE `N° de facture` = #{invoiceNumber}
</select>
<select id="selectByShopsAndPeriod" resultType="org.jeecg.modules.business.vo.FactureDetail">
WITH LatestPrices AS (
SELECT sp.sku_id, sp.price, sp.date

View File

@ -117,6 +117,8 @@ public class PlatformOrderShippingInvoiceService {
@Value("${jeecg.path.shippingInvoiceDetailDir}")
private String INVOICE_DETAIL_DIR;
@Value("${jeecg.path.shippingInvoiceDetailCompleteDir}")
private String INVOICE_DETAIL_COMPLETE_DIR;
@Value("${jeecg.path.shippingInvoicePdfDir}")
private String INVOICE_PDF_DIR;
@Value("${jeecg.path.shippingInvoiceDetailPdfDir}")
@ -388,6 +390,15 @@ public class PlatformOrderShippingInvoiceService {
return factureDetailMapper.selectList(queryWrapper);
}
public List<FactureDetail> getInvoiceDetailWithPurchaseFee(String invoiceNumber) {
QueryWrapper<FactureDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("`N° de facture`", invoiceNumber);
return factureDetailMapper.getInvoiceDetailWithPurchaseFee(invoiceNumber);
}
public List<FactureDetail> getInvoiceDetailByShopsAndPeriod(List<String> shopIds, String startDate, String endDate, String type) throws UserException {
if(!type.equals(String.valueOf(SHIPPING.getType())) && !type.equals(String.valueOf(COMPLETE.getType())))
throw new UserException("Invalid invoice type");
@ -505,7 +516,14 @@ public class PlatformOrderShippingInvoiceService {
sheetManager.moveCol(0);
sheetManager.nextRow();
}
String dir = Invoice.isInvoiceNumber(fileNameInfo) ? INVOICE_DETAIL_DIR : INVOICE_DETAIL_EXPORT_DIR;
String dir;
if (fileNameInfo.contains("complete")) {
dir = INVOICE_DETAIL_COMPLETE_DIR;
} else if (Invoice.isInvoiceNumber(fileNameInfo)) {
dir = INVOICE_DETAIL_DIR;
} else {
dir = INVOICE_DETAIL_EXPORT_DIR;
}
Path target = Paths.get(dir, internalCode + "_(" + invoiceEntity + ")_" + fileNameInfo + "_Détail_calcul_de_facture.xlsx");
int i = 2;
while (Files.exists(target)) {
@ -782,6 +800,10 @@ public class PlatformOrderShippingInvoiceService {
log.info("File asked is of type invoice detail");
pathList = getPath(INVOICE_DETAIL_DIR, invoiceNumber);
}
if (filetype.equals("completeDetail")) {
log.info("File asked is of type complete invoice detail");
pathList = getPath(INVOICE_DETAIL_COMPLETE_DIR, invoiceNumber);
}
if(filetype.equals("inventory")) {
log.info("File asked is of type inventory");
pathList = getPath(PURCHASE_INVENTORY_DIR, invoiceNumber);
@ -805,6 +827,14 @@ public class PlatformOrderShippingInvoiceService {
List<ExtraFeeResult> extraFees = extraFeeService.findByInvoiceNumber(invoiceNumber);
exportToExcel(details, refunds, extraFees, invoiceNumber, client.getInvoiceEntity(), client.getInternalCode());
pathList = getPath(INVOICE_DETAIL_DIR, invoiceNumber);
} else if (filetype.equals("completeDetail")) {
Client client = clientService.getClientFromInvoice(invoiceNumber);
List<FactureDetail> details = getInvoiceDetailWithPurchaseFee(invoiceNumber);
List<SavRefundWithDetail> refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(invoiceNumber);
List<ExtraFeeResult> extraFees = extraFeeService.findByInvoiceNumber(invoiceNumber);
String fileNameInfo = invoiceNumber + "_complete";
exportToExcel(details, refunds, extraFees, fileNameInfo, client.getInvoiceEntity(), client.getInternalCode());
pathList = getPath(INVOICE_DETAIL_COMPLETE_DIR, invoiceNumber);
} else if (filetype.equals("inventory")) {
InvoiceMetaData metaData = purchaseOrderService.getMetaDataFromInvoiceNumbers(invoiceNumber);
List<SkuOrderPage> skuOrderPages = skuService.getInventoryByInvoiceNumber(metaData.getInvoiceCode());