| | |
| | | <include refid="getPurchaseReturnOrderHasAllInfoFormAndColumn"/> |
| | | where pro.id = #{id} |
| | | </select> |
| | | <select id="listPageAccountPurchaseReturn" |
| | | resultType="com.ruoyi.account.bean.vo.PurchaseReturnVo"> |
| | | select pro.id, |
| | | pro.no returnNo, |
| | | t.inboundBatches, |
| | | sm.supplier_name, |
| | | pro.prepared_at, |
| | | pro.total_amount, |
| | | CASE pro.return_type WHEN 0 THEN '退货退款' WHEN 1 THEN '拒收' END AS returnType, |
| | | pl.purchase_contract_number |
| | | from purchase_return_orders pro |
| | | left join |
| | | (select prop.purchase_return_order_id, |
| | | GROUP_CONCAT(sir.inbound_batches SEPARATOR ',') AS inboundBatches |
| | | from purchase_return_order_products prop |
| | | left join stock_in_record sir on prop.stock_in_record_id = sir.id |
| | | GROUP BY prop.purchase_return_order_id) t on t.purchase_return_order_id = pro.id |
| | | left join supplier_manage sm on pro.supplier_id = sm.id |
| | | left join purchase_ledger pl on pro.purchase_ledger_id = pl.id |
| | | where 1=1 |
| | | <if test="req.returnNo != null and req.returnNo != ''"> |
| | | and pro.no like concat('%',#{req.returnNo},'%') |
| | | </if> |
| | | <if test="req.supplierName != null and req.supplierName != ''"> |
| | | and sm.supplier_name like concat('%',#{req.supplierName},'%') |
| | | </if> |
| | | <if test="req.startDate != null and req.endDate != null"> |
| | | AND DATE_FORMAT(pro.prepared_at, '%Y-%m-%d') BETWEEN #{req.startDate} AND #{req.endDate} |
| | | </if> |
| | | order by pro.id DESC |
| | | </select> |
| | | <select id="getByPurchaseLedgerId" resultType="com.ruoyi.purchase.vo.PurchaseStockInProductVo"> |
| | | SELECT |
| | | sir.id, |
| | | sir.product_model_id, |
| | | slp.id salesLedgerProductId, |
| | | slp.product_category, |
| | | slp.specification_model, |
| | | slp.unit, |
| | | slp.is_checked, |
| | | sir.inbound_batches, |
| | | sir.stock_in_num, |
| | | sir.batch_no, |
| | | slp.tax_inclusive_unit_price, |
| | | GREATEST(sir.stock_in_num - COALESCE(rs.total_return_num, 0), 0) AS un_quantity, |
| | | COALESCE(rs.total_return_num, 0) AS total_return_num |
| | | FROM stock_in_record sir |
| | | LEFT JOIN quality_inspect qi ON sir.record_type = 10 AND sir.record_id = qi.id |
| | | 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 |
| | | LEFT JOIN ( |
| | | SELECT |
| | | stock_in_record_id, |
| | | SUM(return_quantity) AS total_return_num |
| | | FROM purchase_return_order_products prop |
| | | left join purchase_return_orders pro on pro.id = prop.purchase_return_order_id |
| | | WHERE 1=1 |
| | | GROUP BY stock_in_record_id |
| | | ) rs ON rs.stock_in_record_id = sir.id |
| | | WHERE sir.approval_status = 1 AND slp.type = 2 |
| | | AND sir.record_type IN ('7','10') |
| | | and pl.id = #{purchaseLedgerId} |
| | | </select> |
| | | <select id="getPurchaseReturnOrderProductsDetailById" |
| | | resultType="com.ruoyi.purchase.vo.PurchaseReturnOrderProductsDetailVo"> |
| | | select prop.id, |
| | | prop.sales_ledger_product_id, |
| | | slp.product_model_id, |
| | | slp.product_category, |
| | | slp.specification_model, |
| | | slp.is_checked, |
| | | slp.unit, |
| | | sir.inbound_batches, |
| | | sir.stock_in_num, |
| | | sir.batch_no, |
| | | slp.tax_inclusive_unit_price, |
| | | prop.return_quantity, |
| | | prop.purchase_return_order_id, |
| | | GREATEST(sir.stock_in_num - COALESCE(prop.return_quantity, 0), 0) AS un_quantity, |
| | | COALESCE(rs.total_return_num, 0) AS total_return_num |
| | | from purchase_return_order_products prop |
| | | left join purchase_return_orders pro on prop.purchase_return_order_id = pro.id |
| | | LEFT JOIN stock_in_record sir ON prop.stock_in_record_id = sir.id and sir.record_type in ('7','10') |
| | | LEFT JOIN sales_ledger_product slp ON prop.sales_ledger_product_id = slp.id and slp.type = 2 |
| | | LEFT JOIN (SELECT stock_in_record_id, |
| | | SUM(return_quantity) AS total_return_num |
| | | FROM purchase_return_order_products |
| | | WHERE 1 = 1 and purchase_return_order_id = #{id} |
| | | GROUP BY stock_in_record_id) rs ON rs.stock_in_record_id = sir.id |
| | | where pro.id = #{id} |
| | | </select> |
| | | </mapper> |