xmlconv2 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/LICENCE.txt +339 -0
- data/Manifest.txt +107 -0
- data/README.txt +25 -0
- data/Rakefile +28 -0
- data/bin/admin +65 -0
- data/bin/xmlconvd +19 -0
- data/data/grammar/i2.grammar +73 -0
- data/src/conversion/bdd_geh.rb +281 -0
- data/src/conversion/bdd_i2.rb +102 -0
- data/src/conversion/bdd_xml.rb +242 -0
- data/src/conversion/geh_bdd.rb +165 -0
- data/src/conversion/i2_bdd.rb +271 -0
- data/src/conversion/xml_bdd.rb +125 -0
- data/src/custom/lookandfeel.rb +47 -0
- data/src/i2/address.rb +33 -0
- data/src/i2/date.rb +37 -0
- data/src/i2/document.rb +26 -0
- data/src/i2/header.rb +24 -0
- data/src/i2/order.rb +44 -0
- data/src/i2/parser.rb +25 -0
- data/src/i2/position.rb +37 -0
- data/src/i2/record.rb +11 -0
- data/src/model/address.rb +20 -0
- data/src/model/agreement.rb +10 -0
- data/src/model/bdd.rb +26 -0
- data/src/model/bsr.rb +16 -0
- data/src/model/delivery.rb +15 -0
- data/src/model/delivery_item.rb +18 -0
- data/src/model/freetext_container.rb +26 -0
- data/src/model/id_container.rb +15 -0
- data/src/model/invoice.rb +18 -0
- data/src/model/invoice_item.rb +11 -0
- data/src/model/item.rb +19 -0
- data/src/model/item_container.rb +15 -0
- data/src/model/name.rb +27 -0
- data/src/model/part_info.rb +10 -0
- data/src/model/part_info_container.rb +15 -0
- data/src/model/party.rb +23 -0
- data/src/model/party_container.rb +20 -0
- data/src/model/price.rb +10 -0
- data/src/model/price_container.rb +18 -0
- data/src/model/transaction.rb +28 -0
- data/src/state/global.rb +28 -0
- data/src/state/global_predefine.rb +11 -0
- data/src/state/login.rb +38 -0
- data/src/state/transaction.rb +13 -0
- data/src/state/transactions.rb +130 -0
- data/src/util/application.rb +143 -0
- data/src/util/destination.rb +130 -0
- data/src/util/invoicer.rb +72 -0
- data/src/util/known_user.rb +16 -0
- data/src/util/polling_manager.rb +78 -0
- data/src/util/session.rb +23 -0
- data/src/util/transaction.rb +105 -0
- data/src/util/validator.rb +20 -0
- data/src/view/foot.rb +27 -0
- data/src/view/head.rb +13 -0
- data/src/view/login.rb +36 -0
- data/src/view/navigation.rb +30 -0
- data/src/view/navigationlink.rb +21 -0
- data/src/view/pager.rb +73 -0
- data/src/view/preformatted.rb +39 -0
- data/src/view/template.rb +17 -0
- data/src/view/transaction.rb +42 -0
- data/src/view/transactions.rb +90 -0
- data/test/mock.rb +149 -0
- data/test/suite.rb +16 -0
- data/test/test_conversion/bdd_geh.rb +533 -0
- data/test/test_conversion/bdd_i2.rb +314 -0
- data/test/test_conversion/bdd_xml.rb +556 -0
- data/test/test_conversion/geh_bdd.rb +372 -0
- data/test/test_conversion/i2_bdd.rb +804 -0
- data/test/test_conversion/xml_bdd.rb +203 -0
- data/test/test_i2/address.rb +88 -0
- data/test/test_i2/date.rb +49 -0
- data/test/test_i2/document.rb +62 -0
- data/test/test_i2/header.rb +39 -0
- data/test/test_i2/order.rb +94 -0
- data/test/test_i2/parser.rb +309 -0
- data/test/test_i2/position.rb +65 -0
- data/test/test_integration/geh_i2.rb +312 -0
- data/test/test_integration/i2_geh.rb +449 -0
- data/test/test_integration/i2_xml.rb +162 -0
- data/test/test_integration/xml_i2.rb +254 -0
- data/test/test_model/address.rb +35 -0
- data/test/test_model/agreement.rb +22 -0
- data/test/test_model/bdd.rb +55 -0
- data/test/test_model/bsr.rb +38 -0
- data/test/test_model/delivery.rb +79 -0
- data/test/test_model/delivery_item.rb +52 -0
- data/test/test_model/freetext_container.rb +45 -0
- data/test/test_model/invoice.rb +65 -0
- data/test/test_model/invoice_item.rb +41 -0
- data/test/test_model/name.rb +57 -0
- data/test/test_model/part_info.rb +24 -0
- data/test/test_model/party.rb +96 -0
- data/test/test_model/price.rb +24 -0
- data/test/test_util/application.rb +168 -0
- data/test/test_util/destination.rb +197 -0
- data/test/test_util/invoicer.rb +36 -0
- data/test/test_util/polling_manager.rb +111 -0
- data/test/test_util/transaction.rb +129 -0
- data/user-stories/UserStories_XmlConv2.txt +381 -0
- data/user-stories/doku/ABB.incoming.HTTP.invoice.xml +315 -0
- data/user-stories/doku/ABB.received.xml +259 -0
- data/user-stories/doku/BO_OrderProcessing.sxw +0 -0
- metadata +195 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# BddI2 -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'i2/document'
|
5
|
+
require 'i2/address'
|
6
|
+
require 'i2/position'
|
7
|
+
|
8
|
+
module XmlConv
|
9
|
+
module Conversion
|
10
|
+
class BddI2
|
11
|
+
I2_ADDR_CODES = {
|
12
|
+
'BillTo' => :buyer,
|
13
|
+
'Employee' => :employee,
|
14
|
+
'ShipTo' => :delivery,
|
15
|
+
}
|
16
|
+
I2_DELIVERY_CODES = {
|
17
|
+
'wird abgeholt' => :pickup,
|
18
|
+
'werkslieferung' => :delivery,
|
19
|
+
'camion' => :camion,
|
20
|
+
}
|
21
|
+
class << self
|
22
|
+
def convert(bdd)
|
23
|
+
doc = I2::Document.new
|
24
|
+
header = I2::Header.new
|
25
|
+
doc.header = header
|
26
|
+
bdd.deliveries.each { |delivery|
|
27
|
+
_doc_add_delivery(doc, delivery)
|
28
|
+
}
|
29
|
+
doc
|
30
|
+
end
|
31
|
+
def _doc_add_delivery(doc, delivery)
|
32
|
+
order = I2::Order.new
|
33
|
+
order.sender_id = delivery.bsr_id
|
34
|
+
# customer_id is in reality the delivery_id assigned by the
|
35
|
+
# customer - the slight confusion is due to automatic naming
|
36
|
+
order.delivery_id = delivery.customer_id
|
37
|
+
order.add_date(I2::Date.from_date(::Date.today))
|
38
|
+
if(customer = delivery.customer)
|
39
|
+
_order_add_customer(order, customer)
|
40
|
+
end
|
41
|
+
if(agreement = delivery.agreement)
|
42
|
+
order.terms_cond = I2_DELIVERY_CODES[agreement.terms_cond]
|
43
|
+
end
|
44
|
+
delivery.items.each { |item|
|
45
|
+
_order_add_item(order, item)
|
46
|
+
}
|
47
|
+
doc.add_order(order)
|
48
|
+
end
|
49
|
+
def _address_add_bdd_addr(address, bdd_addr)
|
50
|
+
if(bdd_addr.size < 2)
|
51
|
+
bdd_addr.lines.each_with_index { |line, idx|
|
52
|
+
address.send("street#{idx.next}=", line)
|
53
|
+
}
|
54
|
+
else
|
55
|
+
ln1, ln2, ln3 = bdd_addr.lines
|
56
|
+
address.name2 = ln1
|
57
|
+
address.street1 = ln2
|
58
|
+
address.street2 = ln3 unless(ln3.nil?)
|
59
|
+
end
|
60
|
+
address.city = bdd_addr.city
|
61
|
+
address.zip_code = bdd_addr.zip_code
|
62
|
+
end
|
63
|
+
def _order_add_customer(order, customer)
|
64
|
+
customer.parties.each { |party|
|
65
|
+
_order_add_party(order, party)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
def _order_add_party(order, party)
|
69
|
+
address = I2::Address.new
|
70
|
+
address.party_id = party.acc_id
|
71
|
+
if(name = party.name)
|
72
|
+
address.name1 = name.to_s
|
73
|
+
end
|
74
|
+
if(code = I2_ADDR_CODES[party.role])
|
75
|
+
address.code = code
|
76
|
+
end
|
77
|
+
if(bdd_addr = party.address)
|
78
|
+
_address_add_bdd_addr(address, bdd_addr)
|
79
|
+
end
|
80
|
+
order.add_address(address)
|
81
|
+
end
|
82
|
+
def _order_add_item(order, item)
|
83
|
+
position = I2::Position.new
|
84
|
+
position.number = item.line_no
|
85
|
+
position.article_ean = item.et_nummer_id
|
86
|
+
if(id = item.customer_id)
|
87
|
+
position.customer_id = id
|
88
|
+
end
|
89
|
+
position.qty = item.qty
|
90
|
+
position.unit = item.unit
|
91
|
+
if(date = item.delivery_date)
|
92
|
+
position.delivery_date = I2::Date.from_date(date)
|
93
|
+
end
|
94
|
+
if(price = item.get_price('NettoPreis'))
|
95
|
+
position.price = price.amount
|
96
|
+
end
|
97
|
+
order.add_position(position)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# BddXml -- xmlconv2 -- 21.06.2004 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
module XmlConv
|
7
|
+
module Conversion
|
8
|
+
class BddXml
|
9
|
+
class << self
|
10
|
+
def convert(bdd)
|
11
|
+
skeleton = <<-EOS
|
12
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
13
|
+
<!DOCTYPE BDD SYSTEM "ABB BDD.dtd">
|
14
|
+
<BDD />
|
15
|
+
EOS
|
16
|
+
doc = REXML::Document.new(skeleton)
|
17
|
+
_xml_add_bdd_bsr(doc.root, bdd.bsr)
|
18
|
+
bdd.deliveries.each { |delivery|
|
19
|
+
_xml_add_bdd_delivery(doc.root, delivery)
|
20
|
+
}
|
21
|
+
bdd.invoices.each { |invoice|
|
22
|
+
_xml_add_bdd_invoice(doc.root, invoice)
|
23
|
+
}
|
24
|
+
doc
|
25
|
+
end
|
26
|
+
def _xml_add_bdd_address(xml_elm, address)
|
27
|
+
xml_addr = REXML::Element.new('Address')
|
28
|
+
address.lines.each { |line|
|
29
|
+
xml_line = REXML::Element.new('AddressLine')
|
30
|
+
xml_line.text = line
|
31
|
+
xml_addr.add_element(xml_line)
|
32
|
+
}
|
33
|
+
if(city = address.city)
|
34
|
+
xml_city = REXML::Element.new('City')
|
35
|
+
xml_city.text = city
|
36
|
+
xml_addr.add_element(xml_city)
|
37
|
+
end
|
38
|
+
if(zip_code = address.zip_code)
|
39
|
+
xml_zip = REXML::Element.new('ZipCode')
|
40
|
+
domain = address.country || 'CH'
|
41
|
+
xml_zip.add_attribute('Domain', domain)
|
42
|
+
xml_zip.text = zip_code
|
43
|
+
xml_addr.add_element(xml_zip)
|
44
|
+
end
|
45
|
+
xml_elm.add_element(xml_addr)
|
46
|
+
end
|
47
|
+
def _xml_add_bdd_agreement(xml_elm, agreement)
|
48
|
+
if(terms_cond = agreement.terms_cond)
|
49
|
+
xml_agreement = REXML::Element.new('Agreement')
|
50
|
+
terms = REXML::Element.new('TermsCond')
|
51
|
+
terms.text = terms_cond
|
52
|
+
xml_agreement.add_element(terms)
|
53
|
+
xml_elm.add_element(xml_agreement)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
def _xml_add_bdd_bsr(xml_bdd, bsr)
|
57
|
+
xml_bsr = REXML::Element.new('BSR')
|
58
|
+
timestamp = REXML::Element.new('Timestamp')
|
59
|
+
time = bsr.timestamp || Time.now
|
60
|
+
zone = sprintf("%+i", time.gmtoff / 3600)
|
61
|
+
timestamp.add_attribute('Zone', zone)
|
62
|
+
timestamp.text = time.strftime('%Y%m%d%H%M%S')
|
63
|
+
xml_bsr.add_element(timestamp)
|
64
|
+
verb = REXML::Element.new('Verb')
|
65
|
+
verb.text = bsr.verb || 'Return'
|
66
|
+
xml_bsr.add_element(verb)
|
67
|
+
noun = REXML::Element.new('Noun')
|
68
|
+
noun.text = bsr.noun || 'Status'
|
69
|
+
xml_bsr.add_element(noun)
|
70
|
+
bsr.parties.each { |party|
|
71
|
+
_xml_add_bdd_party(xml_bsr, party)
|
72
|
+
}
|
73
|
+
xml_bdd.add_element(xml_bsr)
|
74
|
+
end
|
75
|
+
def _xml_add_bdd_delivery(xml_bdd, delivery)
|
76
|
+
xml_delivery = REXML::Element.new('Delivery')
|
77
|
+
_xml_assemble_bdd_transaction(xml_delivery, delivery)
|
78
|
+
xml_bdd.add_element(xml_delivery)
|
79
|
+
end
|
80
|
+
def _xml_add_bdd_invoice(xml_bdd, invoice)
|
81
|
+
xml_invoice = REXML::Element.new('Invoice')
|
82
|
+
if(invoice_id = invoice.invoice_id)
|
83
|
+
domain, idstr = invoice_id
|
84
|
+
_xml_add_domain_id(xml_invoice, domain, idstr, 'InvoiceId')
|
85
|
+
end
|
86
|
+
if(delivery_id = invoice.delivery_id)
|
87
|
+
domain, idstr = delivery_id
|
88
|
+
_xml_add_domain_id(xml_invoice, domain, idstr, 'DeliveryId')
|
89
|
+
end
|
90
|
+
_xml_assemble_bdd_transaction(xml_invoice, invoice)
|
91
|
+
xml_bdd.add_element(xml_invoice)
|
92
|
+
end
|
93
|
+
def _xml_add_bdd_name(xml_elm, name)
|
94
|
+
xml_name = REXML::Element.new('Name')
|
95
|
+
if(name.text)
|
96
|
+
xml_name.text = name.to_s
|
97
|
+
else
|
98
|
+
if(first = name.first)
|
99
|
+
xml_first = REXML::Element.new('FirstName')
|
100
|
+
xml_first.text = first
|
101
|
+
xml_name.add_element(xml_first)
|
102
|
+
end
|
103
|
+
if(last = name.last)
|
104
|
+
xml_last = REXML::Element.new('LastName')
|
105
|
+
xml_last.text = last
|
106
|
+
xml_name.add_element(xml_last)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
xml_elm.add_element(xml_name)
|
110
|
+
end
|
111
|
+
def _xml_add_bdd_party(xml_elm, party)
|
112
|
+
xml_party = REXML::Element.new('Party')
|
113
|
+
xml_party.add_attribute('Version', '2')
|
114
|
+
xml_party.add_attribute('Role', party.role)
|
115
|
+
party.ids.each { |domain, idstr|
|
116
|
+
_xml_add_domain_id(xml_party, domain, idstr, 'PartyId')
|
117
|
+
}
|
118
|
+
if(name = party.name)
|
119
|
+
_xml_add_bdd_name(xml_party, name)
|
120
|
+
end
|
121
|
+
if(addr = party.address)
|
122
|
+
_xml_add_bdd_address(xml_party, addr)
|
123
|
+
end
|
124
|
+
party.parties.each { |subdiv|
|
125
|
+
_xml_add_bdd_party(xml_party, subdiv)
|
126
|
+
}
|
127
|
+
xml_elm.add_element(xml_party)
|
128
|
+
end
|
129
|
+
def _xml_add_delivery_item(xml_delivery, item)
|
130
|
+
xml_item = _xml_add_item(xml_delivery, item, 'DeliveryItem')
|
131
|
+
if((date = item.delivery_date) && date.respond_to?(:strftime))
|
132
|
+
xml_date = REXML::Element.new('DeliveryDate')
|
133
|
+
xml_date.text = date.strftime('%Y%m%d')
|
134
|
+
xml_item.add_element(xml_date)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
def _xml_add_domain_id(xml_elm, domain, idstr, idname)
|
138
|
+
xml_id = REXML::Element.new(idname)
|
139
|
+
xml_id.add_attribute('Domain', domain)
|
140
|
+
xml_id.text = idstr
|
141
|
+
xml_elm.add_element(xml_id)
|
142
|
+
end
|
143
|
+
def _xml_add_free_text(xml_elm, free_text)
|
144
|
+
xml_text = REXML::Element.new('FreeText')
|
145
|
+
if(type = free_text.type)
|
146
|
+
xml_text.add_attribute('Type', type)
|
147
|
+
end
|
148
|
+
xml_text.text = free_text.to_s
|
149
|
+
xml_elm.add_element(xml_text)
|
150
|
+
end
|
151
|
+
def _xml_add_invoice_item(xml_invoice, item)
|
152
|
+
_xml_add_item(xml_invoice, item, 'InvoiceItem')
|
153
|
+
end
|
154
|
+
def _xml_add_item(xml_elm, item, tag)
|
155
|
+
xml_item = REXML::Element.new(tag)
|
156
|
+
_xml_add_item_line_no(xml_item, item.line_no)
|
157
|
+
_xml_add_item_part_id(xml_item, item)
|
158
|
+
xml_qty = REXML::Element.new('Qty')
|
159
|
+
xml_qty.text = item.qty
|
160
|
+
xml_item.add_element(xml_qty)
|
161
|
+
item.prices.each { |price|
|
162
|
+
_xml_add_item_price(xml_item, price)
|
163
|
+
}
|
164
|
+
if(free_text = item.free_text)
|
165
|
+
_xml_add_free_text(xml_item, free_text)
|
166
|
+
end
|
167
|
+
xml_elm.add_element(xml_item)
|
168
|
+
xml_item
|
169
|
+
end
|
170
|
+
def _xml_add_item_line_no(xml_item, line_no)
|
171
|
+
if(line_no)
|
172
|
+
xml_line_no = REXML::Element.new('LineNo')
|
173
|
+
xml_line_no.text = line_no
|
174
|
+
xml_item.add_element(xml_line_no)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
def _xml_add_item_part_id(xml_item, item)
|
178
|
+
ids = item.ids
|
179
|
+
part_infos = item.part_infos
|
180
|
+
unless(ids.empty? && part_infos.empty?)
|
181
|
+
xml_id = REXML::Element.new('PartId')
|
182
|
+
ids.each { |domain, idstr|
|
183
|
+
_xml_add_domain_id(xml_id, domain, idstr, 'IdentNo')
|
184
|
+
}
|
185
|
+
unless(part_infos.empty?)
|
186
|
+
xml_info = REXML::Element.new('PartInfo')
|
187
|
+
part_infos.each { |part_info|
|
188
|
+
xml_value = REXML::Element.new('Value')
|
189
|
+
xml_value.add_attribute('Dimension', part_info.dimension)
|
190
|
+
xml_value.text = part_info.value
|
191
|
+
xml_info.add_element(xml_value)
|
192
|
+
}
|
193
|
+
xml_id.add_element(xml_info)
|
194
|
+
end
|
195
|
+
xml_item.add_element(xml_id)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
def _xml_add_item_price(xml_item, price)
|
199
|
+
xml_price = REXML::Element.new('Price')
|
200
|
+
xml_price.add_attribute('Purpose', price.purpose)
|
201
|
+
xml_price.text = sprintf('%1.2f', price.amount)
|
202
|
+
xml_item.add_element(xml_price)
|
203
|
+
end
|
204
|
+
def _xml_add_item_status(xml_item, trans)
|
205
|
+
status = REXML::Element.new('Status')
|
206
|
+
status.text = trans.status
|
207
|
+
if((date = trans.status_date) && date.respond_to?(:strftime))
|
208
|
+
fmt = "%Y%m%d"
|
209
|
+
if(date.is_a?(Time))
|
210
|
+
fmt << "%H%M%S"
|
211
|
+
end
|
212
|
+
status.add_attribute('Date', date.strftime(fmt))
|
213
|
+
end
|
214
|
+
xml_item.add_element(status)
|
215
|
+
end
|
216
|
+
def _xml_assemble_bdd_transaction(xml_trans, trans)
|
217
|
+
_xml_add_item_status(xml_trans, trans)
|
218
|
+
name = xml_trans.name
|
219
|
+
trans.ids.each { |domain, idstr|
|
220
|
+
_xml_add_domain_id(xml_trans, domain, idstr, name + 'Id')
|
221
|
+
}
|
222
|
+
trans.parties.each { |party|
|
223
|
+
_xml_add_bdd_party(xml_trans, party)
|
224
|
+
}
|
225
|
+
method = "_xml_add_#{name}_item".downcase
|
226
|
+
trans.items.each { |item|
|
227
|
+
self.send(method, xml_trans, item)
|
228
|
+
}
|
229
|
+
trans.prices.each { |price|
|
230
|
+
_xml_add_item_price(xml_trans, price)
|
231
|
+
}
|
232
|
+
if(free_text = trans.free_text)
|
233
|
+
_xml_add_free_text(xml_trans, free_text)
|
234
|
+
end
|
235
|
+
if(agreement = trans.agreement)
|
236
|
+
_xml_add_bdd_agreement(xml_trans, agreement)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# GehBdd -- xmlconv2 -- 17.05.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'rexml/document'
|
5
|
+
require 'model/address'
|
6
|
+
require 'model/agreement'
|
7
|
+
require 'model/bdd'
|
8
|
+
require 'model/bsr'
|
9
|
+
require 'model/delivery'
|
10
|
+
require 'model/delivery_item'
|
11
|
+
require 'model/name'
|
12
|
+
require 'model/party'
|
13
|
+
require 'model/price'
|
14
|
+
|
15
|
+
module XmlConv
|
16
|
+
module Conversion
|
17
|
+
class GehBdd
|
18
|
+
class << self
|
19
|
+
def convert(xml_document)
|
20
|
+
bdd = Model::Bdd.new
|
21
|
+
_bdd_add_xml_delivery(bdd, xml_document)
|
22
|
+
bdd
|
23
|
+
end
|
24
|
+
def parse(xml_src)
|
25
|
+
REXML::Document.new(xml_src)
|
26
|
+
end
|
27
|
+
def _bdd_add_xml_delivery(bdd, xml_document)
|
28
|
+
delivery = Model::Delivery.new
|
29
|
+
xml_header = REXML::XPath.first(xml_document,
|
30
|
+
'OrderRequest/OrderRequestHeader')
|
31
|
+
_bdd_add_xml_header(bdd, xml_header)
|
32
|
+
_delivery_add_xml_header(delivery, xml_header)
|
33
|
+
if(xml_terms = REXML::XPath.first(xml_header,
|
34
|
+
'//TermsOfDeliveryFunctionCodedOther'))
|
35
|
+
agreement = Model::Agreement.new
|
36
|
+
agreement.terms_cond = _latin1(xml_terms.text).downcase
|
37
|
+
delivery.agreement = agreement
|
38
|
+
end
|
39
|
+
REXML::XPath.each(xml_document, 'OrderRequest//ItemDetail') { |xml_item|
|
40
|
+
_delivery_add_xml_item(delivery, xml_item)
|
41
|
+
}
|
42
|
+
delivery.bsr = bdd.bsr
|
43
|
+
bdd.add_delivery(delivery)
|
44
|
+
delivery
|
45
|
+
end
|
46
|
+
def _bdd_add_xml_header(bdd, xml_header)
|
47
|
+
bsr = Model::Bsr.new
|
48
|
+
xml_party = REXML::XPath.first(xml_header, '//BuyerParty/Party')
|
49
|
+
if(xml_id = REXML::XPath.first(xml_party, '//PartyID/Identifier/Ident'))
|
50
|
+
party = Model::Party.new
|
51
|
+
# ACC: ABB-Customer Domain
|
52
|
+
party.role = 'Customer'
|
53
|
+
party.add_id('ACC', _latin1(xml_id.text))
|
54
|
+
bsr.add_party(party)
|
55
|
+
end
|
56
|
+
bdd.bsr = bsr
|
57
|
+
end
|
58
|
+
def _container_add_xml_id(container, xml_id, domain)
|
59
|
+
domain = _latin1(xml_id.attribute('Domain').value)
|
60
|
+
value = _latin1(xml_id.text)
|
61
|
+
container.add_id(domain, value)
|
62
|
+
end
|
63
|
+
def _container_add_xml_party(container, xml_party, role)
|
64
|
+
party = Model::Party.new
|
65
|
+
party.role = role
|
66
|
+
if(xml_id = REXML::XPath.first(xml_party, 'PartyID//Ident'))
|
67
|
+
party.add_id('ACC', _latin1(xml_id.text))
|
68
|
+
end
|
69
|
+
if(xml_address = REXML::XPath.first(xml_party, 'NameAddress'))
|
70
|
+
_party_add_xml_address(party, xml_address)
|
71
|
+
if(xml_name = REXML::XPath.first(xml_address, 'Name1'))
|
72
|
+
_party_add_xml_name(party, xml_name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
if(xml_name = REXML::XPath.first(xml_party, 'OrderContact//ContactName'))
|
76
|
+
employee = Model::Party.new
|
77
|
+
employee.role = 'Employee'
|
78
|
+
_party_add_xml_name(employee, xml_name)
|
79
|
+
party.add_party(employee)
|
80
|
+
end
|
81
|
+
container.add_party(party)
|
82
|
+
party
|
83
|
+
end
|
84
|
+
def _delivery_add_xml_header(delivery, xml_header)
|
85
|
+
xml_id = REXML::XPath.first(xml_header,
|
86
|
+
'OrderRequestNumber/BuyerOrderRequestNumber')
|
87
|
+
delivery.add_id('Customer', _latin1(xml_id.text))
|
88
|
+
xml_buyer = REXML::XPath.first(xml_header,
|
89
|
+
'OrderRequestParty//BuyerParty/Party')
|
90
|
+
customer = _container_add_xml_party(delivery, xml_buyer, 'Customer')
|
91
|
+
_container_add_xml_party(customer, xml_buyer, 'BillTo')
|
92
|
+
if(xml_location = REXML::XPath.first(xml_header,
|
93
|
+
'OrderTermsOfDelivery//TermsOfDelivery/Location'))
|
94
|
+
_container_add_xml_party(customer, xml_location, 'ShipTo')
|
95
|
+
end
|
96
|
+
xml_seller = REXML::XPath.first(xml_header,
|
97
|
+
'OrderRequestParty//SellerParty/Party')
|
98
|
+
_container_add_xml_party(delivery, xml_seller, 'Seller')
|
99
|
+
end
|
100
|
+
def _delivery_add_xml_item(delivery, xml_item)
|
101
|
+
item = Model::DeliveryItem.new
|
102
|
+
xml_line_no = REXML::XPath.first(xml_item,
|
103
|
+
'BaseItemDetail//LineItemNum/*ItemNum')
|
104
|
+
item.line_no = _latin1(xml_line_no.text)
|
105
|
+
=begin # I'm not sure which Id is which..
|
106
|
+
if(xml_id = REXML::XPath.first(xml_item, 'BaseItemDetail//AgencyCoded'))
|
107
|
+
item.add_id('ET-NUMMER', _latin1(xml_id.text))
|
108
|
+
end
|
109
|
+
=end
|
110
|
+
if(xml_id = REXML::XPath.first(xml_item,
|
111
|
+
'BaseItemDetail//SellerPartNumberPartID'))
|
112
|
+
#item.add_id('Seller', _latin1(xml_id.text))
|
113
|
+
item.add_id('ET-NUMMER', _latin1(xml_id.text))
|
114
|
+
end
|
115
|
+
if(xml_id = REXML::XPath.first(xml_item,
|
116
|
+
'BaseItemDetail//BuyerPartNumberPartID'))
|
117
|
+
item.add_id('LIEFERANTENARTIKEL', _latin1(xml_id.text))
|
118
|
+
end
|
119
|
+
xml_qty = REXML::XPath.first(xml_item, 'BaseItemDetail//QuantityValue')
|
120
|
+
item.qty = _latin1(xml_qty.text)
|
121
|
+
if(xml_unit = REXML::XPath.first(xml_item, 'BaseItemDetail//UOMCoded'))
|
122
|
+
item.unit = _latin1(xml_unit.text)
|
123
|
+
end
|
124
|
+
if(xml_date = REXML::XPath.first(xml_item,
|
125
|
+
'DeliveryDetail//RequestedDeliveryDate'))
|
126
|
+
raw = _latin1(xml_date.text)
|
127
|
+
item.delivery_date = begin
|
128
|
+
Date.parse(raw)
|
129
|
+
rescue
|
130
|
+
Date.today
|
131
|
+
end
|
132
|
+
end
|
133
|
+
if(xml_price = REXML::XPath.first(xml_item, 'PricingDetail//UnitPriceValue'))
|
134
|
+
price = Model::Price.new
|
135
|
+
price.purpose = 'NettoPreis'
|
136
|
+
price.amount = _latin1(xml_price.text)
|
137
|
+
item.add_price(price)
|
138
|
+
end
|
139
|
+
delivery.add_item(item)
|
140
|
+
end
|
141
|
+
def _latin1(str)
|
142
|
+
Iconv.iconv('ISO-8859-1', 'UTF8', str).first.strip
|
143
|
+
rescue
|
144
|
+
str
|
145
|
+
end
|
146
|
+
def _party_add_xml_address(party, xml_address)
|
147
|
+
address = Model::Address.new
|
148
|
+
REXML::XPath.each(xml_address, 'Street') { |xml_addr_line|
|
149
|
+
address.add_line(_latin1(xml_addr_line.text))
|
150
|
+
}
|
151
|
+
xml_city = REXML::XPath.first(xml_address, 'City')
|
152
|
+
address.city = _latin1(xml_city.text)
|
153
|
+
xml_zip_code = REXML::XPath.first(xml_address, 'PostalCode')
|
154
|
+
address.zip_code = _latin1(xml_zip_code.text)
|
155
|
+
party.address = address
|
156
|
+
end
|
157
|
+
def _party_add_xml_name(party, xml_name)
|
158
|
+
name = Model::Name.new
|
159
|
+
name.last = _latin1(xml_name.text)
|
160
|
+
party.name = name
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|