eancom 1.6.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -4
  3. data/.gitlab-ci.yml +11 -13
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -4
  6. data/Gemfile.lock +21 -103
  7. data/README.md +46 -0
  8. data/definitions/desadv/d01b.rb +134 -87
  9. data/definitions/desadv/d96a.rb +145 -82
  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 +128 -36
  24. data/definitions/segments/bgm.rb +122 -2
  25. data/definitions/segments/cdi.rb +39 -0
  26. data/definitions/segments/cnt.rb +4 -0
  27. data/definitions/segments/cta.rb +89 -0
  28. data/definitions/segments/cux.rb +9 -2
  29. data/definitions/segments/dgs.rb +34 -0
  30. data/definitions/segments/doc.rb +45 -0
  31. data/definitions/segments/dtm.rb +75 -20
  32. data/definitions/segments/efi.rb +67 -0
  33. data/definitions/segments/eqd.rb +37 -0
  34. data/definitions/segments/ftx.rb +22 -8
  35. data/definitions/segments/gin.rb +113 -0
  36. data/definitions/segments/imd.rb +9 -13
  37. data/definitions/segments/inv.rb +94 -0
  38. data/definitions/segments/lin.rb +24 -4
  39. data/definitions/segments/loc.rb +52 -4
  40. data/definitions/segments/moa.rb +86 -2
  41. data/definitions/segments/nad.rb +69 -9
  42. data/definitions/segments/pac.rb +12 -0
  43. data/definitions/segments/pat.rb +171 -0
  44. data/definitions/segments/pcd.rb +9 -92
  45. data/definitions/segments/pci.rb +110 -0
  46. data/definitions/segments/pgi.rb +7 -3
  47. data/definitions/segments/pia.rb +21 -29
  48. data/definitions/segments/pri.rb +25 -13
  49. data/definitions/segments/qty.rb +208 -2
  50. data/definitions/segments/rff.rb +49 -13
  51. data/definitions/segments/rte.rb +52 -0
  52. data/definitions/segments/tax.rb +17 -10
  53. data/definitions/segments/tdt.rb +24 -0
  54. data/definitions/segments/tod.rb +64 -0
  55. data/definitions/segments/tru.rb +34 -0
  56. data/definitions/segments/una.rb +8 -8
  57. data/definitions/segments/unb.rb +4 -4
  58. data/definitions/segments/unh.rb +70 -5
  59. data/definitions/segments/uns.rb +2 -2
  60. data/definitions/segments/unt.rb +2 -2
  61. data/definitions/slsrpt/d01b.rb +132 -128
  62. data/definitions/slsrpt/d96a.rb +132 -129
  63. data/eancom.gemspec +5 -8
  64. data/lib/eancom/edifact/body.rb +37 -18
  65. data/lib/eancom/edifact/document.rb +20 -16
  66. data/lib/eancom/edifact/footer.rb +1 -0
  67. data/lib/eancom/edifact/item.rb +1 -1
  68. data/lib/eancom/edifact/message.rb +7 -39
  69. data/lib/eancom/edifact/segment.rb +9 -11
  70. data/lib/eancom/edifact/segments/ajt.rb +32 -0
  71. data/lib/eancom/edifact/segments/ali.rb +2 -4
  72. data/lib/eancom/edifact/segments/bgm.rb +4 -3
  73. data/lib/eancom/edifact/segments/cdi.rb +30 -0
  74. data/lib/eancom/edifact/segments/cnt.rb +8 -1
  75. data/lib/eancom/edifact/segments/cps.rb +4 -1
  76. data/lib/eancom/edifact/segments/cta.rb +30 -0
  77. data/lib/eancom/edifact/segments/cux.rb +1 -1
  78. data/lib/eancom/edifact/segments/dgs.rb +31 -0
  79. data/lib/eancom/edifact/segments/doc.rb +30 -0
  80. data/lib/eancom/edifact/segments/dtm.rb +10 -6
  81. data/lib/eancom/edifact/segments/efi.rb +38 -0
  82. data/lib/eancom/edifact/segments/eqd.rb +30 -0
  83. data/lib/eancom/edifact/segments/ftx.rb +2 -2
  84. data/lib/eancom/edifact/segments/gin.rb +45 -0
  85. data/lib/eancom/edifact/segments/imd.rb +1 -1
  86. data/lib/eancom/edifact/segments/inv.rb +43 -0
  87. data/lib/eancom/edifact/segments/lin.rb +7 -4
  88. data/lib/eancom/edifact/segments/loc.rb +8 -9
  89. data/lib/eancom/edifact/segments/mea.rb +1 -0
  90. data/lib/eancom/edifact/segments/moa.rb +3 -3
  91. data/lib/eancom/edifact/segments/nad.rb +11 -6
  92. data/lib/eancom/edifact/segments/pac.rb +3 -1
  93. data/lib/eancom/edifact/segments/pat.rb +37 -0
  94. data/lib/eancom/edifact/segments/pcd.rb +6 -17
  95. data/lib/eancom/edifact/segments/pci.rb +40 -0
  96. data/lib/eancom/edifact/segments/pia.rb +1 -0
  97. data/lib/eancom/edifact/segments/pri.rb +0 -1
  98. data/lib/eancom/edifact/segments/qty.rb +9 -5
  99. data/lib/eancom/edifact/segments/rff.rb +8 -2
  100. data/lib/eancom/edifact/segments/rte.rb +33 -0
  101. data/lib/eancom/edifact/segments/tax.rb +7 -1
  102. data/lib/eancom/edifact/segments/tdt.rb +4 -1
  103. data/lib/eancom/edifact/segments/tod.rb +33 -0
  104. data/lib/eancom/edifact/segments/tru.rb +31 -0
  105. data/lib/eancom/edifact/segments/una.rb +2 -1
  106. data/lib/eancom/edifact/segments/unb.rb +4 -5
  107. data/lib/eancom/edifact/segments/unh.rb +6 -4
  108. data/lib/eancom/edifact/segments/uns.rb +4 -1
  109. data/lib/eancom/edifact/structure.rb +0 -1
  110. data/lib/eancom/edifact.rb +15 -4
  111. data/lib/eancom/factory.rb +1 -1
  112. data/lib/eancom/parser/document.rb +3 -16
  113. data/lib/eancom/parser/segment.rb +9 -10
  114. data/lib/eancom/version.rb +1 -3
  115. data/lib/eancom.rb +3 -1
  116. data/pricat.json +1 -0
  117. metadata +45 -51
  118. data/.rubocop.yml +0 -2
  119. data/.tool-versions +0 -1
  120. data/definitions/segments/qvr.rb +0 -140
  121. data/lib/eancom/edifact/location.rb +0 -56
  122. data/lib/eancom/edifact/segments/qvr.rb +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b5fc9413e1aae3d7677f8e3ae1a779ef9127d4d0432301534022d9b121d35b5
