Class: Backend::JournalEntriesController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/journal_entries_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

#createObject


74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/backend/journal_entries_controller.rb', line 74

def create
  return unless @journal = find_and_check(:journal, params[:journal_id])
  session[:current_journal_id] = @journal.id
  @journal_entry = @journal.entries.build(permitted_params)
  @journal_entry_items = (params[:items] || {}).values
  # raise @journal_entry_items.inspect
  if @journal_entry.save_with_items(@journal_entry_items)
    notify_success(:journal_entry_has_been_saved, number: @journal_entry.number)
    redirect_to controller: :journal_entries, action: :new, journal_id: @journal.id, exchange_rate: @journal_entry.real_currency_rate, printed_on: @journal_entry.printed_on # , :draft_mode => (1 if @journal_entry.draft_mode)
    return
  end
  t3e @journal.attributes
end

#editObject


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

def edit
  return unless @journal_entry = find_and_check
  unless @journal_entry.updateable?
    notify_error(:journal_entry_already_validated)
    redirect_to_back
    return
  end
  @journal = @journal_entry.journal
  t3e @journal_entry.attributes
end

#newObject


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/backend/journal_entries_controller.rb', line 58

def new
  return unless @journal = find_and_check(:journal, params[:journal_id])
  session[:current_journal_id] = @journal.id
  @journal_entry = @journal.entries.build
  @journal_entry.printed_on = params[:printed_on] || Time.zone.today
  @journal_entry.number = @journal.next_number
  @journal_entry.real_currency_rate = params[:exchange_rate].to_f
  @journal_entry_items = []

  if request.xhr?
    render(partial: 'backend/journal_entries/items_form')
  else
    t3e @journal.attributes
  end
end

#updateObject


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/backend/journal_entries_controller.rb', line 99

def update
  return unless @journal_entry = find_and_check
  unless @journal_entry.updateable?
    notify_error(:journal_entry_already_validated)
    redirect_to_back
    return
  end
  @journal = @journal_entry.journal
  @journal_entry.attributes = permitted_params
  @journal_entry_items = (params[:items] || {}).values
  if @journal_entry.save_with_items(@journal_entry_items)
    redirect_to params[:redirect] || { action: :show, id: @journal_entry.id }
    return
  end
  t3e @journal_entry.attributes
end