Class: Kaui::AccountTimelinesController

Inherits:
EngineController
  • Object
show all
Defined in:
app/controllers/kaui/account_timelines_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_ability, #current_user, #options_for_klient

Instance Method Details

#indexObject



3
4
# File 'app/controllers/kaui/account_timelines_controller.rb', line 3

def index
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/kaui/account_timelines_controller.rb', line 6

def show
  @account_id = params[:id]

  begin
    @account  = Kaui::Account.find_by_id(@account_id, false, false, options_for_klient)
    @timeline = Kaui::AccountTimeline.(@account_id, 'MINIMAL', options_for_klient)
  rescue => e
    flash[:error] = "Could not load the account timeline for #{@account_id}: #{as_string(e)}"
    render :action => :index and return
  end

  # Lookup all bundle names
  @bundle_names               = {}
  @bundle_names_by_invoice_id = {}
  @bundle_keys_by_invoice_id  = {}
  @timeline.bundles.each do |bundle|
    load_bundle_name_for_timeline(bundle.external_key)
  end
  @timeline.invoices.each do |invoice|
    @bundle_names_by_invoice_id[invoice.invoice_id] = Set.new
    @bundle_keys_by_invoice_id[invoice.invoice_id]  = Set.new
    (invoice.bundle_keys || '').split(',').each do |bundle_key|
      load_bundle_name_for_timeline(bundle_key)
      @bundle_names_by_invoice_id[invoice.invoice_id] << @bundle_names[bundle_key]
      @bundle_keys_by_invoice_id[invoice.invoice_id] << bundle_key
    end
  end

  # Lookup all invoices
  @invoices_by_id = {}
  @timeline.payments.each do |payment|
    load_invoice_id_for_timeline(payment.target_invoice_id)
  end
  @timeline.invoices.each do |invoice|
    load_invoice_id_for_timeline(invoice.invoice_id)
  end

  if params.has_key?(:external_key)
    @selected_bundle = @bundle_names[params[:external_key]]
  end
end