Module: Kaui::AccountHelper

Defined in:
app/helpers/kaui/account_helper.rb

Instance Method Summary collapse

Instance Method Details

#account_closed?(account = nil) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/kaui/account_helper.rb', line 43

def ( = nil)
   ||= @account # rubocop:disable Rails/HelperInstanceVariable
  return false if .nil?

  # NOTE: we ignore errors here, so that the call doesn't prevent the screen to load. While the error isn't surfaced, if there is an error with the catalog for instance,
  # the AJAX call to compute the next invoice date should hopefully trigger a flash error.
  blocking_states = begin
    .blocking_states('ACCOUNT', 'account-service', 'NONE', Kaui.current_tenant_user_options(current_user, session))
  rescue StandardError
    []
  end

   = false
  blocking_states.each do |blocking_state|
    if blocking_state.state_name.eql?('CLOSE_ACCOUNT')
       = true
      break
    end
  end
  
end

#aviate_plugin_installedObject



24
25
26
27
28
# File 'app/helpers/kaui/account_helper.rb', line 24

def aviate_plugin_installed
  Killbill::Aviate::AviateClient.aviate_plugin_installed(Kaui.current_tenant_user_options(current_user, session)).first
rescue StandardError
  false
end

#billing_info_marginObject



65
66
67
68
69
70
71
72
73
# File 'app/helpers/kaui/account_helper.rb', line 65

def billing_info_margin
  style = ''
  style = "#{style}margin-top:15px;" unless can?(:trigger, Kaui::Payment) && can?(:credit, Kaui::Account) && can?(:charge, Kaui::Account)

  style = "#{style}margin-bottom:15px;" unless can? :trigger, Kaui::Invoice

  style = "style='#{style}'" unless style.empty?
  style
end

#deposit_plugin_available?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/helpers/kaui/account_helper.rb', line 18

def deposit_plugin_available?
  Killbill::Deposit::DepositClient.deposit_plugin_available?(Kaui.current_tenant_user_options(current_user, session)).first
rescue StandardError
  false
end

#effective_bcd(account, bundles = nil) ⇒ Object

Get the effective BCD for an account If there’s an active subscription with its own BCD, return that Otherwise return the account-level BCD



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/kaui/account_helper.rb', line 78

def effective_bcd(, bundles = nil)
  # If bundles are provided, check for subscription BCD
  if bundles.present?
    bundles.each do |bundle|
      next if bundle.subscriptions.blank?

      bundle.subscriptions.each do |subscription|
        # Skip cancelled subscriptions
        next if subscription.state == 'CANCELLED'
        # If subscription has a BCD set, return it (subscription BCD takes precedence)
        return subscription.bill_cycle_day_local if subscription.bill_cycle_day_local.present? && subscription.bill_cycle_day_local.positive?
      end
    end
  end

  # Fall back to account BCD
  .bill_cycle_day_local
end

#email_notifications_plugin_available?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/helpers/kaui/account_helper.rb', line 12

def email_notifications_plugin_available?
  Kenui::EmailNotificationService.email_notification_plugin_available?(Kaui.current_tenant_user_options(current_user, session)).first
rescue StandardError
  false
end

#kpm_plugin_installedObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/kaui/account_helper.rb', line 30

def kpm_plugin_installed
  nodes_info = KillBillClient::Model::NodesInfo.nodes_info(Kaui.current_tenant_user_options(current_user, session)) || []
  return false if nodes_info.empty?

  nodes_info.each do |node_info|
    next if (node_info.plugins_info || []).empty?

    node_info.plugins_info.each do |plugin_info|
      return true if plugin_info.plugin_name == 'org.kill-bill.billing.killbill-platform-osgi-bundles-kpm'
    end
  end
end

#pretty_account_identifier(account = nil) ⇒ Object



5
6
7
8
9
10
# File 'app/helpers/kaui/account_helper.rb', line 5

def ( = nil)
   ||= @account # rubocop:disable Rails/HelperInstanceVariable
  return nil if .nil?

  Kaui..call()
end