You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: batch_update.rb
    path of file: ./repos/hitobito/app/domain/invoice
    
    the code of the file until where you have to start completion: # encoding: utf-8

#  Copyright (c) 2017, Jungwacht Blauring Schweiz. This file is part of
#  hitobito and licensed under the Affero General Public License version 3
#  or later. See the COPYING file at
    
  def call # rubocop:disable Metrics/MethodLength
    invoices.each do |invoice|
      next_state = compute_next_state(invoice)
      next if invalid?(invoice, next_state)

      Invoice.transaction do
        if invoice.update(state: next_state)
          track_state_change(invoice, next_state)
          handle_email(invoice) if send_email?
          create_reminder(invoice) if invoice.overdue?
        else
          result.track_model_error(invoice)
        end
      end
    end