Class: Customer::PricingProgramAssigner
- Inherits:
-
Object
- Object
- Customer::PricingProgramAssigner
- Includes:
- ActiveModel::API, ActiveModel::Attributes, ActiveModel::Validations, ActiveModel::Validations::Callbacks, Heatwave::AttributeNormalizing, StripAttributes
- Defined in:
- app/services/customer/pricing_program_assigner.rb
Overview
Questions
- What profile best describes your business?
- How many offices and showrooms do you have?
- Which buying group, distribution center or franchise are you affiliated with?
- How many radiant heating projects do you complete per year?
- Which Pricing Program would you like?
Constant Summary collapse
- GOLD_LEVEL_MIN_THRESHOLD =
Threshold for gold level min.
5000- GOLD_LEVEL_MAX_THRESHOLD =
Threshold for gold level max.
14_999.99- PLATINUM_LEVEL_MIN_THRESHOLD =
Threshold for platinum level min.
15_000- PLATINUM_LEVEL_MAX_THRESHOLD =
Threshold for platinum level max.
34_999.99- TITANIUM_LEVEL_MIN_THRESHOLD =
Threshold for titanium level min.
35_000
Delegated Instance Attributes collapse
-
#e_commerce_misc? ⇒ Object
Alias for Profile#e_commerce_misc?.
-
#homeowner? ⇒ Object
Alias for Profile#homeowner?.
Instance Method Summary collapse
- #always_msrp? ⇒ Boolean
- #basic_discount ⇒ Object
- #coupon_booster ⇒ Object
- #create_activity_for_a_higher_level(level = nil) ⇒ Object
- #create_multi_office_activity ⇒ Object
-
#customer ⇒ Object
def using_override_pricing? return false if q5_answer.blank? Coupon.find(q5_answer).override? end.
- #determine_discount_level_from_purchases(number_of_orders = nil) ⇒ Object
- #existing_discount ⇒ Object
- #existing_discount_better_than_basic? ⇒ Boolean
- #options_step? ⇒ Boolean
- #orders_eligible ⇒ Object
- #override_discount_options ⇒ Object
- #override_option_selected? ⇒ Boolean
- #profile ⇒ Object
- #progress ⇒ Object
- #send_terms_confirmation_email ⇒ Object
- #unknown? ⇒ Boolean
- #update_customer ⇒ Object
Methods included from Heatwave::AttributeNormalizing
Instance Method Details
#always_msrp? ⇒ Boolean
60 61 62 |
# File 'app/services/customer/pricing_program_assigner.rb', line 60 def always_msrp? homeowner? || unknown? || e_commerce_misc? end |
#basic_discount ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/services/customer/pricing_program_assigner.rb', line 98 def basic_discount if always_msrp? || !customer.catalog.is_main_catalog? Coupon.find_by(code: 'PP-LEVEL-0') elsif q3_answer.present? BuyingGroup.find_or_create_by!(company_id: customer.company.id, name: q3_answer).tier2_program_pricing elsif ['Home office only', 'One office (without showroom)', 'Multiple offices (without showroom)'].include?(q2_answer) q4_answer == '0' ? Coupon.find_by(code: 'PP-LEVEL-1') : determine_discount_level_from_purchases elsif q2_answer == 'One office (with showroom)' if q4_answer == '0' Coupon.find_by(code: 'PP-LEVEL-2') elsif %w[1 2].include?(q4_answer) Coupon.find_by(code: 'PP-LEVEL-3') elsif q4_answer == '3 or more' Coupon.find_by(code: 'PP-LEVEL-4') end elsif q2_answer == 'Multiple offices (with one or more showrooms)' if q4_answer == '0' Coupon.find_by(code: 'PP-LEVEL-3') else Coupon.find_by(code: 'PP-LEVEL-4') end else raise 'Cannot determine basic discount' end end |
#coupon_booster ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'app/services/customer/pricing_program_assigner.rb', line 228 def coupon_booster gold = Coupon::Tier2ProgramPricing.find_by(code: 'PP-GOLD-LEVEL') platinum = Coupon::Tier2ProgramPricing.find_by(code: 'PP-PLATINUM-LEVEL') titanium = Coupon::Tier2ProgramPricing.find_by(code: 'PP-TITANIUM-LEVEL') if customer.customer_record.a12net_rev > TITANIUM_LEVEL_MIN_THRESHOLD && customer.tier2_program_pricing.amount_goods < titanium.amount_goods new_level = titanium elsif customer.customer_record.a12net_rev > PLATINUM_LEVEL_MIN_THRESHOLD && customer.customer_record.a12net_rev <= PLATINUM_LEVEL_MAX_THRESHOLD && customer.tier2_program_pricing.amount_goods < platinum.amount_goods new_level = platinum elsif customer.customer_record.a12net_rev > GOLD_LEVEL_MIN_THRESHOLD && customer.customer_record.a12net_rev <= GOLD_LEVEL_MAX_THRESHOLD && customer.tier2_program_pricing.amount_goods < gold.amount_goods new_level = gold end return unless new_level customer.update(tier2_program_pricing: new_level) create_activity_for_a_higher_level(new_level.code) end |
#create_activity_for_a_higher_level(level = nil) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/services/customer/pricing_program_assigner.rb', line 192 def create_activity_for_a_higher_level(level = nil) task_type = { 'PP-GOLD-LEVEL' => 'PRODISCOUNTGOLD', 'PP-PLATINUM-LEVEL' => 'PRODISCOUNTPLATINUM', 'PP-TITANIUM-LEVEL' => 'PRODISCOUNTTITANIUM' }[level] return unless task_type customer.activities.create(party: customer, activity_type: ActivityType.find_by(task_type: task_type), target_datetime: Time.current, assigned_resource: customer.primary_sales_rep) end |
#create_multi_office_activity ⇒ Object
185 186 187 188 189 190 |
# File 'app/services/customer/pricing_program_assigner.rb', line 185 def create_multi_office_activity customer.activities.create(party: customer, activity_type: ActivityType.find_by(task_type: 'CREATE_SUB_ACCOUNTS'), target_datetime: Time.current, assigned_resource: customer.primary_sales_rep) end |
#customer ⇒ Object
def using_override_pricing?
return false if q5_answer.blank?
Coupon.find(q5_answer).override?
end
54 55 56 57 58 |
# File 'app/services/customer/pricing_program_assigner.rb', line 54 def customer Customer.find(customer_id) rescue StandardError nil end |
#determine_discount_level_from_purchases(number_of_orders = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/services/customer/pricing_program_assigner.rb', line 78 def determine_discount_level_from_purchases(number_of_orders = nil) number_of_orders ||= q4_answer number_of_orders = '3' if number_of_orders == '3 or more' number_of_orders = number_of_orders.to_i case number_of_orders.to_i when 0 Coupon.find_by(code: 'PP-LEVEL-1') when 1 Coupon.find_by(code: 'PP-LEVEL-2') when 2 Coupon.find_by(code: 'PP-LEVEL-3') else Coupon.find_by(code: 'PP-LEVEL-4') end end |
#e_commerce_misc? ⇒ Object
Alias for Profile#e_commerce_misc?
70 |
# File 'app/services/customer/pricing_program_assigner.rb', line 70 delegate :e_commerce_misc?, to: :profile |
#existing_discount ⇒ Object
134 135 136 |
# File 'app/services/customer/pricing_program_assigner.rb', line 134 def existing_discount customer.tier2_program_pricing end |
#existing_discount_better_than_basic? ⇒ Boolean
138 139 140 141 142 |
# File 'app/services/customer/pricing_program_assigner.rb', line 138 def existing_discount_better_than_basic? return false if existing_discount.nil? || basic_discount.nil? existing_discount.amount_goods > basic_discount.amount_goods end |
#homeowner? ⇒ Object
Alias for Profile#homeowner?
64 |
# File 'app/services/customer/pricing_program_assigner.rb', line 64 delegate :homeowner?, to: :profile |
#options_step? ⇒ Boolean
46 47 48 |
# File 'app/services/customer/pricing_program_assigner.rb', line 46 def step == :options end |
#orders_eligible ⇒ Object
206 207 208 209 210 211 212 213 214 215 |
# File 'app/services/customer/pricing_program_assigner.rb', line 206 def orders_eligible grouped_orders = customer.orders.so_only.invoiced.where(Order[:line_total].gteq(200)) .where(Order[:shipped_date].gteq(1.year.ago)) .reorder('') # Need this to allow the grouping to work .group(:opportunity_id) # Group by opportunity id (nil opportunity are unassociated orders) .count num_orders = grouped_orders[nil] || 0 # unassociated orders are counted one for one num_orders += [grouped_orders.keys.size - 1, 0].max # count the number of opportunities with qualifying orders num_orders end |
#override_discount_options ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'app/services/customer/pricing_program_assigner.rb', line 124 def levels = ['PP-LEVEL-0', 'PP-LEVEL-1-OVERRIDE', 'PP-LEVEL-2-OVERRIDE', 'PP-LEVEL-3-OVERRIDE', 'PP-LEVEL-4-OVERRIDE'] # show level 5 for Wholesale Distributor, Dealer and Trade Pro (unless affiliated with a buying group) levels << 'PP-LEVEL-5-OVERRIDE' if profile.direct_pro? && q3_answer.blank? = Coupon.where(code: levels).order(amount_goods: :asc) = .where('amount_goods > ?', basic_discount.amount_goods) if basic_discount end |
#override_option_selected? ⇒ Boolean
94 95 96 |
# File 'app/services/customer/pricing_program_assigner.rb', line 94 def override_option_selected? .map { |d| d.id.to_s }.include?(q5_answer) end |
#profile ⇒ Object
72 73 74 75 76 |
# File 'app/services/customer/pricing_program_assigner.rb', line 72 def profile Profile.find(customer.profile_id) rescue StandardError nil end |
#progress ⇒ Object
217 218 219 220 221 222 223 224 225 226 |
# File 'app/services/customer/pricing_program_assigner.rb', line 217 def progress return 'not eligible' if customer.is_homeowner? || !customer.catalog.is_main_catalog? eligible_program = determine_discount_level_from_purchases(orders_eligible) if eligible_program.discount_percentage > customer.pricing_program_discount customer.update(tier2_program_pricing: eligible_program) else 'nothing to update' end end |
#send_terms_confirmation_email ⇒ Object
179 180 181 182 183 |
# File 'app/services/customer/pricing_program_assigner.rb', line 179 def send_terms_confirmation_email CommunicationBuilder.new(template_system_code: 'PRICING_TERMS', recipient_party: customer, emails: email_terms_to, sender_party: customer.primary_sales_rep || customer.sales_manager).create end |
#unknown? ⇒ Boolean
66 67 68 |
# File 'app/services/customer/pricing_program_assigner.rb', line 66 def unknown? profile.name == 'Unknown' end |
#update_customer ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/services/customer/pricing_program_assigner.rb', line 144 def update_customer tier2_coupon_id = if always_msrp? || !customer.catalog.is_main_catalog? Coupon.find_by(code: 'PP-LEVEL-ZERO').id elsif customer..present? BuyingGroup.find_by(id: customer.).tier2_program_pricing_id else Coupon.find_by(code: 'PP-SILVER-LEVEL').id end c = customer c.tier2_program_pricing coupon = Coupon.find_by(id: tier2_coupon_id) # tier2_coupon_id = q5_answer # old_offices = c.number_of_offices # new_offices = q2_answer if homeowner? # Name fixes np = PersonNameParser.new(c.full_name) np.to_party(c) end # c.profile_id = q1_answer # c.number_of_offices = q2_answer # c.buying_group = q3_answer.blank? ? nil : BuyingGroup.where(company_id: customer.company.id, name: q3_answer).first # c.projects_per_year = q4_answer return unless coupon.amount_goods > c.tier2_program_pricing.amount_goods c.tier2_program_pricing_id = tier2_coupon_id c.save! # send_terms_confirmation_email if old_pp != new_pp and email_terms_to.present? # create_multi_office_activity if old_offices != new_offices and new_offices == 'Multiple offices (with one or more showrooms)' end |