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

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

#closeObject


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/backend/financial_years_controller.rb', line 79

def close
  # Launch close process
  return unless @financial_year = find_and_check
  if request.post?
    params[:journal_id] = Journal.create!(nature: :forward).id if params[:journal_id] == '0'
    if @financial_year.close(params[:financial_year][:stopped_on].to_date, journal_id: params[:journal_id])
      notify_success(:closed_financial_years)
      redirect_to(action: :index)
    end
  else
    journal = Journal.used_for(:forward).first
    params[:journal_id] = (journal ? journal.id : 0)
  end
  t3e @financial_year.attributes
end

#compute_balancesObject


73
74
75
76
77
# File 'app/controllers/backend/financial_years_controller.rb', line 73

def compute_balances
  return unless @financial_year = find_and_check
  @financial_year.compute_balances!
  redirect_to_back
end

#generate_last_journal_entryObject


107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/backend/financial_years_controller.rb', line 107

def generate_last_journal_entry
  return unless @financial_year = find_and_check
  if request.get?
    params[:fixed_assets_depreciations] ||= 1
  elsif request.post?
    # TODO: Defines journal to save the entry
    @financial_year.generate_last_journal_entry(params)
    redirect_to backend_journal_entry_path(@financial_year.last_journal_entry)
  end
  t3e @financial_year.attributes
end

#newObject


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

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


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

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.pdf do
      if params[:n] == 'balance_sheet'
        render_print_balance_sheet(@financial_year)
      else
        render_print_income_statement(@financial_year)
      end
    end
  end
end