Class: HeatingSystemCalculator::SmartServicesFinder
- Inherits:
-
BaseItemFinder
- Object
- BaseItemFinder
- HeatingSystemCalculator::SmartServicesFinder
- Defined in:
- app/services/heating_system_calculator/smart_services_finder.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#smart_services ⇒ Object
readonly
Returns the value of attribute smart_services.
Instance Method Summary collapse
- #find_smart_services(elements, _controls, accessories) ⇒ Object
-
#initialize(options) ⇒ SmartServicesFinder
constructor
A new instance of SmartServicesFinder.
- #installation_is_within_range? ⇒ Boolean
- #service_distance ⇒ Object
Methods inherited from BaseItemFinder
#get_number_of_poles_from_consolidated_elements, #get_total_from_solution
Constructor Details
#initialize(options) ⇒ SmartServicesFinder
Returns a new instance of SmartServicesFinder.
5 6 7 8 9 10 11 12 13 14 |
# File 'app/services/heating_system_calculator/smart_services_finder.rb', line 5 def initialize() @heated_area = [:heated_area] @heating_system = [:heating_system] @accessory_set = [:accessory_set] @smart_service_set = [:smart_service_set] @underlayment_set = [:underlayment_set] @rough_in_kit_for_tstat = [:rough_in_kit_for_tstat] @rough_in_kit_for_power_module = [:rough_in_kit_for_power_module] @installation_postal_code = @heated_area.installation_postal_code end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
3 4 5 |
# File 'app/services/heating_system_calculator/smart_services_finder.rb', line 3 def error @error end |
#smart_services ⇒ Object (readonly)
Returns the value of attribute smart_services.
3 4 5 |
# File 'app/services/heating_system_calculator/smart_services_finder.rb', line 3 def smart_services @smart_services end |
Instance Method Details
#find_smart_services(elements, _controls, accessories) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/services/heating_system_calculator/smart_services_finder.rb', line 16 def find_smart_services(elements, _controls, accessories) @smart_services = [] res = {} return self unless installation_is_within_range? indoor_floating_coverage = indoor_thinset_coverage = outdoor_mat_coverage = outdoor_cable_coverage = underlayment_coverage = service_fee = total = 0 fixed_rate_service_to_apply = nil if @heating_system.heating_system_product_line.environ_flex_roll? || @heating_system.heating_system_product_line.environ_easy_mat? indoor_floating_coverage = elements.sum do |e| e['area'] end end indoor_thinset_coverage = elements.sum { |e| e['area'] } if @heating_system.heating_system_product_line.tempzone? outdoor_mat_coverage = elements.sum { |e| e['area'] } if @heating_system.heating_system_product_line.snow_melt_mat? outdoor_cable_coverage = elements.sum { |e| e['area'] } if @heating_system.heating_system_product_line.snow_melt_cable? underlayment_coverage = accessories.select { |a| a['symbol'] == 'UNDERLAYMENT' }.sum { |a| a['sqft'] } service_skus_and_coverage_by_type = [ { fixed_rate_sku: 'SII_FLOATING_FIXRATE', per_sqft_sku: 'SII_FLOATING_PER_SQFT', min_coverage: 100, coverage: indoor_floating_coverage }, { fixed_rate_sku: 'SII_THINSET_FIXRATE', per_sqft_sku: 'SII_THINSET_PER_SQFT', min_coverage: 50, coverage: indoor_thinset_coverage }, { fixed_rate_sku: 'SIO_MAT_FIXRATE', per_sqft_sku: 'SIO_MAT_PER_SQFT', min_coverage: 0, coverage: outdoor_mat_coverage }, { fixed_rate_sku: 'SIO_CABLE_FIXRATE', per_sqft_sku: 'SIO_CABLE_PER_SQFT', min_coverage: 0, coverage: outdoor_cable_coverage }, { fixed_rate_sku: 'SII_THINSET_FIXRATE', per_sqft_sku: 'SII_UNDERLAYMENT_PER_SQFT', min_coverage: 0, coverage: underlayment_coverage } ] smart_service_included_items = [] service_skus_and_coverage_by_type.each do |service_skus_and_coverage_hash| next unless service_skus_and_coverage_hash[:coverage].positive? && (fixed_rate_service = @smart_service_set.detect do |s| s['sku'] == service_skus_and_coverage_hash[:fixed_rate_sku] end).present? && (per_sqft_service = @smart_service_set.detect do |s| s['sku'] == service_skus_and_coverage_hash[:per_sqft_sku] end).present? coverage = [service_skus_and_coverage_hash[:min_coverage], service_skus_and_coverage_hash[:coverage]].max smart_service_included_items << per_sqft_service.merge({ 'qty' => coverage.ceil }) fixed_rate_service_to_apply ||= fixed_rate_service fixed_rate_service_to_apply = fixed_rate_service if fixed_rate_service['price'] > fixed_rate_service_to_apply['price'] end if fixed_rate_service_to_apply smart_service_included_items << fixed_rate_service_to_apply.merge({ 'qty' => 1 }) new_price = smart_service_included_items.sum { |si| si['qty'] * si['price'] } @smart_services << fixed_rate_service_to_apply.dup.merge({ 'qty' => 1, 'description' => 'SmartInstall Installation Service', 'price' => new_price, 'exclusive_group_type' => 'smart_install_installation_service', 'exclusive_group_name' => 'SmartInstall Installation Service', 'includedItems' => smart_service_included_items }) end self end |
#installation_is_within_range? ⇒ Boolean
63 64 65 66 67 |
# File 'app/services/heating_system_calculator/smart_services_finder.rb', line 63 def installation_is_within_range? return true if service_distance.present? and service_distance <= SMART_SERVICES_MAX_DISTANCE # within 100 miles from office false end |
#service_distance ⇒ Object
69 70 71 72 |
# File 'app/services/heating_system_calculator/smart_services_finder.rb', line 69 def service_distance distance = SmartServicesController.helpers.calculate_distance_from_lz(@installation_postal_code) if @installation_postal_code distance end |