Class: Finance::BankAccountsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/finance/bank_accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#assign_unlinked_transactionsObject



7
8
9
10
11
12
13
# File 'app/controllers/finance/bank_accounts_controller.rb', line 7

def assign_unlinked_transactions
  @bank_account = BankAccount.find(params[:id])
  count = @bank_account.assign_unlinked_transactions
  redirect_to (@bank_account), notice: t('.notice', count: count)
rescue StandardError => e
  redirect_to (@bank_account), alert: t('errors.general_msg', msg: e.message)
end

#importObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/finance/bank_accounts_controller.rb', line 15

def import
  @bank_account = BankAccount.find(params[:id])
  importer = @bank_account.find_connector

  if importer
    importer.load params[:state] && YAML.load(params[:state])

    ok = importer.import params[:controls]

    importer.finish if ok
    flash.notice = t('.notice', count: importer.count) if ok
    @auto_submit = importer.auto_submit
    @controls = importer.controls
    # TODO: encrypt state
    @state = YAML.dump importer.dump
  else
    ok = true
    flash.alert = t('.no_import_method')
  end

  needs_redirect = ok
rescue StandardError => e
  flash.alert = t('errors.general_msg', msg: e.message)
  needs_redirect = true
ensure
  return unless needs_redirect

  redirect_path = (@bank_account)
  if request.post?
    @js_redirect = redirect_path
  else
    redirect_to redirect_path
  end
end

#indexObject



2
3
4
5
# File 'app/controllers/finance/bank_accounts_controller.rb', line 2

def index
  @bank_accounts = BankAccount.order('name')
  redirect_to (@bank_accounts.first) if @bank_accounts.count == 1
end