Module: Kaui::SubscriptionHelper

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

Instance Method Summary collapse

Instance Method Details

#humanized_billing_period(billing_period) ⇒ Object



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

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



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

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 == 'BASE'
    'Base'
  elsif product_category == 'ADD_ON'
    'Add-on'
  else
    product_category.downcase.capitalize
  end
end

#humanized_product_name(product_name) ⇒ Object



30
31
32
# File 'app/helpers/kaui/subscription_helper.rb', line 30

def humanized_product_name(product_name)
    product_name.downcase.capitalize
end

#humanized_subscription_billing_end_date(sub, account) ⇒ Object



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

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, account.time_zone)}"
  end
end

#humanized_subscription_billing_period(sub) ⇒ Object



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

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



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

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



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

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, account.time_zone)}"
  end
end

#humanized_subscription_cancelled_information(sub, account) ⇒ Object



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

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, account)}<br/>#{humanized_subscription_billing_end_date(sub, account)}".html_safe
  end
end

#humanized_subscription_charged_through_date(sub, account) ⇒ Object



108
109
110
111
112
113
114
# File 'app/helpers/kaui/subscription_helper.rb', line 108

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_full_product_name(sub) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/helpers/kaui/subscription_helper.rb', line 58

def humanized_subscription_full_product_name(sub)
  humanized_product_name   = humanized_subscription_product_name(sub)
  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_phase_type(sub) ⇒ Object



96
97
98
# File 'app/helpers/kaui/subscription_helper.rb', line 96

def humanized_subscription_phase_type(sub)
  sub.phase_type
end

#humanized_subscription_price_list(sub, show_default = true) ⇒ Object



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

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) ⇒ Object



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

def humanized_subscription_product_name(sub)
  if !sub.present? or !sub.product_name.present?
    nil
  else
    humanized_product_name(sub.product_name)
  end
end

#humanized_subscription_start_date(sub, account) ⇒ Object



100
101
102
103
104
105
106
# File 'app/helpers/kaui/subscription_helper.rb', line 100

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



148
149
150
# File 'app/helpers/kaui/subscription_helper.rb', line 148

def humanized_time_unit(time_unit)
  time_unit.downcase.capitalize
end

#is_subscription_cancelled?(sub) ⇒ Boolean

Returns:

  • (Boolean)


157
158
159
# File 'app/helpers/kaui/subscription_helper.rb', line 157

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

#is_subscription_future_cancelled?(sub, account) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
# File 'app/helpers/kaui/subscription_helper.rb', line 153

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