| | |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="supplierTransactions" resultType="com.ruoyi.purchase.vo.SupplierTransactionsVo"> |
| | | select T1.supplier_id, |
| | | SELECT T1.supplier_id, |
| | | sm.supplier_name, |
| | | T1.contractAmounts, |
| | | IFNULL(T2.paymentAmount, 0) AS paymentAmount, |
| | | IFNULL(T3.InboundAmount, 0) - IFNULL(T4.returnAmount, 0) AS payableAmount |
| | | from (select supplier_id, sum(contract_amount) as contractAmounts from purchase_ledger group by supplier_id) T1 |
| | | left join (select supplier_id, sum(payment_amount) as paymentAmount from account_purchase_payment group by supplier_id) T2 on T1.supplier_id = T2.supplier_id |
| | | left join ( |
| | | SELECT |
| | | pl.supplier_id, |
| | | sum(sir.stock_in_num * slp.tax_inclusive_unit_price) AS InboundAmount |
| | | FROM stock_in_record sir |
| | | -- 10 类型才关联质检表 |
| | | LEFT JOIN quality_inspect qi ON sir.record_type = 10 AND sir.record_id = qi.id |
| | | -- 动态关联采购(自动适配 7 和 10) |
| | | LEFT JOIN purchase_ledger pl |
| | | ON pl.id = IF(sir.record_type = 7, sir.record_id, qi.purchase_ledger_id) |
| | | -- 产品关联不动 |
| | | LEFT JOIN sales_ledger_product slp ON pl.id = slp.sales_ledger_id |
| | | -- 条件 |
| | | WHERE sir.approval_status = 1 AND slp.type = 2 |
| | | AND sir.record_type IN ('7','10') |
| | | group by pl.supplier_id |
| | | ) T3 on T3.supplier_id=T1.supplier_id |
| | | left join ( |
| | | select |
| | | supplier_id, |
| | | sum(total_amount) as returnAmount |
| | | from purchase_return_orders pro |
| | | group by supplier_id |
| | | ) T4 on T4.supplier_id=T1.supplier_id |
| | | left join supplier_manage sm on T1.supplier_id = sm.id |
| | | IFNULL(T3.InboundAmount, 0) AS shippedAmount, |
| | | T1.contractAmounts - IFNULL(T3.InboundAmount, 0) AS unshippedAmount |
| | | FROM (SELECT supplier_id, SUM(contract_amount) AS contractAmounts FROM purchase_ledger GROUP BY supplier_id) T1 |
| | | LEFT JOIN ( |
| | | SELECT t.supplier_id, |
| | | SUM(t.inbound_amount) AS InboundAmount |
| | | FROM ( |
| | | SELECT sir.stock_in_num * slp.tax_inclusive_unit_price AS inbound_amount, pl.supplier_id |
| | | FROM stock_in_record sir |
| | | INNER JOIN sales_ledger_product slp ON slp.id = sir.record_id |
| | | INNER JOIN purchase_ledger pl ON pl.id = slp.sales_ledger_id |
| | | WHERE sir.approval_status = 1 AND sir.record_type = 7 AND slp.type = 2 |
| | | UNION ALL |
| | | SELECT |
| | | sir.stock_in_num * slp_agg.tax_inclusive_unit_price AS inbound_amount, |
| | | pl2.supplier_id |
| | | FROM stock_in_record sir |
| | | INNER JOIN quality_inspect qi |
| | | ON qi.id = sir.record_id |
| | | INNER JOIN purchase_ledger pl2 |
| | | ON pl2.id = qi.purchase_ledger_id |
| | | INNER JOIN ( |
| | | SELECT |
| | | sales_ledger_id, |
| | | product_model_id, |
| | | MIN(tax_inclusive_unit_price) AS tax_inclusive_unit_price |
| | | FROM sales_ledger_product |
| | | WHERE type = 2 |
| | | GROUP BY sales_ledger_id, product_model_id |
| | | ) slp_agg |
| | | ON slp_agg.sales_ledger_id = pl2.id |
| | | AND slp_agg.product_model_id = sir.product_model_id |
| | | WHERE sir.approval_status = 1 AND sir.record_type = 10 |
| | | ) t |
| | | GROUP BY t.supplier_id |
| | | ) T3 ON T3.supplier_id = T1.supplier_id |
| | | LEFT JOIN supplier_manage sm ON T1.supplier_id = sm.id |
| | | <where> |
| | | <if test="supplierName!=null and supplierName!=''"> |
| | | AND sm.supplier_name LIKE CONCAT('%',#{supplierName},'%') |
| | |
| | | </where> |
| | | order by T1.supplier_id desc |
| | | </select> |
| | | |
| | | <select id="supplierTransactionsDetails" |
| | | resultType="com.ruoyi.purchase.vo.SupplierTransactionsDetailsVo"> |
| | | select pl.id purchaseLedgerId, |
| | | SELECT pl.id purchaseLedgerId, |
| | | pl.purchase_contract_number, |
| | | pl.execution_date, |
| | | pl.contract_amount, |