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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'app/services/item/materials/checks/roof_deicing.rb', line 37
def process(container:, options:{})
return Result.new(status: :skipped) unless qualify?(container)
material_alerts = []
rg_heating_elements = get_rg_heating_elements(container)
all_bundled_rg_skus = DEICING_CONTROL_BUNDLES_BY_GROUP.map{|k,v| v}.flatten
all_controls_rg_skus = DEICING_CONTROL_BUNDLES_BY_GROUP.map{|k,v| v.first}
controls = container.line_items.select{|li| all_controls_rg_skus.include?(li.sku)}
relay_panels = container.line_items.relay_panels
if (num_controls = controls.sum{|li| li.quantity}) > (num_heating_elements = rg_heating_elements.sum{|li| li.quantity})
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = num_heating_elements
ma_options[:actual_qty] = num_controls
ma_options[:items] = controls.map{|li| li.item}.compact
ma_options[:name] = "At least one heating element per control is recommended."
material_alerts << Item::Materials::Alert.new(ma_options)
end
DEICING_CONTROL_BUNDLES_BY_GROUP.select{|k,v| controls.any?{|li| v.include?(li.sku)}}.each do |group_sku, bundled_rg_skus|
rg_control = Item.find_by(sku: DEICING_CONTROL_BUNDLES_BY_GROUP[group_sku].first)
if (non_group_bundle_lis = container.line_items.select{|li| (all_bundled_rg_skus - bundled_rg_skus).include?(li.sku)}).any?
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = 0
ma_options[:actual_qty] = 1
items = non_group_bundle_lis.map{|li| li.item}.compact
ma_options[:name] = "Using the following items is not recommended with the #{DEICING_CONTROL_BUNDLE_SKU_NAME_HASH[group_sku]} roof and gutter deicing control:"
ma_options[:items] = items
ma_options[:unmaskable] = true
material_alerts << Item::Materials::Alert.new(ma_options)
end
bundled_skus_not_in_lis = bundled_rg_skus.select{|sku| container.line_items.detect{|li| li.sku == sku}.nil?}
if bundled_skus_not_in_lis.any?
items = bundled_skus_not_in_lis.map{|sku| Item.find_by(sku: sku)}
if items.any? and items.all?{|item| container.catalog.catalog_items.by_skus(item.sku).first.present?}
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = controls.select{|li| li.sku == rg_control.sku}.sum{|li| li.quantity}
ma_options[:actual_qty] = 0
ma_options[:name] = "The following items are recommended with the #{DEICING_CONTROL_BUNDLE_SKU_NAME_HASH[group_sku]} roof and gutter deicing control:"
ma_options[:items] = items
ma_options[:unmaskable] = true
material_alerts << Item::Materials::Alert.new(ma_options)
end
end
end
if controls.any?
volts_arr = container.line_items.heating_elements.collect{|li| li.item.voltage}.uniq
qtys_arr = volts_arr.map{|v| container.line_items.heating_elements.with_product_specification(:voltage, v).to_a.select{|li| li.item.product_lines.any?{|pl| pl.roof_deicing?}}.sum{|li| li.quantity}}
poles = 0
qtys_arr.each_with_index do |q, i|
poles += (q/MAX_FT_PER_30_AMP_CIRCUIT_120V_R_G_DEICING_CABLE).ceil
end
actual_poles = relay_panels.to_a.sum{|li| li.num_poles.to_i*li.quantity}
if actual_poles < poles
relay_panels_sku_qty = HeatingElementProductLineOption.get_relay_panels_from_poles(poles)
relay_panels_sku_qty.each do |sku, qty|
actual_qty = relay_panels.select{|li| li.sku == sku}.sum{|li| li.quantity}
if qty != actual_qty and container.catalog.catalog_items.by_skus(sku).first.present? and (item = Item.find_by(sku: sku)).present?
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = qty
ma_options[:actual_qty] = actual_qty
ma_options[:items] = [item]
ma_options[:unmaskable] = true
material_alerts << Item::Materials::Alert.new(ma_options)
end
end
end
rcos = container.line_items.select{|li| li.sku == "RCO"}
if rcos.any? and controls.detect{|li| ["SCA-DUAL"].include?(li.sku)}.nil? and (item = Item.find_by(sku: "RCO")).present?
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = 0
ma_options[:actual_qty] = rcos.sum{|li| li.quantity}
ma_options[:items] = [item]
ma_options[:unmaskable] = true
ma_options[:name] = "The RCO is only compatible with the Advanced roof and gutter deicing control."
material_alerts << Item::Materials::Alert.new(ma_options)
end
end
if container_or_rooms_have_floor_type_but_no_line_items_with_sku_fragment?(container, :is_slate_shingle?, "ET-CL-CU-SLS") and (items = Item.available_to_public.where("items.sku ilike '%ET-CL-CU-SLS%'")).any?
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = 1
ma_options[:actual_qty] = 0
ma_options[:items] = items
ma_options[:unmaskable] = true
ma_options[:name] = "We recommend one of these special order copper 3-prong roof clips with Slate shingle roof and roof and gutter deicing."
material_alerts << Item::Materials::Alert.new(ma_options)
end
if container_or_rooms_have_floor_type_but_no_line_items_with_sku_fragment?(container, :is_copper?, "ET-CL-CU-P25") and (items = Item.available_to_public.where("items.sku ilike '%ET-CL-CU-P25%'")).any?
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = 1
ma_options[:actual_qty] = 0
ma_options[:items] = items
ma_options[:unmaskable] = true
ma_options[:name] = "We recommend one of these special order copper 3-prong roof clips with Copper roof and roof and gutter deicing."
material_alerts << Item::Materials::Alert.new(ma_options)
end
if (container.line_items.select{|li| li.item.sku.index("SR-PWR-KIT")}.empty? and container.line_items.select{|li| li.item.sku.index("SR-PLUG-KIT")}.empty?)
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = 1
ma_options[:actual_qty] = 0
ma_options[:items] = [Item.find_by(sku: "SR-PWR-KIT"), Item.find_by(sku: "SR-PLUG-KIT")]
ma_options[:unmaskable] = true
ma_options[:name] = "We recommend one of these Power Connection Kits with roof and gutter deicing cable."
material_alerts << Item::Materials::Alert.new(ma_options)
end
Result.new(status: :ok, alerts: material_alerts)
end
|