From 6be17495cd29ba8b28af35da7ba171cbc0d61c21 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 12 六月 2026 14:18:49 +0800
Subject: [PATCH] 根据单个员工计算工资
---
src/main/resources/mapper/sales/SalesLedgerProductMapper.xml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
index e2e6277..f9a5d1a 100644
--- a/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -14,11 +14,14 @@
T1.tax_rate,
T1.tax_inclusive_unit_price,
T1.tax_inclusive_total_price,
+ T1.freight_unit_price,
+ T1.total_freight,
T1.tax_exclusive_total_price,
T1.invoice_type,
T1.type,
T1.product_id,
T1.product_model_id,
+ T1.stock_type,
T1.register,
T1.register_date,
T1.approve_status,
@@ -30,7 +33,12 @@
pm.model as specification_model,
pm.unit as unit,
CASE
- WHEN (IFNULL(t2.qualitity, 0) - IFNULL(t2.locked_quantity, 0)) >0 THEN 1
+ WHEN IFNULL(
+ CASE
+ WHEN T1.stock_type = 'waste' THEN t2.waste_available_quantity
+ ELSE t2.qualified_available_quantity
+ END, 0
+ ) >= (IFNULL(T1.quantity, 0) - IFNULL(t3.shipped_quantity, 0)) THEN 1
ELSE 0
END as has_sufficient_stock,
(IFNULL(T1.quantity, 0) - IFNULL(t3.shipped_quantity, 0)) as no_quantity,
@@ -50,9 +58,47 @@
FROM
sales_ledger_product T1
LEFT JOIN (
- SELECT product_model_id, SUM(qualitity) as qualitity, SUM(locked_quantity) as locked_quantity
- FROM stock_inventory
- GROUP BY product_model_id
+ SELECT
+ t.product_model_id,
+ SUM(t.qualified_available_quantity) as qualified_available_quantity,
+ SUM(t.waste_available_quantity) as waste_available_quantity
+ FROM (
+ SELECT
+ si.product_model_id,
+ (IFNULL(si.qualitity, 0) - IFNULL(si.locked_quantity, 0) - IFNULL((
+ SELECT SUM(sor.stock_out_num)
+ FROM stock_out_record sor
+ WHERE sor.product_model_id = si.product_model_id
+ AND (
+ (si.batch_no IS NULL AND sor.batch_no IS NULL)
+ OR si.batch_no = sor.batch_no
+ )
+ AND sor.type = '0'
+ AND sor.approval_status IN (0, 3)
+ ), 0)) as qualified_available_quantity,
+ 0 as waste_available_quantity
+ FROM stock_inventory si
+
+ UNION ALL
+
+ SELECT
+ su.product_model_id,
+ 0 as qualified_available_quantity,
+ (IFNULL(su.qualitity, 0) - IFNULL(su.locked_quantity, 0) - IFNULL((
+ SELECT SUM(sor.stock_out_num)
+ FROM stock_out_record sor
+ WHERE sor.product_model_id = su.product_model_id
+ AND (
+ (su.batch_no IS NULL AND sor.batch_no IS NULL)
+ OR su.batch_no = sor.batch_no
+ )
+ AND sor.type = '1'
+ AND sor.approval_status IN (0, 3)
+ ), 0)) as waste_available_quantity
+ FROM stock_uninventory su
+ WHERE COALESCE(su.type, 'unqualified') = 'waste'
+ ) t
+ GROUP BY t.product_model_id
) t2 ON T1.product_model_id = t2.product_model_id
LEFT JOIN (
SELECT sales_ledger_product_id, IFNULL(SUM(spd.quantity), 0) as shipped_quantity
--
Gitblit v1.9.3