INSERT INTO trans_detail ( site, trans_no, item_no, part_no, trans_qty, batch_no, location_id, direction, wdr_no, eng_chg_level ) VALUES ( #{site}, #{transNo}, #{itemNo}, #{partNo}, #{transQty}, #{batchNo}, #{locationId}, #{direction}, #{wdrNo}, #{engChgLevel} ) INSERT INTO trans_detail_sub ( site, trans_no, item_no, seq_no, sub_no, sub_qty, direction, part_no, batch_no, location_id, eng_chg_level, order_ref1, order_ref3, order_ref4 ) VALUES ( #{site}, #{transNo}, #{itemNo}, #{seqNo}, #{subNo}, #{subQty}, #{direction}, #{partNo}, #{batchNo}, #{locationId}, #{engChgLevel}, #{orderRef1}, #{orderRef3}, #{orderRef4} ) UPDATE handling_unit SET qty = #{qty}, in_stock_flag = #{inStockFlag}, modified_by = #{username}, modified_date = GETDATE() WHERE site = #{site} AND unit_id = #{unitId} UPDATE count_result SET handle_flag = 'Y' WHERE id = #{countResultId} INSERT INTO inventory_stock ( site, warehouse_id, part_no, batch_no, location_id, wdr, eng_chg_level, in_qty, in_standard_value, in_actual_value, out_qty, qty_on_hand, qty_reserved, freeze_flag, first_in_date, latest_in_date, active_date ) VALUES ( #{site}, #{warehouseId}, #{partNo}, #{batchNo}, #{locationId}, #{wdr}, #{engChgLevel}, 0, 0, 0, 0, 0, 0, 'N', GETDATE(), GETDATE(), GETDATE() ) UPDATE inventory_stock SET out_qty = out_qty + #{reduceQty}, qty_on_hand = qty_on_hand - #{reduceQty}, latest_out_date = GETDATE() WHERE site = #{site} AND warehouse_id = #{warehouseId} AND part_no = #{partNo} AND (batch_no = #{batchNo} OR (batch_no IS NULL AND #{batchNo} IS NULL)) AND location_id = #{locationId} AND (wdr = #{wdr} OR (wdr IS NULL AND #{wdr} IS NULL)) AND (eng_chg_level = #{engChgLevel} OR (eng_chg_level IS NULL AND #{engChgLevel} IS NULL)) UPDATE inventory_stock SET in_qty = in_qty + #{addQty}, qty_on_hand = qty_on_hand + #{addQty}, latest_in_date = GETDATE() WHERE site = #{site} AND warehouse_id = #{warehouseId} AND part_no = #{partNo} AND (batch_no = #{batchNo} OR (batch_no IS NULL AND #{batchNo} IS NULL)) AND location_id = #{locationId} AND (wdr = #{wdr} OR (wdr IS NULL AND #{wdr} IS NULL)) AND (eng_chg_level = #{engChgLevel} OR (eng_chg_level IS NULL AND #{engChgLevel} IS NULL))