4
- data.tar.gz: b29cc881d48fa8544cbb6e3779144db51ffbd88d5fe47dbf56bb7f38b9f4c6dd
3
+ metadata.gz: 37e80db4ce2849be0d078d6cc80719f660f401b0a3f3141953af97568487a6b7
4
+ data.tar.gz: d95843f6ca45bc82ad47d49a1f5843d137f07626d6e230d04627a9e548cec48a
5
5
  SHA512:
6
- metadata.gz: 3caae6575a4b5276ff6914e6f59688a4237077bbc8ca4227d29a1f527788526c5b9d850d37ef22a8f9e6032e8a1f15f7c88d32be4e85fa3d8e13b464c101effb
7
- data.tar.gz: 29e2a100a09c4b15dc9e566742306548547688c2ceabd0696fb6ca2247b7a6b37e051f2eeeb894afecedff58579f4c0bc832a42393cb57b4cdb43b86787b0edb
6
+ metadata.gz: 9e4de3651ecc8acbe7beaf5e1f2d0a8f60d0fd1bc036af2a139c8d328bfae568585494298f555d1472fe06f0e7e0bda8324bce2e72f99e2fd9fea6c4bc0b009c
7
+ data.tar.gz: 020572b6a835b381c3d1519fcdf4445c53f5cc82722ca56882451e4d6bed7c39f3a61405f71c83740712060cc3eed1890ade00b0c79440ff991e666bc1c9ebba
data/.gitignore CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  ### macOS ###
21
21
  # General
22
- *.DS_Store
22
+ .DS_Store
23
23
  .AppleDouble
