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
|
# File 'app/services/item/materials/checks/towel_warmer.rb', line 11
def process(container:, options:{})
return Result.new(status: :skipped) unless qualify?(container)
material_alerts = []
num_towel_warmers_dual = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_dual_connect? }.sum{|l| l.quantity}
num_towel_warmers_plug_in = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_plug_in? }.sum{|l| l.quantity}
num_towel_warmers_hardwired = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_hardwired? }.sum{|l| l.quantity}
num_towel_warmer_controls_plug_in = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_plug_in_control? }.sum{|l| l.quantity}
num_towel_warmer_controls_hardwired = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_hardwired_control? }.sum{|l| l.quantity}
if (num_towel_warmer_controls_plug_in != num_towel_warmers_plug_in) && (num_towel_warmer_controls_plug_in != num_towel_warmers_plug_in + num_towel_warmers_dual) && container.catalog.catalog_items.by_skus(Item.towel_warmer_controls_plug_in.pluck(:sku)).public_catalog_items.any?
diff_qty = num_towel_warmer_controls_plug_in - (num_towel_warmers_plug_in + num_towel_warmers_dual)
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = diff_qty.positive? ? (num_towel_warmers_plug_in + num_towel_warmers_dual) : num_towel_warmers_plug_in ma_options[:actual_qty] = num_towel_warmer_controls_plug_in
if (ctrl_lis = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_plug_in_control? }).any?
ma_options[:items] = ctrl_lis.map{|l| l.item}
else
ma_options[:items] = Item.towel_warmer_controls_plug_in.to_a
end
ma_options[:unmaskable] = true
ma_options[:name] = "One plug in control per plug in towel warmer is recommended."
material_alerts << Item::Materials::Alert.new(ma_options)
end
if (num_towel_warmer_controls_hardwired != num_towel_warmers_hardwired) && (num_towel_warmer_controls_hardwired != num_towel_warmers_hardwired + num_towel_warmers_dual) && container.catalog.catalog_items.by_skus(Item.towel_warmer_controls_hardwired.pluck(:sku)).public_catalog_items.any?
diff_qty = num_towel_warmer_controls_hardwired - (num_towel_warmers_hardwired + num_towel_warmers_dual)
ma_options = {}.merge(options)
ma_options[:room] = container
ma_options[:recommended_qty] = diff_qty.positive? ? (num_towel_warmers_hardwired + num_towel_warmers_dual) : num_towel_warmers_hardwired ma_options[:actual_qty] = num_towel_warmer_controls_hardwired
if (ctrl_lis = container.line_items.parents_only.select{|l| l.item.is_towel_warmer_hardwired_control? }).any?
ma_options[:items] = ctrl_lis.map{|l| l.item}
else
ma_options[:items] = Item.towel_warmer_controls_hardwired.order_towel_warmer_controls_hardwired.to_a
end
ma_options[:unmaskable] = true
ma_options[:name] = "One hardwired control per hardwired towel warmer is recommended."
material_alerts << Item::Materials::Alert.new(ma_options)
end
Result.new(status: :ok, alerts: material_alerts)
end
|