Module: Kaui::SubscriptionHelper

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

Instance Method Summary collapse

Instance Method Details

#humanized_billing_period(billing_period) ⇒ Object



56
57
58
59
60
61
62
# File 'app/helpers/kaui/subscription_helper.rb', line 56

def humanized_billing_period(billing_period)
  if billing_period == 'NO_BILLING_PERIOD'
    'No billing period'
  else
    billing_period.downcase.capitalize
  end
end

#humanized_price_override(sub, separation = ', ', open_bracket = '', close_bracket = '') ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/kaui/subscription_helper.rb', line 97

def humanized_price_override(sub, separation = ', ', open_bracket = '', close_bracket = '')
  if sub.plan_name.scan(/ *-\d+$/).empty?
    ''
  else
    current_plan = sub.prices.select { |price| price['phaseType'] == sub.phase_type && price['planName'] == sub.plan_name }
    price_override = current_plan.last['fixedPrice'] || current_plan.last['recurringPrice']

    if price_override.blank?
      ''
    else
      span = "<span data-toggle=\"popover\" class=\"price-override-popover\" data-content=\"#{price_override}\"><b>price override</b></span>"
      "#{open_bracket}#{separation}#{span}#{close_bracket}"
    end
  end
end

#humanized_product_category(product_category) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/helpers/kaui/subscription_helper.rb', line 12

def humanized_product_category(product_category)
  if product_category.to_s == 'BASE'
    'Base'
  elsif product_category.to_s == 'ADD_ON'
    'Add-on'
  else
    product_category.to_s.downcase.capitalize
  end
end

#humanized_product_name(product_name) ⇒ Object



43
44
45
46
# File 'app/helpers/kaui/subscription_helper.rb', line 43

def humanized_product_name(product_name)
  # Don't change the casing to avoid confusions (could lead to different products with different casing)
  product_name
end

#humanized_subscription_billing_end_date(sub, account) ⇒ Object



149
150
151
152
153
154
155
# File 'app/helpers/kaui/subscription_helper.rb', line 149

def humanized_subscription_billing_end_date(sub, )
  if !sub.present? or !sub.billing_end_date.present? or !.present? or !.time_zone.present?
    nil
  else
    "Billing date: #{format_date(sub.billing_end_date, .time_zone)}"
  end
end

#humanized_subscription_billing_period(sub) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/kaui/subscription_helper.rb', line 48

def humanized_subscription_billing_period(sub)
  if !sub.present? or !sub.billing_period.present?
    nil
  else
    humanized_billing_period(sub.billing_period)
  end
end

#humanized_subscription_billing_start_date(sub, account) ⇒ Object



141
142
143
144
145
146
147
# File 'app/helpers/kaui/subscription_helper.rb', line 141

def humanized_subscription_billing_start_date(sub, )
  if !sub.present? or !sub.billing_start_date.present? or !.present? or !.time_zone.present?
    nil
  else
    format_date(sub.billing_start_date, .time_zone).html_safe
  end
end

#humanized_subscription_cancelled_date(sub, account) ⇒ Object



133
134
135
136
137
138
139
# File 'app/helpers/kaui/subscription_helper.rb', line 133

def humanized_subscription_cancelled_date(sub, )
  if !sub.present? or !sub.cancelled_date.present? or !.present? or !.time_zone.present?
    nil
  else
    "Entitlement date: #{format_date(sub.cancelled_date, .time_zone)}"
  end
end

#humanized_subscription_cancelled_information(sub, account) ⇒ Object



157
158
159
160
161
162
163
# File 'app/helpers/kaui/subscription_helper.rb', line 157

def humanized_subscription_cancelled_information(sub, )
  if !sub.present? or !sub.cancelled_date.present? or !.present? or !.time_zone.present?
    nil
  else
    "#{humanized_subscription_cancelled_date(sub, )}<br/>#{humanized_subscription_billing_end_date(sub, )}".html_safe
  end
end

#humanized_subscription_charged_through_date(sub, account) ⇒ Object



125
126
127
128
129
130
131
# File 'app/helpers/kaui/subscription_helper.rb', line 125

def humanized_subscription_charged_through_date(sub, )
  if !sub.present? or !sub.charged_through_date.present? or !.present? or !.time_zone.present?
    nil
  else
    format_date(sub.charged_through_date, .time_zone).html_safe
  end
end

