eancom 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -3
  3. data/.gitlab-ci.yml +11 -13
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -4
  6. data/Gemfile.lock +23 -103
  7. data/README.md +46 -0
  8. data/definitions/desadv/d01b.rb +139 -93
  9. data/definitions/desadv/d96a.rb +187 -101
  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 +128 -0
  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 +85 -1
  32. data/definitions/segments/efi.rb +67 -0
  33. data/definitions/segments/eqd.rb +37 -0
  34. data/definitions/segments/ftx.rb +24 -2
  35. data/definitions/segments/gin.rb +113 -0
  36. data/definitions/segments/imd.rb +5 -1
  37. data/definitions/segments/inv.rb +94 -0
  38. data/definitions/segments/lin.rb +23 -3
  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 +72 -0
  45. data/definitions/segments/pci.rb +110 -0
  46. data/definitions/segments/pgi.rb +6 -2
  47. data/definitions/segments/pia.rb +21 -21
  48. data/definitions/segments/pri.rb +21 -1
  49. data/definitions/segments/qty.rb +219 -5
  50. data/definitions/segments/rff.rb +51 -7
  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 +7 -7
  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 +104 -100
  62. data/definitions/slsrpt/d96a.rb +104 -99
  63. data/eancom.gemspec +5 -8
  64. data/lib/eancom/edifact/document.rb +2 -2
  65. data/lib/eancom/edifact/footer.rb +1 -0
  66. data/lib/eancom/edifact/segment.rb +2 -2
  67. data/lib/eancom/edifact/segments/ajt.rb +32 -0
  68. data/lib/eancom/edifact/segments/ali.rb +2 -4
  69. data/lib/eancom/edifact/segments/bgm.rb +4 -3
  70. data/lib/eancom/edifact/segments/cdi.rb +30 -0
  71. data/lib/eancom/edifact/segments/cnt.rb +8 -1
  72. data/lib/eancom/edifact/segments/cps.rb +4 -1
  73. data/lib/eancom/edifact/segments/cta.rb +30 -0
  74. data/lib/eancom/edifact/segments/cux.rb +1 -1
  75. data/lib/eancom/edifact/segments/dgs.rb +31 -0
  76. data/lib/eancom/edifact/segments/doc.rb +30 -0
  77. data/lib/eancom/edifact/segments/dtm.rb +10 -6
  78. data/lib/eancom/edifact/segments/efi.rb +38 -0
  79. data/lib/eancom/edifact/segments/eqd.rb +30 -0
  80. data/lib/eancom/edifact/segments/ftx.rb +2 -2
  81. data/lib/eancom/edifact/segments/gin.rb +45 -0
  82. data/lib/eancom/edifact/segments/imd.rb +1 -1
  83. data/lib/eancom/edifact/segments/inv.rb +43 -0
  84. data/lib/eancom/edifact/segments/lin.rb +7 -3
  85. data/lib/eancom/edifact/segments/loc.rb +8 -5
  86. data/lib/eancom/edifact/segments/mea.rb +1 -0
  87. data/lib/eancom/edifact/segments/moa.rb +3 -3
  88. data/lib/eancom/edifact/segments/nad.rb +11 -6
  89. data/lib/eancom/edifact/segments/pac.rb +3 -1
  90. data/lib/eancom/edifact/segments/pat.rb +37 -0
  91. data/lib/eancom/edifact/segments/pcd.rb +33 -0
  92. data/lib/eancom/edifact/segments/pci.rb +40 -0
  93. data/lib/eancom/edifact/segments/pia.rb +1 -0
  94. data/lib/eancom/edifact/segments/pri.rb +0 -1
  95. data/lib/eancom/edifact/segments/qty.rb +9 -5
  96. data/lib/eancom/edifact/segments/rff.rb +8 -2
  97. data/lib/eancom/edifact/segments/rte.rb +33 -0
  98. data/lib/eancom/edifact/segments/tax.rb +7 -1
  99. data/lib/eancom/edifact/segments/tdt.rb +4 -1
  100. data/lib/eancom/edifact/segments/tod.rb +33 -0
  101. data/lib/eancom/edifact/segments/tru.rb +31 -0
  102. data/lib/eancom/edifact/segments/una.rb +2 -1
  103. data/lib/eancom/edifact/segments/unb.rb +4 -5
  104. data/lib/eancom/edifact/segments/unh.rb +6 -4
  105. data/lib/eancom/edifact/segments/uns.rb +3 -0
  106. data/lib/eancom/edifact/structure.rb +0 -1
  107. data/lib/eancom/edifact.rb +15 -1
  108. data/lib/eancom/factory.rb +1 -1
  109. data/lib/eancom/parser/document.rb +2 -10
  110. data/lib/eancom/version.rb +1 -1
  111. data/lib/eancom.rb +3 -1
  112. data/pricat.json +1 -0
  113. metadata +51 -52
  114. data/.rspec_status +0 -225
  115. data/.rubocop.yml +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 234d2c930145821b399f6cc46e30ddd7e127a551b35461fa7a3a682d3ee5d894
4
- data.tar.gz: 5b6a38ff945ee619af277dcc0d2ed978b54065fe318922de2a0f5c5058a36f16
3
+ metadata.gz: 37e80db4ce2849be0d078d6cc80719f660f401b0a3f3141953af97568487a6b7
4
+ data.tar.gz: d95843f6ca45bc82ad47d49a1f5843d137f07626d6e230d04627a9e548cec48a
5
5
  SHA512:
6
- metadata.gz: ea6621ef1b1515437e516789f1ef414e152f5941bcbd6dab51b215c74e219cd7a03b735423fde3272fe669552b366b59f75820ae0ee01c1cbab02c07c92cbf9e
7
- data.tar.gz: 525516ac844aeb5212c9771b28c8664bdd5e71a49398617ffb9e6ced6ffe6a806d9e1574760dd471c003286e1366f99b4646c17f9826c7b8e61c445ec87cd620
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
 
