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
|
# File 'app/services/bom/xml_from_zone.rb', line 71
def insert_xml_from_bom_soln_into_element(bom, est_element, legacy_style, pricing_formula=nil)
logger.debug "bom['foundsolution']: #{bom['foundsolution']}"
logger.debug "bom['controls']: #{bom['controls'].inspect}"
unless bom['foundsolution'] == false
if legacy_style
bom['controls'].sort_by{|i| [i['price'], i['description']]}.each do |control|
ct_element = REXML::Element.new control['symbol'].downcase
ct_element.add_attribute("qty", control['qty'].to_s)
ct_element.add_attribute("price", get_pricing(control['price'].round(2), pricing_formula).to_s)
ct_element.add_attribute("description", control['description'])
ct_element.add_attribute("sku", control['sku'])
ct_element.add_attribute("third_party_part_number", control['third_party_part_number'])
ct_element.add_attribute("third_party_sku", control['third_party_sku'])
ct_element.add_attribute("cat_id", control['cat_id'].to_s)
item = Item.find_by(sku: control['sku'])
ct_element.add_attribute("image_url", item.thumbnail_url)
est_element.add_element ct_element
end
else
bom_control_groups = (bom['controls'] || []).group_by{|p| p["bundle_sku"]}
bom_required_controls = bom_control_groups[nil] || []
bom_required_controls.sort_by{|i| [i['price'], i['description']]}.each do |control|
ct_element = REXML::Element.new control['symbol'].downcase
ct_element.add_attribute("qty", control['qty'].to_s)
ct_element.add_attribute("price", get_pricing(control['price'].round(2), pricing_formula).to_s)
ct_element.add_attribute("description", control['description'])
ct_element.add_attribute("sku", control['sku'])
ct_element.add_attribute("third_party_part_number", control['third_party_part_number'])
ct_element.add_attribute("third_party_sku", control['third_party_sku'])
ct_element.add_attribute("cat_id", control['cat_id'].to_s)
item = Item.find_by(sku: control['sku'])
ct_element.add_attribute("image_url", item.thumbnail_url)
est_element.add_element ct_element
end
bom_optional_groups = []
bom_control_groups.each do |bundle_sku, products|
bom_optional_groups << products if bundle_sku
end
bom_optional_groups.each do |control_group|
cg_element = REXML::Element.new 'control_group'
cg_element.add_attribute("description", control_group.first['description'])
control_group.each do |control|
ct_element = REXML::Element.new control['symbol'].downcase
ct_element.add_attribute("qty", control['qty'].to_s)
ct_element.add_attribute("price", get_pricing(control['price'].round(2), pricing_formula).to_s)
ct_element.add_attribute("description", control['description'])
ct_element.add_attribute("sku", control['sku'])
ct_element.add_attribute("third_party_part_number", control['third_party_part_number'])
ct_element.add_attribute("third_party_sku", control['third_party_sku'])
ct_element.add_attribute("cat_id", control['cat_id'].to_s)
item = Item.find_by(sku: control['sku'])
ct_element.add_attribute("image_url", item.thumbnail_url)
cg_element.add_element ct_element
end
est_element.add_element cg_element
end
end
bom['elements'].sort_by{|i| [i['price'], i['description']]}.each do |element|
he_element = REXML::Element.new "heating_element"
he_element.add_attribute("qty", element['qty'].to_s)
he_element.add_attribute("price", get_pricing(element['price'].round(2), pricing_formula).to_s)
he_element.add_attribute("description", element['description'])
he_element.add_attribute("sku", element['sku'])
he_element.add_attribute("third_party_part_number", element['third_party_part_number'])
he_element.add_attribute("third_party_sku", element['third_party_sku'])
he_element.add_attribute("cat_id", element['cat_id'].to_s)
item = Item.find_by(sku: element['sku'])
he_element.add_attribute("image_url", item.thumbnail_url)
est_element.add_element he_element
end
(bom['accessories'] || []).select{|i| i['exclusive_group_type'].nil?}.sort_by{|i| [i['price'], i['description']]}.each do |element|
ac_element = REXML::Element.new "accessory"
ac_element.add_attribute("qty", element['qty'].to_s)
ac_element.add_attribute("price", get_pricing(element['price'].round(2), pricing_formula).to_s)
ac_element.add_attribute("description", element['description'])
ac_element.add_attribute("sku", element['sku'])
ac_element.add_attribute("third_party_part_number", element['third_party_part_number'])
ac_element.add_attribute("third_party_sku", element['third_party_sku'])
ac_element.add_attribute("cat_id", element['cat_id'].to_s)
item = Item.find_by(sku: element['sku'])
ac_element.add_attribute("image_url", item.thumbnail_url)
est_element.add_element ac_element
end
end
end
|