inv_id, wh_id, sku_id, non_std_code, inv_qty, outing_qty, usable_qty, cost_price, cost_amt, remarks, flg_valid, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user, freeze_qty
tpi.inv_id, tpi.wh_id, tpi.sku_id, tpi.non_std_code, tpi.inv_qty, tpi.outing_qty,
tpi.usable_qty, tpi.cost_price, tpi.cost_amt, tpi.remarks, tpi.flg_valid, tpi.cp_id,tpi.freeze_qty
AND tpi.wh_id = #{whId}::UUID
AND tpi.wh_id =
any(#{whIds, typeHandler=UuidListTypeHandler})
AND tpi.sku_id = #{skuId}
AND tpi.non_std_code = #{nonStdCode}
AND tpi.inv_qty = #{invQty}
AND tpi.outing_qty = #{outingQty}
AND tpi.usable_qty = #{usableQty}
AND tpi.cost_price = #{costPrice}
AND tpi.cost_amt = #{costAmt}
AND tpi.flg_valid = #{flgValid}
AND tpi.inv_qty != 0
AND tpi.cp_id = #{cpId}
AND tpi.freeze_qty = #{freezeQty}
AND tmgs.category_id = #{categoryId}::UUID
AND tmgs.brand_id = #{brandId}::UUID
AND (tmgs.sku_model like concat('%', my_ex.likequery(#{searchText}) , '%')
OR tmgs.sku_name like concat('%', my_ex.likequery(#{searchText}) , '%')
OR tpi.non_std_code like concat('%', my_ex.likequery(#{searchText}) , '%')
)
and tpi.inv_qty != 0
WHERE inv_id in
#{item}
left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpi.sku_id
left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
LEFT JOIN dkic_b.t_mst_unit tmu ON tmu.unit_id = tmgs.unit_id
LEFT JOIN dkic_b.t_mst_unit subtmu ON subtmu.unit_id = tmgs.sub_unit_id
left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
insert into dkic_b.t_psi_inventory
(
wh_id,
sku_id,
non_std_code,
inv_qty,
outing_qty,
usable_qty,
cost_price,
cost_amt,
remarks,
cp_id,
op_app_code,
freeze_qty,
)
values
(
#{item.whId}::uuid,
#{item.skuId}::uuid,
#{item.nonStdCode},
#{item.invQty},
#{item.outingQty},
#{item.usableQty},
#{item.costPrice},
#{item.costAmt},
#{item.remarks},
#{item.cpId},
#{item.opAppCode},
#{item.freezeQty},
)
update dkic_b.t_psi_inventory
inv_qty = inv_qty + #{invQty,jdbcType=NUMERIC},
usable_qty = (inv_qty + #{invQty,jdbcType=NUMERIC}) - outing_qty - freeze_qty,
cost_amt = 0,
cost_price = 0 ,
cost_amt = cost_amt + #{costAmt,jdbcType=NUMERIC},
cost_price = (cost_amt + #{costAmt,jdbcType=NUMERIC}) / (inv_qty + #{invQty,jdbcType=NUMERIC}) ,
where inv_id =#{invId,typeHandler=UuidTypeHandler}
and inv_qty + #{invQty,jdbcType=NUMERIC}>=0
and cost_amt + #{costAmt,jdbcType=NUMERIC}>=0
update dkic_b.t_psi_inventory
inv_qty = #{invQty,jdbcType=NUMERIC},
usable_qty = #{usableQty,jdbcType=NUMERIC},
cost_price = #{costPrice,jdbcType=NUMERIC},
cost_amt = #{costAmt,jdbcType=NUMERIC},
where inv_id =#{invId,typeHandler=UuidTypeHandler}
and #{invQty,jdbcType=NUMERIC}>=0
and #{costAmt,jdbcType=NUMERIC}>=0
DELETE
FROM dkic_b.t_psi_inventory
where inv_id = #{invId,typeHandler=UuidTypeHandler}
update dkic_b.t_psi_inventory
cost_price = #{costPrice,jdbcType=NUMERIC},
cost_amt = #{costAmt,jdbcType=NUMERIC},
where inv_id =#{invId,typeHandler=UuidTypeHandler}