#humanized_subscription_phase_type(sub) ⇒ Object



113
114
115
# File 'app/helpers/kaui/subscription_helper.rb', line 113

def humanized_subscription_phase_type(sub)
  sub.phase_type
end

#humanized_subscription_plan_or_product_name(sub, catalog = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/kaui/subscription_helper.rb', line 72

def humanized_subscription_plan_or_product_name(sub, catalog = nil)
  pretty_plan_name = humanized_subscription_pretty_plan_name(sub, catalog)
  return pretty_plan_name unless pretty_plan_name.nil?

  humanized_product_name   = humanized_subscription_product_name(sub, catalog)
  humanized_billing_period = humanized_subscription_billing_period(sub)
  humanized_price_list     = humanized_subscription_price_list(sub, false)

  if humanized_billing_period.nil?
    if humanized_price_list.nil?
      humanized_product_name = humanized_product_name + humanized_price_override(sub, '', '(', ')')
    else
      humanized_product_name = humanized_product_name + ' (' + humanized_price_list.downcase + humanized_price_override(sub) + ')'
    end
  else
    if humanized_price_list.nil?
      humanized_product_name = humanized_product_name + ' (' + humanized_billing_period.downcase + humanized_price_override(sub) + ')'
    else
      humanized_product_name = humanized_product_name + ' (' + humanized_billing_period.downcase + ', ' + humanized_price_list.downcase + humanized_price_override(sub) + ')'
    end
  end

  humanized_product_name.html_safe
end

#humanized_subscription_pretty_plan_name(sub, catalog = nil) ⇒ Object



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

def humanized_subscription_pretty_plan_name(sub, catalog = nil)
  if !sub.present? || !sub.product_name.present?
    nil
  else
    product = catalog.nil? ? nil : catalog.products.find { |p| p.name == sub.product_name }
    return nil if product.nil?

    plan = product.plans.find { |p| p.name == sub.plan_name }
    plan.nil? || plan.pretty_name.blank? ? nil : plan.pretty_name
  end
end

#humanized_subscription_price_list(sub, show_default = true) ⇒ Object



64
65
66
67
68
69
70
# File 'app/helpers/kaui/subscription_helper.rb', line 64

def humanized_subscription_price_list(sub, show_default=true)
  if !sub.present? or !sub.price_list.present? or (!show_default and sub.price_list.upcase == 'DEFAULT')
    nil
  else
    sub.price_list.downcase.capitalize
  end
end

#humanized_subscription_product_category(sub) ⇒ Object



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

def humanized_subscription_product_category(sub)
  if !sub.present? or !sub.product_category.present?
    nil
  else
    humanized_product_category(sub.product_category)
  end
end

#humanized_subscription_product_name(sub, catalog = nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/helpers/kaui/subscription_helper.rb', line 22

def humanized_subscription_product_name(sub, catalog = nil)
  if !sub.present? || !sub.product_name.present?
    nil
  else
    product = catalog.nil? ? nil : catalog.products.find { |p| p.name == sub.product_name }
    humanized_product_name(!product.nil? && !product.pretty_name.blank? ? product.pretty_name : sub.product_name)
  end
end

#humanized_subscription_start_date(sub, account) ⇒ Object



117
118
119
120
121
122
123
# File 'app/helpers/kaui/subscription_helper.rb', line 117

def humanized_subscription_start_date(sub, )
  if !sub.present? or !sub.start_date.present? or !.present? or !.time_zone.present?
    nil
  else
    format_date(sub.start_date, .time_zone).html_safe
  end
end

#humanized_time_unit(time_unit) ⇒ Object



165
166
167
# File 'app/helpers/kaui/subscription_helper.rb', line 165

def humanized_time_unit(time_unit)
  time_unit.downcase.capitalize
end

#is_subscription_cancelled?(sub) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
# File 'app/helpers/kaui/subscription_helper.rb', line 174

def is_subscription_cancelled?(sub)
  sub.present? and sub.billing_end_date.present?
end

#is_subscription_future_cancelled?(sub, account) ⇒ Boolean

Returns:

  • (Boolean)


170
171
172
# File 'app/helpers/kaui/subscription_helper.rb', line 170

def is_subscription_future_cancelled?(sub, )
  sub.present? && sub.state != 'CANCELLED' && sub.billing_end_date.present? && Time.parse(sub.billing_end_date) > current_time(.time_zone)
end