Class: RogIQ::Commands::Billing

Inherits:
Base
  • Object
show all
Defined in:
lib/rogiq/commands/billing.rb

Instance Method Summary collapse

Instance Method Details

#coins(identifier) ⇒ Object



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
# File 'lib/rogiq/commands/billing.rb', line 9

def coins(identifier)
  RogIQ.load_rails!
   = RogIQ::Helpers.(identifier)
  unless 
    fmt.error_msg("Account not found")
    exit 1
  end

  w = .rogue_coin_wallet
  unless w
    fmt.output(wallet: nil, message: "No RogueCoinWallet for account")
    return
  end

  txs = w.transactions.order(created_at: :desc).limit(25).map do |t|
    [t.created_at.iso8601, t.transaction_type, t.amount, t.description.to_s.truncate(60)]
  end
  fmt.output(
    account_id: .id,
    balance: w.balance,
    lifetime_purchased: w.lifetime_purchased,
    lifetime_spent: w.lifetime_spent,
    recent_transactions: txs
  )
end

#invoices(identifier) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rogiq/commands/billing.rb', line 65

def invoices(identifier)
  RogIQ.load_rails!
   = RogIQ::Helpers.(identifier)
  unless 
    fmt.error_msg("Account not found")
    exit 1
  end

  rows = .invoices.order(created_at: :desc).limit(options[:limit]).map do |inv|
    [
      inv.id,
      inv.invoice_number,
      inv.status,
      inv.total.to_f,
      inv.striven_invoice_id,
      inv.created_at.iso8601
    ]
  end
  fmt.output(
    headers: %w[id invoice_number status total striven_invoice_id created_at],
    rows: rows
  )
end

#overagesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rogiq/commands/billing.rb', line 37

def overages
  RogIQ.load_rails!
  rows = ::UsageOverage.status_pending.includes(:account).order(created_at: :desc).limit(options[:limit]).map do |o|
    [
      o.id,
      o.&.name,
      o.metric_type,
      o.total_charge.to_f,
      o.created_at.iso8601
    ]
  end
  fmt.output(headers: %w[id account metric total_charge created_at], rows: rows)
end

#summaryObject



56
57
58
59
60
61
# File 'lib/rogiq/commands/billing.rb', line 56

def summary
  RogIQ.load_rails!
  date = options[:date].present? ? Date.parse(options[:date]) : nil
  ::Billing::DailyBillingSummaryJob.perform_later(date: date)
  fmt.success("Billing::DailyBillingSummaryJob enqueued.")
end