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

account_lettering_states_crit, accounts_range_crit, amount_range_crit, crit_params, journal_entries_states_crit, journal_letter_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name, #session_controller?

Class Method Details

.account_moves_conditions(_options = {}) ⇒ Object


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

def self.(_options = {})
  code = ''
  code << search_conditions({ journal_entry_item: %i[name debit credit real_debit real_credit], journal_entry: [:number], product_nature_variant: [:name] }, 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


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

def self.
  code = search_conditions(accounts: %i[name number]) + "[0] += ' AND reconcilable = ?'\n"
  code << "c << true\n"
  code << ('params')
  code << 'c'
  code.c
end

.accounts_conditionsObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/backend/accounts_controller.rb', line 29

def self.accounts_conditions
  code = ''
  code << search_conditions(accounts: %i[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


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

def index; end

#loadObject


165
166
167
168
169
170
171
172
173
174
175
# File 'app/controllers/backend/accounts_controller.rb', line 165

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


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/controllers/backend/accounts_controller.rb', line 142

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

#mask_lettered_itemsObject


200
201
202
203
204
205
206
# File 'app/controllers/backend/accounts_controller.rb', line 200

def mask_lettered_items
  preference_name = 'backend/accounts'
  preference_name << ".#{params[:context]}" if params[:context]
  preference_name << '.lettered_items.masked'
  current_user.prefer!(preference_name, params[:masked].to_s == 'true', :boolean)
  head :ok
end

#reconciliable_listObject


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'app/controllers/backend/accounts_controller.rb', line 177

def reconciliable_list
  return unless @account = Account.find_by_id(params[:id])

  if params.key?(:masked)
    preference_name = 'backend/accounts'
    preference_name << ".#{params[:context]}" if params[:context]
    preference_name << '.lettered_items.masked'
    current_user.prefer!(preference_name, params[:masked].to_s == 'true', :boolean)
  end

  lettered_items_preference = current_user.preference(preference_name, 'true', :boolean)

  @items = @account.reconcilable_entry_items(params[:period], params[:started_on], params[:stopped_on], hide_lettered: lettered_items_preference.value)

  @unmark_label = :unmark.ta
  @unmark_title = :unmark.tl
  @confirm_label = :are_you_sure.tl
  @account_id = @account.id
  @currency = Preference[:currency]
  @precision = Nomen::Currency[@currency].precision

end

#reconciliationObject


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

def reconciliation; end

#showObject


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/backend/accounts_controller.rb', line 57

def show
  return unless @account = find_and_check
  t3e @account
  respond_to do |format|
    format.html {}
    format.odt do
      
      if params[:non_letter] == 'true'
        filename = :extract_unlettered_account_x.tl(account_number: @account.number).tr(' ', '_')
        send_data non_letter_odt.generate, type: 'application/vnd.oasis.opendocument.text', disposition: 'attachment', filename: filename << '.odt'
      else
        filename = :extract_account_x.tl(account_number: @account.number).tr(' ', '_')
        send_data to_odt.generate, type: 'application/vnd.oasis.opendocument.text', disposition: 'attachment', filename: filename << '.odt'
      end
    end
    format.pdf do
      if params[:template].present?
        respond_with(@account, methods: [],
                               include: [
                                 { journal_entry_items: { include: %i[financial_year tax tax_declaration_item] } }
                               ],
                               procs: proc { |options| options[:builder].tag!(:url, (@account)) })
      else
        
        to_pdf
      end
    end
  end
end

#unmarkObject


159
160
161
162
163
# File 'app/controllers/backend/accounts_controller.rb', line 159

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