eancom 0.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +190 -5
- data/.gitlab-ci.yml +25 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +22 -18
- data/README.md +46 -0
- data/bin/console +3 -2
- data/definitions/desadv/d01b.rb +251 -0
- data/definitions/desadv/d96a.rb +208 -87
- data/definitions/invoic/d01b.rb +559 -0
- data/definitions/invoic/d96a.rb +389 -0
- data/definitions/invrpt/d01b.rb +134 -0
- data/definitions/invrpt/d96a.rb +125 -0
- data/definitions/orders/d01b.rb +182 -0
- data/definitions/orders/d96b.rb +198 -0
- data/definitions/ordrsp/d01b.rb +251 -0
- data/definitions/ordrsp/d96b.rb +226 -0
- data/definitions/pricat/d01b.rb +225 -0
- data/definitions/pricat/d96b.rb +207 -0
- data/definitions/retann/d01b.rb +172 -0
- data/definitions/retann/d96b.rb +221 -0
- data/definitions/segments/ajt.rb +47 -0
- data/definitions/segments/alc.rb +328 -0
- data/definitions/segments/ali.rb +93 -0
- data/definitions/segments/bgm.rb +395 -0
- data/definitions/segments/cav.rb +122 -0
- data/definitions/segments/cci.rb +136 -0
- data/definitions/segments/cdi.rb +39 -0
- data/definitions/segments/cnt.rb +82 -0
- data/definitions/segments/cps.rb +76 -0
- data/definitions/segments/cta.rb +89 -0
- data/definitions/segments/cux.rb +174 -0
- data/definitions/segments/dgs.rb +34 -0
- data/definitions/segments/doc.rb +45 -0
- data/definitions/segments/dtm.rb +243 -0
- data/definitions/segments/efi.rb +67 -0
- data/definitions/segments/eqd.rb +37 -0
- data/definitions/segments/ftx.rb +165 -0
- data/definitions/segments/gin.rb +113 -0
- data/definitions/segments/imd.rb +360 -0
- data/definitions/segments/inv.rb +94 -0
- data/definitions/segments/lin.rb +133 -0
- data/definitions/segments/loc.rb +137 -0
- data/definitions/segments/mea.rb +189 -0
- data/definitions/segments/moa.rb +228 -0
- data/definitions/segments/nad.rb +314 -0
- data/definitions/segments/pac.rb +262 -0
- data/definitions/segments/pat.rb +171 -0
- data/definitions/segments/pcd.rb +72 -0
- data/definitions/segments/pci.rb +110 -0
- data/definitions/segments/pgi.rb +152 -0
- data/definitions/segments/pia.rb +501 -0
- data/definitions/segments/pri.rb +208 -0
- data/definitions/segments/qty.rb +293 -0
- data/definitions/segments/rff.rb +210 -0
- data/definitions/segments/rte.rb +52 -0
- data/definitions/segments/tax.rb +266 -0
- data/definitions/segments/tdt.rb +278 -0
- data/definitions/segments/tod.rb +64 -0
- data/definitions/segments/tru.rb +34 -0
- data/definitions/segments/una.rb +85 -0
- data/definitions/segments/unb.rb +284 -0
- data/definitions/segments/unh.rb +183 -0
- data/definitions/segments/uns.rb +40 -0
- data/definitions/segments/unt.rb +48 -0
- data/definitions/segments/unz.rb +48 -0
- data/definitions/slsrpt/d01b.rb +206 -0
- data/definitions/slsrpt/d96a.rb +199 -0
- data/eancom.gemspec +2 -1
- data/lib/eancom.rb +61 -16
- data/lib/eancom/definition.rb +1 -1
- data/lib/eancom/edifact.rb +60 -13
- data/lib/eancom/edifact/body.rb +63 -0
- data/lib/eancom/edifact/composite.rb +38 -0
- data/lib/eancom/edifact/data.rb +108 -0
- data/lib/eancom/edifact/document.rb +43 -11
- data/lib/eancom/edifact/document_element.rb +26 -0
- data/lib/eancom/edifact/footer.rb +7 -0
- data/lib/eancom/edifact/header.rb +15 -0
- data/lib/eancom/edifact/item.rb +40 -0
- data/lib/eancom/edifact/message.rb +24 -16
- data/lib/eancom/edifact/segment.rb +131 -12
- data/lib/eancom/edifact/segments/ajt.rb +32 -0
- data/lib/eancom/edifact/segments/alc.rb +61 -0
- data/lib/eancom/edifact/segments/ali.rb +50 -0
- data/lib/eancom/edifact/segments/bgm.rb +46 -0
- data/lib/eancom/edifact/segments/cav.rb +47 -0
- data/lib/eancom/edifact/segments/cci.rb +53 -0
- data/lib/eancom/edifact/segments/cdi.rb +30 -0
- data/lib/eancom/edifact/segments/cnt.rb +40 -0
- data/lib/eancom/edifact/segments/cps.rb +33 -0
- data/lib/eancom/edifact/segments/cta.rb +30 -0
- data/lib/eancom/edifact/segments/cux.rb +60 -0
- data/lib/eancom/edifact/segments/dgs.rb +31 -0
- data/lib/eancom/edifact/segments/doc.rb +30 -0
- data/lib/eancom/edifact/segments/dtm.rb +47 -0
- data/lib/eancom/edifact/segments/efi.rb +38 -0
- data/lib/eancom/edifact/segments/eqd.rb +30 -0
- data/lib/eancom/edifact/segments/ftx.rb +63 -0
- data/lib/eancom/edifact/segments/gin.rb +45 -0
- data/lib/eancom/edifact/segments/imd.rb +69 -0
- data/lib/eancom/edifact/segments/inv.rb +43 -0
- data/lib/eancom/edifact/segments/lin.rb +47 -0
- data/lib/eancom/edifact/segments/loc.rb +46 -0
- data/lib/eancom/edifact/segments/mea.rb +54 -0
- data/lib/eancom/edifact/segments/moa.rb +45 -0
- data/lib/eancom/edifact/segments/nad.rb +112 -0
- data/lib/eancom/edifact/segments/pac.rb +56 -0
- data/lib/eancom/edifact/segments/pat.rb +37 -0
- data/lib/eancom/edifact/segments/pcd.rb +33 -0
- data/lib/eancom/edifact/segments/pci.rb +40 -0
- data/lib/eancom/edifact/segments/pgi.rb +45 -0
- data/lib/eancom/edifact/segments/pia.rb +108 -0
- data/lib/eancom/edifact/segments/pri.rb +53 -0
- data/lib/eancom/edifact/segments/qty.rb +44 -0
- data/lib/eancom/edifact/segments/rff.rb +47 -0
- data/lib/eancom/edifact/segments/rte.rb +33 -0
- data/lib/eancom/edifact/segments/tax.rb +78 -0
- data/lib/eancom/edifact/segments/tdt.rb +57 -0
- data/lib/eancom/edifact/segments/tod.rb +33 -0
- data/lib/eancom/edifact/segments/tru.rb +31 -0
- data/lib/eancom/edifact/segments/una.rb +52 -0
- data/lib/eancom/edifact/segments/unb.rb +68 -0
- data/lib/eancom/edifact/segments/unh.rb +50 -0
- data/lib/eancom/edifact/segments/uns.rb +32 -0
- data/lib/eancom/edifact/segments/unt.rb +28 -0
- data/lib/eancom/edifact/segments/unz.rb +28 -0
- data/lib/eancom/edifact/structure.rb +90 -0
- data/lib/eancom/factory.rb +9 -8
- data/lib/eancom/parser.rb +7 -0
- data/lib/eancom/parser/document.rb +60 -0
- data/lib/eancom/parser/segment.rb +71 -0
- data/lib/eancom/version.rb +1 -1
- data/pricat.json +1 -0
- metadata +141 -9
- data/lib/eancom/edifact/element.rb +0 -16
- data/lib/eancom/edifact/envelope.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37e80db4ce2849be0d078d6cc80719f660f401b0a3f3141953af97568487a6b7
|
4
|
+
data.tar.gz: d95843f6ca45bc82ad47d49a1f5843d137f07626d6e230d04627a9e548cec48a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e4de3651ecc8acbe7beaf5e1f2d0a8f60d0fd1bc036af2a139c8d328bfae568585494298f555d1472fe06f0e7e0bda8324bce2e72f99e2fd9fea6c4bc0b009c
|
7
|
+
data.tar.gz: 020572b6a835b381c3d1519fcdf4445c53f5cc82722ca56882451e4d6bed7c39f3a61405f71c83740712060cc3eed1890ade00b0c79440ff991e666bc1c9ebba
|
data/.gitignore
CHANGED
@@ -1,11 +1,196 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/git,vim,ruby,rails,macos
|
3
|
+
# Edit at https://www.gitignore.io/?templates=git,vim,ruby,rails,macos
|
4
|
+
|
5
|
+
### Git ###
|
6
|
+
# Created by git for backups. To disable backups in Git:
|
7
|
+
# $ git config --global mergetool.keepBackup false
|
8
|
+
*.orig
|
9
|
+
|
10
|
+
# Created by git when using merge tools for conflicts
|
11
|
+
*.BACKUP.*
|
12
|
+
*.BASE.*
|
13
|
+
*.LOCAL.*
|
14
|
+
*.REMOTE.*
|
15
|
+
*_BACKUP_*.txt
|
16
|
+
*_BASE_*.txt
|
17
|
+
*_LOCAL_*.txt
|
18
|
+
*_REMOTE_*.txt
|
19
|
+
|
20
|
+
### macOS ###
|
21
|
+
# General
|
22
|
+
.DS_Store
|
23
|
+
.AppleDouble
|
24
|
+
.LSOverride
|
25
|
+
|
26
|
+
# Icon must end with two \r
|
27
|
+
Icon
|
28
|
+
|
29
|
+
# Thumbnails
|
30
|
+
._*
|
31
|
+
|
32
|
+
# Files that might appear in the root of a volume
|
33
|
+
.DocumentRevisions-V100
|
34
|
+
.fseventsd
|
35
|
+
.Spotlight-V100
|
36
|
+
.TemporaryItems
|
37
|
+
.Trashes
|
38
|
+
.VolumeIcon.icns
|
39
|
+
.com.apple.timemachine.donotpresent
|
40
|
+
|
41
|
+
# Directories potentially created on remote AFP share
|
42
|
+
.AppleDB
|
43
|
+
.AppleDesktop
|
44
|
+
Network Trash Folder
|
45
|
+
Temporary Items
|
46
|
+
.apdisk
|
47
|
+
|
48
|
+
### Rails ###
|
49
|
+
*.rbc
|
50
|
+
capybara-*.html
|
51
|
+
.rspec
|
52
|
+
/db/*.sqlite3
|
53
|
+
/db/*.sqlite3-journal
|
54
|
+
/public/system
|
4
55
|
/coverage/
|
5
|
-
/
|
56
|
+
/spec/tmp
|
57
|
+
rerun.txt
|
58
|
+
pickle-email-*.html
|
59
|
+
|
60
|
+
# Ignore all logfiles and tempfiles.
|
61
|
+
/log/*
|
62
|
+
/tmp/*
|
63
|
+
!/log/.keep
|
64
|
+
!/tmp/.keep
|
65
|
+
|
66
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
67
|
+
config/initializers/secret_token.rb
|
68
|
+
config/master.key
|
69
|
+
|
70
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
71
|
+
# config/secrets.yml
|
72
|
+
|
73
|
+
# dotenv
|
74
|
+
# TODO Comment out this rule if environment variables can be committed
|
75
|
+
.env
|
76
|
+
|
77
|
+
## Environment normalization:
|
78
|
+
/.bundle
|
79
|
+
/vendor/bundle
|
80
|
+
|
81
|
+
# these should all be checked in to normalize the environment:
|
82
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
83
|
+
|
84
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
85
|
+
.rvmrc
|
86
|
+
|
87
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
88
|
+
/vendor/assets/bower_components
|
89
|
+
*.bowerrc
|
90
|
+
bower.json
|
91
|
+
|
92
|
+
# Ignore pow environment settings
|
93
|
+
.powenv
|
94
|
+
|
95
|
+
# Ignore Byebug command history file.
|
96
|
+
.byebug_history
|
97
|
+
|
98
|
+
# Ignore node_modules
|
99
|
+
node_modules/
|
100
|
+
|
101
|
+
# Ignore precompiled javascript packs
|
102
|
+
/public/packs
|
103
|
+
/public/packs-test
|
104
|
+
/public/assets
|
105
|
+
|
106
|
+
# Ignore yarn files
|
107
|
+
/yarn-error.log
|
108
|
+
yarn-debug.log*
|
109
|
+
.yarn-integrity
|
110
|
+
|
111
|
+
# Ignore uploaded files in development
|
112
|
+
/storage/*
|
113
|
+
!/storage/.keep
|
114
|
+
|
115
|
+
### Ruby ###
|
116
|
+
*.gem
|
117
|
+
/.config
|
118
|
+
/InstalledFiles
|
6
119
|
/pkg/
|
7
120
|
/spec/reports/
|
121
|
+
/spec/examples.txt
|
122
|
+
/test/tmp/
|
123
|
+
/test/version_tmp/
|
8
124
|
/tmp/
|
9
125
|
|
10
|
-
#
|
126
|
+
# Used by dotenv library to load environment variables.
|
127
|
+
# .env
|
128
|
+
|
129
|
+
# Ignore Byebug command history file.
|
130
|
+
|
131
|
+
## Specific to RubyMotion:
|
132
|
+
.dat*
|
133
|
+
.repl_history
|
134
|
+
build/
|
135
|
+
*.bridgesupport
|
136
|
+
build-iPhoneOS/
|
137
|
+
build-iPhoneSimulator/
|
138
|
+
|
139
|
+
## Specific to RubyMotion (use of CocoaPods):
|
140
|
+
#
|
141
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
142
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
143
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
144
|
+
# vendor/Pods/
|
145
|
+
|
146
|
+
## Documentation cache and generated files:
|
147
|
+
/.yardoc/
|
148
|
+
/_yardoc/
|
149
|
+
/doc/
|
150
|
+
/rdoc/
|
151
|
+
|
152
|
+
/.bundle/
|
153
|
+
/lib/bundler/man/
|
154
|
+
|
155
|
+
# for a library or gem, you might want to ignore these files since the code is
|
156
|
+
# intended to run in multiple environments; otherwise, check them in:
|
157
|
+
# Gemfile.lock
|
158
|
+
# .ruby-version
|
159
|
+
# .ruby-gemset
|
160
|
+
|
161
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
162
|
+
|
163
|
+
### Ruby Patch ###
|
164
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
165
|
+
# .rubocop-https?--*
|
166
|
+
|
167
|
+
### Vim ###
|
168
|
+
# Swap
|
169
|
+
[._]*.s[a-v][a-z]
|
170
|
+
[._]*.sw[a-p]
|
171
|
+
[._]s[a-rt-v][a-z]
|
172
|
+
[._]ss[a-gi-z]
|
173
|
+
[._]sw[a-p]
|
174
|
+
|
175
|
+
# Session
|
176
|
+
Session.vim
|
177
|
+
Sessionx.vim
|
178
|
+
|
179
|
+
# Temporary
|
180
|
+
.netrwhist
|
181
|
+
*~
|
182
|
+
|
183
|
+
# Auto-generated tag files
|
184
|
+
tags
|
185
|
+
|
186
|
+
# Persistent undo
|
187
|
+
[._]*.un~
|
188
|
+
|
189
|
+
# Coc configuration directory
|
190
|
+
.vim
|
191
|
+
|
192
|
+
# Ignore Gemfile.lock
|
193
|
+
Gemfile.lock
|
194
|
+
|
195
|
+
# Rspec
|
11
196
|
.rspec_status
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
include:
|
2
|
+
- project: fadendaten/meta
|
3
|
+
file: gitlab-ci.base.yml
|
4
|
+
|
5
|
+
|
6
|
+
stages:
|
7
|
+
- pre-test
|
8
|
+
- test
|
9
|
+
|
10
|
+
Cache assets:
|
11
|
+
stage: pre-test
|
12
|
+
extends: .cache_assets
|
13
|
+
|
14
|
+
rspec:
|
15
|
+
stage: test
|
16
|
+
cache:
|
17
|
+
key: ${CI_PROJECT_NAME}-bundle-cache
|
18
|
+
paths:
|
19
|
+
- vendor/ruby
|
20
|
+
policy: pull
|
21
|
+
image: ruby:3.0.0
|
22
|
+
before_script:
|
23
|
+
- bundle check --path=vendor || bundle install --path=vendor --jobs=$(nproc)
|
24
|
+
script:
|
25
|
+
- bundle exec rspec spec/
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eancom (0.1
|
4
|
+
eancom (1.0.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
coderay (1.1.
|
10
|
-
diff-lcs (1.
|
11
|
-
docile (1.3.
|
9
|
+
coderay (1.1.3)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
docile (1.3.5)
|
12
12
|
method_source (0.9.2)
|
13
13
|
pry (0.12.2)
|
14
14
|
coderay (~> 1.1.0)
|
@@ -19,24 +19,27 @@ GEM
|
|
19
19
|
pry (~> 0.9)
|
20
20
|
slop (~> 3.0)
|
21
21
|
rake (12.3.3)
|
22
|
-
rspec (3.
|
23
|
-
rspec-core (~> 3.
|
24
|
-
rspec-expectations (~> 3.
|
25
|
-
rspec-mocks (~> 3.
|
26
|
-
rspec-core (3.
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-expectations (3.
|
22
|
+
rspec (3.10.0)
|
23
|
+
rspec-core (~> 3.10.0)
|
24
|
+
rspec-expectations (~> 3.10.0)
|
25
|
+
rspec-mocks (~> 3.10.0)
|
26
|
+
rspec-core (3.10.1)
|
27
|
+
rspec-support (~> 3.10.0)
|
28
|
+
rspec-expectations (3.10.1)
|
29
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.
|
31
|
-
rspec-mocks (3.
|
30
|
+
rspec-support (~> 3.10.0)
|
31
|
+
rspec-mocks (3.10.2)
|
32
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-support (3.
|
35
|
-
simplecov (0.
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-support (3.10.2)
|
35
|
+
simplecov (0.21.2)
|
36
36
|
docile (~> 1.1)
|
37
37
|
simplecov-html (~> 0.11)
|
38
|
-
|
38
|
+
simplecov_json_formatter (~> 0.1)
|
39
|
+
simplecov-html (0.12.3)
|
40
|
+
simplecov_json_formatter (0.1.2)
|
39
41
|
slop (3.6.0)
|
42
|
+
timecop (0.9.4)
|
40
43
|
|
41
44
|
PLATFORMS
|
42
45
|
ruby
|
@@ -49,6 +52,7 @@ DEPENDENCIES
|
|
49
52
|
rake (~> 12.0)
|
50
53
|
rspec (~> 3.0)
|
51
54
|
simplecov
|
55
|
+
timecop
|
52
56
|
|
53
57
|
BUNDLED WITH
|
54
|
-
2.
|
58
|
+
2.2.11
|
data/README.md
CHANGED
@@ -1,2 +1,48 @@
|
|
1
1
|
# Eancom
|
2
2
|
|
3
|
+
This software translates EDI to JSON messages.
|
4
|
+
The following message types are supported:
|
5
|
+
|
6
|
+
* ORDRSP
|
7
|
+
* PRICAT
|
8
|
+
* ORDERS
|
9
|
+
* DESADV
|
10
|
+
* INVOIC
|
11
|
+
* SLSRPT
|
12
|
+
* RETANN
|
13
|
+
|
14
|
+
It will be expanded into a fully fledged gem later on.
|
15
|
+
|
16
|
+
## Translate EDI to JSON messages
|
17
|
+
|
18
|
+
In order to translate EDI to JSON messages, open the terminal and type in the following commands within the project structure.
|
19
|
+
|
20
|
+
* `bin/console`<br/>
|
21
|
+
Opens the console.
|
22
|
+
* `edi_file = File.open('filepath')`<br/>
|
23
|
+
Opens the EDI file that needs to be translated.
|
24
|
+
* `json = Eancom::Parser::Document.new(file: edi_file).parse.to_json`<br/>
|
25
|
+
Translates the EDI file to a JSON file and stores it under the name json.
|
26
|
+
|
27
|
+
## Translate JSON to EDI messages
|
28
|
+
|
29
|
+
Similarily, in order to translate JSON to EDI messages, open the terminal and type the following commands within the project structure.
|
30
|
+
|
31
|
+
* `bin/console`<br/>
|
32
|
+
Opens the console.
|
33
|
+
* `json_file = File.open('filepath')`<br/>
|
34
|
+
Opens the EDI file that needs to be translated.
|
35
|
+
* `edi = Eancom::Factory.new(json: json_file.read).build.to_s`<br/>
|
36
|
+
Translates the JSON file to a EDI file and stores it under the name edi.
|
37
|
+
|
38
|
+
## Supported message formats
|
39
|
+
|
40
|
+
The GS1 standard contains many different messaging formats. Two of the most popular ones are the D96A and the D01B formats, both of which are implemented in this translator. The main difference between them is how the messages are structured, not what kind of segments or descriptions they contain. Please respect the structure defined by these formats. Otherwise the translator may reject your file.
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
You can add this gem to your project by either installing it using `bundle install prime-eancom` or by adding `gem "prime-eancom", "~> 0.1.0"` to your Gemfile. If you choose the latter option, go to your projects file structure within the terminal, type `bundle install` and hit `enter`. The prime-eancom now serenely inhabits your project.
|
45
|
+
|
46
|
+
## Testing
|
47
|
+
|
48
|
+
The prime-eancom is being tested with `rspec`. If you wan't to run the tests, go to the projects file structure within the terminal, type `rspec` and hit `enter`. You can also use `bundle exec rspec spec/` if the former option doesn't work.
|
data/bin/console
CHANGED
@@ -0,0 +1,251 @@
|
|
1
|
+
Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
|
2
|
+
document.header do |header|
|
3
|
+
header.segment Eancom::Edifact::UNA.new
|
4
|
+
|
5
|
+
header.segment Eancom::Edifact::UNB.new(
|
6
|
+
syntax_identifier: 'UNOC',
|
7
|
+
syntax_version_number: '3',
|
8
|
+
interchange_sender_identification: config.header.interchange_sender_identification,
|
9
|
+
sender_identifiction_code_qualifier: '14',
|
10
|
+
interchange_recipient_identification: config.header.interchange_recipient_identification,
|
11
|
+
recipient_identifiction_code_qualifier: '14',
|
12
|
+
date: config.header.date,
|
13
|
+
time: config.header.time,
|
14
|
+
interchange_control_reference: config.header.interchange_control_reference,
|
15
|
+
application_reference: config.header.application_reference,
|
16
|
+
interchange_agreement_identifier: config.header.interchange_agreement_identifier,
|
17
|
+
test_indicator: '0'
|
18
|
+
)
|
19
|
+
|
20
|
+
header.segment Eancom::Edifact::UNH.new(
|
21
|
+
message_reference_number: config.header.message_reference_number,
|
22
|
+
message_type: config.header.message_type,
|
23
|
+
message_version_number: config.header.message_version_number,
|
24
|
+
message_release_number: config.header.message_release_number,
|
25
|
+
controlling_agency: config.header.controlling_agency,
|
26
|
+
association_assigned_code: config.header.association_assigned_code
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
document.body do |body|
|
31
|
+
# Messages
|
32
|
+
messages = config.body.messages
|
33
|
+
|
34
|
+
messages.each do |message|
|
35
|
+
body.segment Eancom::Edifact::BGM.new(
|
36
|
+
document_name_code: message.document_name_code,
|
37
|
+
document_identifier: message.document_identifier,
|
38
|
+
message_function_code: message.message_function_code
|
39
|
+
)
|
40
|
+
|
41
|
+
date_time_messages = message.date_time_messages
|
42
|
+
date_time_messages.each_with_index do |dtm, index|
|
43
|
+
next unless index == 0
|
44
|
+
|
45
|
+
structure = Eancom.find_structure(tag: 'DTM')
|
46
|
+
key = dtm.identifier.intern.to_sym
|
47
|
+
body.segment Eancom::Edifact::DTM.new(
|
48
|
+
type: structure.dictionary_lookup(:type, dtm.identifier),
|
49
|
+
date_time: dtm[key].date_time,
|
50
|
+
format: '204'
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
date_time_messages.each_with_index do |dtm, index|
|
55
|
+
next unless index == 1
|
56
|
+
|
57
|
+
structure = Eancom.find_structure(tag: 'DTM')
|
58
|
+
key = dtm.identifier.intern.to_sym
|
59
|
+
body.segment Eancom::Edifact::DTM.new(
|
60
|
+
type: structure.dictionary_lookup(:type, dtm.identifier),
|
61
|
+
date_time: dtm[key].date_time,
|
62
|
+
format: '204'
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
references = message.references
|
67
|
+
references.each_with_index do |rff, index|
|
68
|
+
next unless index == 0
|
69
|
+
structure = Eancom.find_structure(tag: 'RFF')
|
70
|
+
key = rff.identifier.intern.to_sym
|
71
|
+
body.segment Eancom::Edifact::RFF.new(
|
72
|
+
reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
|
73
|
+
reference_identifier: rff[key].reference_identifier
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Supplier
|
78
|
+
nads = message.nads
|
79
|
+
nads.each_with_index do |nad, index|
|
80
|
+
next unless index == 0
|
81
|
+
|
82
|
+
structure = Eancom.find_structure(tag: 'NAD')
|
83
|
+
key = nad.identifier.intern.to_sym
|
84
|
+
body.segment Eancom::Edifact::NAD.new(
|
85
|
+
party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
|
86
|
+
party_identifier: nad[key].party_identifier,
|
87
|
+
code_list_responsible_agency_code_1: '9'
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Manufacturer ILN
|
92
|
+
nads = message.nads
|
93
|
+
nads.each_with_index do |nad, index|
|
94
|
+
next unless index == 1
|
95
|
+
|
96
|
+
structure = Eancom.find_structure(tag: 'NAD')
|
97
|
+
key = nad.identifier.intern.to_sym
|
98
|
+
body.segment Eancom::Edifact::NAD.new(
|
99
|
+
party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
|
100
|
+
party_identifier: nad[key].party_identifier,
|
101
|
+
code_list_responsible_agency_code_1: '9'
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
nads = message.nads
|
106
|
+
nads.each_with_index do |nad, index|
|
107
|
+
next unless index == 2
|
108
|
+
|
109
|
+
structure = Eancom.find_structure(tag: 'NAD')
|
110
|
+
key = nad.identifier.intern.to_sym
|
111
|
+
body.segment Eancom::Edifact::NAD.new(
|
112
|
+
party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
|
113
|
+
party_identifier: nad[key].party_identifier,
|
114
|
+
code_list_responsible_agency_code_1: '9',
|
115
|
+
city_name: nad[key].city_name,
|
116
|
+
party_name_1: nad[key].party_name_1,
|
117
|
+
postal_identification_code: nad[key].postal_identification_code,
|
118
|
+
street_and_number_1: nad[key].street_and_number_1,
|
119
|
+
country_name_code: nad[key].country_name_code
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Ultimate consignee
|
124
|
+
nads = message.nads
|
125
|
+
nads.each_with_index do |nad, index|
|
126
|
+
next unless index == 3
|
127
|
+
|
128
|
+
structure = Eancom.find_structure(tag: 'NAD')
|
129
|
+
key = nad.identifier.intern.to_sym
|
130
|
+
body.segment Eancom::Edifact::NAD.new(
|
131
|
+
party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
|
132
|
+
party_identifier: nad[key].party_identifier,
|
133
|
+
code_list_responsible_agency_code_1: '9',
|
134
|
+
city_name: nad[key].city_name,
|
135
|
+
party_name_1: nad[key].party_name_1,
|
136
|
+
postal_identification_code: nad[key].postal_identification_code,
|
137
|
+
street_and_number_1: nad[key].street_and_number_1,
|
138
|
+
country_name_code: nad[key].country_name_code
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
structure = Eancom.find_structure(tag: 'TDT')
|
143
|
+
qualifier = structure.dictionary_lookup(:transport_stage_code_qualifier, message.transport_stage_code_qualifier)
|
144
|
+
body.segment Eancom::Edifact::TDT.new(
|
145
|
+
transport_stage_code_qualifier: qualifier,
|
146
|
+
transport_mode_name_code: message.transport_mode_name_code
|
147
|
+
)
|
148
|
+
# CPS can remain hardcoded.
|
149
|
+
body.segment Eancom::Edifact::CPS.new(
|
150
|
+
hierarchical_structure_level_identifier: '1'
|
151
|
+
)
|
152
|
+
|
153
|
+
body.segment Eancom::Edifact::PAC.new(
|
154
|
+
package_quantity: message.package_quantity
|
155
|
+
)
|
156
|
+
|
157
|
+
body.segment Eancom::Edifact::CPS.new(
|
158
|
+
hierarchical_structure_level_identifier: '2',
|
159
|
+
hierarchical_structure_parent_identifier: message.hierarchical_structure_parent_identifier
|
160
|
+
)
|
161
|
+
|
162
|
+
# Items
|
163
|
+
total_quantity = 0
|
164
|
+
|
165
|
+
items = message.items
|
166
|
+
|
167
|
+
items.each_with_index do |item, index|
|
168
|
+
total_quantity += item.quantity.to_i
|
169
|
+
|
170
|
+
structure = Eancom.find_structure(tag: 'LIN')
|
171
|
+
body.segment Eancom::Edifact::LIN.new(
|
172
|
+
line_item_identifier_1: (index + 1).to_s,
|
173
|
+
item_identifier: item.ean,
|
174
|
+
item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
|
175
|
+
)
|
176
|
+
|
177
|
+
if additional_product_id = item.additional_product_id
|
178
|
+
additional_product_id.each do |id|
|
179
|
+
next unless additional_information = id.additional_information
|
180
|
+
|
181
|
+
structure = Eancom.find_structure(tag: 'PIA')
|
182
|
+
body.segment Eancom::Edifact::PIA.new(
|
183
|
+
product_identifier_code_qualifier: structure.dictionary_lookup(:product_identifier_code_qualifier, additional_information.product_identifier_code_qualifier),
|
184
|
+
item_identifier_1: additional_information.item_identifier_1,
|
185
|
+
item_type_identification_code_1: structure.dictionary_lookup(:item_type_identification_code_1,
|
186
|
+
additional_information.item_type_identification_code_1)
|
187
|
+
)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
item_descriptions = item.item_descriptions
|
192
|
+
item_descriptions.each do |description|
|
193
|
+
structure = Eancom.find_structure(tag: 'IMD')
|
194
|
+
body.segment Eancom::Edifact::IMD.new(
|
195
|
+
description_format_code: structure.dictionary_lookup(:description_format_code,
|
196
|
+
description.description_format_code),
|
197
|
+
item_description_code: structure.dictionary_lookup(:item_description_code,
|
198
|
+
description.item_description_code),
|
199
|
+
code_list_responsible_agency_code_1: structure.dictionary_lookup(:code_list_responsible_agency_code_1, description.code_list_responsible_agency_code_1)
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
quantities = item.quantities
|
204
|
+
quantities.each_with_index do |qty, index|
|
205
|
+
next unless index == 0
|
206
|
+
structure = Eancom.find_structure(tag: 'QTY')
|
207
|
+
key = qty.identifier.intern.to_sym
|
208
|
+
body.segment Eancom::Edifact::QTY.new(
|
209
|
+
quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
|
210
|
+
quantity: qty[key].quantity.to_s
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
quantities.each_with_index do |qty, index|
|
215
|
+
next unless index == 1
|
216
|
+
structure = Eancom.find_structure(tag: 'QTY')
|
217
|
+
key = qty.identifier.intern.to_sym
|
218
|
+
body.segment Eancom::Edifact::QTY.new(
|
219
|
+
quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
|
220
|
+
quantity: qty[key].quantity.to_s
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
references = item.references
|
226
|
+
references.each_with_index do |rff, index|
|
227
|
+
structure = Eancom.find_structure(tag: 'RFF')
|
228
|
+
key = rff.identifier.intern.to_sym
|
229
|
+
body.segment Eancom::Edifact::RFF.new(
|
230
|
+
reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
|
231
|
+
reference_identifier: rff[key].reference_identifier,
|
232
|
+
document_line_identifier: rff[key].document_line_identifier
|
233
|
+
)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
body.segment Eancom::Edifact::UNT.new(
|
238
|
+
number_of_segments_in_message: (document.total_segments + 2).to_s,
|
239
|
+
message_reference_number: config.header.message_reference_number
|
240
|
+
)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
messages = config.body.messages
|
245
|
+
document.footer do |footer|
|
246
|
+
footer.segment Eancom::Edifact::UNZ.new(
|
247
|
+
interchange_control_count: messages.size.to_s,
|
248
|
+
interchange_control_reference: config.header.interchange_control_reference.to_s
|
249
|
+
)
|
250
|
+
end
|
251
|
+
end
|