Class: Api::V1::BomController

Inherits:
BaseController show all
Defined in:
app/controllers/api/v1/bom_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#catalog_for_request, #error!, #locale_for_request, #logger, #render_bad_request_response, #render_internal_server_error, #render_not_found_response, #render_result, #render_unprocessable_entity_response, #set_locale, #store_for_request, #underscore_params

Instance Method Details

#get_bill_of_materials_xmlObject



3
4
5
6
7
8
9
10
11
12
13
14
15
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
62
# File 'app/controllers/api/v1/bom_controller.rb', line 3

def get_bill_of_materials_xml
  quick_estimator = log_qe_bom_request_if_needed("get_bill_of_materials_xml", params[:api_key])
  valid_args = false

  zones = []

  if catalog && !(params[:floor_type_id].nil? || (params[:floor_type_id].strip.empty? rescue true) || params[:floor_type_id] == "-1" || params[:heating_system_type_code].nil? || (params[:heating_system_type_code].strip.empty? rescue true))
    floor_type = FloorType.find(params[:floor_type_id].to_i) rescue nil
    if floor_type.nil? and params[:floor_type_id].to_i > 0
      # handle deprecated/removed floor type ids
      floor_type = (FloorType.find_by(name: "Tile, Marble or Stone") rescue nil) if params[:floor_type_id].to_i == 7
      floor_type = (FloorType.find_by(name: "Tile, Marble or Stone") rescue nil) if params[:floor_type_id].to_i == 25
      floor_type = (FloorType.find_by(name: "Resilients, Vinyl and Luxury Vinyl Tile (LVT)") rescue nil) if params[:floor_type_id].to_i == 8
    end
    heating_system_pl = HeatingElementProductLineOption.get_product_line_from_heating_system_type_code(params[:heating_system_type_code].upcase)
    if floor_type && heating_system_pl
      unless params[:zones].nil? || params[:zones].empty?
        # need at least one zone to be valid
        params[:zones].each{|zone_ind, zone_data|
          zone = {}
          zone[:sqft] = zone_data[:sqft].to_f
          zone[:length] = zone_data[:length].to_f if zone_data[:length].to_f > 0.0
          zone[:width] = zone_data[:width].to_f if zone_data[:width].to_f > 0.0
          if (zone[:sqft] > 9.0 && zone[:sqft] < 10000.0)
            valid_args = true
            zones  << zone
            # tire tracks require some length definition
            if params[:coverage_state] == 'tire_tracks'
              valid_args = false unless zone[:length].to_f > 1.0
            end
          end
        }
      end

    end
  end

  if valid_args
    options = {}
    options[:coverage_state] = params[:coverage_state]
    options[:voltage] = Voltage.find(params[:voltage].to_i) rescue nil
    require_expansion_joint = HeatingElementProductLineOption.get_field_array_from_options(:require_expansion_joint, {:floor_type_id => floor_type.id, :product_line_id => heating_system_pl.id}).first
    options[:expansion_joint_spacing] = (params[:expansion_joint_spacing].to_f rescue nil) if (params[:expansion_joint_spacing] && require_expansion_joint)
    options[:cable_spacing] = params[:cable_spacing].to_f if params[:cable_spacing]
    options[:pricing_formula] = quick_estimator.get_pricing_formula if quick_estimator
    bfz = Bom::XmlFromZone.new(catalog: catalog,
                         floor_type: floor_type,
                         heating_system_pl: heating_system_pl,
                         zones: zones,
                         options: options,
                         third_party_name_locale: third_party_name_locale,
                         quick_estimator: quick_estimator)
    xmlstr = bfz.call
  else
    xmlstr = ""
    err_msg = "RoomController#get_bill_of_materials_xml valid args is false."
    ErrorReporting.warning(err_msg, request)
  end
  render xml: xmlstr
end