@@ -162,7 +162,7 @@ build-iPhoneSimulator/
162
162
 
163
163
  ### Ruby Patch ###
164
164
  # Used by RuboCop. Remote config files pulled in from inherit_from directive.
165
- .rubocop-https?--*
165
+ # .rubocop-https?--*
166
166
 
167
167
  ### Vim ###
168
168
  # Swap
@@ -189,4 +189,8 @@ tags
189
189
  # Coc configuration directory
190
190
  .vim
191
191
 
192
- # 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.3.0)
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.3.2)
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,67 +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.18.5)
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
- simplecov-html (0.12.2)
38
+ simplecov_json_formatter (~> 0.1)
39
+ simplecov-html (0.12.3)
40
+ simplecov_json_formatter (0.1.2)
114
41
  slop (3.6.0)
115
- terminal-table (3.0.2)
116
- unicode-display_width (>= 1.1.1, < 3)
117
- thor (1.2.1)
118
- timecop (0.9.1)
119
- unicode-display_width (2.1.0)
42
+ timecop (0.9.4)
120
43
 
121
44
  PLATFORMS
122
45
  ruby
123
46
 
124
47
  DEPENDENCIES
125
48
  eancom!
126
- pronto
127
- pronto-rubocop
128
49
  pry
129
50
  pry-nav
130
51
  pry-remote
131
- rake
132
- rspec
133
- rubocop
52
+ rake (~> 12.0)
53
+ rspec (~> 3.0)
134
54
  simplecov
135
55
  timecop
136
56
 
137
57
  BUNDLED WITH
138
- 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.
@@ -1,6 +1,6 @@
1
1
  Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
2
2
  document.header do |header|
3
- header.segment Eancom::Edifact::UNA.new()
3
+ header.segment Eancom::Edifact::UNA.new
4
4
 
5
5
  header.segment Eancom::Edifact::UNB.new(
6
6
  syntax_identifier: 'UNOC',
@@ -12,8 +12,8 @@ Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
12
12
  date: config.header.date,
13
13
  time: config.header.time,
14
14
  interchange_control_reference: config.header.interchange_control_reference,
15
- application_reference: 'DESADV0720',
16
- interchange_agreement_identifier: 'EANCOM76170270000007613067000000900',
15
+ application_reference: config.header.application_reference,
16
+ interchange_agreement_identifier: config.header.interchange_agreement_identifier,
17
17
  test_indicator: '0'
18
18
  )
19
19
 
@@ -28,113 +28,135 @@ Eancom::Definition.create(name: 'D01B', type: :desadv) do |document, config|
28
28
  end
29
29
 
30
30
  document.body do |body|
31
-
32
31
  # Messages
33
32
  messages = config.body.messages
34
33
 
35
- messages.each do |message|
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 reference_identifier = message.order_number.reference_identifier
61
- body.segment Eancom::Edifact::RFF.new(
62
- reference_code_qualifier: 'ON',
63
- reference_identifier: 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,61 +167,85 @@ 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
 
148
-
170
+ structure = Eancom.find_structure(tag: 'LIN')
149
171
  body.segment Eancom::Edifact::LIN.new(
150
- line_item_identifier_1: "#{index + 1}",
172
+ line_item_identifier_1: (index + 1).to_s,
151
173
  item_identifier: item.ean,
152
- item_type_identification_code: 'SRV'
174
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
153
175
  )
154
176
 
155
177
  if additional_product_id = item.additional_product_id
156
178
  additional_product_id.each do |id|
157
- if additional_information = id.additional_information
158
- body.segment Eancom::Edifact::PIA.new(
159
- product_identifier_code_qualifier: '1',
160
- item_identifier_1: additional_information.item_identifier_1,
161
- item_type_identification_code_1: 'IN'
162
- )
163
- 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
+ )
164
188
  end
165
189
  end
166
190
 
167
- body.segment Eancom::Edifact::IMD.new(
168
- description_format_code: 'C',
169
- item_description_code: 'CU',
170
- code_list_responsible_agency_code_1: '9'
171
- )
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
172
202
 
173
- body.segment Eancom::Edifact::QTY.new(
174
- quantity_type_code_qualifier: '12',
175
- quantity: "#{item.despatch_quantity.quantity}"
176
- )
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
177
223
 
178
- body.segment Eancom::Edifact::QTY.new(
179
- quantity_type_code_qualifier: '59',
180
- quantity: "#{item.despatch_quantity.quantity}"
181
- )
182
224
 
183
- if order_number = message.order_number
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
184
229
  body.segment Eancom::Edifact::RFF.new(
185
- reference_code_qualifier: 'ON',
186
- reference_identifier: order_number.reference_identifier,
187
- document_line_identifier: "#{(index + 1) * 10}"
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
188
233
  )
189
234
  end
190
235
  end
191
236
 
192
237
  body.segment Eancom::Edifact::UNT.new(
193
- number_of_segments_in_message: "#{document.total_segments + 2}",
194
- message_reference_number: '1'
238
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
239
+ message_reference_number: config.header.message_reference_number
195
240
  )
196
- end
241
+ end
197
242
  end
198
243
 
244
+ messages = config.body.messages
199
245
  document.footer do |footer|
200
246
  footer.segment Eancom::Edifact::UNZ.new(
201
- interchange_control_count: '1',
202
- interchange_control_reference: "#{config.header.interchange_control_reference}"
247
+ interchange_control_count: messages.size.to_s,
248
+ interchange_control_reference: config.header.interchange_control_reference.to_s
203
249
  )
204
250
  end
205
251
  end