Module: Kaui::SubscriptionHelper
- Defined in:
- app/helpers/kaui/subscription_helper.rb
Instance Method Summary collapse
- #humanized_billing_period(billing_period) ⇒ Object
- #humanized_price_override(sub, separation = ', ', open_bracket = '', close_bracket = '') ⇒ Object
- #humanized_product_category(product_category) ⇒ Object
- #humanized_product_name(product_name) ⇒ Object
- #humanized_subscription_billing_end_date(sub, account) ⇒ Object
- #humanized_subscription_billing_period(sub) ⇒ Object
- #humanized_subscription_billing_start_date(sub, account) ⇒ Object
- #humanized_subscription_cancelled_date(sub, account) ⇒ Object
- #humanized_subscription_cancelled_information(sub, account) ⇒ Object
- #humanized_subscription_charged_through_date(sub, account) ⇒ Object
- #humanized_subscription_phase_type(sub) ⇒ Object
- #humanized_subscription_plan_or_product_name(sub, catalog = nil) ⇒ Object
- #humanized_subscription_pretty_plan_name(sub, catalog = nil) ⇒ Object
- #humanized_subscription_price_list(sub, show_default) ⇒ Object
- #humanized_subscription_product_category(sub) ⇒ Object
- #humanized_subscription_product_name(sub, catalog = nil) ⇒ Object
- #humanized_subscription_start_date(sub, account) ⇒ Object
- #humanized_time_unit(time_unit) ⇒ Object
- #subscription_cancelled?(sub) ⇒ Boolean
- #subscription_future_cancelled?(sub, account) ⇒ Boolean
Instance Method Details
#humanized_billing_period(billing_period) ⇒ Object
57 58 59 60 61 62 63 |
# File 'app/helpers/kaui/subscription_helper.rb', line 57 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
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/kaui/subscription_helper.rb', line 96 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
13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/kaui/subscription_helper.rb', line 13 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
44 45 46 47 |
# File 'app/helpers/kaui/subscription_helper.rb', line 44 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
148 149 150 151 152 153 154 |
# File 'app/helpers/kaui/subscription_helper.rb', line 148 def humanized_subscription_billing_end_date(sub, account) if !sub.present? || !sub.billing_end_date.present? || !account.present? || !account.time_zone.present? nil else "Billing date: #{format_date(sub.billing_end_date, account.time_zone)}" end end |
#humanized_subscription_billing_period(sub) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/helpers/kaui/subscription_helper.rb', line 49 def humanized_subscription_billing_period(sub) if !sub.present? || !sub.billing_period.present? nil else humanized_billing_period(sub.billing_period) end end |
#humanized_subscription_billing_start_date(sub, account) ⇒ Object
140 141 142 143 144 145 146 |
# File 'app/helpers/kaui/subscription_helper.rb', line 140 def humanized_subscription_billing_start_date(sub, account) if !sub.present? || !sub.billing_start_date.present? || !account.present? || !account.time_zone.present? nil else format_date(sub.billing_start_date, account.time_zone).html_safe end end |
#humanized_subscription_cancelled_date(sub, account) ⇒ Object
132 133 134 135 136 137 138 |
# File 'app/helpers/kaui/subscription_helper.rb', line 132 def humanized_subscription_cancelled_date(sub, account) if !sub.present? || !sub.cancelled_date.present? || !account.present? || !account.time_zone.present? nil else "Entitlement date: #{format_date(sub.cancelled_date, account.time_zone)}" end end |
#humanized_subscription_cancelled_information(sub, account) ⇒ Object
156 157 158 159 160 161 162 |
# File 'app/helpers/kaui/subscription_helper.rb', line 156 def humanized_subscription_cancelled_information(sub, account) if !sub.present? || !sub.cancelled_date.present? || !account.present? || !account.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
124 125 126 127 128 129 130 |
# File 'app/helpers/kaui/subscription_helper.rb', line 124 def humanized_subscription_charged_through_date(sub, account) if !sub.present? || !sub.charged_through_date.present? || !account.present? || !account.time_zone.present? nil else format_date(sub.charged_through_date, account.time_zone).html_safe end end |
#humanized_subscription_phase_type(sub) ⇒ Object
112 113 114 |
# File 'app/helpers/kaui/subscription_helper.rb', line 112 def humanized_subscription_phase_type(sub) sub.phase_type end |
#humanized_subscription_plan_or_product_name(sub, catalog = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/kaui/subscription_helper.rb', line 73 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) humanized_product_name = if humanized_billing_period.nil? if humanized_price_list.nil? humanized_product_name + humanized_price_override(sub, '', '(', ')') else "#{humanized_product_name} (#{humanized_price_list.downcase}#{humanized_price_override(sub)})" end elsif humanized_price_list.nil? "#{humanized_product_name} (#{humanized_billing_period.downcase}#{humanized_price_override(sub)})" else "#{humanized_product_name} (#{humanized_billing_period.downcase}, #{humanized_price_list.downcase}#{humanized_price_override(sub)})" end humanized_product_name.html_safe end |
#humanized_subscription_pretty_plan_name(sub, catalog = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/kaui/subscription_helper.rb', line 32 def humanized_subscription_pretty_plan_name(sub, catalog = nil) if !sub.present? || !sub.product_name.present? nil else product = 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) ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/helpers/kaui/subscription_helper.rb', line 65 def humanized_subscription_price_list(sub, show_default) if !sub.present? || !sub.price_list.present? || (!show_default && (sub.price_list.upcase == 'DEFAULT')) nil else sub.price_list.downcase.capitalize end end |
#humanized_subscription_product_category(sub) ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/helpers/kaui/subscription_helper.rb', line 5 def humanized_subscription_product_category(sub) if !sub.present? || !sub.product_category.present? nil else humanized_product_category(sub.product_category) end end |
#humanized_subscription_product_name(sub, catalog = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/helpers/kaui/subscription_helper.rb', line 23 def humanized_subscription_product_name(sub, catalog = nil) if !sub.present? || !sub.product_name.present? nil else product = 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
116 117 118 119 120 121 122 |
# File 'app/helpers/kaui/subscription_helper.rb', line 116 def humanized_subscription_start_date(sub, account) if !sub.present? || !sub.start_date.present? || !account.present? || !account.time_zone.present? nil else format_date(sub.start_date, account.time_zone).html_safe end end |
#humanized_time_unit(time_unit) ⇒ Object
164 165 166 |
# File 'app/helpers/kaui/subscription_helper.rb', line 164 def humanized_time_unit(time_unit) time_unit.downcase.capitalize end |
#subscription_cancelled?(sub) ⇒ Boolean
172 173 174 |
# File 'app/helpers/kaui/subscription_helper.rb', line 172 def subscription_cancelled?(sub) sub.present? and sub.billing_end_date.present? end |
#subscription_future_cancelled?(sub, account) ⇒ Boolean
168 169 170 |
# File 'app/helpers/kaui/subscription_helper.rb', line 168 def subscription_future_cancelled?(sub, account) sub.present? && sub.state != 'CANCELLED' && sub.billing_end_date.present? && Time.parse(sub.billing_end_date) > current_time(account.time_zone) end |