zss
20 小时以前 451acd4ad80af35a0dfcfa950170b1d8c915615c
src/main/resources/mapper/purchase/PurchaseReturnOrdersMapper.xml
@@ -80,9 +80,12 @@
    <select id="getByPurchaseLedgerId" resultType="com.ruoyi.purchase.vo.PurchaseStockInProductVo">
         SELECT
            sir.id,
            sir.product_model_id,
            slp.id saleLedgerProductId,
            slp.product_category,
            slp.specification_model,
            slp.unit,
            slp.is_checked,
            sir.inbound_batches,
            sir.stock_in_num,
            sir.batch_no,
@@ -93,7 +96,7 @@
            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.product_id
            LEFT JOIN sales_ledger_product slp ON pl.id = slp.sales_ledger_id
            LEFT JOIN (
                SELECT
                    stock_in_record_id,
@@ -107,4 +110,32 @@
        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>