Class: Aviate::UsageController

Inherits:
EngineController
  • Object
show all
Defined in:
app/controllers/aviate/usage_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/aviate/usage_controller.rb', line 9

def index
  cached_options = options_for_klient
  @account_id = params.require(:account_id)
  @account = Kaui::Account.find_by_id(@account_id, false, false, cached_options)

  bundles = @account.bundles(cached_options)
  @subscriptions = []
  bundles.each do |bundle|
    (bundle.subscriptions || []).each do |sub|
      @subscriptions << sub if sub.billing_end_date.blank?
    end
  end
end

#showObject



23
24
25
26
27
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
# File 'app/controllers/aviate/usage_controller.rb', line 23

def show
  cached_options = options_for_klient
  subscription_id = params.require(:id)

  @subscription = Kaui::Subscription.find_by_id(subscription_id, 'NONE', cached_options)
  @account_id = @subscription.
  @account = Kaui::Account.find_by_id(@account_id, false, false, cached_options)

  start_date, end_date = billing_period(@subscription)
  @period_start = format_date(start_date)
  @period_end = format_date(end_date)
  @period_closed = end_date < Time.zone.today

  # Step 3: Retrieve unit types from catalog
  unit_types = fetch_unit_types(@subscription, start_date, cached_options)

  # Step 4: Fetch daily usage time-series in parallel
  samples_by_unit = fetch_all_samples(subscription_id, unit_types, start_date, end_date, cached_options)

  # Step 5: Build cumulative series per unit type
  @chart_data = build_chart_data(samples_by_unit, unit_types)

  # Step 6: Fetch invoice dry run for accrued cost
  @accrued_cost = fetch_accrued_cost(@account_id, cached_options)

  # Step 7: Fetch wallet balance
  @wallet_balance = fetch_wallet_balance(@account_id, cached_options)

  # Build chart JSON for the view
  @chart_json = build_chart_json(@chart_data)
end