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_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



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

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



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



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

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



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

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



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

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



90
91
92
93
94
95
96
# File 'app/helpers/kaui/subscription_helper.rb', line 90

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
# 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
    else
      humanized_product_name+ ' (' + humanized_price_list.downcase + ')'
    end
  else
    if humanized_price_list.nil?
      humanized_product_name + ' (' + humanized_billing_period.downcase + ')'
    else
      humanized_product_name+ ' (' + humanized_billing_period.downcase + ', ' + humanized_price_list.downcase + ')'
    end
  end
end

#humanized_subscription_phase_type(sub) ⇒ Object



78
79
80
# File 'app/helpers/kaui/subscription_helper.rb', line 78

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



82
83
84
85
86
87
88
# File 'app/helpers/kaui/subscription_helper.rb', line 82

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



130
131
132
# File 'app/helpers/kaui/subscription_helper.rb', line 130

def humanized_time_unit(time_unit)
  time_unit.downcase.capitalize
end

#is_subscription_cancelled?(sub) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
# File 'app/helpers/kaui/subscription_helper.rb', line 139

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

#is_subscription_future_cancelled?(sub, account) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'app/helpers/kaui/subscription_helper.rb', line 135

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