out_id, out_no, out_type, from_id, from_no, org_id, staff_id, cus_id, sup_id, out_status, sys.f_remove_zero(outing_qty) as outing_qty, outing_amt, sys.f_remove_zero(out_qty) as out_qty, out_amt, sys.f_remove_zero(return_qty) as return_qty, return_amt, out_date, remarks, annex_paths, make_staff, make_time, receivable_id, flg_valid, cp_id,out_reason,flg_auto_handle,flg_handle_setting tpo.out_id, tpo.out_no, tpo.out_type, tpo.from_id, tpo.from_no, tpo.org_id, tpo.staff_id, tpo.cus_id, tpo.sup_id, tpo.out_status, sys.f_remove_zero(tpo.outing_qty) as outing_qty, tpo.outing_amt, sys.f_remove_zero(tpo.out_qty) as out_qty, tpo.out_amt, sys.f_remove_zero(tpo.return_qty) as return_qty, tpo.return_amt, tpo.out_date, tpo.remarks, tpo.annex_paths, tpo.make_staff, tpo.make_time, tpo.receivable_id, tpo.flg_valid, tpo.cp_id,tpo.out_reason, tpo.flg_auto_handle,tpo.flg_handle_setting AND t.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%') AND t.out_type = #{outType} AND t.out_type =any(#{outTypeList,typeHandler=StringListTypeHandler}) AND t.out_reason =any(#{outReasonList,typeHandler=UuidListTypeHandler}) AND ( t.out_no LIKE concat('%',my_ex.likequery(#{searchText}),'%') or t.from_no LIKE concat('%',my_ex.likequery(#{searchText}),'%') or tmc.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%') or tmc.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%') or tmo.org_name LIKE concat('%',my_ex.likequery(#{searchText}),'%') or tmp.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%') or tms.staff_name LIKE concat('%',my_ex.likequery(#{searchText}),'%') ) AND tmo.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%') AND tmc.address_full LIKE concat('%',my_ex.likequery(#{addressFull}),'%') AND t.staff_id = any(#{staffIds, typeHandler=uuidListTypeHandler}) AND t.org_id = any(#{orgIds, typeHandler=uuidListTypeHandler}) AND tmp.sup_name LIKE concat('%',my_ex.likequery(#{supName}),'%') AND tms.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%') AND t.from_id = #{fromId}::uuid AND t.from_no = #{fromNo} AND t.org_id = #{orgId} AND t.staff_id = #{staffId} AND t.cus_id = #{cusId}::uuid AND t.sup_id = #{supId} AND t.out_status = #{outStatus} AND t.outing_qty = #{outingQty} AND t.outing_amt = #{outingAmt} AND t.out_qty = #{outQty} AND t.out_amt = #{outAmt} AND t.return_qty = #{returnQty} AND t.return_amt = #{returnAmt} AND t.remarks = #{remarks} AND t.annex_paths = #{annexPaths} AND t.make_staff = #{makeStaff} AND t.receivable_id = #{receivableId} AND t.cp_id = #{cpId} AND t.from_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%') AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%') AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%') AND t.org_id =any(#{orgIds, typeHandler=uuidListTypeHandler}) AND t.staff_id =any(#{staffIds, typeHandler=uuidListTypeHandler}) AND t.out_status =any(#{outStatusList, typeHandler=StringListTypeHandler}) AND t.out_date >= #{outDateStart}::timestamp with time zone AND t.out_date < #{outDateEnd}::timestamp with time zone + interval '1 day' AND t.make_time >= #{makeTimeStart}::timestamp with time zone AND t.make_time < #{makeTimeEnd}::timestamp with time zone + interval '1 day' AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler}) AND t.flg_valid = true AND t.flg_valid = #{flgValid} AND tpoi.out_qty - tpoi.return_qty > 0 WHERE out_id in #{item} insert into dkic_b.t_psi_outbound ( out_no, out_type, from_id, from_no, org_id, staff_id, order_id, order_no, into_return_id, into_return_no, cus_id, sup_id, out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt, out_date, remarks, annex_paths, make_staff, make_time, receivable_id, cp_id, op_app_code, ) values ( #{item.outNo}, #{item.outType}, #{item.fromId}::uuid, #{item.fromNo}, #{item.orgId}::uuid, #{item.staffId}::uuid, #{item.cusId}::uuid, #{item.supId}::uuid, #{item.outStatus}, #{item.outingQty}, #{item.outingAmt}, #{item.outQty}, #{item.outAmt}, #{item.returnQty}, #{item.returnAmt}, #{item.outDate}, #{item.remarks}, #{item.annexPaths}, #{item.makeStaff}::uuid, #{item.makeTime}, #{item.receivableId}::uuid, #{item.cpId}, #{item.opAppCode}, ) update dkic_b.t_psi_outbound return_qty = return_qty + #{returnQty,jdbcType=NUMERIC}, return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC}, where out_id = #{outId,typeHandler=UuidTypeHandler} and out_qty >= return_qty tpo.out_id , tpo.out_no , tpo.out_type , tpo.from_id, tpo.from_no, tpo.org_id, tpo.staff_id, tpo.cus_id, tpo.sup_id, tpo.out_status, sys.f_remove_zero(tpo.outing_qty) as outing_qty , tpo.outing_amt, sys.f_remove_zero(tpo.out_qty) as out_qty , tpo.out_amt , sys.f_remove_zero(tpo.return_qty) as return_qty, tpo.return_amt, tpo.out_date , tpo.remarks, tpo.annex_paths, tpo.make_staff, tpo.make_time, tpo.out_reason, tpo.flg_valid, tpo.flg_auto_handle, tpo.flg_handle_setting, tpo.op_update_time tpi.into_id as out_id, tpi.into_no as out_no, tpi.into_type as out_type, tpi.from_id, tpi.from_no, tpi.org_id, tpi.staff_id, tpi.cus_id, tpi.sup_id, tpi.into_status as out_status , sys.f_remove_zero(tpi.intoing_qty) as outing_qty , tpi.intoing_amt as outing_amt , sys.f_remove_zero(tpi.into_qty) as out_qty , tpi.into_amt as out_amt, sys.f_remove_zero(tpi.return_qty) as return_qty, tpi.return_amt, tpi.into_date as out_date, tpi.remarks, tpi.annex_paths, tpi.make_staff, tpi.make_time, tpi.into_reason as out_reason, tpi.flg_valid, tpi.flg_auto_handle, tpi.flg_handle_setting, tpi.op_update_time Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpo.sup_id Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpo.make_staff LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpo.out_status LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpo.out_type left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpo.out_reason Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff LEFT JOIN sys.t_data_kind tdk ON tdk.kind_code = tpi.into_status LEFT JOIN sys.t_data_kind tdktype ON tdktype.kind_code = tpi.into_type left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason tpoi.item_id AS "list_item_id", tpoi.out_id AS "list_out_id", tpoi.sup_id AS "list_sup_id", t.out_no AS "list_out_no", tpoi.out_type AS "list_out_type", tpoi.from_id AS "list_from_id", tpoi.from_item_id AS "list_from_item_id", tpoi.item_index AS "list_item_index", tpoi.sku_id AS "list_sku_id", tpoi.price_out AS "list_price_out", tpoi.non_std_code AS "list_non_std_code", tpoi.out_status AS "list_out_status", sys.f_remove_zero(tpoi.outing_qty) AS "list_outing_qty", tpoi.outing_amt AS "list_outing_amt", sys.f_remove_zero(tpoi.out_qty) AS "list_out_qty", tpoi.out_amt AS "list_out_amt", sys.f_remove_zero(tpoi.return_qty) AS "list_return_qty", tpoi.return_amt AS "list_return_amt", tpoi.remarks AS "list_remarks", tpoi.inv_id AS "list_inv_id", tpoi.cost_price AS "list_cost_price", tpoi.cost_amt AS "list_cost_amt", tpoi.flg_valid AS "list_flg_valid", tpoi.cp_id AS "list_cp_id", tpoi.s_out_id AS "list_s_out_id", tpoi.s_out_item_id AS "list_s_out_item_id", tpoi.s_order_id AS "list_s_order_id", tpoi.s_order_item_id AS "list_s_order_item_id", tmgs.sku_code AS list_sku_code, tpoi.sku_model AS list_sku_model, tpoi.sku_name AS list_sku_name, tmgs.sku_spec AS list_sku_spec, tpoi.fact_price AS list_fact_price, tpoi.fact_amt AS list_fact_amt, case when tpoi.sku_id is null then '外协' else tmgb.brand_name end AS list_brand_name, tmgb.short_name AS list_short_name, tmgs.price_purchase AS list_price_purchase, tmgs.price_standard AS list_price_standard, tmgs.sku_images AS list_sku_images, tpity.wh_id AS list_wh_id, tmw.wh_name AS list_wh_name ,sys.f_remove_zero(tpi.inv_qty) as "list_invQty" ,sys.f_remove_zero(tpi.usable_qty) as "list_usableQty" ,tmgus.unit_name as "list_subUnitName" ,tmgu.unit_name as "list_unitName" ,tpoi.pack_box as "list_pack_box" ,tmgs.flg_sub_unit as "list_flgSubUnit" ,tpoi.outing_box as "list_outing_box" ,tpoi.outing_piece as "list_outing_piece" ,tpoi.out_box as "list_out_box" ,tpoi.out_piece as "list_out_piece" ,case when t.out_status = '出库状态-已出库' then dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tpoi.out_box,tpoi.out_piece) else dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tpoi.outing_box,tpoi.outing_piece) end as "list_pack_box_text" ,tmgu.decimal_places as "list_decimal_places"