sandozxmlconv 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ # Conversion::ProPharmaBdd -- xmlconv2 -- 14.09.2007 -- hwyss@ywesee.com
3
+
4
+ require 'rockit/rockit'
5
+ require 'xmlconv/model/bdd'
6
+ require 'xmlconv/model/bsr'
7
+ require 'xmlconv/model/delivery'
8
+ require 'xmlconv/model/delivery_item'
9
+ require 'xmlconv/model/name'
10
+ require 'xmlconv/model/party'
11
+
12
+ module XmlConv
13
+ module Conversion
14
+ class ProPharmaBdd
15
+ @parser = Parse.generate_parser <<-EOG
16
+ Grammar ProPharma
17
+ Tokens
18
+ DATA = /[^\n]+/
19
+ NL = /\n/
20
+ Productions
21
+ Bdd -> Customer Order
22
+ Customer -> '[KUNDE]' NL CId CName Location
23
+ CId -> 'idt=' DATA NL
24
+ CName -> 'nam=' DATA NL
25
+ Location -> 'ort=' DATA NL
26
+ Order -> '[BSTELL]' NL Reference Date Time Item+
27
+ [: _, _, reference, date, time, items ]
28
+ Reference -> 'ref=' DATA NL
29
+ Date -> 'dat=' DATA NL
30
+ Time -> 'tim=' DATA NL
31
+ Item -> '[ARTIK]' NL Type PCode Description Quantity
32
+ Type -> 'typ=' DATA NL
33
+ PCode -> 'phc=' DATA NL
34
+ Description -> 'art=' DATA NL
35
+ Quantity -> 'mge=' DATA NL
36
+ EOG
37
+ class << self
38
+ def convert(ast)
39
+ bdd = Model::Bdd.new
40
+ delivery = _bdd_add_delivery(bdd, ast.order)
41
+ _delivery_add_customer(delivery, ast.customer)
42
+ bdd
43
+ end
44
+ def parse(src)
45
+ @parser.parse(src)
46
+ end
47
+ def _bdd_add_delivery(bdd, ast)
48
+ delivery = Model::Delivery.new
49
+ bsr = Model::Bsr.new
50
+ delivery.add_id('Customer', _named_data(:reference, ast))
51
+ _delivery_add_seller(delivery)
52
+ delivery.bsr = bsr
53
+ ast.items.each { |item|
54
+ _delivery_add_item(delivery, item)
55
+ }
56
+ bdd.add_delivery(delivery)
57
+ delivery
58
+ end
59
+ def _bsr_add_customer_id(bsr, id)
60
+ customer = Model::Party.new
61
+ customer.role = 'Customer'
62
+ ## Propharma sends the Supplier-side Customer-ID, not the public EAN13 as it
63
+ # is the case in Propharma -> Globopharm
64
+ customer.add_id('supplier', id)
65
+ bsr.add_party(customer)
66
+ end
67
+ def _delivery_add_customer(delivery, ast)
68
+ _bsr_add_customer_id(delivery.bsr, _named_data(:cid, ast))
69
+ customer = Model::Party.new
70
+ customer.role = "Customer"
71
+ ## Propharma sends the Supplier-side Customer-ID, not the public EAN13 as it
72
+ # is the case in Propharma -> Globopharm
73
+ customer.add_id('customer', _named_data(:cid, ast))
74
+ name = Model::Name.new
75
+ name.text = _named_data(:cname, ast)
76
+ customer.name = name
77
+ delivery.add_party(customer)
78
+ customer
79
+ end
80
+ def _delivery_add_item(delivery, ast)
81
+ item = Model::DeliveryItem.new
82
+ item.line_no = delivery.items.size.next.to_s
83
+ item.add_id('Pharmacode', _named_data(:pcode, ast))
84
+ item.qty = _named_data(:quantity, ast)
85
+ item.unit = 'PCE'
86
+ delivery.add_item(item)
87
+ end
88
+ def _delivery_add_seller(delivery)
89
+ party = Model::Party.new
90
+ party.role = 'Seller'
91
+ party.add_id("ACC", "7601001000681")
92
+ delivery.add_party(party)
93
+ end
94
+ def _named_data(key, ast)
95
+ ast.send(key).data.value
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env ruby
2
+ # Conversion::SunStoreBdd -- xmlconv2 -- 12.12.2008 -- hwyss@ywesee.com
3
+
4
+ require 'rexml/document'
5
+ require 'xmlconv/model/bdd'
6
+
7
+ require 'xmlconv/model/address'
8
+ require 'xmlconv/model/bsr'
9
+ require 'xmlconv/model/delivery'
10
+ require 'xmlconv/model/delivery_item'
11
+ require 'xmlconv/model/name'
12
+ require 'xmlconv/model/party'
13
+
14
+
15
+ module XmlConv
16
+ module Conversion
17
+ class SunStoreBdd
18
+ class << self
19
+ def convert(xml_document)
20
+ bdd = Model::Bdd.new
21
+ bsr = Model::Bsr.new
22
+ _bsr_add_customer_id(bsr, 'YWESEESS')
23
+ bdd.bsr = bsr
24
+ REXML::XPath.each(xml_document, '//customerOrder') do |xml_delivery|
25
+ _bdd_add_xml_delivery(bdd, xml_delivery)
26
+ end
27
+ bdd
28
+ end
29
+ def parse(xml_src)
30
+ REXML::Document.new(xml_src)
31
+ end
32
+ def respond(transaction, responses)
33
+ doc = REXML::Document.new <<-EOS
34
+ <?xml version="1.0" encoding="UTF-8"?>
35
+ <customerOrderResponse xmlns="http://www.e-galexis.com/schemas/"
36
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37
+ xsi:schemaLocation="http://www.e-galexis.com/schemas/ http://www.e-galexis.com/schemas/POS/customerOrder/customerOrderResponse.xsd"
38
+ version="1.0" roundUpForCondition="false" backLogDesired="false"
39
+ language="de" productDescriptionDesired="false">
40
+ </customerOrderResponse>
41
+ EOS
42
+ root = doc.root
43
+ transaction.model.deliveries.each_with_index do |delivery, idx|
44
+ if data = responses[idx]
45
+ number = if(order_id = data[:order_id])
46
+ _utf8 order_id
47
+ else
48
+ "error-#{transaction.transaction_id}-#{idx}"
49
+ end
50
+ root.add_element('clientResponse').add_attribute('number', number)
51
+ if data[:products].compact.size == delivery.items.size
52
+ header = root.add_element 'orderHeaderResponse'
53
+ header.add_attribute 'referenceNumber', _utf8(delivery.customer_id)
54
+ if ship_to = delivery.customer.ship_to
55
+ attrs = { 'line1' => _utf8(ship_to.name.text) }
56
+ attrs2 = {}
57
+ if addr = ship_to.address
58
+ addr.lines.each_with_index do |line, idx|
59
+ line = _utf8 line
60
+ case idx
61
+ when 0
62
+ attrs2.store 'line2', line
63
+ when 1
64
+ attrs2.store 'line3', line
65
+ when 2
66
+ attrs.store 'line4', line
67
+ end
68
+ end
69
+ attrs.store 'line5PostalCode', _utf8(addr.zip_code)
70
+ attrs.store 'line5City', _utf8(addr.city)
71
+ end
72
+ address = header.add_element 'deliveryAddress'
73
+ address.add_attributes attrs
74
+ unless attrs2.empty?
75
+ line2 = address.add_element 'addressLine2And3Text'
76
+ line2.add_attributes attrs2
77
+ end
78
+ end
79
+ lines = root.add_element 'orderLinesResponse'
80
+ delivery.items.each_with_index do |item, idx|
81
+ presp = data[:products][idx]
82
+ available = presp[:quantity] == presp[:deliverable]
83
+ attrs = {
84
+ 'lineAccepted' => _boolean(available),
85
+ 'backLogLine' => _boolean(presp[:backorder]),
86
+ 'roundUpForConditionDone' => 'false',
87
+ 'productReplaced' => 'false',
88
+ }
89
+ prod = lines.add_element 'productOrderLineResponse'
90
+ prod.add_attributes attrs
91
+ pol = prod.add_element 'productOrderLine'
92
+ pol.add_attribute 'orderQuantity', item.qty
93
+ if pcode = item.pharmacode_id
94
+ pol.add_element('pharmaCode').add_attribute('id', pcode)
95
+ end
96
+ if ean = item.et_nummer_id
97
+ pol.add_element('EAN').add_attribute('id', ean)
98
+ end
99
+ attrs = {
100
+ 'wholesalerProductCode' => presp[:article_number],
101
+ 'description' => presp[:description],
102
+ }
103
+ presp = prod.add_element 'productResponse'
104
+ presp.add_attributes attrs
105
+ prod.add_element 'availability',
106
+ 'status' => available ? 'yes' : 'no'
107
+ end
108
+ else
109
+ root.add_element 'orderHeaderErrorResponse'
110
+ end
111
+ else
112
+ root.add_element 'clientErrorResponse'
113
+ end
114
+ end
115
+ doc
116
+ end
117
+ def _bdd_add_xml_delivery(bdd, xml_delivery)
118
+ delivery = Model::Delivery.new
119
+ bsr = Model::Bsr.new
120
+ xml_client = REXML::XPath.first(xml_delivery, 'client')
121
+ _bsr_add_customer_id(bsr, xml_client.attributes['number'])
122
+ delivery.bsr = bsr
123
+ _delivery_add_xml_header(delivery, xml_delivery)
124
+ if(xml_lines = REXML::XPath.first(xml_delivery, 'orderLines'))
125
+ REXML::XPath.each(xml_lines,
126
+ 'productOrderLine|productLabelOrderLine') do |xml_item|
127
+ _delivery_add_xml_item(delivery, xml_item)
128
+ end
129
+ end
130
+ bdd.add_delivery(delivery)
131
+ delivery
132
+ end
133
+ def _boolean(item)
134
+ item ? 'true' : 'false'
135
+ end
136
+ def _bsr_add_customer_id(bsr, id)
137
+ customer = Model::Party.new
138
+ customer.role = 'Customer'
139
+ customer.add_id('ACC', id)
140
+ bsr.add_party(customer)
141
+ end
142
+ def _customer_add_party(customer, id, role)
143
+ party = Model::Party.new
144
+ party.role = role
145
+ party.add_id('ACC', id)
146
+ customer.add_party(party)
147
+ party
148
+ end
149
+ def _delivery_add_xml_customer(delivery, xml_delivery)
150
+ customer = Model::Party.new
151
+ customer.role = 'Customer'
152
+ _customer_add_party(customer, '1075', 'BillTo')
153
+ xml_client = REXML::XPath.first(xml_delivery, 'client')
154
+ id = _latin1(xml_client.attributes['number'])
155
+ customer.add_id('ACC', id)
156
+ ship_to = _customer_add_party(customer, id, 'ShipTo')
157
+ if(xml_header = REXML::XPath.first(xml_delivery, 'orderHeader'))
158
+ name = Model::Name.new
159
+ # The SunStore formant does not specify which part of the Delivery-Address
160
+ # contains the customer's name. We're just guessing it might be in the first
161
+ # line.
162
+ if(xml_name = REXML::XPath.first(xml_header, 'deliveryAddress'))
163
+ name.text = _latin1(xml_name.attributes['line1'])
164
+ end
165
+ customer.name = name
166
+ ship_to.name = name
167
+ _party_add_xml_address(ship_to, xml_header)
168
+ end
169
+ if(xml_email = REXML::XPath.first(xml_delivery, '//groupe/online/email'))
170
+ customer.add_id('email', _latin1(xml_email.text))
171
+ end
172
+ delivery.add_party(customer)
173
+ end
174
+ def _delivery_add_xml_header(delivery, xml_delivery)
175
+ xml_order = REXML::XPath.first(xml_delivery, 'orderHeader')
176
+ delivery.add_id('Customer', _latin1(xml_order.attributes['referenceNumber']))
177
+ _delivery_add_xml_customer(delivery, xml_delivery)
178
+ end
179
+ def _delivery_add_xml_item(delivery, xml_item)
180
+ item = Model::DeliveryItem.new
181
+ item.line_no = _latin1(delivery.items.size.next.to_s)
182
+ if(xml_pcode = REXML::XPath.first(xml_item, 'EAN'))
183
+ item.add_id('ET-Nummer', _latin1(xml_pcode.attributes['id']))
184
+ end
185
+ if(xml_pcode = REXML::XPath.first(xml_item, 'pharmaCode'))
186
+ item.add_id('Pharmacode', _latin1(xml_pcode.attributes['id']))
187
+ end
188
+ xml_qty = xml_item.attributes['orderQuantity'] \
189
+ || xml_item.attributes['defaultOrderQuantity']
190
+ item.qty = _latin1(xml_qty)
191
+ item.unit = 'PCE'
192
+ delivery.add_item(item)
193
+ end
194
+ def _party_add_xml_address(party, xml_header)
195
+ if(xml_address = REXML::XPath.first(xml_header, 'deliveryAddress'))
196
+ address = Model::Address.new
197
+ address.zip_code = _latin1(xml_address.attributes['line5PostalCode'])
198
+ address.city = _latin1(xml_address.attributes['line5City'])
199
+ if(xml_lines = REXML::XPath.first(xml_address, 'addressLine2And3Text'))
200
+ address.add_line(_latin1(xml_lines.attributes['line2']))
201
+ address.add_line(_latin1(xml_lines.attributes['line3']))
202
+ end
203
+ if(line = xml_address.attributes['line4'])
204
+ address.add_line(_latin1(line))
205
+ end
206
+ party.address = address
207
+ end
208
+ end
209
+ def _latin1(str)
210
+ Iconv.iconv('ISO-8859-1//TRANSLIT//IGNORE', 'UTF8', str).first.strip
211
+ rescue
212
+ str
213
+ end
214
+ def _utf8(str)
215
+ Iconv.iconv('UTF-8//TRANSLIT//IGNORE', 'ISO-8859-1', str).first.strip
216
+ rescue
217
+ str
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env ruby
2
+ # Conversion::WbmbBdd -- xmlconv2 -- 23.08.2006 -- hwyss@ywesee.com
3
+
4
+ require 'soap/marshal'
5
+ require 'xmlconv/model/address'
6
+ require 'xmlconv/model/agreement'
7
+ require 'xmlconv/model/bdd'
8
+ require 'xmlconv/model/bsr'
9
+ require 'xmlconv/model/delivery'
10
+ require 'xmlconv/model/delivery_item'
11
+ require 'xmlconv/model/name'
12
+ require 'xmlconv/model/party'
13
+ require 'xmlconv/model/price'
14
+
15
+ module XmlConv
16
+ module Conversion
17
+ class WbmbBdd
18
+ class << self
19
+ def convert(soap_mapping)
20
+ bdd = Model::Bdd.new
21
+ texted, normal = soap_mapping.artikelliste.partition { |article|
22
+ article.respond_to?(:positionstext)
23
+ }
24
+ unless(normal.empty?)
25
+ _bdd_add_xml_delivery(bdd, soap_mapping, normal)
26
+ end
27
+ unless(texted.empty?)
28
+ _bdd_add_xml_delivery(bdd, soap_mapping, texted)
29
+ end
30
+ bdd
31
+ end
32
+ def parse(src)
33
+ SOAP::Marshal.unmarshal(src)
34
+ end
35
+ def _bdd_add_xml_delivery(bdd, soap_mapping, positions)
36
+ delivery = Model::Delivery.new
37
+ if(soap_mapping.respond_to?(:absender))
38
+ _delivery_add_sender_ids(delivery, soap_mapping.absender)
39
+ end
40
+ if(soap_mapping.respond_to?(:empfaenger))
41
+ _delivery_add_recipient_ids(delivery, soap_mapping.empfaenger)
42
+ end
43
+ if(soap_mapping.respond_to?(:auftrag_info))
44
+ _delivery_add_soap_info(delivery, soap_mapping.auftrag_info)
45
+ end
46
+ _delivery_add_soap_positions(delivery, positions)
47
+ bdd.add_delivery(delivery)
48
+ end
49
+ def _delivery_add_sender_ids(delivery, ids)
50
+ bsr = Model::Bsr.new
51
+ customer = Model::Party.new
52
+ customer.role = 'Customer'
53
+ party = Model::Party.new
54
+ party.role = 'Customer'
55
+ ids.each { |id|
56
+ value = _latin1(id.idvalue)
57
+ case _latin1(id.idtype)
58
+ when 'auftragsnummer'
59
+ delivery.add_id('Customer', value)
60
+ when 'ean13'
61
+ party.add_id('ET-Nummer', value)
62
+ when 'email'
63
+ customer.add_id('email', value)
64
+ when 'kundennummer'
65
+ party.add_id('ACC', value)
66
+ customer.add_id('ACC', value)
67
+ when 'name'
68
+ name = Model::Name.new
69
+ name.text = value
70
+ customer.name = name
71
+ end
72
+ }
73
+ bill_to = Model::Party.new
74
+ bill_to.role = 'BillTo'
75
+ bill_to.add_id('ACC', '1075')
76
+ customer.add_party(bill_to)
77
+ delivery.add_party(customer)
78
+ bsr.add_party(party)
79
+ delivery.bsr = bsr
80
+ end
81
+ def _delivery_add_recipient_ids(delivery, ids)
82
+ party = Model::Party.new
83
+ party.role = 'Seller'
84
+ ids.each { |id|
85
+ key = case _latin1(id.idtype)
86
+ when 'ean13'
87
+ party.add_id('ACC', _latin1(id.idvalue))
88
+ when 'auftragsnummer'
89
+ delivery.add_id('ACC', _latin1(id.idvalue))
90
+ end
91
+ }
92
+ if(party.acc_id.to_s.empty?)
93
+ party.add_id("ACC", "7601001000681")
94
+ end
95
+ delivery.add_party(party)
96
+ party
97
+ end
98
+ def _delivery_add_soap_info(delivery, infos)
99
+ infos.each { |info|
100
+ case _latin1(info.infotype)
101
+ when 'schnittstelle'
102
+ delivery.bsr.interface = _latin1(info.infovalue)
103
+ when 'lieferadresse'
104
+ _party_add_delivery_address(delivery.customer, info)
105
+ when 'lieferung_bis'
106
+ delivery.delivery_date = begin
107
+ DateTime.parse(_latin1(info.infovalue))
108
+ rescue
109
+ DateTime.now
110
+ end
111
+ when 'text'
112
+ text = Model::FreeText.new
113
+ text << _latin1(info.infovalue)
114
+ delivery.add_free_text('text', text)
115
+ when 'versandkosten'
116
+ delivery.transport_cost = _latin1(info.infovalue)
117
+ end
118
+ }
119
+ end
120
+ def _delivery_add_soap_positions(delivery, positions)
121
+ positions.each_with_index { |pos, idx|
122
+ item = Model::DeliveryItem.new
123
+ item.line_no = idx.next.to_s
124
+ _item_add_soap_ids(item, [pos.identifier].flatten)
125
+ item.qty = _latin1(pos.bestellmenge)
126
+ item.unit = 'PCE'
127
+ if(amount = _named_value(pos, :artikelpreis))
128
+ price = Model::Price.new
129
+ price.purpose = 'NettoPreis'
130
+ price.amount = amount
131
+ item.add_price(price)
132
+ end
133
+ if(value = _named_value(pos, :positionstext))
134
+ txt = Model::FreeText.new
135
+ txt << _latin1(value)
136
+ item.add_free_text('text', txt)
137
+ end
138
+ delivery.add_item(item)
139
+ }
140
+ end
141
+ def _item_add_soap_ids(item, ids)
142
+ ids.each { |id|
143
+ key = _latin1(id.idtype)
144
+ value = _latin1(id.idvalue)
145
+ case key
146
+ when 'ean13'
147
+ item.add_id('ET-Nummer', value)
148
+ when 'pcode'
149
+ item.add_id('Pharmacode', value)
150
+ when 'gag-code'
151
+ item.add_id('LieferantenArtikel', value)
152
+ else
153
+ item.add_id(key, value)
154
+ end
155
+ }
156
+ end
157
+ def _named_value(parent, name)
158
+ if(parent.respond_to?(name))
159
+ _latin1(parent.send(name))
160
+ end
161
+ end
162
+ def _party_add_delivery_address(party, info)
163
+ shipto = Model::Party.new
164
+ shipto.role = 'ShipTo'
165
+ address = Model::Address.new
166
+ names = []
167
+ lines = []
168
+ info.address.each { |part|
169
+ value = _latin1(part.infovalue)
170
+ case _latin1(part.infotype)
171
+ when 'name'
172
+ names.push(value)
173
+ when 'strasse'
174
+ lines.push(value)
175
+ when 'plz'
176
+ address.zip_code = value
177
+ when 'ort'
178
+ address.city = value
179
+ when 'land'
180
+ address.country = value
181
+ end
182
+ }
183
+ name = Model::Name.new
184
+ name.text = names.shift
185
+ shipto.name = name
186
+ names.concat(lines).each { |line| address.add_line(line) }
187
+ shipto.address = address
188
+ party.add_party(shipto)
189
+ end
190
+ def _latin1(txt)
191
+ if(txt.is_a?(String))
192
+ Iconv.iconv('latin1', 'utf8', txt).first
193
+ end
194
+ rescue
195
+ txt
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end