2018-09-14 19:33:27 +02:00
|
|
|
class Finance::BankAccountsController < Finance::BaseController
|
|
|
|
def index
|
|
|
|
@bank_accounts = BankAccount.order('name')
|
|
|
|
redirect_to finance_bank_account_transactions_url(@bank_accounts.first) if @bank_accounts.count == 1
|
|
|
|
end
|
|
|
|
|
2017-01-26 13:27:30 +01:00
|
|
|
def assign_unlinked_transactions
|
|
|
|
@bank_account = BankAccount.find(params[:id])
|
|
|
|
count = @bank_account.assign_unlinked_transactions
|
2019-10-30 12:42:41 +01:00
|
|
|
redirect_to finance_bank_account_transactions_url(@bank_account), notice: t('.notice', count: count)
|
2017-01-26 13:27:30 +01:00
|
|
|
rescue => error
|
|
|
|
redirect_to finance_bank_account_transactions_url(@bank_account), alert: t('errors.general_msg', msg: error.message)
|
|
|
|
end
|
|
|
|
|
2018-10-11 23:26:12 +02:00
|
|
|
def import
|
|
|
|
@bank_account = BankAccount.find(params[:id])
|
2020-02-24 14:22:58 +01:00
|
|
|
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
|
2021-03-01 15:27:26 +01:00
|
|
|
# TODO: encrypt state
|
2020-02-24 14:22:58 +01:00
|
|
|
@state = YAML.dump importer.dump
|
2018-10-11 23:26:12 +02:00
|
|
|
else
|
2020-02-24 14:22:58 +01:00
|
|
|
ok = true
|
|
|
|
flash.alert = t('.no_import_method')
|
2018-10-11 23:26:12 +02:00
|
|
|
end
|
2020-02-24 14:22:58 +01:00
|
|
|
|
|
|
|
needs_redirect = ok
|
2018-10-11 23:26:12 +02:00
|
|
|
rescue => error
|
2020-02-24 14:22:58 +01:00
|
|
|
flash.alert = t('errors.general_msg', msg: error.message)
|
|
|
|
needs_redirect = true
|
|
|
|
ensure
|
|
|
|
return unless needs_redirect
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2020-02-24 14:22:58 +01:00
|
|
|
redirect_path = finance_bank_account_transactions_url(@bank_account)
|
|
|
|
if request.post?
|
|
|
|
@js_redirect = redirect_path
|
|
|
|
else
|
|
|
|
redirect_to redirect_path
|
|
|
|
end
|
2018-10-11 23:26:12 +02:00
|
|
|
end
|
2018-09-14 19:33:27 +02:00
|
|
|
end
|