| | |
| | | GROUP_CONCAT(sour.outbound_batches SEPARATOR ',') AS outboundBatches |
| | | from account_invoice_application aia |
| | | left join customer c on aia.customer_id = c.id |
| | | <!-- 手工发货单出库按 stock_out_record_ids 找,油品出库按绑定行 stock_out_binding_ids 反查所在的出库单 --> |
| | | left join stock_out_record sour on FIND_IN_SET(sour.id, aia.stock_out_record_ids) > 0 |
| | | OR EXISTS (select 1 from stock_out_record_sales_ledger b |
| | | where b.stock_out_record_id = sour.id |
| | | and FIND_IN_SET(b.id, aia.stock_out_binding_ids) > 0) |
| | | GROUP BY aia.id)A |
| | | <where> |
| | | <if test="req.customerId != null"> |
| | |
| | | </where> |
| | | order by A.id desc |
| | | </select> |
| | | <!-- 可开票的销售出库候选。 |
| | | ① record_type='13' 的手工发货单出库 → b.id 为 NULL,用 stock_out_record_ids 判重; |
| | | ② 油品出库(type 为空)按「出库单×客户」拆到绑定行 → 用 stock_out_binding_ids 判重。 |
| | | 两个 id 空间都是小整数,混在一列里会撞号,所以必须按 b.id 是否为空分开比。 --> |
| | | <select id="getOutboundBatchesByCustomer" |
| | | resultType="com.ruoyi.account.bean.vo.sales.SalesOutboundVo"> |
| | | SELECT |
| | | sor.id, |
| | | sor.outbound_batches, |
| | | sl.customer_name, |
| | | IFNULL(b.customer_name, sl.customer_name) AS customerName, |
| | | sor.create_time as shippingDate, |
| | | p.product_name, |
| | | pm.model as specification_model, |
| | | slp.tax_rate, |
| | | sor.stock_out_num * slp.tax_inclusive_unit_price as outboundAmount, |
| | | IFNULL(pb.product_name, p.product_name) AS productName, |
| | | IFNULL(pmb.model, pm.model) as specification_model, |
| | | IFNULL(slpb.tax_rate, slp.tax_rate) as tax_rate, |
| | | CASE |
| | | WHEN b.id IS NOT NULL THEN b.quantity * slpb.tax_inclusive_unit_price |
| | | ELSE sor.stock_out_num * slp.tax_inclusive_unit_price |
| | | END as outboundAmount, |
| | | s.shipping_no, |
| | | sl.sales_contract_no |
| | | IFNULL(slb.sales_contract_no, sl.sales_contract_no) as sales_contract_no, |
| | | b.id AS bindingId, |
| | | IFNULL(b.customer_id, sl.customer_id) AS customer_id |
| | | FROM stock_out_record sor |
| | | LEFT JOIN stock_out_record_sales_ledger b ON b.stock_out_record_id = sor.id |
| | | left join shipping_info s on sor.record_id = s.id |
| | | LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id |
| | | LEFT JOIN sales_ledger_product slp ON s.sales_ledger_product_id = slp.id and slp.type = 1 |
| | | LEFT JOIN sales_ledger slb ON slb.id = b.sales_ledger_id |
| | | LEFT JOIN sales_ledger_product slpb ON slpb.id = b.sales_ledger_product_id and slpb.type = 1 |
| | | left join product_model pm on slp.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | WHERE sor.record_type='13' and sor.approval_status=1 |
| | | and sl.customer_id=#{customerId} |
| | | |
| | | and sor.id NOT IN ( |
| | | SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(a.stock_out_record_ids, ',', n.n), ',', -1) |
| | | FROM account_invoice_application a |
| | | CROSS JOIN ( |
| | | SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL |
| | | SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 |
| | | ) n |
| | | WHERE n.n <= CHAR_LENGTH(a.stock_out_record_ids) - CHAR_LENGTH(REPLACE(a.stock_out_record_ids, ',', '')) + 1 |
| | | and a.status!=2 |
| | | left join product_model pmb on sor.product_model_id = pmb.id |
| | | left join product pb on pmb.product_id = pb.id |
| | | WHERE sor.approval_status=1 |
| | | AND ( |
| | | sor.record_type='13' |
| | | OR (b.id IS NOT NULL AND (sor.type IS NULL OR sor.type = '')) |
| | | ) |
| | | |
| | | order by sor.id DESC |
| | | AND IFNULL(b.customer_id, sl.customer_id) = #{customerId} |
| | | AND NOT EXISTS ( |
| | | SELECT 1 |
| | | FROM account_invoice_application a |
| | | WHERE a.status != 2 |
| | | AND ( |
| | | (b.id IS NULL AND FIND_IN_SET(sor.id, a.stock_out_record_ids) > 0) |
| | | OR (b.id IS NOT NULL AND FIND_IN_SET(b.id, a.stock_out_binding_ids) > 0) |
| | | ) |
| | | ) |
| | | order by sor.id DESC, IFNULL(b.id, 0) |
| | | </select> |
| | | <select id="existsByStockOutRecordId" resultType="java.lang.Boolean"> |
| | | SELECT COUNT(*) > 0 |
| | |
| | | AND ( |
| | | <foreach collection="stockOutRecordIds" item="id" separator=" OR "> |
| | | FIND_IN_SET(#{id}, stock_out_record_ids) > 0 |
| | | </foreach> |
| | | ) |
| | | </select> |
| | | <!-- 油品出库的绑定行与出库单是两个独立 id 空间,判重要分开查 --> |
| | | <select id="existsByStockOutBindingId" resultType="java.lang.Boolean"> |
| | | SELECT COUNT(*) > 0 |
| | | FROM account_invoice_application |
| | | WHERE status != 2 |
| | | AND ( |
| | | <foreach collection="stockOutBindingIds" item="id" separator=" OR "> |
| | | FIND_IN_SET(#{id}, stock_out_binding_ids) > 0 |
| | | </foreach> |
| | | ) |
| | | </select> |
| | |
| | | from account_invoice_application aia |
| | | left join customer c on aia.customer_id = c.id |
| | | left join stock_out_record sour on FIND_IN_SET(sour.id, aia.stock_out_record_ids) > 0 |
| | | OR EXISTS (select 1 from stock_out_record_sales_ledger b |
| | | where b.stock_out_record_id = sour.id |
| | | and FIND_IN_SET(b.id, aia.stock_out_binding_ids) > 0) |
| | | left join account_sales_invoice asi on aia.id = asi.account_invoice_application_id |
| | | GROUP BY aia.id |
| | | )A |