Class: Backend::ExportsController

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

#indexObject


23
24
25
26
# File 'app/controllers/backend/exports_controller.rb', line 23

def index
  # FIXME: It should not be necessary to do that
  DocumentTemplate.load_defaults unless DocumentTemplate.any?
end

#showObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/backend/exports_controller.rb', line 28

def show
  unless klass = Aggeratio[params[:id]]
    notify_error :aggeratio_not_found
    redirect_to action: :index
    return
  end

  klass.parameters.each do |parameter|
    next if parameter.record_list?
    value_preference = "exports.#{klass.name}.parameters.#{parameter.name}.value"
    value = current_user.preference(value_preference, parameter.default).value
    params[parameter.name] ||= value
    current_user.prefer!(value_preference, params[parameter.name])
  end

  @aggregator = klass.new(params)
  aggregator_parameters = @aggregator.class.parameters.map(&:name).uniq
  t3e name: klass.human_name
  if params[:format] == 'pdf'
    ExportJob.perform_later(JSON(params), current_user.id)
    notify_success(:document_in_preparation)
    redirect_to :back
  else
    if (aggregator_parameters - params.keys).empty?
      notify(:information_success_print)
      @btn_class = "btn-primary"
    end
    respond_with @aggregator
  end
end