Class: Backend::AccountsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Class Method Summary collapse

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

Class Method Details

.account_moves_conditions(_options = {}) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/backend/accounts_controller.rb', line 53

def self.(_options = {})
  code = ''
  code << search_conditions({ journal_entry_item: [:name, :debit, :credit, :real_debit, :real_credit], journal_entry: [:number] }, conditions: 'c', variable: 'params[:b]'.c) + "\n"
  code << journal_period_crit('params')
  code << journal_entries_states_crit('params')
  # code << journals_crit("params")
  code << "c[0] << ' AND #{JournalEntryItem.table_name}.account_id = ?'\n"
  code << "c << params[:id]\n"
  code << "c\n"
  code.c
end

.account_reconciliation_conditionsObject


87
88
89
90
91
92
93
# File 'app/controllers/backend/accounts_controller.rb', line 87

def self.
  code = search_conditions(accounts: [:name, :number, :description], journal_entries: [:number], JournalEntryItem.table_name => [:name, :debit, :credit]) + "[0] += ' AND accounts.reconcilable = ?'\n"
  code << "c << true\n"
  code << "c[0] += ' AND (letter IS NULL OR LENGTH(TRIM(letter)) <= 0)'\n"
  code << 'c'
  code.c
end

.accounts_conditionsObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/backend/accounts_controller.rb', line 25

def self.accounts_conditions
  code = ''
  code << search_conditions(accounts: [:name, :number, :description]) + ';'
  code << "if params[:prefix]\n"
  code << "  c[0] += ' AND number LIKE ?'\n"
  code << "  c << params[:prefix].to_s+'%'\n"
  code << "end\n"
  code << "unless params[:period].blank? or params[:period]='all'\n"
  code << "  c[0] += ' AND id IN (SELECT account_id FROM #{JournalEntryItem.table_name} AS jel JOIN #{JournalEntry.table_name} AS je ON (entry_id=je.id) WHERE '+JournalEntry.period_condition(params[:period], params[:started_on], params[:stopped_on], 'je')+')'\n"
  code << "end\n"
  code << "c\n"
  # list = code.split("\n"); list.each_index{|x| puts((x+1).to_s.rjust(4)+": "+list[x])}
  code.c
end

Instance Method Details

#indexObject

Displays the main page with the list of accounts


50
51
# File 'app/controllers/backend/accounts_controller.rb', line 50

def index
end

#loadObject


134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/backend/accounts_controller.rb', line 134

def load
  if request.post?
    Account.accounting_system = params[:accounting_system]
    if Nomen::Account.property_natures.keys.include?(Account.accounting_system.to_s)
      Account.load_defaults
    else
      raise 'Arrrggggg'
    end
    redirect_to action: :index
  end
end

#markObject


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/backend/accounts_controller.rb', line 111

def mark
  return unless @account = find_and_check
  if request.post?
    if params[:journal_entry_item]
      letter = @account.mark(params[:journal_entry_item].select { |_k, v| v[:to_mark].to_i == 1 }.collect { |k, _v| k.to_i })
      if letter.nil?
        notify_error_now(:cannot_mark_entry_items)
      else
        notify_success_now(:journal_entry_items_marked_with_letter, letter: letter)
      end
    else
      notify_warning_now(:select_entry_items_to_mark_together)
    end
  end
  t3e @account.attributes
end

#reconciliationObject


108
109
# File 'app/controllers/backend/accounts_controller.rb', line 108

def reconciliation
end

#unmarkObject


128
129
130
131
132
# File 'app/controllers/backend/accounts_controller.rb', line 128

def unmark
  return unless @account = find_and_check
  @account.unmark(params[:letter]) if params[:letter]
  redirect_to_back
end