src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -55,11 +55,17 @@
        GROUP BY 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
        SELECT si.sales_ledger_product_id, IFNULL(SUM(spd.quantity), 0) as shipped_quantity
        FROM shipping_info si
        LEFT JOIN shipping_product_detail spd ON si.id = spd.shipping_info_id
        where si.status = '审核通过' OR si.status = '已发货'
        GROUP BY sales_ledger_product_id
        INNER JOIN shipping_product_detail spd ON si.id = spd.shipping_info_id
        WHERE si.status IN ('审核通过', '已发货')
          AND EXISTS (
            SELECT 1 FROM stock_out_record sor
            WHERE sor.record_id = si.id
              AND TRIM(sor.record_type) = '13'
              AND sor.approval_status = 1
          )
        GROUP BY si.sales_ledger_product_id
        ) t3 ON t3.sales_ledger_product_id = T1.id
        LEFT JOIN (
        SELECT rel.sales_ledger_product_id,
@@ -95,11 +101,17 @@
        GROUP BY rel.sales_ledger_product_id
        ) t4 ON t4.sales_ledger_product_id = T1.id
        LEFT JOIN (
        SELECT sales_ledger_product_id, IFNULL(SUM(spd.quantity), 0) as pending_approval_quantity
        SELECT si.sales_ledger_product_id, IFNULL(SUM(spd.quantity), 0) as pending_approval_quantity
        FROM shipping_info si
        LEFT JOIN shipping_product_detail spd ON si.id = spd.shipping_info_id
        WHERE si.status IN ('待审核', '审核中')
        GROUP BY sales_ledger_product_id
           OR (si.status = '审核通过' AND NOT EXISTS (
                SELECT 1 FROM stock_out_record sor
                WHERE sor.record_id = si.id
                  AND TRIM(sor.record_type) = '13'
                  AND sor.approval_status = 1
           ))
        GROUP BY si.sales_ledger_product_id
        ) t5 ON t5.sales_ledger_product_id = T1.id
        left join product_model pm ON T1.product_model_id = pm.id
        left join product p ON pm.product_id = p.id