Class: Backend::FinancialYearsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

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?

Instance Method Details

#closeObject


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/controllers/backend/financial_years_controller.rb', line 113

def close
  # Launch close process
  return unless @financial_year = find_and_check
  if request.post? && @financial_year.closable?
    closed_on = params[:financial_year][:stopped_on].to_date
    if params[:result_journal_id] == '0'
      params[:result_journal_id] = Journal.create_one!(:result, @financial_year.currency).id
    end
    if params[:forward_journal_id] == '0'
      params[:forward_journal_id] = Journal.create_one!(:forward, @financial_year.currency).id
    end
    if params[:closure_journal_id] == '0'
      params[:closure_journal_id] = Journal.create_one!(:closure, @financial_year.currency).id
    end
    FinancialYearCloseJob.perform_later(@financial_year, current_user, closed_on.to_s, **params.symbolize_keys.slice(:result_journal_id, :forward_journal_id, :closure_journal_id))
    notify_success(:closure_process_started)
    return redirect_to(action: :index)
  end

  @financial_year.closure_obstructions.each do |obstruction|
    notify_error obstruction.tn
  end

  journal = Journal.where(currency: @financial_year.currency, nature: :result).first
  params[:result_journal_id] = (journal ? journal.id : 0)
  journal = Journal.where(currency: @financial_year.currency, nature: :forward).first
  params[:forward_journal_id] = (journal ? journal.id : 0)
  journal = Journal.where(currency: @financial_year.currency, nature: :closure).first
  params[:closure_journal_id] = (journal ? journal.id : 0)
  t3e @financial_year.attributes
end

#compute_balancesObject


105
106
107
108
109
110
111
# File 'app/controllers/backend/financial_years_controller.rb', line 105

def compute_balances
  return unless @financial_year = find_and_check
  if @financial_year.closed? && @financial_year..empty?
    @financial_year.compute_balances!
  end
  redirect_to_back
end

#newObject


93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/backend/financial_years_controller.rb', line 93

def new
  @financial_year = FinancialYear.new
  f = FinancialYear.last
  @financial_year.started_on = f.stopped_on + 1 unless f.nil?
  @financial_year.started_on ||= Time.zone.today
  @financial_year.stopped_on = ((@financial_year.started_on - 1) >> 12).end_of_month
  @financial_year.code = @financial_year.default_code
  @financial_year.currency = @financial_year.previous.currency if @financial_year.previous
  @financial_year.currency ||= Preference[:currency]
  # render_restfully_form
end

#showObject

Displays details of one financial year selected with params


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/backend/financial_years_controller.rb', line 64

def show
  return unless @financial_year = find_and_check
  respond_to do |format|
    format.html do
      if @financial_year.closed? && @financial_year..empty?
        @financial_year.compute_balances!
      end
      t3e @financial_year.attributes
    end
    format.xml do
      FecExportJob.perform_later(@financial_year, params[:fiscal_position], params[:interval], current_user, 'xml')
      notify_success(:document_in_preparation)
      redirect_to :back
    end
    format.text do
      FecExportJob.perform_later(@financial_year, params[:fiscal_position], params[:interval], current_user, 'text')
      notify_success(:document_in_preparation)
      redirect_to :back
    end
    format.pdf do
      if params[:n] == 'balance_sheet'
        render_print_balance_sheet(@financial_year)
      else
        render_print_income_statement(@financial_year)
      end
    end
  end
end