eancom 1.6.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,559 @@
1
+ Eancom::Definition.create(name: 'D01B', type: :invoic) 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
+ body.segment Eancom::Edifact::BGM.new(
34
+ document_name_code: message.document_name_code,
35
+ document_identifier: message.document_identifier,
36
+ message_function_code: message.message_function_code
37
+ )
38
+
39
+ date_time_messages = message.date_time_messages
40
+ date_time_messages.each_with_index do |dtm, index|
41
+ next unless index == 0
42
+
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
+
55
+ structure = Eancom.find_structure(tag: 'DTM')
56
+ key = dtm.identifier.intern.to_sym
57
+ body.segment Eancom::Edifact::DTM.new(
58
+ type: structure.dictionary_lookup(:type, dtm.identifier),
59
+ date_time: dtm[key].date_time,
60
+ format: '102'
61
+ )
62
+ end
63
+
64
+ free_texts = message.free_texts
65
+
66
+ free_texts.each do |free_text|
67
+ free_text_function_code = if free_text.free_text_function_code.nil?
68
+ ''
69
+ else
70
+ free_text.free_text_function_code
71
+ end
72
+ free_text_value_code = if free_text.free_text_value_code.nil?
73
+ ''
74
+ else
75
+ free_text.free_text_value_code
76
+ end
77
+ code_list_identification_code = if free_text.code_list_identification_code.nil?
78
+ ''
79
+ else
80
+ free_text.code_list_identification_code
81
+ end
82
+ structure = Eancom.find_structure(tag: 'FTX')
83
+ body.segment Eancom::Edifact::FTX.new(
84
+ text_subject_code_qualifier: free_text.text_subject_code_qualifier,
85
+ free_text_function_code: free_text_function_code,
86
+ free_text_value_code: free_text_value_code,
87
+ code_list_identification_code: code_list_identification_code,
88
+ free_text_value_1: free_text.free_text_value_1
89
+ )
90
+ end
91
+
92
+ references = message.references
93
+ references.each_with_index do |rff, index|
94
+ next unless index == 0
95
+
96
+ structure = Eancom.find_structure(tag: 'RFF')
97
+ key = rff.identifier.intern.to_sym
98
+ body.segment Eancom::Edifact::RFF.new(
99
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
100
+ reference_identifier: rff[key].reference_identifier
101
+ )
102
+ end
103
+
104
+ date_time_messages.each_with_index do |dtm, index|
105
+ next unless index == 2
106
+
107
+ structure = Eancom.find_structure(tag: 'DTM')
108
+ key = dtm.identifier.intern.to_sym
109
+ body.segment Eancom::Edifact::DTM.new(
110
+ type: structure.dictionary_lookup(:type, dtm.identifier),
111
+ date_time: dtm[key].date_time,
112
+ format: '102'
113
+ )
114
+ end
115
+
116
+ references.each_with_index do |rff, index|
117
+ next unless index == 1
118
+
119
+ structure = Eancom.find_structure(tag: 'RFF')
120
+ key = rff.identifier.intern.to_sym
121
+ body.segment Eancom::Edifact::RFF.new(
122
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
123
+ reference_identifier: rff[key].reference_identifier
124
+ )
125
+ end
126
+
127
+ date_time_messages.each_with_index do |dtm, index|
128
+ next unless index == 3
129
+
130
+ structure = Eancom.find_structure(tag: 'DTM')
131
+ key = dtm.identifier.intern.to_sym
132
+ body.segment Eancom::Edifact::DTM.new(
133
+ type: structure.dictionary_lookup(:type, dtm.identifier),
134
+ date_time: dtm[key].date_time,
135
+ format: '102'
136
+ )
137
+ end
138
+
139
+ references.each_with_index do |rff, index|
140
+ next unless index == 2
141
+
142
+ structure = Eancom.find_structure(tag: 'RFF')
143
+ key = rff.identifier.intern.to_sym
144
+ body.segment Eancom::Edifact::RFF.new(
145
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
146
+ reference_identifier: rff[key].reference_identifier
147
+ )
148
+ end
149
+
150
+ date_time_messages.each_with_index do |dtm, index|
151
+ next unless index == 4
152
+
153
+ structure = Eancom.find_structure(tag: 'DTM')
154
+ key = dtm.identifier.intern.to_sym
155
+ body.segment Eancom::Edifact::DTM.new(
156
+ type: structure.dictionary_lookup(:type, dtm.identifier),
157
+ date_time: dtm[key].date_time,
158
+ format: '102'
159
+ )
160
+ end
161
+
162
+ nads = message.nads
163
+ nads.each_with_index do |nad, index|
164
+ next unless index == 0
165
+
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
+ name_and_address_description_1: nad[key].name_and_address_description_1
173
+ )
174
+ end
175
+
176
+ nads.each_with_index do |nad, index|
177
+ next unless index == 1
178
+
179
+ structure = Eancom.find_structure(tag: 'NAD')
180
+ key = nad.identifier.intern.to_sym
181
+ body.segment Eancom::Edifact::NAD.new(
182
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
183
+ party_identifier: nad[key].party_identifier,
184
+ code_list_responsible_agency_code_1: '9',
185
+ name_and_address_description_1: nad[key].name_and_address_description_1
186
+ )
187
+ end
188
+
189
+ references.each_with_index do |rff, index|
190
+ next unless index == 3
191
+
192
+ structure = Eancom.find_structure(tag: 'RFF')
193
+ key = rff.identifier.intern.to_sym
194
+ body.segment Eancom::Edifact::RFF.new(
195
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
196
+ reference_identifier: rff[key].reference_identifier
197
+ )
198
+ end
199
+
200
+ references.each_with_index do |rff, index|
201
+ next unless index == 4
202
+
203
+ structure = Eancom.find_structure(tag: 'RFF')
204
+ key = rff.identifier.intern.to_sym
205
+ body.segment Eancom::Edifact::RFF.new(
206
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
207
+ reference_identifier: rff[key].reference_identifier
208
+ )
209
+ end
210
+
211
+ nads.each_with_index do |nad, index|
212
+ next unless index == 2
213
+
214
+ structure = Eancom.find_structure(tag: 'NAD')
215
+ key = nad.identifier.intern.to_sym
216
+ body.segment Eancom::Edifact::NAD.new(
217
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
218
+ party_identifier: nad[key].party_identifier,
219
+ code_list_responsible_agency_code_1: '9',
220
+ name_and_address_description_1: nad[key].name_and_address_description_1
221
+ )
222
+ end
223
+
224
+ nads.each_with_index do |nad, index|
225
+ next unless index == 3
226
+
227
+ structure = Eancom.find_structure(tag: 'NAD')
228
+ key = nad.identifier.intern.to_sym
229
+ body.segment Eancom::Edifact::NAD.new(
230
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
231
+ party_identifier: nad[key].party_identifier,
232
+ code_list_responsible_agency_code_1: '9',
233
+ name_and_address_description_1: nad[key].name_and_address_description_1
234
+ )
235
+ end
236
+
237
+ if taxes = message.taxes
238
+ taxes.each do |tax|
239
+ next unless tax = tax.tax
240
+
241
+ structure = Eancom.find_structure(tag: 'TAX')
242
+ body.segment Eancom::Edifact::TAX.new(
243
+ duty_or_tax_or_fee_function_code_qualifier: structure.dictionary_lookup(
244
+ :duty_or_tax_or_fee_function_code_qualifier, tax.duty_or_tax_or_fee_function_code_qualifier
245
+ ),
246
+ duty_or_tax_or_fee_name_code: structure.dictionary_lookup(:duty_or_tax_or_fee_name_code,
247
+ tax.duty_or_tax_or_fee_name_code),
248
+ duty_or_tax_or_fee_account_code: tax.duty_or_tax_or_fee_account_code,
249
+ duty_tax_fee_rate_code: tax.duty_tax_fee_rate_code,
250
+ code_list_identification_code_3: tax.code_list_identification_code_3,
251
+ code_list_responsibility_agency_code_3: tax.code_list_responsibility_agency_code_3,
252
+ code_list_responsibility_agency_code_4: '9',
253
+ duty_or_tax_or_fee_category_code: 'S'
254
+ )
255
+ end
256
+ end
257
+
258
+ structure = Eancom.find_structure(tag: 'CUX')
259
+ body.segment Eancom::Edifact::CUX.new(
260
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1,
261
+ message.currency.currency_usage_code_qualifier_1),
262
+ currency_identification_code_1: message.currency.currency_identification_code_1,
263
+ currency_type_code_qualifier_1: structure.dictionary_lookup(:currency_type_code_qualifier_1,
264
+ message.currency.currency_type_code_qualifier_1)
265
+ )
266
+ if allowances_or_charges = message.allowances_or_charges
267
+
268
+ allowances_or_charges.each do |allowance_or_charge|
269
+ allowance_or_charge_identifier = if allowance_or_charge.allowance_or_charge_identifier.nil?
270
+ ''
271
+ else
272
+ allowance_or_charge.allowance_or_charge
273
+ end
274
+ allowance_or_charge_identification_code = if allowance_or_charge.allowance_or_charge_identification_code.nil?
275
+ ''
276
+ else
277
+ allowance_or_charge.allowance_or_charge_identification_code
278
+ end
279
+ settlement_mean_code = if allowance_or_charge.settlement_mean_code.nil?
280
+ ''
281
+ else
282
+ allowance_or_charge.settlement_mean_code
283
+ end
284
+ structure = Eancom.find_structure(tag: 'ALC')
285
+ body.segment Eancom::Edifact::ALC.new(
286
+ allowance_or_charge_code_qualifier: structure.dictionary_lookup(:allowance_or_charge_code_qualifier,
287
+ allowance_or_charge.allowance_or_charge_code_qualifier),
288
+ allowance_or_charge_identifier: allowance_or_charge_identifier,
289
+ allowance_or_charge_identification_code: allowance_or_charge_identification_code,
290
+ settlement_mean_code: settlement_mean_code,
291
+ special_service_description_code: structure.dictionary_lookup(:special_service_description_code,
292
+ allowance_or_charge.special_service_description_code)
293
+ )
294
+ end
295
+ end
296
+
297
+ monetary_amounts = message.monetary_amounts
298
+ monetary_amounts.each do |amount|
299
+ monetary_amount = if amount.monetary_amount.nil?
300
+ ''
301
+ else
302
+ amount.monetary_amount
303
+ end
304
+ structure = Eancom.find_structure(tag: 'MOA')
305
+ body.segment Eancom::Edifact::MOA.new(
306
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier,
307
+ amount.monetary_amount_type_code_qualifier),
308
+ monetary_amount: monetary_amount
309
+ )
310
+ end
311
+
312
+ items = message.items
313
+
314
+ items.each_with_index do |item, index|
315
+ structure = Eancom.find_structure(tag: 'LIN')
316
+ body.segment Eancom::Edifact::LIN.new(
317
+ line_item_identifier_1: (index + 1).to_s,
318
+ item_identifier: item.ean,
319
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code,
320
+ item.item_type_identification_code)
321
+ )
322
+ if additional_product_id = item.additional_product_id
323
+ additional_product_id.each do |id|
324
+ next unless additional_information = id.additional_information
325
+
326
+ structure = Eancom.find_structure(tag: 'PIA')
327
+ body.segment Eancom::Edifact::PIA.new(
328
+ product_identifier_code_qualifier: structure.dictionary_lookup(:product_identifier_code_qualifier,
329
+ additional_information.product_identifier_code_qualifier),
330
+ item_identifier_1: additional_information.item_identifier_1,
331
+ item_type_identification_code_1: structure.dictionary_lookup(:item_type_identification_code_1,
332
+ additional_information.item_type_identification_code_1)
333
+ )
334
+ end
335
+ end
336
+
337
+ if item_descriptions = item.item_descriptions
338
+ item_descriptions.each do |description|
339
+ structure = Eancom.find_structure(tag: 'IMD')
340
+ body.segment Eancom::Edifact::IMD.new(
341
+ description_format_code: structure.dictionary_lookup(:description_format_code,
342
+ description.description_format_code),
343
+ item_characteristic_code: structure.dictionary_lookup(:item_characteristic_code,
344
+ description.item_characteristic_code),
345
+ item_description_code: description.item_description_code,
346
+ code_list_identification_code_1: description.item_description_code,
347
+ code_list_responsible_agency_code_1: description.item_description_code,
348
+ item_description_1: description.item_description_1
349
+ )
350
+ end
351
+ end
352
+
353
+ quantities = item.quantities
354
+ quantities.each_with_index do |qty, index|
355
+ structure = Eancom.find_structure(tag: 'QTY')
356
+ key = qty.identifier.intern.to_sym
357
+ body.segment Eancom::Edifact::QTY.new(
358
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
359
+ quantity: qty[key].quantity,
360
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
361
+ )
362
+ end
363
+
364
+ monetary_amounts = item.monetary_amounts
365
+
366
+ monetary_amounts.each_with_index do |amount, index|
367
+ if index == 0
368
+ monetary_amount = if amount.monetary_amount.nil?
369
+ ''
370
+ else
371
+ amount.monetary_amount
372
+ end
373
+ structure = Eancom.find_structure(tag: 'MOA')
374
+ body.segment Eancom::Edifact::MOA.new(
375
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier,
376
+ amount.monetary_amount_type_code_qualifier),
377
+ monetary_amount: monetary_amount
378
+ )
379
+ else
380
+ next
381
+ end
382
+ end
383
+
384
+ prices = item.prices
385
+ prices.each do |price|
386
+ next unless price = price.price
387
+
388
+ structure = Eancom.find_structure(tag: 'PRI')
389
+ body.segment Eancom::Edifact::PRI.new(
390
+ price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
391
+ price_amount: price.price_amount,
392
+ price_type_code: structure.dictionary_lookup(:price_type_code, price.price_type_code),
393
+ price_specification_code: structure.dictionary_lookup(:price_specification_code,
394
+ price.price_specification_code)
395
+ )
396
+ end
397
+
398
+ references = item.references
399
+ references.each_with_index do |rff, index|
400
+ structure = Eancom.find_structure(tag: 'RFF')
401
+ key = rff.identifier.intern.to_sym
402
+ body.segment Eancom::Edifact::RFF.new(
403
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
404
+ reference_identifier: rff[key].reference_identifier
405
+ )
406
+ end
407
+
408
+ date_time_messages = item.date_time_messages
409
+ date_time_messages.each_with_index do |dtm, index|
410
+ key = dtm.identifier.intern.to_sym
411
+ structure = Eancom.find_structure(tag: 'DTM')
412
+ body.segment Eancom::Edifact::DTM.new(
413
+ type: structure.dictionary_lookup(:type, dtm.identifier),
414
+ date_time: dtm[key].date_time,
415
+ format: '102'
416
+ )
417
+ end
418
+ end
419
+ end
420
+
421
+ document.footer do |footer|
422
+ footer.segment Eancom::Edifact::UNS.new(
423
+ section_identification: 'S'
424
+ )
425
+ messages = config.body.messages
426
+
427
+ messages.each do |message|
428
+ items = message.items
429
+ control_total_value = 0
430
+
431
+ items.each_with_index do |item, index|
432
+ quantities = item.quantities
433
+ quantities.each do |qty|
434
+ key = qty.identifier.intern.to_sym
435
+ control_total_value += qty[key].quantity.to_i
436
+ end
437
+ next unless index == items.size - 1
438
+
439
+ counts = item.counts
440
+ counts.each_with_index do |cnt, index|
441
+ structure = Eancom.find_structure(tag: 'CNT')
442
+ footer.segment Eancom::Edifact::CNT.new(
443
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier,
444
+ cnt.control_total_type_code_quantifier),
445
+ control_total_value: (control_total_value - 1).to_s
446
+ )
447
+ end
448
+ end
449
+
450
+ items = message.items
451
+ items.each do |item|
452
+ monetary_amounts = item.monetary_amounts
453
+
454
+ monetary_amount = 0
455
+ monetary_amounts.each_with_index do |amount, index|
456
+ next unless index >= items.size - 4 && index <= items.size - 2
457
+
458
+ monetary_amount = if amount.monetary_amount.nil?
459
+ ''
460
+ else
461
+ amount.monetary_amount
462
+ end
463
+ structure = Eancom.find_structure(tag: 'MOA')
464
+ footer.segment Eancom::Edifact::MOA.new(
465
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier,
466
+ amount.monetary_amount_type_code_qualifier),
467
+ monetary_amount: monetary_amount
468
+ )
469
+ end
470
+ end
471
+
472
+ if taxes = message.taxes
473
+ taxes.each do |tax|
474
+ next unless tax = tax.tax
475
+
476
+ structure = Eancom.find_structure(tag: 'TAX')
477
+ footer.segment Eancom::Edifact::TAX.new(
478
+ duty_or_tax_or_fee_function_code_qualifier: '7',
479
+ duty_or_tax_or_fee_name_code: structure.dictionary_lookup(:duty_or_tax_or_fee_name_code,
480
+ tax.duty_or_tax_or_fee_name_code),
481
+ duty_or_tax_or_fee_account_code: tax.duty_or_tax_or_fee_account_code,
482
+ duty_tax_fee_rate_code: tax.duty_tax_fee_rate_code,
483
+ code_list_identification_code_3: tax.code_list_identification_code_3,
484
+ code_list_responsibility_agency_code_3: tax.code_list_responsibility_agency_code_3,
485
+ code_list_responsibility_agency_code_4: '9',
486
+ duty_or_tax_or_fee_category_code: 'S'
487
+ )
488
+ end
489
+ end
490
+
491
+ items.each do |item|
492
+ monetary_amounts = item.monetary_amounts
493
+
494
+ monetary_amount = 0
495
+ monetary_amounts.each_with_index do |amount, index|
496
+ next unless index == items.size - 1
497
+
498
+ monetary_amount = if amount.monetary_amount.nil?
499
+ ''
500
+ else
501
+ amount.monetary_amount
502
+ end
503
+ structure = Eancom.find_structure(tag: 'MOA')
504
+ footer.segment Eancom::Edifact::MOA.new(
505
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier,
506
+ amount.monetary_amount_type_code_qualifier),
507
+ monetary_amount: monetary_amount
508
+ )
509
+ end
510
+ end
511
+ next unless allowances_or_charges = message.allowances_or_charges
512
+
513
+ allowances_or_charges.each do |allowance_or_charge|
514
+ allowance_or_charge_identifier = if allowance_or_charge.allowance_or_charge_identifier.nil?
515
+ ''
516
+ else
517
+ allowance_or_charge.allowance_or_charge_identifier
518
+ end
519
+ structure = Eancom.find_structure(tag: 'ALC')
520
+ footer.segment Eancom::Edifact::ALC.new(
521
+ allowance_or_charge_code_qualifier: structure.dictionary_lookup(:allowance_or_charge_code_qualifier,
522
+ allowance_or_charge.allowance_or_charge_code_qualifier),
523
+ allowance_or_charge_identifier: allowance_or_charge_identifier,
524
+ allowance_or_charge_identification_code: '64'
525
+ )
526
+ end
527
+
528
+ items.each do |item|
529
+ monetary_amounts = item.monetary_amounts
530
+
531
+ monetary_amount = 0
532
+ monetary_amounts.each_with_index do |amount, index|
533
+ next unless index == items.size
534
+
535
+ monetary_amount = if amount.monetary_amount.nil?
536
+ ''
537
+ else
538
+ amount.monetary_amount
539
+ end
540
+ structure = Eancom.find_structure(tag: 'MOA')
541
+ footer.segment Eancom::Edifact::MOA.new(
542
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier,
543
+ amount.monetary_amount_type_code_qualifier),
544
+ monetary_amount: monetary_amount
545
+ )
546
+ end
547
+ end
548
+ end
549
+ footer.segment Eancom::Edifact::UNT.new(
550
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
551
+ message_reference_number: config.header.message_reference_number
552
+ )
553
+ footer.segment Eancom::Edifact::UNZ.new(
554
+ interchange_control_count: messages.size.to_s,
555
+ interchange_control_reference: config.header.interchange_control_reference
556
+ )
557
+ end
558
+ end
559
+ end