| | |
| | | AND T1.is_white = #{supplierManageDto.isWhite} |
| | | </if> |
| | | </where> |
| | | order by T1.id desc |
| | | </select> |
| | | |
| | | <select id="supplierExportList" resultType="com.ruoyi.basic.excel.SupplierManageExcelDto"> |
| | |
| | | AND sm.supplier_name LIKE CONCAT('%',#{supplierName},'%') |
| | | </if> |
| | | </where> |
| | | order by T1.supplier_id desc |
| | | </select> |
| | | |
| | | <select id="supplierTransactionsDetails" |
| | |
| | | pl.purchase_contract_number, |
| | | pl.execution_date, |
| | | pl.contract_amount, |
| | | IFNULL(T2.InboundAmount, 0) AS shippedAmount, |
| | | pl.contract_amount - IFNULL(T2.InboundAmount, 0) AS unshippedAmount |
| | | FROM purchase_ledger pl |
| | | LEFT JOIN ( |
| | | SELECT t.sales_ledger_id, |
| | | SUM(t.inbound_amount) AS InboundAmount |
| | | FROM ( |
| | | SELECT sir.stock_in_num * slp.tax_inclusive_unit_price AS inbound_amount, slp.sales_ledger_id |
| | | FROM stock_in_record sir |
| | | INNER JOIN sales_ledger_product slp ON slp.id = sir.record_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, |
| | | slp_agg.sales_ledger_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.sales_ledger_id |
| | | ) T2 ON T2.sales_ledger_id = pl.id |
| | | WHERE pl.supplier_id = #{supplierId} |
| | | IFNULL(T1.paymentAmount, 0) AS paymentAmount, |
| | | IFNULL(T2.InboundAmount, 0) - IFNULL(T3.returnAmount, 0) AS payableAmount |
| | | from purchase_ledger pl |
| | | left join ( |
| | | select |
| | | pl.id, |
| | | sum(app.payment_amount) as paymentAmount |
| | | from account_purchase_payment app |
| | | left join account_payment_application apa on app.account_payment_application_id = apa.id |
| | | left join stock_in_record sir on FIND_IN_SET(sir.id, apa.stock_in_record_ids) > 0 |
| | | -- 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) |
| | | WHERE sir.approval_status = 1 |
| | | AND sir.record_type IN ('7','10') |
| | | group by pl.id |
| | | )T1 on T1.id = pl.id |
| | | left join ( |
| | | SELECT |
| | | pl.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.id |
| | | )T2 on T2.id = pl.id |
| | | left join ( |
| | | select pl.id, |
| | | sum(pro.total_amount) as returnAmount |
| | | from purchase_return_orders pro |
| | | left join purchase_ledger pl on pro.purchase_ledger_id = pl.id |
| | | group by pl.id |
| | | )T3 on T3.id = pl.id |
| | | where pl.supplier_id = #{supplierId} |
| | | order by pl.id desc |
| | | </select> |
| | | |
| | | </mapper> |