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
@@ -0,0 +1,251 @@
1
+ Eancom::Definition.create(name: 'D01B', type: :ordrsp) 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: nil
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 = config.body.messages
32
+ messages.each do |message|
33
+
34
+ body.segment Eancom::Edifact::BGM.new(
35
+ document_name_code: message.document_name_code,
36
+ document_identifier: message.document_identifier,
37
+ message_function_code: message.message_function_code
38
+ )
39
+
40
+ date_time_messages = message.date_time_messages
41
+ date_time_messages.each_with_index do |dtm, index|
42
+ next unless index == 0
43
+ structure = Eancom.find_structure(tag: 'DTM')
44
+ key = dtm.identifier.intern.to_sym
45
+ body.segment Eancom::Edifact::DTM.new(
46
+ type: structure.dictionary_lookup(:type, dtm.identifier),
47
+ date_time: dtm[key].date_time,
48
+ format: '102'
49
+ )
50
+ end
51
+
52
+ date_time_messages.each_with_index do |dtm, index|
53
+ next unless index == 1
54
+ structure = Eancom.find_structure(tag: 'DTM')
55
+ key = dtm.identifier.intern.to_sym
56
+ body.segment Eancom::Edifact::DTM.new(
57
+ type: structure.dictionary_lookup(:type, dtm.identifier),
58
+ date_time: dtm[key].date_time,
59
+ format: '102'
60
+ )
61
+ end
62
+
63
+ date_time_messages.each_with_index do |dtm, index|
64
+ next unless index == 2
65
+ structure = Eancom.find_structure(tag: 'DTM')
66
+ key = dtm.identifier.intern.to_sym
67
+ body.segment Eancom::Edifact::DTM.new(
68
+ type: structure.dictionary_lookup(:type, dtm.identifier),
69
+ date_time: dtm[key].date_time,
70
+ format: '102'
71
+ )
72
+ end
73
+
74
+ free_texts = message.free_texts
75
+
76
+ free_texts.each do |free_text|
77
+ structure = Eancom.find_structure(tag: 'FTX')
78
+ body.segment Eancom::Edifact::FTX.new(
79
+ text_subject_code_qualifier: free_text.text_subject_code_qualifier,
80
+ free_text_function_code: structure.dictionary_lookup(:free_text_function_code,
81
+ free_text.free_text_function_code),
82
+ free_text_value_code: free_text.free_text_value_code,
83
+ code_list_identification_code: free_text.code_list_identification_code
84
+ )
85
+ end
86
+
87
+ references = message.references
88
+ references.each_with_index do |rff, index|
89
+ next unless index == 0
90
+ structure = Eancom.find_structure(tag: 'RFF')
91
+ key = rff.identifier.intern.to_sym
92
+ body.segment Eancom::Edifact::RFF.new(
93
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
94
+ reference_identifier: rff[key].reference_identifier
95
+ )
96
+ end
97
+
98
+ date_time_messages.each_with_index do |dtm, index|
99
+ next unless index == 3
100
+ structure = Eancom.find_structure(tag: 'DTM')
101
+ key = dtm.identifier.intern.to_sym
102
+ body.segment Eancom::Edifact::DTM.new(
103
+ type: structure.dictionary_lookup(:type, dtm.identifier),
104
+ date_time: dtm[key].date_time,
105
+ format: '102'
106
+ )
107
+ end
108
+
109
+ references.each_with_index do |rff, index|
110
+ next unless index == 1
111
+ structure = Eancom.find_structure(tag: 'RFF')
112
+ key = rff.identifier.intern.to_sym
113
+ body.segment Eancom::Edifact::RFF.new(
114
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
115
+ reference_identifier: rff[key].reference_identifier
116
+ )
117
+ end
118
+
119
+ date_time_messages.each_with_index do |dtm, index|
120
+ next unless index == 4
121
+ structure = Eancom.find_structure(tag: 'DTM')
122
+ key = dtm.identifier.intern.to_sym
123
+ body.segment Eancom::Edifact::DTM.new(
124
+ type: structure.dictionary_lookup(:type, dtm.identifier),
125
+ date_time: dtm[key].date_time,
126
+ format: '102'
127
+ )
128
+ end
129
+
130
+ nads = message.nads
131
+ nads.each_with_index do |nad, index|
132
+ next unless index == 0
133
+ structure = Eancom.find_structure(tag: 'NAD')
134
+ key = nad.identifier.intern.to_sym
135
+ body.segment Eancom::Edifact::NAD.new(
136
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
137
+ party_identifier: nad[key].party_identifier,
138
+ code_list_responsible_agency_code_1: '9'
139
+ )
140
+ end
141
+
142
+ nads.each_with_index do |nad, index|
143
+ next unless index == 1
144
+ structure = Eancom.find_structure(tag: 'NAD')
145
+ key = nad.identifier.intern.to_sym
146
+ body.segment Eancom::Edifact::NAD.new(
147
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
148
+ party_identifier: nad[key].party_identifier,
149
+ code_list_responsible_agency_code_1: '9'
150
+ )
151
+ end
152
+
153
+ nads.each_with_index do |nad, index|
154
+ next unless index == 2
155
+ structure = Eancom.find_structure(tag: 'NAD')
156
+ key = nad.identifier.intern.to_sym
157
+ body.segment Eancom::Edifact::NAD.new(
158
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
159
+ party_identifier: nad[key].party_identifier,
160
+ code_list_responsible_agency_code_1: '9'
161
+ )
162
+ end
163
+
164
+ nads.each_with_index do |nad, index|
165
+ next unless index == 3
166
+ structure = Eancom.find_structure(tag: 'NAD')
167
+ key = nad.identifier.intern.to_sym
168
+ body.segment Eancom::Edifact::NAD.new(
169
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
170
+ party_identifier: nad[key].party_identifier,
171
+ code_list_responsible_agency_code_1: '9'
172
+ )
173
+ end
174
+
175
+ total_quantity = 0
176
+
177
+ items = message.items
178
+
179
+ items.each_with_index do |item, index|
180
+ total_quantity += item.quantity.to_i
181
+
182
+ structure = Eancom.find_structure(tag: 'LIN')
183
+ body.segment Eancom::Edifact::LIN.new(
184
+ line_item_identifier_1: (index + 1).to_s,
185
+ item_identifier: item.ean,
186
+ action_request_notification_description_code: item.action_request_notification_description_code,
187
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
188
+ )
189
+ qty = item.quantities
190
+ qty.each_with_index do |qty, index|
191
+ structure = Eancom.find_structure(tag: 'QTY')
192
+ key = qty.identifier.intern.to_sym
193
+ body.segment Eancom::Edifact::QTY.new(
194
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
195
+ quantity: qty[key].quantity
196
+ )
197
+ end
198
+ end
199
+ end
200
+ end
201
+
202
+ document.footer do |footer|
203
+ footer.segment Eancom::Edifact::UNS.new(
204
+ section_identification: 'S'
205
+ )
206
+
207
+ messages = config.body.messages
208
+
209
+ messages.each do |message|
210
+ items = message.items
211
+ control_total_value = 0
212
+
213
+ items.each_with_index do |item, index|
214
+ quantities = item.quantities
215
+ quantities.each do |qty|
216
+ key = qty.identifier.intern.to_sym
217
+ control_total_value += qty[key].quantity.to_i
218
+ end
219
+
220
+ next unless index == items.size - 1
221
+
222
+ counts = item.counts
223
+ counts.each_with_index do |cnt, index|
224
+ next unless index == 0
225
+ structure = Eancom.find_structure(tag: 'CNT')
226
+ footer.segment Eancom::Edifact::CNT.new(
227
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier, cnt.control_total_type_code_quantifier),
228
+ control_total_value: (control_total_value - 1).to_s
229
+ )
230
+ end
231
+
232
+ counts.each_with_index do |cnt, index|
233
+ next unless index == 1
234
+ structure = Eancom.find_structure(tag: 'CNT')
235
+ footer.segment Eancom::Edifact::CNT.new(
236
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier, cnt.control_total_type_code_quantifier),
237
+ control_total_value: (control_total_value).to_s
238
+ )
239
+ end
240
+ end
241
+ end
242
+ footer.segment Eancom::Edifact::UNT.new(
243
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
244
+ message_reference_number: config.header.message_reference_number
245
+ )
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
@@ -0,0 +1,226 @@
1
+ Eancom::Definition.create(name: 'D96A', type: :ordrsp) 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: nil
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 = config.body.messages
32
+
33
+ messages.each do |message|
34
+ structure = Eancom.find_structure(tag: 'BGM')
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
+ structure = Eancom.find_structure(tag: 'DTM')
45
+ key = dtm.identifier.intern.to_sym
46
+ body.segment Eancom::Edifact::DTM.new(
47
+ type: structure.dictionary_lookup(:type, dtm.identifier),
48
+ date_time: dtm[key].date_time,
49
+ format: '102'
50
+ )
51
+ end
52
+
53
+ references = message.references
54
+ references.each_with_index do |rff, index|
55
+ next unless index == 0
56
+ structure = Eancom.find_structure(tag: 'RFF')
57
+ key = rff.identifier.intern.to_sym
58
+ body.segment Eancom::Edifact::RFF.new(
59
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
60
+ reference_identifier: rff[key].reference_identifier
61
+ )
62
+ end
63
+
64
+ date_time_messages.each_with_index do |dtm, index|
65
+ next unless index == 1
66
+ structure = Eancom.find_structure(tag: 'DTM')
67
+ key = dtm.identifier.intern.to_sym
68
+ body.segment Eancom::Edifact::DTM.new(
69
+ type: structure.dictionary_lookup(:type, dtm.identifier),
70
+ date_time: dtm[key].date_time,
71
+ format: '102'
72
+ )
73
+ end
74
+
75
+ nads = message.nads
76
+ nads.each_with_index do |nad, index|
77
+ next unless index == 0
78
+ structure = Eancom.find_structure(tag: 'NAD')
79
+ key = nad.identifier.intern.to_sym
80
+ body.segment Eancom::Edifact::NAD.new(
81
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
82
+ party_identifier: nad[key].party_identifier,
83
+ code_list_responsible_agency_code_1: '9'
84
+ )
85
+ end
86
+
87
+ structure = Eancom.find_structure(tag: 'CTA')
88
+ body.segment Eancom::Edifact::CTA.new(
89
+ contact_function_code: structure.dictionary_lookup(:contact_function_code, message.contact_function_code)
90
+ )
91
+
92
+ nads.each_with_index do |nad, index|
93
+ next unless index == 1
94
+ structure = Eancom.find_structure(tag: 'NAD')
95
+ key = nad.identifier.intern.to_sym
96
+ body.segment Eancom::Edifact::NAD.new(
97
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
98
+ party_identifier: nad[key].party_identifier,
99
+ code_list_responsible_agency_code_1: '9'
100
+ )
101
+ end
102
+
103
+ nads.each_with_index do |nad, index|
104
+ next unless index == 2
105
+ structure = Eancom.find_structure(tag: 'NAD')
106
+ key = nad.identifier.intern.to_sym
107
+ body.segment Eancom::Edifact::NAD.new(
108
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
109
+ party_identifier: nad[key].party_identifier,
110
+ code_list_responsible_agency_code_1: '9'
111
+ )
112
+ end
113
+
114
+ structure = Eancom.find_structure(tag: 'CTA')
115
+ body.segment Eancom::Edifact::CTA.new(
116
+ contact_function_code: structure.dictionary_lookup(:contact_function_code, message.contact_function_code)
117
+ )
118
+
119
+ structure = Eancom.find_structure(tag: 'CUX')
120
+ body.segment Eancom::Edifact::CUX.new(
121
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, message.currency.currency_usage_code_qualifier_1),
122
+ currency_identification_code_1: message.currency.currency_identification_code_1
123
+ )
124
+
125
+ total_quantity = 0
126
+
127
+ items = message.items
128
+
129
+ items.each_with_index do |item, index|
130
+ total_quantity += item.quantity.to_i
131
+
132
+ structure = Eancom.find_structure(tag: 'LIN')
133
+ body.segment Eancom::Edifact::LIN.new(
134
+ line_item_identifier_1: (index + 1).to_s,
135
+ item_identifier: item.ean,
136
+ action_request_notification_description_code: item.action_request_notification_description_code,
137
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
138
+ )
139
+
140
+ qty = item.quantities
141
+ qty.each_with_index do |qty, index|
142
+ next unless index == 0
143
+ structure = Eancom.find_structure(tag: 'QTY')
144
+ key = qty.identifier.intern.to_sym
145
+ body.segment Eancom::Edifact::QTY.new(
146
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
147
+ quantity: qty[key].quantity,
148
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
149
+ )
150
+ end
151
+
152
+ qty.each_with_index do |qty, index|
153
+ next unless index == 1
154
+ structure = Eancom.find_structure(tag: 'QTY')
155
+ key = qty.identifier.intern.to_sym
156
+ body.segment Eancom::Edifact::QTY.new(
157
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
158
+ quantity: qty[key].quantity,
159
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
160
+ )
161
+ end
162
+
163
+ date_time_messages = item.date_time_messages
164
+ date_time_messages.each_with_index do |dtm, index|
165
+ structure = Eancom.find_structure(tag: 'DTM')
166
+ key = dtm.identifier.intern.to_sym
167
+ body.segment Eancom::Edifact::DTM.new(
168
+ type: structure.dictionary_lookup(:type, dtm.identifier),
169
+ date_time: dtm[key].date_time,
170
+ format: '102'
171
+ )
172
+ end
173
+
174
+ prices = item.prices
175
+ prices.each do |price|
176
+ next unless price = price.price
177
+
178
+ structure = Eancom.find_structure(tag: 'PRI')
179
+ body.segment Eancom::Edifact::PRI.new(
180
+ price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier,
181
+ price.price_code_qualifier),
182
+ price_amount: price.price_amount,
183
+ price_type_code: structure.dictionary_lookup(:price_type_code, price.price_type_code),
184
+ price_specification_code: structure.dictionary_lookup(:price_specification_code,
185
+ price.price_specification_code)
186
+ )
187
+ end
188
+
189
+ structure = Eancom.find_structure(tag: 'CUX')
190
+ body.segment Eancom::Edifact::CUX.new(
191
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, message.currency.currency_usage_code_qualifier_1),
192
+ currency_identification_code_1: message.currency.currency_identification_code_1,
193
+ currency_type_code_qualifier_1: message.currency.currency_type_code_qualifier_1
194
+ )
195
+
196
+ references = item.references
197
+ references.each_with_index do |rff, index|
198
+ next unless index == 0
199
+ structure = Eancom.find_structure(tag: 'RFF')
200
+ key = rff.identifier.intern.to_sym
201
+ body.segment Eancom::Edifact::RFF.new(
202
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
203
+ reference_identifier: rff[key].reference_identifier,
204
+ document_line_identifier: rff[key].document_line_identifier
205
+ )
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ document.footer do |footer|
212
+ messages = config.body.messages
213
+
214
+ footer.segment Eancom::Edifact::UNS.new(
215
+ section_identification: 'S'
216
+ )
217
+ footer.segment Eancom::Edifact::UNT.new(
218
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
219
+ message_reference_number: config.header.message_reference_number
220
+ )
221
+ footer.segment Eancom::Edifact::UNZ.new(
222
+ interchange_control_count: messages.size.to_s,
223
+ interchange_control_reference: config.header.interchange_control_reference.to_s
224
+ )
225
+ end
226
+ end