eancom 0.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +190 -5
  3. data/.gitlab-ci.yml +25 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile.lock +22 -18
  6. data/README.md +46 -0
  7. data/bin/console +3 -2
  8. data/definitions/desadv/d01b.rb +251 -0
  9. data/definitions/desadv/d96a.rb +208 -87
  10. data/definitions/invoic/d01b.rb +559 -0
  11. data/definitions/invoic/d96a.rb +389 -0
  12. data/definitions/invrpt/d01b.rb +134 -0
  13. data/definitions/invrpt/d96a.rb +125 -0
  14. data/definitions/orders/d01b.rb +182 -0
  15. data/definitions/orders/d96b.rb +198 -0
  16. data/definitions/ordrsp/d01b.rb +251 -0
  17. data/definitions/ordrsp/d96b.rb +226 -0
  18. data/definitions/pricat/d01b.rb +225 -0
  19. data/definitions/pricat/d96b.rb +207 -0
  20. data/definitions/retann/d01b.rb +172 -0
  21. data/definitions/retann/d96b.rb +221 -0
  22. data/definitions/segments/ajt.rb +47 -0
  23. data/definitions/segments/alc.rb +328 -0
  24. data/definitions/segments/ali.rb +93 -0
  25. data/definitions/segments/bgm.rb +395 -0
  26. data/definitions/segments/cav.rb +122 -0
  27. data/definitions/segments/cci.rb +136 -0
  28. data/definitions/segments/cdi.rb +39 -0
  29. data/definitions/segments/cnt.rb +82 -0
  30. data/definitions/segments/cps.rb +76 -0
  31. data/definitions/segments/cta.rb +89 -0
  32. data/definitions/segments/cux.rb +174 -0
  33. data/definitions/segments/dgs.rb +34 -0
  34. data/definitions/segments/doc.rb +45 -0
  35. data/definitions/segments/dtm.rb +243 -0
  36. data/definitions/segments/efi.rb +67 -0
  37. data/definitions/segments/eqd.rb +37 -0
  38. data/definitions/segments/ftx.rb +165 -0
  39. data/definitions/segments/gin.rb +113 -0
  40. data/definitions/segments/imd.rb +360 -0
  41. data/definitions/segments/inv.rb +94 -0
  42. data/definitions/segments/lin.rb +133 -0
  43. data/definitions/segments/loc.rb +137 -0
  44. data/definitions/segments/mea.rb +189 -0
  45. data/definitions/segments/moa.rb +228 -0
  46. data/definitions/segments/nad.rb +314 -0
  47. data/definitions/segments/pac.rb +262 -0
  48. data/definitions/segments/pat.rb +171 -0
  49. data/definitions/segments/pcd.rb +72 -0
  50. data/definitions/segments/pci.rb +110 -0
  51. data/definitions/segments/pgi.rb +152 -0
  52. data/definitions/segments/pia.rb +501 -0
  53. data/definitions/segments/pri.rb +208 -0
  54. data/definitions/segments/qty.rb +293 -0
  55. data/definitions/segments/rff.rb +210 -0
  56. data/definitions/segments/rte.rb +52 -0
  57. data/definitions/segments/tax.rb +266 -0
  58. data/definitions/segments/tdt.rb +278 -0
  59. data/definitions/segments/tod.rb +64 -0
  60. data/definitions/segments/tru.rb +34 -0
  61. data/definitions/segments/una.rb +85 -0
  62. data/definitions/segments/unb.rb +284 -0
  63. data/definitions/segments/unh.rb +183 -0
  64. data/definitions/segments/uns.rb +40 -0
  65. data/definitions/segments/unt.rb +48 -0
  66. data/definitions/segments/unz.rb +48 -0
  67. data/definitions/slsrpt/d01b.rb +206 -0
  68. data/definitions/slsrpt/d96a.rb +199 -0
  69. data/eancom.gemspec +2 -1
  70. data/lib/eancom.rb +61 -16
  71. data/lib/eancom/definition.rb +1 -1
  72. data/lib/eancom/edifact.rb +60 -13
  73. data/lib/eancom/edifact/body.rb +63 -0
  74. data/lib/eancom/edifact/composite.rb +38 -0
  75. data/lib/eancom/edifact/data.rb +108 -0
  76. data/lib/eancom/edifact/document.rb +43 -11
  77. data/lib/eancom/edifact/document_element.rb +26 -0
  78. data/lib/eancom/edifact/footer.rb +7 -0
  79. data/lib/eancom/edifact/header.rb +15 -0
  80. data/lib/eancom/edifact/item.rb +40 -0
  81. data/lib/eancom/edifact/message.rb +24 -16
  82. data/lib/eancom/edifact/segment.rb +131 -12
  83. data/lib/eancom/edifact/segments/ajt.rb +32 -0
  84. data/lib/eancom/edifact/segments/alc.rb +61 -0
  85. data/lib/eancom/edifact/segments/ali.rb +50 -0
  86. data/lib/eancom/edifact/segments/bgm.rb +46 -0
  87. data/lib/eancom/edifact/segments/cav.rb +47 -0
  88. data/lib/eancom/edifact/segments/cci.rb +53 -0
  89. data/lib/eancom/edifact/segments/cdi.rb +30 -0
  90. data/lib/eancom/edifact/segments/cnt.rb +40 -0
  91. data/lib/eancom/edifact/segments/cps.rb +33 -0
  92. data/lib/eancom/edifact/segments/cta.rb +30 -0
  93. data/lib/eancom/edifact/segments/cux.rb +60 -0
  94. data/lib/eancom/edifact/segments/dgs.rb +31 -0
  95. data/lib/eancom/edifact/segments/doc.rb +30 -0
  96. data/lib/eancom/edifact/segments/dtm.rb +47 -0
  97. data/lib/eancom/edifact/segments/efi.rb +38 -0
  98. data/lib/eancom/edifact/segments/eqd.rb +30 -0
  99. data/lib/eancom/edifact/segments/ftx.rb +63 -0
  100. data/lib/eancom/edifact/segments/gin.rb +45 -0
  101. data/lib/eancom/edifact/segments/imd.rb +69 -0
  102. data/lib/eancom/edifact/segments/inv.rb +43 -0
  103. data/lib/eancom/edifact/segments/lin.rb +47 -0
  104. data/lib/eancom/edifact/segments/loc.rb +46 -0
  105. data/lib/eancom/edifact/segments/mea.rb +54 -0
  106. data/lib/eancom/edifact/segments/moa.rb +45 -0
  107. data/lib/eancom/edifact/segments/nad.rb +112 -0
  108. data/lib/eancom/edifact/segments/pac.rb +56 -0
  109. data/lib/eancom/edifact/segments/pat.rb +37 -0
  110. data/lib/eancom/edifact/segments/pcd.rb +33 -0
  111. data/lib/eancom/edifact/segments/pci.rb +40 -0
  112. data/lib/eancom/edifact/segments/pgi.rb +45 -0
  113. data/lib/eancom/edifact/segments/pia.rb +108 -0
  114. data/lib/eancom/edifact/segments/pri.rb +53 -0
  115. data/lib/eancom/edifact/segments/qty.rb +44 -0
  116. data/lib/eancom/edifact/segments/rff.rb +47 -0
  117. data/lib/eancom/edifact/segments/rte.rb +33 -0
  118. data/lib/eancom/edifact/segments/tax.rb +78 -0
  119. data/lib/eancom/edifact/segments/tdt.rb +57 -0
  120. data/lib/eancom/edifact/segments/tod.rb +33 -0
  121. data/lib/eancom/edifact/segments/tru.rb +31 -0
  122. data/lib/eancom/edifact/segments/una.rb +52 -0
  123. data/lib/eancom/edifact/segments/unb.rb +68 -0
  124. data/lib/eancom/edifact/segments/unh.rb +50 -0
  125. data/lib/eancom/edifact/segments/uns.rb +32 -0
  126. data/lib/eancom/edifact/segments/unt.rb +28 -0
  127. data/lib/eancom/edifact/segments/unz.rb +28 -0
  128. data/lib/eancom/edifact/structure.rb +90 -0
  129. data/lib/eancom/factory.rb +9 -8
  130. data/lib/eancom/parser.rb +7 -0
  131. data/lib/eancom/parser/document.rb +60 -0
  132. data/lib/eancom/parser/segment.rb +71 -0
  133. data/lib/eancom/version.rb +1 -1
  134. data/pricat.json +1 -0
  135. metadata +141 -9
  136. data/lib/eancom/edifact/element.rb +0 -16
  137. data/lib/eancom/edifact/envelope.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66282d8cdd5814a9cd6ddb733530d578c025da6b215e577a0d5f890b1324295f
