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
data/README.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= xmlconv2
|
2
|
+
|
3
|
+
* http://scm.ywesee.com/?p=xmlconv2/.git;a=summary
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Converts XML files to flat files. Works nicely with i2.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Sometimes hangs.
|
12
|
+
|
13
|
+
== INSTALL:
|
14
|
+
|
15
|
+
* sudo gem install xmlconv2
|
16
|
+
|
17
|
+
== DEVELOPERS:
|
18
|
+
|
19
|
+
* Masaomi Hatakeyama
|
20
|
+
* Zeno R.R. Davatz
|
21
|
+
* Hannes Wyss (up to Version 1.0)
|
22
|
+
|
23
|
+
== LICENSE:
|
24
|
+
|
25
|
+
* GPLv2
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
# Hoe.plugin :compiler
|
7
|
+
# Hoe.plugin :cucumberfeatures
|
8
|
+
# Hoe.plugin :gem_prelude_sucks
|
9
|
+
# Hoe.plugin :inline
|
10
|
+
# Hoe.plugin :inline
|
11
|
+
# Hoe.plugin :manifest
|
12
|
+
# Hoe.plugin :newgem
|
13
|
+
# Hoe.plugin :racc
|
14
|
+
# Hoe.plugin :rubyforge
|
15
|
+
# Hoe.plugin :rubyforge
|
16
|
+
# Hoe.plugin :website
|
17
|
+
|
18
|
+
Hoe.spec 'xmlconv2' do
|
19
|
+
# HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
|
20
|
+
# you'll never have to touch them again!
|
21
|
+
# (delete this comment too, of course)
|
22
|
+
|
23
|
+
developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
|
24
|
+
|
25
|
+
# self.rubyforge_name = 'xmlconv2x' # if different than 'xmlconv2'
|
26
|
+
end
|
27
|
+
|
28
|
+
# vim: syntax=ruby
|
data/bin/admin
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Admin -- xmlconv -- 09.07.2003 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('..', File.dirname(__FILE__))
|
5
|
+
$: << File.expand_path('../src', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'util/application'
|
8
|
+
require 'etc/config'
|
9
|
+
require 'readline'
|
10
|
+
include Readline
|
11
|
+
|
12
|
+
Kernel.trap('INT') {
|
13
|
+
if($current.respond_to?(:exit))
|
14
|
+
$current.exit
|
15
|
+
$current = nil
|
16
|
+
else
|
17
|
+
puts "<ctrl-c> is used to kill admin-threads."
|
18
|
+
puts "Type <quit> or <exit> to exit."
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
prompt = 'xmlconv> '
|
23
|
+
DRb.start_service
|
24
|
+
xmlconv = DRbObject.new(nil, XmlConv::SERVER_URI)
|
25
|
+
last_error = nil
|
26
|
+
priority = -1
|
27
|
+
while(line = readline(prompt, true))
|
28
|
+
result = ''
|
29
|
+
result.extend(DRb::DRbUndumped)
|
30
|
+
line.strip!
|
31
|
+
$stdout.print "-> "
|
32
|
+
case line.downcase
|
33
|
+
when 'exit', 'quit'
|
34
|
+
$stdout.puts 'Goodbye'
|
35
|
+
break
|
36
|
+
when 'bt', 'backtrace'
|
37
|
+
if last_error.respond_to?(:backtrace)
|
38
|
+
$stdout.puts last_error.backtrace
|
39
|
+
else
|
40
|
+
$stdout.puts 'No Error'
|
41
|
+
end
|
42
|
+
when /^last_error/
|
43
|
+
begin
|
44
|
+
$stdout.puts eval(line)
|
45
|
+
rescue Exception => last_error
|
46
|
+
$stdout.puts last_error
|
47
|
+
end
|
48
|
+
when /sp\s+(-?\d+)/, /set_priority\s+(-?\d+)/
|
49
|
+
priority = $~[1].to_i
|
50
|
+
$stdout.puts "setting Priority to #{priority}"
|
51
|
+
else
|
52
|
+
begin
|
53
|
+
bgflag = line.slice!(/\s*\&\s*$/)
|
54
|
+
$current = xmlconv._admin(line, result, priority)
|
55
|
+
unless(bgflag)
|
56
|
+
$current.join
|
57
|
+
end
|
58
|
+
$stdout.puts result
|
59
|
+
rescue Exception => last_error
|
60
|
+
$stdout.puts last_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
$current = nil
|
64
|
+
$stdout.flush
|
65
|
+
end
|
data/bin/xmlconvd
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# XmlConv -- xmlconv2 -- 07.06.2004 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.expand_path('../src', File.dirname(__FILE__))
|
5
|
+
$: << File.expand_path('..', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'drb/drb'
|
8
|
+
require 'util/application'
|
9
|
+
require 'etc/config'
|
10
|
+
require 'etc/access'
|
11
|
+
|
12
|
+
$0 = "XmlConv2"
|
13
|
+
|
14
|
+
xmlconv = XmlConvApp.new
|
15
|
+
|
16
|
+
DRb.start_service(XmlConv::SERVER_URI, xmlconv)
|
17
|
+
puts 'drb-service started'
|
18
|
+
|
19
|
+
DRb.thread.join
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Grammar I2
|
2
|
+
Tokens
|
3
|
+
BLANK = /\s+/ [:Skip]
|
4
|
+
QUOTE = /"/
|
5
|
+
CHAR = /[^"]+/
|
6
|
+
Productions
|
7
|
+
Document -> Record+
|
8
|
+
[: records]
|
9
|
+
Record -> Header
|
10
|
+
[^: record]
|
11
|
+
| Commission
|
12
|
+
[^: record]
|
13
|
+
| Address
|
14
|
+
[^: record]
|
15
|
+
| HeaderText
|
16
|
+
[^: record]
|
17
|
+
| Position
|
18
|
+
[^: record]
|
19
|
+
| PositionText
|
20
|
+
[^: record]
|
21
|
+
| Footer
|
22
|
+
[^: record]
|
23
|
+
Header -> QUOTE "00" QUOTE
|
24
|
+
Field Field Field Field Field Field
|
25
|
+
[: _, rtype, _,
|
26
|
+
sender, recipient, date, time, mtype, test]
|
27
|
+
Commission -> QUOTE "01" QUOTE
|
28
|
+
Field Field Field Field Field
|
29
|
+
Field Field
|
30
|
+
[: _, rtype, _,
|
31
|
+
btype, receipt, rdate, reference, commission,
|
32
|
+
contact, employee]
|
33
|
+
Address -> QUOTE "02" QUOTE
|
34
|
+
Field Field Field Field Field Field Field
|
35
|
+
[: _, rtype, _,
|
36
|
+
atype, name1, name2, street, city, code, country]
|
37
|
+
HeaderText -> QUOTE "05" QUOTE Field
|
38
|
+
[: _, rtype, _, text]
|
39
|
+
Position -> QUOTE "10" QUOTE
|
40
|
+
Field Field Field
|
41
|
+
Field Field Field
|
42
|
+
Field Field Field
|
43
|
+
Field Field
|
44
|
+
Field Field
|
45
|
+
[: _, rtype, _,
|
46
|
+
lineno, eancode, buyercode,
|
47
|
+
qty, ddate, pricenettopce,
|
48
|
+
pricenetto, discountpce, discount,
|
49
|
+
extradiscountpce, extradiscount,
|
50
|
+
pricebruttopce, pricebrutto]
|
51
|
+
| QUOTE "10" QUOTE
|
52
|
+
Field Field Field
|
53
|
+
Field Field Field
|
54
|
+
Field Field Field
|
55
|
+
Field Field Field
|
56
|
+
Field Field
|
57
|
+
[: _, rtype, _,
|
58
|
+
lineno, eancode, buyercode,
|
59
|
+
qty, pricenettopce, pricenetto,
|
60
|
+
discountpce, discount, extradiscountpce,
|
61
|
+
extradiscount, pricebruttopce, pricebrutto,
|
62
|
+
origin, customs]
|
63
|
+
PositionText-> QUOTE "15" QUOTE Field
|
64
|
+
[: _, rtype, _, text]
|
65
|
+
Footer -> QUOTE "90" QUOTE
|
66
|
+
Field Field Field
|
67
|
+
Field Field
|
68
|
+
[: _, rtype, _,
|
69
|
+
pricenetto, vatpercent, vatamount,
|
70
|
+
pricebrutto, agreement]
|
71
|
+
Field -> QUOTE CHAR QUOTE
|
72
|
+
[^: _, field, _]
|
73
|
+
| QUOTE QUOTE
|
@@ -0,0 +1,281 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Conversion::BddGeh -- xmlconv2 -- 18.05.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
module XmlConv
|
7
|
+
module Conversion
|
8
|
+
class BddGeh
|
9
|
+
class << self
|
10
|
+
SELLER_ID = 663 # DTSTTCPW-approach. Could also be passed in, e.g. from the
|
11
|
+
# PollingMission
|
12
|
+
def convert(bdd)
|
13
|
+
docs = []
|
14
|
+
bdd.deliveries.each { |delivery|
|
15
|
+
skeleton = <<-EOS
|
16
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
17
|
+
<OrderResponse />
|
18
|
+
EOS
|
19
|
+
doc = REXML::Document.new(skeleton)
|
20
|
+
_xml_add_bdd_delivery(doc.root, delivery)
|
21
|
+
docs.push(doc)
|
22
|
+
}
|
23
|
+
bdd.invoices.each { |invoice|
|
24
|
+
skeleton = <<-EOS
|
25
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
26
|
+
<Invoice />
|
27
|
+
EOS
|
28
|
+
doc = REXML::Document.new(skeleton)
|
29
|
+
_xml_add_bdd_invoice(doc.root, invoice)
|
30
|
+
docs.push(doc)
|
31
|
+
}
|
32
|
+
docs
|
33
|
+
end
|
34
|
+
def _utf8(str)
|
35
|
+
Iconv.iconv('UTF8', 'ISO-8859-1', str).first.strip
|
36
|
+
rescue
|
37
|
+
str
|
38
|
+
end
|
39
|
+
def _xml_add_base_item_detail(xml_item, item, type=:order_response)
|
40
|
+
tag = case type
|
41
|
+
when :invoice
|
42
|
+
'InvoiceBaseItemDetail'
|
43
|
+
else
|
44
|
+
'BaseItemDetail'
|
45
|
+
end
|
46
|
+
xml_base = REXML::Element.new(tag)
|
47
|
+
_xml_add_item_line_no(xml_base, item.line_no)
|
48
|
+
_xml_add_item_part_id(xml_base, item)
|
49
|
+
_xml_add_item_quantity(xml_base, item)
|
50
|
+
xml_item.add_element(xml_base)
|
51
|
+
end
|
52
|
+
def _xml_add_bdd_delivery(xml_root, delivery)
|
53
|
+
_xml_add_delivery_header(xml_root, delivery)
|
54
|
+
_xml_add_bdd_detail(xml_root, delivery)
|
55
|
+
end
|
56
|
+
def _xml_add_bdd_detail(xml_root, delivery)
|
57
|
+
xml_detail = _xml_element("OrderResponseDetail")
|
58
|
+
xml_list = _xml_element('ListOfOrderResponseItemDetail')
|
59
|
+
delivery.items.each { |item|
|
60
|
+
_xml_add_item(xml_list, item)
|
61
|
+
}
|
62
|
+
xml_detail.add_element(xml_list)
|
63
|
+
xml_root.add_element(xml_detail)
|
64
|
+
end
|
65
|
+
def _xml_add_bdd_invoice(xml_root, invoice)
|
66
|
+
_xml_add_invoice_header(xml_root, invoice)
|
67
|
+
_xml_add_invoice_detail(xml_root, invoice)
|
68
|
+
_xml_add_invoice_summary(xml_root, invoice)
|
69
|
+
end
|
70
|
+
def _xml_add_bdd_party(xml_container, party, employee=nil)
|
71
|
+
role = party.role
|
72
|
+
case role
|
73
|
+
when 'Customer'
|
74
|
+
party.parties.each { |part|
|
75
|
+
_xml_add_bdd_party(xml_container, part, party.employee)
|
76
|
+
}
|
77
|
+
when 'BillTo'
|
78
|
+
_xml_add_party(xml_container, party, employee, 'BuyerParty')
|
79
|
+
when 'Employee'
|
80
|
+
else
|
81
|
+
_xml_add_party(xml_container, party, employee, sprintf("%sParty", role))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
def _xml_add_party(xml_container, party, employee, tagname)
|
85
|
+
xml_name_party = _xml_element(tagname)
|
86
|
+
xml_party = _xml_element('Party')
|
87
|
+
if(pid = party.party_id)
|
88
|
+
xml_party.add_element(_xml_nested_text(pid, 'PartyID', 'Identifier',
|
89
|
+
'Ident'))
|
90
|
+
end
|
91
|
+
if(addr = party.address)
|
92
|
+
_xml_add_name_address(xml_party, addr)
|
93
|
+
end
|
94
|
+
if(employee)
|
95
|
+
xml_party.add_element(_xml_nested_text(employee.name.to_s,
|
96
|
+
'OrderContact', 'Contact', 'ContactName'))
|
97
|
+
end
|
98
|
+
xml_name_party.add_element(xml_party)
|
99
|
+
xml_container.add_element(xml_name_party)
|
100
|
+
end
|
101
|
+
def _xml_add_delivery_detail(xml_item, item)
|
102
|
+
if(date = item.delivery_date)
|
103
|
+
xml_item.add_element(_xml_nested_text(date.strftime('%Y%m%d'),
|
104
|
+
'DeliveryDetail', 'ListOfScheduleLine',
|
105
|
+
'ScheduleLine', 'RequestedDeliveryDate'))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
def _xml_add_delivery_header(xml_root, delivery)
|
109
|
+
xml_header = _xml_element("OrderResponseHeader")
|
110
|
+
xml_header.add_element(_xml_nested_text(delivery.reference_id,
|
111
|
+
"OrderResponseNumber", "BuyerOrderResponseNumber"))
|
112
|
+
xml_header.add_element(_xml_nested_text(delivery.customer_id,
|
113
|
+
'OrderReference', 'Reference', 'RefNum'))
|
114
|
+
if(date = delivery.status_date)
|
115
|
+
str = date.strftime('%Y%m%d%H%M%S')
|
116
|
+
xml_header.add_element(_xml_nested_text(str, 'OrderResponseIssueDate'))
|
117
|
+
end
|
118
|
+
if((seller = delivery.seller) && !seller.party_id)
|
119
|
+
seller.add_id('ACC', SELLER_ID)
|
120
|
+
end
|
121
|
+
delivery.parties.each { |party|
|
122
|
+
_xml_add_bdd_party(xml_header, party)
|
123
|
+
}
|
124
|
+
xml_root.add_element(xml_header)
|
125
|
+
end
|
126
|
+
def _xml_add_invoice_detail(xml_root, invoice)
|
127
|
+
xml_detail = _xml_element('InvoiceDetail')
|
128
|
+
xml_list = _xml_element('ListOfInvoiceItemDetail')
|
129
|
+
invoice.items.each { |item|
|
130
|
+
_xml_add_invoice_item(xml_list, item)
|
131
|
+
}
|
132
|
+
xml_detail.add_element(xml_list)
|
133
|
+
xml_root.add_element(xml_detail)
|
134
|
+
end
|
135
|
+
def _xml_add_invoice_header(xml_root, invoice)
|
136
|
+
xml_header = _xml_element('InvoiceHeader')
|
137
|
+
xml_header.add_element(_xml_nested_text(invoice.invoice_id.last,
|
138
|
+
'InvoiceNumber', 'Reference', 'RefNum'))
|
139
|
+
if(date = invoice.status_date)
|
140
|
+
xml_header.add_element(_xml_nested_text(date.strftime('%Y%m%d%H%M%S'),
|
141
|
+
'InvoiceIssueDate'))
|
142
|
+
end
|
143
|
+
_xml_add_invoice_references(xml_header, invoice)
|
144
|
+
if(party = invoice.seller)
|
145
|
+
unless(party.party_id)
|
146
|
+
party.add_id('ACC', SELLER_ID)
|
147
|
+
end
|
148
|
+
_xml_add_bdd_party(xml_header, party)
|
149
|
+
end
|
150
|
+
xml_root.add_element(xml_header)
|
151
|
+
end
|
152
|
+
def _xml_add_invoice_item(xml_elm, item)
|
153
|
+
xml_item = _xml_element('InvoiceItemDetail')
|
154
|
+
_xml_add_base_item_detail(xml_item, item, :invoice)
|
155
|
+
_xml_add_pricing_detail(xml_item, item, :invoice)
|
156
|
+
xml_elm.add_element(xml_item)
|
157
|
+
xml_item
|
158
|
+
end
|
159
|
+
def _xml_add_invoice_references(xml_header, invoice)
|
160
|
+
xml_refs = _xml_element('InvoiceReferences')
|
161
|
+
xml_refs.add_element(_xml_nested_text(invoice.customer_id,
|
162
|
+
'PurchaseOrderReference', 'PurchaseOrderNumber',
|
163
|
+
'Reference', 'RefNum'))
|
164
|
+
xml_header.add_element(xml_refs)
|
165
|
+
end
|
166
|
+
def _xml_add_invoice_summary(xml_root, invoice)
|
167
|
+
xml_summary = _xml_nested_text(invoice.items.size, 'InvoiceSummary',
|
168
|
+
'NumberOfLines')
|
169
|
+
xml_totals = _xml_element('InvoiceTotals')
|
170
|
+
if(price = invoice.get_price('SummePositionen'))
|
171
|
+
xml_net = _xml_nested_text(sprintf('%1.2f', price.amount),
|
172
|
+
'NetValue', 'MonetaryValue', 'MonetaryAmount')
|
173
|
+
xml_totals.add_element(xml_net)
|
174
|
+
end
|
175
|
+
if(price = invoice.get_price('Mehrwertsteuer'))
|
176
|
+
xml_tax = _xml_nested_text(sprintf('%1.2f', price.amount),
|
177
|
+
'TotalTax', 'MonetaryValue', 'MonetaryAmount')
|
178
|
+
xml_totals.add_element(xml_tax)
|
179
|
+
end
|
180
|
+
if(price = invoice.get_price('Endbetrag'))
|
181
|
+
xml_total = _xml_nested_text(sprintf('%1.2f', price.amount),
|
182
|
+
'TotalAmountPlusTax', 'MonetaryValue',
|
183
|
+
'MonetaryAmount')
|
184
|
+
xml_totals.add_element(xml_total)
|
185
|
+
end
|
186
|
+
xml_summary.add_element(xml_totals)
|
187
|
+
xml_root.add_element(xml_summary)
|
188
|
+
end
|
189
|
+
def _xml_add_item(xml_elm, item)
|
190
|
+
xml_item = _xml_element('OrderResponseItemDetail')
|
191
|
+
_xml_add_base_item_detail(xml_item, item)
|
192
|
+
_xml_add_pricing_detail(xml_item, item)
|
193
|
+
_xml_add_delivery_detail(xml_item, item)
|
194
|
+
xml_elm.add_element(xml_item)
|
195
|
+
xml_item
|
196
|
+
end
|
197
|
+
def _xml_add_item_line_no(xml_item, line_no)
|
198
|
+
xml_item.add_element(_xml_nested_text(line_no, 'LineItemNum',
|
199
|
+
'BuyerLineItemNum'))
|
200
|
+
end
|
201
|
+
def _xml_add_item_part_id(xml_item, item)
|
202
|
+
xml_ids = _xml_element('ItemIdentifiers')
|
203
|
+
xml_pns = _xml_element('PartNumbers')
|
204
|
+
item.ids.each { |domain, idstr|
|
205
|
+
tagname = case domain
|
206
|
+
when 'ET-Nummer'
|
207
|
+
'BuyerPartNumber'
|
208
|
+
else
|
209
|
+
'SellerPartNumber'
|
210
|
+
end
|
211
|
+
xml_pns.add_element(_xml_nested_text(idstr, tagname, 'PartNum', 'PartID'))
|
212
|
+
}
|
213
|
+
xml_ids.add_element(xml_pns)
|
214
|
+
xml_item.add_element(xml_ids)
|
215
|
+
end
|
216
|
+
def _xml_add_item_quantity(xml_item, item)
|
217
|
+
xml_total = _xml_element('TotalQuantity')
|
218
|
+
xml_qty = _xml_nested_text(item.qty, 'Quantity', 'QuantityValue')
|
219
|
+
xml_qty.add_element(_xml_nested_text('EA', 'UnitOfMeasurement', 'UOMCoded'))
|
220
|
+
xml_total.add_element(xml_qty)
|
221
|
+
xml_item.add_element(xml_total)
|
222
|
+
end
|
223
|
+
def _xml_add_name_address(xml_party, addr)
|
224
|
+
xml_name_address = _xml_element('NameAddress')
|
225
|
+
lines = addr.lines.dup
|
226
|
+
street = lines.pop
|
227
|
+
name = lines.shift
|
228
|
+
xml_name_address.add_element(_xml_nested_text(name.to_s, 'Name1'))
|
229
|
+
unless(lines.empty?)
|
230
|
+
xml_name_address.add_element(_xml_nested_text(lines.join(" "), 'Name2'))
|
231
|
+
end
|
232
|
+
xml_name_address.add_element(_xml_nested_text(street, 'Street'))
|
233
|
+
xml_name_address.add_element(_xml_nested_text(addr.zip_code, 'PostalCode'))
|
234
|
+
xml_name_address.add_element(_xml_nested_text(addr.city, 'City'))
|
235
|
+
xml_party.add_element(xml_name_address)
|
236
|
+
end
|
237
|
+
def _xml_add_pricing_detail(xml_item, item, type=:order_response)
|
238
|
+
tag = 'PricingDetail'
|
239
|
+
total = 'TotalValue'
|
240
|
+
case type
|
241
|
+
when :invoice
|
242
|
+
tag = 'InvoicePricingDetail'
|
243
|
+
total = 'InvoiceCurrencyTotalValue'
|
244
|
+
end
|
245
|
+
xml_base = _xml_element(tag)
|
246
|
+
if(price = item.get_price('NettoPreis'))
|
247
|
+
xml_list = _xml_element('ListOfPrice')
|
248
|
+
xml_price = _xml_element('Price')
|
249
|
+
xml_unit = _xml_nested_text('CHF', 'UnitPrice', 'Currency',
|
250
|
+
'CurrencyCoded')
|
251
|
+
xml_value = _xml_nested_text(sprintf('%1.2f', price.amount),
|
252
|
+
'UnitPriceValue')
|
253
|
+
xml_unit.add_element(xml_value)
|
254
|
+
xml_price.add_element(xml_unit)
|
255
|
+
xml_list.add_element(xml_price)
|
256
|
+
xml_base.add_element(xml_list)
|
257
|
+
end
|
258
|
+
if(price = item.get_price('NettoPreisME'))
|
259
|
+
xml_price = _xml_nested_text(sprintf('%1.2f', price.amount),
|
260
|
+
total, 'MonetaryValue', 'MonetaryAmount')
|
261
|
+
xml_base.add_element(xml_price)
|
262
|
+
end
|
263
|
+
xml_item.add_element(xml_base)
|
264
|
+
end
|
265
|
+
def _xml_element(name)
|
266
|
+
REXML::Element.new(name)
|
267
|
+
end
|
268
|
+
def _xml_nested_text(text, *hierarchy)
|
269
|
+
parent = _xml_element(hierarchy.pop)
|
270
|
+
parent.text = _utf8(text)
|
271
|
+
hierarchy.reverse.each { |name|
|
272
|
+
child = parent
|
273
|
+
parent = _xml_element(name)
|
274
|
+
parent.add_element(child)
|
275
|
+
}
|
276
|
+
parent
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|