Class: Backend::BankStatementsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/bank_statements_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

accounts_range_crit, crit_params, journal_entries_states_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name

Instance Method Details

#importObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/backend/bank_statements_controller.rb', line 55

def import
  @cash = Cash.find_by(id: params[:cash_id])
  if request.post?
    file = params[:upload]
    @import = OfxImport.new(file, @cash)
    if @import.run
      redirect_to action: :show, id: @import.bank_statement.id
    elsif @import.recoverable?
      @cash = @import.cash
      @bank_statement = @import.bank_statement
      @bank_statement.errors.add(:cash, :no_cash_match_ofx) unless @cash.valid?
      render :new
    end
  end
end

#indexObject

Displays the main page with the list of bank statements


42
43
44
# File 'app/controllers/backend/bank_statements_controller.rb', line 42

def index
  redirect_to backend_cashes_path
end

#reconciliationObject


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/backend/bank_statements_controller.rb', line 71

def reconciliation
  return unless @bank_statement = find_and_check
  if request.post?
    @bank_statement.attributes = permitted_params
    items = (params[:items] || {}).values
    journal_entry_items = (params[:journal_entry_items] || {})
    if @bank_statement.save_with_items(items)
      journal_entry_items.each do |journal_entry_item_id, attributes|
        letter = attributes[:bank_statement_letter].presence
        JournalEntryItem.where(id: journal_entry_item_id).update_all(
          bank_statement_id: @bank_statement.id,
          bank_statement_letter: letter
        )
      end
      redirect_to params[:redirect] || { action: :show, id: @bank_statement.id }
      return
    end
  end
  bank_statement_items = @bank_statement.items.order('ABS(debit-credit)')
  journal_entry_items = @bank_statement.eligible_journal_entry_items.order('ABS(real_debit-real_credit)')
  unless journal_entry_items.any?
    notify_error :need_entries_to_reconciliate
    redirect_to params[:redirect] || { action: :show, id: @bank_statement.id }
    return
  end
  @items = bank_statement_items + journal_entry_items
  @items_grouped_by_date = @items.group_by do |item|
    BankStatementItem === item ? item.transfered_on : item.printed_on
  end.sort
  t3e @bank_statement, cash: @bank_statement.cash_name, started_on: @bank_statement.started_on, stopped_on: @bank_statement.stopped_on
end