Sha256: e87c45a0e59c988ccb1c3eb30923ae42967e3dc21a36abd8bee1b3676e1b3da7
Contents?: true
Size: 1.71 KB
Versions: 3
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true module Kaui class AccountTimelinesController < Kaui::EngineController def show timeline = Kaui::AccountTimeline.find_by_account_id(params.require(:account_id), 'FULL', options_for_klient) @account = timeline.account @bundles = timeline.bundles @invoices = timeline.invoices @payments = timeline.payments extract_invoices_by_id(@invoices) # Lookup all bundle names @bundle_names = {} @bundle_names_by_invoice_id = {} @bundle_keys_by_invoice_id = {} @bundles.each do |bundle| load_bundle_name_for_timeline(bundle.external_key) end @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 @selected_bundle = params.key?(:external_key) ? @bundle_names[params[:external_key]] : nil end private def load_bundle_name_for_timeline(bundle_key) @bundle_names[bundle_key] ||= Kaui.bundle_key_display_string.call(bundle_key) end def extract_invoices_by_id(all_invoices) return {} if all_invoices.nil? || all_invoices.empty? # Convert into Kaui::Invoice to benefit from additional methods xxx_to_money @invoices_by_id = all_invoices.each_with_object({}) do |invoice, hsh| hsh[invoice.invoice_id] = Kaui::Invoice.build_from_raw_invoice(invoice) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems