edi4r 0.9.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AuthorCopyright +10 -0
- data/COPYING +56 -0
- data/ChangeLog +106 -0
- data/README +66 -0
- data/TO-DO +35 -0
- data/Tutorial +609 -0
- data/VERSION +1 -0
- data/bin/edi2xml.rb +103 -0
- data/bin/editool.rb +151 -0
- data/bin/xml2edi.rb +50 -0
- data/data/edifact/iso9735/SDCD.10000.csv +10 -0
- data/data/edifact/iso9735/SDCD.20000.csv +10 -0
- data/data/edifact/iso9735/SDCD.30000.csv +11 -0
- data/data/edifact/iso9735/SDCD.40000.csv +31 -0
- data/data/edifact/iso9735/SDCD.40100.csv +31 -0
- data/data/edifact/iso9735/SDED.10000.csv +37 -0
- data/data/edifact/iso9735/SDED.20000.csv +37 -0
- data/data/edifact/iso9735/SDED.30000.csv +43 -0
- data/data/edifact/iso9735/SDED.40000.csv +129 -0
- data/data/edifact/iso9735/SDED.40100.csv +130 -0
- data/data/edifact/iso9735/SDMD.10000.csv +0 -0
- data/data/edifact/iso9735/SDMD.20000.csv +0 -0
- data/data/edifact/iso9735/SDMD.30000.csv +6 -0
- data/data/edifact/iso9735/SDMD.40000.csv +17 -0
- data/data/edifact/iso9735/SDMD.40100.csv +17 -0
- data/data/edifact/iso9735/SDSD.10000.csv +8 -0
- data/data/edifact/iso9735/SDSD.20000.csv +8 -0
- data/data/edifact/iso9735/SDSD.30000.csv +12 -0
- data/data/edifact/iso9735/SDSD.40000.csv +34 -0
- data/data/edifact/iso9735/SDSD.40100.csv +34 -0
- data/data/edifact/untdid/EDCD.d01b.csv +200 -0
- data/data/edifact/untdid/EDCD.d96a.csv +161 -0
- data/data/edifact/untdid/EDED.d01b.csv +641 -0
- data/data/edifact/untdid/EDED.d96a.csv +462 -0
- data/data/edifact/untdid/EDMD.d01b.csv +3419 -0
- data/data/edifact/untdid/EDMD.d96a.csv +2144 -0
- data/data/edifact/untdid/EDSD.d01b.csv +158 -0
- data/data/edifact/untdid/EDSD.d96a.csv +127 -0
- data/data/edifact/untdid/IDCD.d01b.csv +95 -0
- data/data/edifact/untdid/IDMD.d01b.csv +238 -0
- data/data/edifact/untdid/IDSD.d01b.csv +75 -0
- data/lib/edi4r.rb +928 -0
- data/lib/edi4r/diagrams.rb +567 -0
- data/lib/edi4r/edi4r-1.2.dtd +20 -0
- data/lib/edi4r/edifact-rexml.rb +221 -0
- data/lib/edi4r/edifact.rb +1627 -0
- data/lib/edi4r/rexml.rb +256 -0
- data/lib/edi4r/standards.rb +495 -0
- data/test/eancom2webedi.rb +380 -0
- data/test/groups.edi +1 -0
- data/test/in1.edi +1 -0
- data/test/in1.inh +3 -0
- data/test/in2.edi +1 -0
- data/test/in2.xml +350 -0
- data/test/test_basics.rb +209 -0
- data/test/test_edi_split.rb +53 -0
- data/test/test_loopback.rb +21 -0
- data/test/test_minidemo.rb +84 -0
- data/test/test_rexml.rb +98 -0
- data/test/test_tut_examples.rb +131 -0
- data/test/webedi2eancom.rb +408 -0
- metadata +110 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# :include: ../AuthorCopyright
|
3
|
+
|
4
|
+
# Load path magic...
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
require 'edi4r'
|
10
|
+
require 'edi4r/edifact'
|
11
|
+
|
12
|
+
# require "rubygems"
|
13
|
+
# require_gem "edi4r"
|
14
|
+
# require_gem "edi4r-tdid"
|
15
|
+
|
16
|
+
class Tutorial_Tests < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def test_tutorial_samples
|
19
|
+
ic = ic2 = nil
|
20
|
+
assert_nothing_raised do
|
21
|
+
ic = EDI::E::Interchange.new
|
22
|
+
ic2 = EDI::E::Interchange.new( :version => 3, :charset => 'UNOB' )
|
23
|
+
end
|
24
|
+
assert_equal( ic.to_s, ic2.to_s )
|
25
|
+
|
26
|
+
msg = msg1 = nil
|
27
|
+
assert_nothing_raised do
|
28
|
+
msg1 = ic.new_message
|
29
|
+
msg = ic.new_message(:msg_type=>'ORDERS', :version=>'D', :release=>'96A',
|
30
|
+
:resp_agency=>'UN' )
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_raise(EDI::EDILookupError) { ic.add( msg ) }
|
34
|
+
assert_nothing_raised { ic.add( msg, false ) }
|
35
|
+
|
36
|
+
|
37
|
+
assert_nothing_raised do
|
38
|
+
seg = msg.new_segment( 'BGM' )
|
39
|
+
msg.add( seg )
|
40
|
+
end
|
41
|
+
assert_equal( 1, msg.size )
|
42
|
+
|
43
|
+
order_number = nil
|
44
|
+
assert_nothing_raised do
|
45
|
+
bgm = msg.new_segment( 'BGM' )
|
46
|
+
bgm.d1004 = '123456ABC'
|
47
|
+
bgm.cC002.d1001 = 220
|
48
|
+
|
49
|
+
cde = bgm.cC002
|
50
|
+
order_number = bgm.d1004 if cde.d1001 == 220
|
51
|
+
end
|
52
|
+
assert_equal( '123456ABC', order_number )
|
53
|
+
|
54
|
+
|
55
|
+
assert_nothing_raised do
|
56
|
+
seg = msg.new_segment('PIA')
|
57
|
+
cde_list = seg.aC212
|
58
|
+
cde_list[0].d7140 = '54321'
|
59
|
+
cde_list[0].d7143 = 'SA'
|
60
|
+
cde_list[0].d3055 = 91
|
61
|
+
cde_list[1].d7140 = '12356' # etc
|
62
|
+
|
63
|
+
seg = msg.new_segment('NAD')
|
64
|
+
seg.cC080.a3036[0].value = 'E. X. Ample'
|
65
|
+
seg.cC080.a3036[1].value = 'Sales dept.'
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
assert_nothing_raised do
|
70
|
+
ic.header.cS002.d0004 = '1234567'
|
71
|
+
ic.header.d0035 = 1
|
72
|
+
ic.show_una = false
|
73
|
+
ic.show_una = true
|
74
|
+
end
|
75
|
+
assert_equal( 'UNA:+.? \'', ic.una.to_s )
|
76
|
+
|
77
|
+
assert_nothing_raised do
|
78
|
+
pri = msg.parse_segment("PRI+AAA:123::LIU", 'PRI')
|
79
|
+
pri.cC509.d5118 = 30.1
|
80
|
+
assert_equal( "PRI+AAA:30.1::LIU", pri.to_s )
|
81
|
+
ic.una.decimal_sign = ?,
|
82
|
+
assert_equal( "PRI+AAA:30,1::LIU", pri.to_s )
|
83
|
+
ic.una.ce_sep = ?/
|
84
|
+
assert_equal( "PRI+AAA/30,1//LIU", pri.to_s )
|
85
|
+
end
|
86
|
+
|
87
|
+
assert_raise(EDI::EDILookupError) {ic.validate}
|
88
|
+
|
89
|
+
ic = nil
|
90
|
+
assert_nothing_raised do
|
91
|
+
File.open("remadv101.edi") {|hnd| ic = EDI::E::Interchange.parse( hnd )}
|
92
|
+
|
93
|
+
ic.each do |msg|
|
94
|
+
|
95
|
+
msg.each do |seg|
|
96
|
+
seg_name = seg.name
|
97
|
+
seg_name += ' ' + seg.sg_name if seg.sg_name
|
98
|
+
case seg_name
|
99
|
+
when "BGM"
|
100
|
+
# do this ...
|
101
|
+
when "DTM"
|
102
|
+
# do that ...
|
103
|
+
when 'NAD SG2'
|
104
|
+
# react only if NAD occurs in segment group 2
|
105
|
+
|
106
|
+
# ... etc., finally:
|
107
|
+
default
|
108
|
+
raise "Segment #{seg_name}: Not accounted for!"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
n=0
|
115
|
+
assert_nothing_raised {n = ic.validate}
|
116
|
+
assert_equal( 0, n )
|
117
|
+
|
118
|
+
second_msg = ic[1]
|
119
|
+
last_msg = ic.last
|
120
|
+
d = last_msg['DTM'] # Array of all DTM segments, any segment group
|
121
|
+
assert( d. is_a?( Array ) )
|
122
|
+
d = msg.find_all {|seg| seg.name == 'DTM' && seg.sg_name == 'SG4'}
|
123
|
+
assert_equal( 11, d.size )
|
124
|
+
|
125
|
+
doc1 = last_msg['DOC'].first
|
126
|
+
assert_equal( 12, doc1.children.size )
|
127
|
+
assert_equal( 13, doc1.children_and_self.size )
|
128
|
+
assert_equal( 15, doc1.descendants.size )
|
129
|
+
assert_equal( 16, doc1.descendants_and_self.size )
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,408 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Mapping demo: Outbound, from inhouse to EANCOM
|
4
|
+
#
|
5
|
+
# Inhouse format: GS1 Germany's WebEDI ASCII interface for ORDERS
|
6
|
+
# Output format: EANCOM'02 ORDERS, according to GS1 Germany'
|
7
|
+
# recommendations for application
|
8
|
+
# (EDI-Anwendungsempfehlungen V 2.0 (ORDERS) in EANCOM 2002 S3)
|
9
|
+
# and the general EANCOM 2002 (ORDERS) documentation
|
10
|
+
# Comments:
|
11
|
+
#
|
12
|
+
# Inhouse and output format were selected, because they represent typical
|
13
|
+
# data structures and tasks for users, and because documentation of
|
14
|
+
# these formats is freely available.
|
15
|
+
#
|
16
|
+
# $Id: webedi2eancom.rb,v 1.1 2006/05/28 16:08:48 werntges Exp $
|
17
|
+
#
|
18
|
+
# Author: Heinz W. Werntges (edi@informatik.fh-wiesbaden.de)
|
19
|
+
#
|
20
|
+
# License: This code is put under the Ruby license
|
21
|
+
#
|
22
|
+
# Copyright (c) 2006 Heinz W. Werntges, FH Wiesbaden
|
23
|
+
#
|
24
|
+
|
25
|
+
# Include statement during test setup:
|
26
|
+
|
27
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
28
|
+
require 'edi4r'
|
29
|
+
require 'edi4r/edifact'
|
30
|
+
|
31
|
+
# Regular include statements:
|
32
|
+
|
33
|
+
#require "rubygems"
|
34
|
+
#require_gem "edi4r"
|
35
|
+
#require "edi4r/edifact"
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
class WebEDI_to_EANCOM02_Map_ORDERS
|
40
|
+
include EDI
|
41
|
+
|
42
|
+
# Mengeneinheit_cvt = {'STK' => 'PCE', 'KG' => 'KGM'}
|
43
|
+
# UNBsender_cvt = {'10' => '4333099000009', # Kaufhof ILN
|
44
|
+
# '1034' => '(C+C ILN)',
|
45
|
+
# '1037' => '(extra ILN)',
|
46
|
+
# '1063' => '(real,- ILN)',
|
47
|
+
# # etc.
|
48
|
+
# }
|
49
|
+
|
50
|
+
attr_accessor :with_rff_va
|
51
|
+
#
|
52
|
+
# Variable names for header record, derived from original documentation
|
53
|
+
# Adaptations:
|
54
|
+
# lower-case names, no umlaut chars, uniqueness of name (see "ust-id")
|
55
|
+
#
|
56
|
+
|
57
|
+
def processHeader( line )
|
58
|
+
bestellung, satzartkennung, iln_lieferanschrift, iln_kaeufer,
|
59
|
+
bestellnummer, releasenummer,
|
60
|
+
iln_lieferant, lieferantennummer, ust_id_lieferant,
|
61
|
+
abteilung_beim_kaeufer, ust_id_kaeufer,
|
62
|
+
iln_rechnungsempfaenger, abteilung_beim_rechnungsempfaenger, ust_id_re,
|
63
|
+
abteilung_der_lieferanschrift,
|
64
|
+
iln_endempfaenger, abteilung_beim_endempfaenger,
|
65
|
+
datum_der_bestellung, lieferdatum_gefordert, pick_up_datum,
|
66
|
+
waehrung, nr_der_werbeaktion, von_um, bis, _others = line.split(';')
|
67
|
+
|
68
|
+
raise "Header line mismatch: Too many fields" unless _others.nil?
|
69
|
+
|
70
|
+
# Store for consistency checks at line item level:
|
71
|
+
@unique_document_id=[iln_lieferanschrift, iln_kaeufer, bestellnummer]
|
72
|
+
|
73
|
+
unb = @ic.header
|
74
|
+
unb.cS002.d0004 = iln_kaeufer
|
75
|
+
unb.cS002.d0007 = 14
|
76
|
+
unb.cS003.d0010 = iln_lieferant
|
77
|
+
unb.cS003.d0007 = 14
|
78
|
+
# unb.d0035 = '1' if whatever ...
|
79
|
+
|
80
|
+
bgm = @msg.new_segment("BGM")
|
81
|
+
bgm.cC002.d1001 = bestellung # expected: '220'
|
82
|
+
bgm.cC106.d1004 = bestellnummer
|
83
|
+
bgm.d1225 = 9
|
84
|
+
@msg.add(bgm)
|
85
|
+
|
86
|
+
raise "Mandatory element missing: datum_der_bestellung" if datum_der_bestellung.empty?
|
87
|
+
dtm = @msg.new_segment("DTM")
|
88
|
+
dtm.cC507.d2005 = 137
|
89
|
+
dtm.cC507.d2380 = datum_der_bestellung
|
90
|
+
dtm.cC507.d2379 = 102
|
91
|
+
@msg.add(dtm)
|
92
|
+
|
93
|
+
unless lieferdatum_gefordert.empty?
|
94
|
+
dtm = @msg.new_segment("DTM")
|
95
|
+
dtm.cC507.d2005 = 2
|
96
|
+
lieferdatum_gefordert =~ /(\d\d\d\d)(\d\d)(\d\d)/
|
97
|
+
date = $1+$2+$3 # showing off a bit here...
|
98
|
+
if von_um.empty? and bis.empty?
|
99
|
+
dtm.cC507.d2380 = date
|
100
|
+
dtm.cC507.d2379 = 102
|
101
|
+
elsif bis.empty?
|
102
|
+
raise "Format error in 'von_um'" unless von_um =~ /\d*(\d\d\d\d)$/
|
103
|
+
dtm.cC507.d2380 = date+$1
|
104
|
+
dtm.cC507.d2379 = 203
|
105
|
+
else
|
106
|
+
raise "Format error in 'von_um'" unless von_um =~ /\d*(\d\d\d\d)$/
|
107
|
+
von = $1
|
108
|
+
raise "Format error in 'bis'" unless bis =~ /\d*(\d\d\d\d)$/
|
109
|
+
bis = $1
|
110
|
+
dtm.cC507.d2380 = date+von+date+bis
|
111
|
+
dtm.cC507.d2379 = 719
|
112
|
+
end
|
113
|
+
@msg.add(dtm)
|
114
|
+
end
|
115
|
+
|
116
|
+
unless pick_up_datum.empty?
|
117
|
+
dtm = @msg.new_segment("DTM")
|
118
|
+
dtm.cC507.d2005 = '200'
|
119
|
+
dtm.cC507.d2380 = pick_up_datum
|
120
|
+
dtm.cC507.d2379 = '102'
|
121
|
+
@msg.add(dtm)
|
122
|
+
end
|
123
|
+
|
124
|
+
unless nr_der_werbeaktion.empty?
|
125
|
+
rff = @msg.new_segment("RFF")
|
126
|
+
cde = rff.cC506
|
127
|
+
cde.d1153 = 'PD'
|
128
|
+
cde.d1154 = nr_der_werbeaktion
|
129
|
+
@msg.add(rff)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Use a loop for the NAD group
|
133
|
+
|
134
|
+
[ [iln_lieferant, 'SU', nil, nil, lieferantennummer, ust_id_lieferant],
|
135
|
+
[iln_kaeufer, 'BY', abteilung_beim_kaeufer, 'PD', nil, ust_id_kaeufer],
|
136
|
+
[iln_rechnungsempfaenger, 'IV', abteilung_beim_rechnungsempfaenger, 'OC', nil, ust_id_re],
|
137
|
+
[iln_lieferanschrift, 'DP', abteilung_der_lieferanschrift, 'DL', nil, nil],
|
138
|
+
[iln_endempfaenger, 'UC', abteilung_beim_endempfaenger, 'GR', nil, nil]
|
139
|
+
].each do |nad_params|
|
140
|
+
iln, qu, dept, qu_dept, no, ust_id = nad_params
|
141
|
+
|
142
|
+
raise "Mandatory ILN missing for #{qu}" if iln.nil? or iln.empty?
|
143
|
+
nad = @msg.new_segment("NAD")
|
144
|
+
nad.d3035 = qu
|
145
|
+
cde = nad.cC082
|
146
|
+
cde.d3039 = iln
|
147
|
+
cde.d3055 = '9'
|
148
|
+
@msg.add(nad)
|
149
|
+
|
150
|
+
# Special treatment - depending segments - in some cases:
|
151
|
+
|
152
|
+
if qu=='SU' and no and !no.empty?
|
153
|
+
rff = @msg.new_segment("RFF")
|
154
|
+
cde = rff.cC506
|
155
|
+
cde.d1153 = 'YC1'
|
156
|
+
cde.d1154 = no
|
157
|
+
@msg.add(rff)
|
158
|
+
end
|
159
|
+
|
160
|
+
if with_rff_va
|
161
|
+
# ust_id: reserved for INVOIC ?!
|
162
|
+
unless ust_id.nil?
|
163
|
+
rff = @msg.new_segment("RFF")
|
164
|
+
cde = rff.cC506
|
165
|
+
cde.d1153 = 'VA'
|
166
|
+
cde.d1154 = ust_id
|
167
|
+
@msg.add(rff)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
if dept and !dept.empty?
|
172
|
+
cta = @msg.new_segment("CTA")
|
173
|
+
cta.d3139 = qu_dept
|
174
|
+
cta.cC056.d3413 = dept
|
175
|
+
@msg.add(cta)
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
unless waehrung.empty?
|
181
|
+
seg = @msg.new_segment("CUX")
|
182
|
+
cde = seg.aC504.first # [0]
|
183
|
+
cde.d6347 = '2'
|
184
|
+
cde.d6345 = waehrung
|
185
|
+
cde.d6343 = '9'
|
186
|
+
@msg.add(seg)
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
def processItem( line )
|
193
|
+
|
194
|
+
bestellung, satzartkennung, iln_lieferanschrift, iln_kaeufer,
|
195
|
+
bestellnummer,
|
196
|
+
positionsnummer, ean, artikelbezeichnung, farbe, groesse,
|
197
|
+
lieferantenartikelnummer, kaeuferartikelnummer,
|
198
|
+
bestellmenge, einheit, preisbezugseinheit, ek, vk = line.split(';')
|
199
|
+
|
200
|
+
# Consistency check
|
201
|
+
if @unique_document_id != [iln_lieferanschrift, iln_kaeufer, bestellnummer]
|
202
|
+
puts @unique_document_id
|
203
|
+
puts [iln_lieferanschrift, iln_kaeufer, bestellnummer]
|
204
|
+
raise "Item does not match header!"
|
205
|
+
end
|
206
|
+
|
207
|
+
# LIN
|
208
|
+
lin = @msg.new_segment("LIN")
|
209
|
+
lin.d1082 = positionsnummer
|
210
|
+
lin.cC212.d7140 = ean
|
211
|
+
lin.cC212.d7143 = "SRV" unless ean.empty?
|
212
|
+
@msg.add(lin)
|
213
|
+
|
214
|
+
#PIA
|
215
|
+
if ean.empty?
|
216
|
+
raise "Mandatory article id missing" if lieferantenartikelnummer.empty?
|
217
|
+
pia = @msg.new_segment("PIA")
|
218
|
+
pia.d4347 = '5'
|
219
|
+
cde = pia.cC212[0]
|
220
|
+
cde.d7140 = lieferantenartikelnummer
|
221
|
+
cde.d7143 = 'SA'
|
222
|
+
cde.d3055 = '91'
|
223
|
+
end
|
224
|
+
|
225
|
+
unless kaeuferartikelnummer.empty? and lieferantenartikelnummer.empty?
|
226
|
+
pia = @msg.new_segment("PIA")
|
227
|
+
pia.d4347 = '1'
|
228
|
+
cde = pia.aC212[0]
|
229
|
+
if !lieferantenartikelnummer.empty?
|
230
|
+
cde.d7140 = lieferantenartikelnummer
|
231
|
+
cde.d7143 = 'SA'
|
232
|
+
cde.d3055 = '91'
|
233
|
+
if !kaeuferartikelnummer.empty?
|
234
|
+
cde = pia.aC212[1]
|
235
|
+
cde.d7140 = kaeuferartikelnummer
|
236
|
+
cde.d7143 = 'IN'
|
237
|
+
cde.d3055 = '92'
|
238
|
+
end
|
239
|
+
else
|
240
|
+
cde.d7140 = lieferantenartikelnummer
|
241
|
+
cde.d7143 = 'BP'
|
242
|
+
cde.d3055 = '92'
|
243
|
+
end
|
244
|
+
@msg.add(pia)
|
245
|
+
end
|
246
|
+
|
247
|
+
# IMD
|
248
|
+
unless artikelbezeichnung.empty?
|
249
|
+
imd = @msg.new_segment("IMD")
|
250
|
+
imd.d7077 = 'A'
|
251
|
+
imd.cC273.a7008[0].value = artikelbezeichnung
|
252
|
+
@msg.add(imd)
|
253
|
+
end
|
254
|
+
|
255
|
+
unless farbe.empty?
|
256
|
+
imd = @msg.new_segment("IMD")
|
257
|
+
imd.d7077 = 'F'
|
258
|
+
imd.cC272.d7081 = '35'
|
259
|
+
imd.cC273.a7008[0].value = farbe
|
260
|
+
@msg.add(imd)
|
261
|
+
end
|
262
|
+
|
263
|
+
unless groesse.empty?
|
264
|
+
imd = @msg.new_segment("IMD")
|
265
|
+
imd.d7077 = 'F'
|
266
|
+
imd.cC272.d7081 = '98'
|
267
|
+
imd.cC273.a7008[0].value = groesse
|
268
|
+
@msg.add(imd)
|
269
|
+
end
|
270
|
+
|
271
|
+
# QTY
|
272
|
+
qty = @msg.new_segment("QTY")
|
273
|
+
cde = qty.cC186
|
274
|
+
cde.d6063 = '21'
|
275
|
+
cde.d6060 = bestellmenge.to_i
|
276
|
+
cde.d6411 = einheit unless einheit == 'PCE' # Mengeneinheit_cvt[masseinh_menge]
|
277
|
+
cde.root = @ic
|
278
|
+
@msg.add(qty)
|
279
|
+
|
280
|
+
# PRI
|
281
|
+
[[ek,'AAA'], [vk, 'AAE']].each do |params|
|
282
|
+
preis, qu = params
|
283
|
+
unless preis.empty?
|
284
|
+
pri = @msg.new_segment("PRI")
|
285
|
+
cde = pri.cC509
|
286
|
+
cde.d5125 = qu
|
287
|
+
cde.d5118 = preis.sub(/,/,'.').to_f # decimal sign adjustment
|
288
|
+
if qu == 'AAA'
|
289
|
+
cde.d5387 = 'LIU'
|
290
|
+
else
|
291
|
+
cde.d5387 = 'SRP'
|
292
|
+
cde.d5284 = preisbezugseinheit
|
293
|
+
# cde.d6411 = 'PCE' ??
|
294
|
+
end
|
295
|
+
@msg.add(pri)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
def wrapup_msg # Fine as long as we don't create a summary section
|
303
|
+
return if @msg.nil?
|
304
|
+
uns = @msg.new_segment("UNS")
|
305
|
+
uns.d0081 = 'S'
|
306
|
+
@msg.add(uns)
|
307
|
+
@ic.add(@msg)
|
308
|
+
@msg = nil
|
309
|
+
end
|
310
|
+
|
311
|
+
# Dispatcher
|
312
|
+
#
|
313
|
+
# Call specialized mapping methods, depending on record type
|
314
|
+
#
|
315
|
+
def processLine( line )
|
316
|
+
case line
|
317
|
+
when /^#.*/ # Skip comment lines
|
318
|
+
|
319
|
+
when /^220;100;.*/ # Header: Triggers a new message
|
320
|
+
wrapup_msg
|
321
|
+
params = {
|
322
|
+
:msg_type => 'ORDERS',
|
323
|
+
:version => 'D',
|
324
|
+
:release => '01B',
|
325
|
+
:resp_agency => 'UN',
|
326
|
+
:assigned_code => 'EAN010'
|
327
|
+
}
|
328
|
+
@msg = @ic.new_message( params )
|
329
|
+
processHeader( line.chomp )
|
330
|
+
|
331
|
+
when /^220;200;.*/ # Item: Requires a message to add to
|
332
|
+
raise "Illegal state: Item before header?" if @msg == nil
|
333
|
+
processItem(line.chomp)
|
334
|
+
|
335
|
+
when /^\W*$/ # EOF: Add message to interchange
|
336
|
+
wrapup_msg
|
337
|
+
|
338
|
+
else
|
339
|
+
print "Illegal line: #{line}\n"
|
340
|
+
wrapup_msg
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
|
345
|
+
def initialize(interchange)
|
346
|
+
@msg = nil
|
347
|
+
@with_rf_va = false
|
348
|
+
@ic = interchange
|
349
|
+
end
|
350
|
+
|
351
|
+
def validate
|
352
|
+
@ic.validate
|
353
|
+
end
|
354
|
+
|
355
|
+
def write(hnd)
|
356
|
+
@ic.write(hnd)
|
357
|
+
end
|
358
|
+
end # class WebEDI_to_EANCOM02_Mapper
|
359
|
+
|
360
|
+
|
361
|
+
#
|
362
|
+
# MAIN
|
363
|
+
#
|
364
|
+
|
365
|
+
# We assume that all input is subject to the same mapping code,
|
366
|
+
# and that all resulting messages go into the same interchange.
|
367
|
+
#
|
368
|
+
# Sender and recipient code of this interchange's UNB segment
|
369
|
+
# are determined by buyer and supplier of one of the messages.
|
370
|
+
#
|
371
|
+
# In "real live", you may have to sort input documents according
|
372
|
+
# to message type, sender/recipient, and required mapping code.
|
373
|
+
|
374
|
+
ic = EDI::E::Interchange.new({:show_una => true,
|
375
|
+
:charset => 'UNOC',
|
376
|
+
:version => 3,
|
377
|
+
:interchange_control_reference => Time.now.to_f.to_s[0...14] ,
|
378
|
+
# :application_reference => 'EANCOM' ,
|
379
|
+
# :output_mode => :verbatim,
|
380
|
+
# :acknowledgment_request => true,
|
381
|
+
:interchange_agreement_id => 'EANCOM'+'' , # your ref here!
|
382
|
+
:test_indicator => 1,
|
383
|
+
})
|
384
|
+
|
385
|
+
with_rff_va = false
|
386
|
+
|
387
|
+
while ARGV[0] =~ /^-(\w)/
|
388
|
+
opt = ARGV.shift
|
389
|
+
case $1
|
390
|
+
when 'v' # verbose mode - here: use formatted output
|
391
|
+
ic.output_mode = :indented
|
392
|
+
when 'a'
|
393
|
+
with_rff_va = true
|
394
|
+
else
|
395
|
+
raise "Option not supported: #{opt}"
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
map = WebEDI_to_EANCOM02_Map_ORDERS.new( ic )
|
400
|
+
map.with_rff_va = with_rff_va
|
401
|
+
|
402
|
+
while (line=gets)
|
403
|
+
map.processLine( line )
|
404
|
+
end
|
405
|
+
map.wrapup_msg
|
406
|
+
ic.validate
|
407
|
+
$stdout.write ic
|
408
|
+
# ic.inspect
|