24
24
  .LSOverride
25
25
 
@@ -49,7 +49,6 @@ Temporary Items
49
49
  *.rbc
50
50
  capybara-*.html
51
51
  .rspec
52
- .rspec_status
53
52
  /db/*.sqlite3
54
53
  /db/*.sqlite3-journal
55
54
  /public/system
@@ -163,7 +162,7 @@ build-iPhoneSimulator/
163
162
 
164
163
  ### Ruby Patch ###
165
164
  # Used by RuboCop. Remote config files pulled in from inherit_from directive.
166
- .rubocop-https?--*
165
+ # .rubocop-https?--*
167
166
 
168
167
  ### Vim ###
169
168
  # Swap
@@ -190,4 +189,8 @@ tags
190
189
  # Coc configuration directory
191
190
  .vim
192
191
 
193
- # End of https://www.gitignore.io/api/git,vim,ruby,rails,macos
192
+ # Ignore Gemfile.lock
193
+ Gemfile.lock
194
+
195
+ # Rspec
196
+ .rspec_status
data/.gitlab-ci.yml CHANGED
@@ -1,27 +1,25 @@
1
- variables:
2
- RUBY_DOCKER_IMAGE: eu.gcr.io/fadendaten-staging/ruby:3.0.2-alpine-dev
3
-
4
1
  include:
5
- - project: fadendaten/infrastructure/gitlab-runner
6
- file: gitlabci/base.yml
2
+ - project: fadendaten/meta
3
+ file: gitlab-ci.base.yml
4
+
7
5
 
8
6
  stages:
9
7
  - pre-test
10
- - lint
11
8
  - test
12
9
 
13
10
  Cache assets:
14
11
  stage: pre-test
15
- extends: .cache_assets:fadendaten
16
-
17
- pronto:
18
- stage: pre-test
19
- extends: .pronto:fadendaten
12
+ extends: .cache_assets
20
13
 
21
14
  rspec:
22
15
  stage: test
23
- extends: .rspec:base:fadendaten
24
- before_script: # exclude rake db:schema:load in before_script
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:
25
23
  - bundle check --path=vendor || bundle install --path=vendor --jobs=$(nproc)
26
24
  script:
27
25
  - bundle exec rspec spec/
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 3.0.0
data/Gemfile CHANGED
@@ -3,7 +3,5 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in eancom.gemspec
4
4
  gemspec
5
5
 
6
- group :development, :lint do
7
- gem 'pronto'
8
- gem 'pronto-rubocop'
9
- end
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock CHANGED
@@ -1,69 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eancom (1.6.1)
4
+ eancom (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- addressable (2.8.0)
10
- public_suffix (>= 2.0.2, < 5.0)
11
- ast (2.4.2)
12
- coderay (1.1.2)
13
- diff-lcs (1.3)
14
- docile (1.4.0)
15
- faraday (1.10.0)
16
- faraday-em_http (~> 1.0)
17
- faraday-em_synchrony (~> 1.0)
18
- faraday-excon (~> 1.1)
19
- faraday-httpclient (~> 1.0)
20
- faraday-multipart (~> 1.0)
21
- faraday-net_http (~> 1.0)
22
- faraday-net_http_persistent (~> 1.0)
23
- faraday-patron (~> 1.0)
24
- faraday-rack (~> 1.0)
25
- faraday-retry (~> 1.0)
26
- ruby2_keywords (>= 0.0.4)
27
- faraday-em_http (1.0.0)
28
- faraday-em_synchrony (1.0.0)
29
- faraday-excon (1.1.0)
30
- faraday-httpclient (1.0.1)
31
- faraday-multipart (1.0.3)
32
- multipart-post (>= 1.2, < 3)
33
- faraday-net_http (1.0.1)
34
- faraday-net_http_persistent (1.2.0)
35
- faraday-patron (1.0.0)
36
- faraday-rack (1.0.0)
37
- faraday-retry (1.0.3)
38
- gitlab (4.18.0)
39
- httparty (~> 0.18)
40
- terminal-table (>= 1.5.1)
41
- httparty (0.20.0)
42
- mime-types (~> 3.0)
43
- multi_xml (>= 0.5.2)
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ docile (1.3.5)
44
12
  method_source (0.9.2)
45
- mime-types (3.4.1)
46
- mime-types-data (~> 3.2015)
47
- mime-types-data (3.2022.0105)
48
- multi_xml (0.6.0)
49
- multipart-post (2.1.1)
50
- octokit (4.22.0)
51
- faraday (>= 0.9)
52
- sawyer (~> 0.8.0, >= 0.5.3)
53
- parallel (1.22.1)
54
- parser (3.1.2.0)
55
- ast (~> 2.4.1)
56
- pronto (0.11.0)
57
- gitlab (~> 4.4, >= 4.4.0)
58
- httparty (>= 0.13.7)
59
- octokit (~> 4.7, >= 4.7.0)
60
- rainbow (>= 2.2, < 4.0)
61
- rexml (~> 3.2)
62
- rugged (>= 0.23.0, < 1.1.0)
63
- thor (>= 0.20.3, < 2.0)
64
- pronto-rubocop (0.11.1)
65
- pronto (~> 0.11.0)
66
- rubocop (>= 0.63.1, < 2.0)
67
13
  pry (0.12.2)
68
14
  coderay (~> 1.1.0)
69
15
  method_source (~> 0.9.0)
@@ -72,69 +18,41 @@ GEM
72
18
  pry-remote (0.1.8)
73
19
  pry (~> 0.9)
74
20
  slop (~> 3.0)
75
- public_suffix (4.0.7)
76
- rainbow (3.1.1)
77
21
  rake (12.3.3)
78
- regexp_parser (2.4.0)
79
- rexml (3.2.5)
80
- rspec (3.9.0)
81
- rspec-core (~> 3.9.0)
82
- rspec-expectations (~> 3.9.0)
83
- rspec-mocks (~> 3.9.0)
84
- rspec-core (3.9.1)
85
- rspec-support (~> 3.9.1)
86
- 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)
87
29
  diff-lcs (>= 1.2.0, < 2.0)
88
- rspec-support (~> 3.9.0)
89
- rspec-mocks (3.9.1)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-mocks (3.10.2)
90
32
  diff-lcs (>= 1.2.0, < 2.0)
91
- rspec-support (~> 3.9.0)
92
- rspec-support (3.9.2)
93
- rubocop (1.29.1)
94
- parallel (~> 1.10)
95
- parser (>= 3.1.0.0)
96
- rainbow (>= 2.2.2, < 4.0)
97
- regexp_parser (>= 1.8, < 3.0)
98
- rexml (>= 3.2.5, < 4.0)
99
- rubocop-ast (>= 1.17.0, < 2.0)
100
- ruby-progressbar (~> 1.7)
101
- unicode-display_width (>= 1.4.0, < 3.0)
102
- rubocop-ast (1.18.0)
103
- parser (>= 3.1.1.0)
104
- ruby-progressbar (1.11.0)
105
- ruby2_keywords (0.0.5)
106
- rugged (1.0.1)
107
- sawyer (0.8.2)
108
- addressable (>= 2.3.5)
109
- faraday (> 0.8, < 2.0)
110
- simplecov (0.22.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-support (3.10.2)
35
+ simplecov (0.21.2)
111
36
  docile (~> 1.1)
112
37
  simplecov-html (~> 0.11)
113
38
  simplecov_json_formatter (~> 0.1)
114
39
  simplecov-html (0.12.3)
115
- simplecov_json_formatter (0.1.4)
40
+ simplecov_json_formatter (0.1.2)
116
41
  slop (3.6.0)
117
- terminal-table (3.0.2)
118
- unicode-display_width (>= 1.1.1, < 3)
119
- thor (1.2.1)
120
- timecop (0.9.1)
121
- unicode-display_width (2.1.0)
42
+ timecop (0.9.4)
122
43
 
123
44
  PLATFORMS
124
45
  ruby
125
46
 
126
47
  DEPENDENCIES
127
48
  eancom!
128
- pronto
129
- pronto-rubocop
130
49
  pry
131
50
  pry-nav
132
51
  pry-remote
133
- rake
134
- rspec
135
- rubocop
52
+ rake (~> 12.0)
53
+ rspec (~> 3.0)
136
54
  simplecov
137
55
  timecop
138
56
 
139
57
  BUNDLED WITH
140
- 2.2.22
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.
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
4
2
  document.header do |header|
5
3
  header.segment Eancom::Edifact::UNA.new
@@ -14,8 +12,8 @@ Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
14
12
  date: config.header.date,
15
13
  time: config.header.time,
16
14
  interchange_control_reference: config.header.interchange_control_reference,
17
- application_reference: 'DESADV0720',
18
- interchange_agreement_identifier: 'EANCOM76170270000007613067000000900',
15
+ application_reference: config.header.application_reference,
16
+ interchange_agreement_identifier: config.header.interchange_agreement_identifier,
19
17
  test_indicator: '0'
20
18
  )
21
19
 
@@ -35,106 +33,130 @@ Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
35
33
 
36
34
  messages.each do |message|
37
35
  body.segment Eancom::Edifact::BGM.new(
38
- document_name_code: '351',
36
+ document_name_code: message.document_name_code,
39
37
  document_identifier: message.document_identifier,
40
- message_function_code: '9'
38
+ message_function_code: message.message_function_code
41
39
  )
42
40
 
43
- # Document Date
44
- body.segment Eancom::Edifact::DTM.new(
45
- type: '137',
46
- date_time: message.document_message_date_time.date_time,
47
- format: '204'
48
- )
41
+ date_time_messages = message.date_time_messages
42
+ date_time_messages.each_with_index do |dtm, index|
43
+ next unless index == 0
49
44
 
50
- # Delivery Date Estimated
51
- if date_time = message.delivery_date_time_estimated.date_time
45
+ structure = Eancom.find_structure(tag: 'DTM')
46
+ key = dtm.identifier.intern.to_sym
52
47
  body.segment Eancom::Edifact::DTM.new(
53
- type: '17',
54
- date_time: date_time,
48
+ type: structure.dictionary_lookup(:type, dtm.identifier),
49
+ date_time: dtm[key].date_time,
55
50
  format: '204'
56
51
  )
57
52
  end
58
53
 
59
- # Order Reference
60
- if order_number_buyer = message.order_number_buyer
61
- body.segment Eancom::Edifact::RFF.new(
62
- reference_code_qualifier: 'ON',
63
- reference_identifier: order_number_buyer.reference_identifier
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'
64
63
  )
65
64
  end
66
65
 
67
- # Buyer
68
- if buyer = message.buyer
69
- body.segment Eancom::Edifact::NAD.new(
70
- party_function_code_qualifier: 'BY',
71
- party_identifier: buyer.party_identifier,
72
- code_list_responsible_agancy_code_1: '9'
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
73
74
  )
74
75
  end
75
76
 
76
77
  # Supplier
77
- if supplier = message.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
78
84
  body.segment Eancom::Edifact::NAD.new(
79
- party_function_code_qualifier: 'SU',
80
- party_identifier: supplier.party_identifier,
81
- code_list_responsible_agancy_code_1: '9'
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'
82
88
  )
83
89
  end
84
90
 
85
91
  # Manufacturer ILN
86
- if manufacturer = message.manufacturer
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
87
98
  body.segment Eancom::Edifact::NAD.new(
88
- party_function_code_qualifier: 'MF',
89
- party_identifier: manufacturer.party_identifier,
90
- code_list_responsible_agancy_code_1: '9'
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'
91
102
  )
92
103
  end
93
104
 
94
- # Delivery Party
95
- if delivery_party = message.delivery_party
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
96
111
  body.segment Eancom::Edifact::NAD.new(
97
- party_function_code_qualifier: 'DP',
98
- party_identifier: delivery_party.party_identifier,
99
- code_list_responsible_agancy_code_1: '9',
100
- city_name: delivery_party.city_name,
101
- party_name_1: delivery_party.party_name_1,
102
- postal_identification_code: delivery_party.postal_identification_code,
103
- street_and_number_1: delivery_party.street_and_number_1,
104
- country_name_code: delivery_party.country_name_code
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
105
120
  )
106
121
  end
107
122
 
108
123
  # Ultimate consignee
109
- if ultimate_consignee = message.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
110
130
  body.segment Eancom::Edifact::NAD.new(
111
- party_function_code_qualifier: 'UC',
112
- party_identifier: ultimate_consignee.party_identifier,
113
- code_list_responsible_agancy_code_1: '9',
114
- city_name: ultimate_consignee.city_name,
115
- party_name_1: ultimate_consignee.party_name_1,
116
- postal_identification_code: ultimate_consignee.postal_identification_code,
117
- street_and_number_1: ultimate_consignee.street_and_number_1,
118
- country_name_code: ultimate_consignee.country_name_code
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
119
139
  )
120
140
  end
121
141
 
142
+ structure = Eancom.find_structure(tag: 'TDT')
143
+ qualifier = structure.dictionary_lookup(:transport_stage_code_qualifier, message.transport_stage_code_qualifier)
122
144
  body.segment Eancom::Edifact::TDT.new(
123
- transport_stage_code_qualifier: '20',
124
- transport_mode_name_code: '30'
145
+ transport_stage_code_qualifier: qualifier,
146
+ transport_mode_name_code: message.transport_mode_name_code
125
147
  )
126
- # Delivery Note Mode
148
+ # CPS can remain hardcoded.
127
149
  body.segment Eancom::Edifact::CPS.new(
128
150
  hierarchical_structure_level_identifier: '1'
129
151
  )
130
152
 
131
153
  body.segment Eancom::Edifact::PAC.new(
132
- package_quantity: '1'
154
+ package_quantity: message.package_quantity
133
155
  )
134
156
 
135
157
  body.segment Eancom::Edifact::CPS.new(
136
158
  hierarchical_structure_level_identifier: '2',
137
- hierarchical_structure_parent_identifier: '1'
159
+ hierarchical_structure_parent_identifier: message.hierarchical_structure_parent_identifier
138
160
  )
139
161
 
140
162
  # Items
@@ -145,59 +167,84 @@ Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
145
167
  items.each_with_index do |item, index|
146
168
  total_quantity += item.quantity.to_i
147
169
 
170
+ structure = Eancom.find_structure(tag: 'LIN')
148
171
  body.segment Eancom::Edifact::LIN.new(
149
- line_item_identifier_1: item.line_item_identifier_1 || index,
172
+ line_item_identifier_1: (index + 1).to_s,
150
173
  item_identifier: item.ean,
151
- item_type_identification_code: 'SRV'
174
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
152
175
  )
153
176
 
154
177
  if additional_product_id = item.additional_product_id
155
178
  additional_product_id.each do |id|
156
- if (additional_information = id.additional_information)
157
- body.segment Eancom::Edifact::PIA.new(
158
- product_identifier_code_qualifier: '1',
159
- item_identifier_1: additional_information.item_identifier_1,
160
- item_type_identification_code_1: 'IN'
161
- )
162
- end
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
+ )
163
188
  end
164
189
  end
165
190
 
166
- body.segment Eancom::Edifact::IMD.new(
167
- description_format_code: 'C',
168
- item_description_code: 'CU',
169
- code_list_responsible_agency_code_1: '9'
170
- )
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
171
202
 
172
- body.segment Eancom::Edifact::QTY.new(
173
- quantity_type_code_qualifier: '12',
174
- quantity: item.despatch_quantity.quantity.to_s
175
- )
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
176
223
 
177
- body.segment Eancom::Edifact::QTY.new(
178
- quantity_type_code_qualifier: '59',
179
- quantity: item.despatch_quantity.quantity.to_s
180
- )
181
224
 
182
- if (order_number_buyer = message.order_number_buyer)
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
183
229
  body.segment Eancom::Edifact::RFF.new(
184
- reference_code_qualifier: 'ON',
185
- reference_identifier: order_number_buyer.reference_identifier,
186
- document_line_identifier: ((index + 1) * 10).to_s
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
187
233
  )
188
234
  end
189
235
  end
190
236
 
191
237
  body.segment Eancom::Edifact::UNT.new(
192
238
  number_of_segments_in_message: (document.total_segments + 2).to_s,
193
- message_reference_number: '1'
239
+ message_reference_number: config.header.message_reference_number
194
240
  )
195
241
  end
196
242
  end
197
243
 
244
+ messages = config.body.messages
198
245
  document.footer do |footer|
199
246
  footer.segment Eancom::Edifact::UNZ.new(
200
- interchange_control_count: '1',
247
+ interchange_control_count: messages.size.to_s,
201
248
  interchange_control_reference: config.header.interchange_control_reference.to_s
202
249
  )
203
250
  end