Module: Kaui::SubscriptionHelper

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

Instance Method Summary collapse

Instance Method Details

#humanized_billing_end_date(sub, account) ⇒ Object



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

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

#humanized_billing_period(sub) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/helpers/kaui/subscription_helper.rb', line 24

def humanized_billing_period(sub)
  if !sub.present? or !sub.billing_period.present?
    nil
  elsif sub.billing_period == 'NO_BILLING_PERIOD'
    'No billing period'
  else
    sub.billing_period.downcase.capitalize
  end
end

#humanized_billing_start_date(sub, account) ⇒ Object



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

def humanized_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_cancelled_date(sub, account) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/kaui/subscription_helper.rb', line 78

def humanized_cancelled_date(sub, )
  if !sub.present? or !sub.cancelled_date.present? or !.present? or !.time_zone.present?
    nil
  else
    cancelled_date = format_date(sub.cancelled_date, .time_zone).html_safe
    if Time.parse(sub.cancelled_date) > Time.now
      'Pending cancellation on ' + cancelled_date
    else
      'Canceled on ' + cancelled_date
    end
  end
end

#humanized_charged_through_date(sub, account) ⇒ Object



70
71
72
73
74
75
76
# File 'app/helpers/kaui/subscription_helper.rb', line 70

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



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

def humanized_full_product_name(sub)
  humanized_product_name   = humanized_product_name(sub)
  humanized_billing_period = humanized_billing_period(sub)
  humanized_price_list     = humanized_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_price_list(sub, show_default = true) ⇒ Object



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

def humanized_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_product_category(sub) ⇒ Object



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

def humanized_product_category(sub)
  if !sub.present? or !sub.product_category.present?
    nil
  elsif sub.product_category == 'BASE'
    'Base'
  elsif sub.product_category == 'ADD_ON'
    'Add-on'
  else
    sub.product_category.downcase.capitalize
  end
end

#humanized_product_name(sub) ⇒ Object



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

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

#humanized_start_date(sub, account) ⇒ Object



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

def humanized_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

#is_cancelled?(sub) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/helpers/kaui/subscription_helper.rb', line 111

def is_cancelled?(sub)
  sub.present? and !sub.billing_end_date.present?
end

#is_future_cancelled?(sub) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/helpers/kaui/subscription_helper.rb', line 107

def is_future_cancelled?(sub)
  sub.present? and sub.billing_end_date.present? and Time.parse(sub.billing_end_date) > Time.now
end