Class: RoomConfiguration::CalculateQuote

Inherits:
Object
  • Object
show all
Includes:
Heatwave::AttributeNormalizing, Memery, Service
Defined in:
app/services/room_configuration/calculate_quote.rb

Instance Method Summary collapse

Methods included from Heatwave::AttributeNormalizing

normalize

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Instance Method Details

#callObject



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
# File 'app/services/room_configuration/calculate_quote.rb', line 31

def call
  @msg_arr = []
  pre_process_attributes
  return Result.new(error_status: :missing_catalog, error_message: 'Catalog is missing.', params: attributes_used) if catalog_id.nil?
  return Result.new(error_status: :missing_room_type, error_message: 'Room/Area type is missing.', params: attributes_used) if room_type.nil?
  return Result.new(error_status: :missing_sub_floor_type, error_message: 'Sub Floor type is missing.', params: attributes_used) if room_type.environment.downcase.index('indoor') && sub_floor_type.nil?
  return Result.new(error_status: :missing_floor_type, error_message: 'Floor/Surface type is missing.', params: attributes_used) if floor_type.nil?
  return Result.new(error_status: :missing_heated_areas, error_message: 'Zones or Sq.Ft. must be present to get an instant quote.', params: attributes_used) if heated_area_sqft.to_f == 0.0

  boms = generate_fresh_bom

  if boms.present?
    build_result boms.sort_by { |e| e[:price] }, last_modified: Time.current
  else
    error_message = @msg_arr.compact.uniq.join(' ')
    ErrorReporting.warning(
      error_message,
      attributes_used.merge(
        tried_product_lines: @tried_product_line_urls,
        floor_type_name: floor_type&.name,
        room_type_name: room_type&.name
      )
    )
    Result.new(error_status: :error, error_message:, params: attributes_used)
  end
end