4
- data.tar.gz: 39b225da80ab4dbc9886259b7cf61146e68364855f5f584c66348daee02e31d1
3
+ metadata.gz: 37e80db4ce2849be0d078d6cc80719f660f401b0a3f3141953af97568487a6b7
4
+ data.tar.gz: d95843f6ca45bc82ad47d49a1f5843d137f07626d6e230d04627a9e548cec48a
5
5
  SHA512:
6
- metadata.gz: a0efc78d25648823163e8e2e19b8c7e5aea2db94206bdf691ef1a2ba066501b8bc72799ad6de0d89dc42d66999600a61595dbb3f83e3a855fe088ddf7257f56c
7
- data.tar.gz: 5791816403f0ebd74821f43c8fc8aaa8f609c9f44fb99429ed61e59eb1c91ea8122a220fc9f9ec960b2019adbad5bed239bf2301f6d536aa4f7da5f5aa6d1bfe
6
+ metadata.gz: 9e4de3651ecc8acbe7beaf5e1f2d0a8f60d0fd1bc036af2a139c8d328bfae568585494298f555d1472fe06f0e7e0bda8324bce2e72f99e2fd9fea6c4bc0b009c
7
+ data.tar.gz: 020572b6a835b381c3d1519fcdf4445c53f5cc82722ca56882451e4d6bed7c39f3a61405f71c83740712060cc3eed1890ade00b0c79440ff991e666bc1c9ebba
data/.gitignore CHANGED
@@ -1,11 +1,196 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
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
- /doc/
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
- # rspec failure tracking
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.0)
4
+ eancom (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- coderay (1.1.2)
10
- diff-lcs (1.3)
11
- docile (1.3.2)
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.9.0)
23
- rspec-core (~> 3.9.0)
24
- rspec-expectations (~> 3.9.0)
25
- rspec-mocks (~> 3.9.0)
26
- rspec-core (3.9.1)
27
- rspec-support (~> 3.9.1)
28
- rspec-expectations (3.9.0)
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.9.0)
31
- rspec-mocks (3.9.1)
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.9.0)
34
- rspec-support (3.9.2)
35
- simplecov (0.18.5)
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
- simplecov-html (0.12.2)
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.1.4
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
@@ -10,5 +10,6 @@ require "eancom"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
14
- IRB.start(__FILE__)
13
+ # require "irb"
14
+ require 'pry'
15
+ Pry.start
@@ -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