where mob.purchase_order_id = mpo.purchase_order_id
and mob.safe_flag = '0') bound_amount,
(select ifnull(sum(mob.bind_amount), 0)
from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id
and sale_order_id = #{saleOrderId}
and mob.safe_flag = '0') sale_bind_amount,
(select ifnull(sum(bind_amount), 0)
from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id
and mob.safe_flag = '1') safe_amount,
(select ifnull(sum(mob.barcode_amount), 0)
from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id
and mob.safe_flag = '1') barcode_amount
from mes_purchase_order mpo
from mes_purchase_order mpo
left join mes_base_material_info mbmi on mbmi.material_id = mpo.material_id
left join mes_base_material_info mbmi on mbmi.material_id = mpo.material_id
<where>
<where>
not exists(select 1 from mes_order_bind o where o.purchase_order_id = mpo.purchase_order_id and o.sale_order_id = #{saleOrderId})
<iftest="poNo != null and poNo != ''"> and mpo.po_no = #{poNo}</if>
<iftest="poNo != null and poNo != ''"> and mpo.po_no = #{poNo}</if>
<iftest="materialCode != null and materialCode != ''"> and mpo.material_code = #{materialCode}</if>
<iftest="materialCode != null and materialCode != ''"> and mpo.material_code = #{materialCode}</if>
<iftest="materialName != null and materialName != ''"> and mpo.material_name like concat('%', #{materialName}, '%')</if>
<iftest="materialName != null and materialName != ''"> and mpo.material_name like concat('%', #{materialName}, '%')</if>
<iftest="specificationParameter != null and specificationParameter != ''"> and mpo.specification_parameter like concat('%', #{specificationParameter}, '%')</if>