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,389 @@
1
+ Eancom::Definition.create(name: 'D96A', 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
+ structure = Eancom.find_structure(tag: 'DTM')
43
+ key = dtm.identifier.intern.to_sym
44
+ body.segment Eancom::Edifact::DTM.new(
45
+ type: structure.dictionary_lookup(:type, dtm.identifier),
46
+ date_time: dtm[key].date_time,
47
+ format: '102'
48
+ )
49
+ end
50
+
51
+ date_time_messages.each_with_index do |dtm, index|
52
+ next unless index == 1
53
+ structure = Eancom.find_structure(tag: 'DTM')
54
+ key = dtm.identifier.intern.to_sym
55
+ body.segment Eancom::Edifact::DTM.new(
56
+ type: structure.dictionary_lookup(:type, dtm.identifier),
57
+ date_time: dtm[key].date_time,
58
+ format: '102'
59
+ )
60
+ end
61
+
62
+ date_time_messages.each_with_index do |dtm, index|
63
+ next unless index == 2
64
+ structure = Eancom.find_structure(tag: 'DTM')
65
+ key = dtm.identifier.intern.to_sym
66
+ body.segment Eancom::Edifact::DTM.new(
67
+ type: structure.dictionary_lookup(:type, dtm.identifier),
68
+ date_time: dtm[key].date_time,
69
+ format: '102'
70
+ )
71
+ end
72
+
73
+ references = message.references
74
+ references.each_with_index do |rff, index|
75
+ next unless index == 0
76
+ structure = Eancom.find_structure(tag: 'RFF')
77
+ key = rff.identifier.intern.to_sym
78
+ body.segment Eancom::Edifact::RFF.new(
79
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
80
+ reference_identifier: rff[key].reference_identifier
81
+ )
82
+ end
83
+
84
+ references.each_with_index do |rff, index|
85
+ next unless index == 1
86
+ structure = Eancom.find_structure(tag: 'RFF')
87
+ key = rff.identifier.intern.to_sym
88
+ body.segment Eancom::Edifact::RFF.new(
89
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
90
+ reference_identifier: rff[key].reference_identifier
91
+ )
92
+ end
93
+
94
+ references.each_with_index do |rff, index|
95
+ next unless index == 2
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
+ structure = Eancom.find_structure(tag: 'NAD')
105
+ nads = message.nads
106
+ nads.each_with_index do |nad, index|
107
+ next unless index == 0
108
+ key = nad.identifier.intern.to_sym
109
+ body.segment Eancom::Edifact::NAD.new(
110
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
111
+ party_identifier: nad[key].party_identifier,
112
+ code_list_responsible_agency_code_1: '9',
113
+ name_and_address_description_1: nad[key].name_and_address_description_1
114
+ )
115
+ end
116
+
117
+ references.each_with_index do |rff, index|
118
+ next unless index == 3
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
+ nads = message.nads
128
+ nads.each_with_index do |nad, index|
129
+ next unless index == 1
130
+ structure = Eancom.find_structure(tag: 'NAD')
131
+ key = nad.identifier.intern.to_sym
132
+ body.segment Eancom::Edifact::NAD.new(
133
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
134
+ party_identifier: nad[key].party_identifier,
135
+ code_list_responsible_agency_code_1: '9',
136
+ name_and_address_description_1: nad[key].name_and_address_description_1
137
+ )
138
+ end
139
+
140
+ nads = message.nads
141
+ nads.each_with_index do |nad, index|
142
+ next unless index == 2
143
+ structure = Eancom.find_structure(tag: 'NAD')
144
+ key = nad.identifier.intern.to_sym
145
+ body.segment Eancom::Edifact::NAD.new(
146
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
147
+ party_identifier: nad[key].party_identifier,
148
+ code_list_responsible_agency_code_1: '9',
149
+ name_and_address_description_1: nad[key].name_and_address_description_1
150
+ )
151
+ end
152
+
153
+ nads = message.nads
154
+ nads.each_with_index do |nad, index|
155
+ next unless index == 3
156
+ structure = Eancom.find_structure(tag: 'NAD')
157
+ key = nad.identifier.intern.to_sym
158
+ body.segment Eancom::Edifact::NAD.new(
159
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
160
+ party_identifier: nad[key].party_identifier,
161
+ code_list_responsible_agency_code_1: '9',
162
+ name_and_address_description_1: nad[key].name_and_address_description_1
163
+ )
164
+ end
165
+
166
+ references = message.references
167
+ references.each_with_index do |rff, index|
168
+ next unless index == 4
169
+
170
+ structure = Eancom.find_structure(tag: 'RFF')
171
+ key = rff.identifier.intern.to_sym
172
+ body.segment Eancom::Edifact::RFF.new(
173
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
174
+ reference_identifier: rff[key].reference_identifier
175
+ )
176
+ end
177
+
178
+ nads = message.nads
179
+ nads.each_with_index do |nad, index|
180
+ next unless index == 4
181
+ structure = Eancom.find_structure(tag: 'NAD')
182
+ key = nad.identifier.intern.to_sym
183
+ body.segment Eancom::Edifact::NAD.new(
184
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
185
+ party_identifier: nad[key].party_identifier,
186
+ code_list_responsible_agency_code_1: '9',
187
+ name_and_address_description_1: nad[key].name_and_address_description_1
188
+ )
189
+ end
190
+
191
+ structure = Eancom.find_structure(tag: 'CUX')
192
+ body.segment Eancom::Edifact::CUX.new(
193
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, message.currency.currency_usage_code_qualifier_1),
194
+ currency_identification_code_1: message.currency.currency_identification_code_1,
195
+ currency_type_code_qualifier_1: structure.dictionary_lookup(:currency_type_code_qualifier_1,
196
+ message.currency.currency_type_code_qualifier_1)
197
+ )
198
+
199
+ structure = Eancom.find_structure(tag: 'PAT')
200
+ body.segment Eancom::Edifact::PAT.new(
201
+ payment_terms_type_code_qualifier: structure.dictionary_lookup(:payment_terms_type_code_qualifier,
202
+ config.header.payment_terms_type_code_qualifier),
203
+ payment_terms_type_description_identifier: config.header.payment_terms_type_description_identifier,
204
+ time_reference_code: config.header.time_reference_code
205
+ )
206
+
207
+ # TODO: Replace hardcoded values
208
+ structure = Eancom.find_structure(tag: 'PCD')
209
+ body.segment Eancom::Edifact::PCD.new(
210
+ percentage_type_code_qualifier: structure.dictionary_lookup(:percentage_type_code_qualifier,
211
+ config.header.percentage_type_code_qualifier),
212
+ percentage: config.header.percentage
213
+ )
214
+
215
+ total_quantity = 0
216
+
217
+ items = message.items
218
+
219
+ items.each_with_index do |item, index|
220
+
221
+ structure = Eancom.find_structure(tag: 'LIN')
222
+ body.segment Eancom::Edifact::LIN.new(
223
+ line_item_identifier_1: (index + 1).to_s,
224
+ item_identifier: item.ean,
225
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
226
+ )
227
+
228
+ if additional_product_id = item.additional_product_id
229
+ additional_product_id.each do |id|
230
+ next unless additional_information = id.additional_information
231
+
232
+ structure = Eancom.find_structure(tag: 'PIA')
233
+ body.segment Eancom::Edifact::PIA.new(
234
+ product_identifier_code_qualifier: structure.dictionary_lookup(:product_identifier_code_qualifier, additional_information.product_identifier_code_qualifier),
235
+ item_identifier_1: additional_information.item_identifier_1,
236
+ item_type_identification_code_1: structure.dictionary_lookup(:item_type_identification_code_1,
237
+ additional_information.item_type_identification_code_1)
238
+ )
239
+ end
240
+ end
241
+
242
+ quantities = item.quantities
243
+ quantities.each_with_index do |qty, index|
244
+ next unless index == 0
245
+ structure = Eancom.find_structure(tag: 'QTY')
246
+ key = qty.identifier.intern.to_sym
247
+ body.segment Eancom::Edifact::QTY.new(
248
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
249
+ quantity: qty[key].quantity
250
+ )
251
+ end
252
+
253
+ quantities.each_with_index do |qty, index|
254
+ next unless index == 1
255
+ structure = Eancom.find_structure(tag: 'QTY')
256
+ key = qty.identifier.intern.to_sym
257
+ body.segment Eancom::Edifact::QTY.new(
258
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
259
+ quantity: qty[key].quantity
260
+ )
261
+ end
262
+
263
+ date_time_messages = item.date_time_messages
264
+ date_time_messages.each do |dtm, index|
265
+ structure = Eancom.find_structure(tag: 'DTM')
266
+ key = dtm.identifier.intern.to_sym
267
+ body.segment Eancom::Edifact::DTM.new(
268
+ type: structure.dictionary_lookup(:type, dtm.identifier),
269
+ date_time: dtm[key].date_time,
270
+ format: '102'
271
+ )
272
+ end
273
+
274
+ prices = item.prices
275
+ prices.each do |price|
276
+ next unless price = price.price
277
+
278
+ structure = Eancom.find_structure(tag: 'PRI')
279
+ body.segment Eancom::Edifact::PRI.new(
280
+ price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
281
+ price_amount: price.price_amount,
282
+ price_type_code: structure.dictionary_lookup(:price_type_code, price.price_type_code),
283
+ price_specification_code: structure.dictionary_lookup(:price_specification_code,
284
+ price.price_specification_code)
285
+ )
286
+ end
287
+
288
+ if taxes = item.taxes
289
+ taxes.each_with_index do |tax, index|
290
+ next unless tax = tax.tax
291
+ next unless index == 0
292
+
293
+ structure = Eancom.find_structure(tag: 'TAX')
294
+ body.segment Eancom::Edifact::TAX.new(
295
+ duty_or_tax_or_fee_function_code_qualifier: '7',
296
+ duty_or_tax_or_fee_name_code: structure.dictionary_lookup(:duty_or_tax_or_fee_name_code,
297
+ tax.duty_or_tax_or_fee_name_code)
298
+ )
299
+ end
300
+ end
301
+
302
+ next unless monetary_amounts = item.monetary_amounts
303
+
304
+ monetary_amounts.each_with_index do |amount, index|
305
+ next unless index == 0
306
+
307
+ structure = Eancom.find_structure(tag: 'MOA')
308
+ body.segment Eancom::Edifact::MOA.new(
309
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier, amount.monetary_amount_type_code_qualifier),
310
+ monetary_amount: amount.monetary_amount
311
+ )
312
+ end
313
+ end
314
+ end
315
+ end
316
+ document.footer do |footer|
317
+ footer.segment Eancom::Edifact::UNS.new(
318
+ section_identification: 'S'
319
+ )
320
+
321
+ messages = config.body.messages
322
+
323
+ messages.each do |message|
324
+ items = message.items
325
+
326
+ items.each_with_index do |item, index|
327
+ next unless index == items.size - 1
328
+
329
+ counts = item.counts
330
+ counts.each_with_index do |cnt, index|
331
+ structure = Eancom.find_structure(tag: 'CNT')
332
+ footer.segment Eancom::Edifact::CNT.new(
333
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier, cnt.control_total_type_code_quantifier),
334
+ control_total_value: (index + 1).to_s
335
+ )
336
+ end
337
+ end
338
+ end
339
+
340
+ messages = config.body.messages
341
+ messages.each do |message|
342
+ items = message.items
343
+ items.each do |item|
344
+ monetary_amounts = item.monetary_amounts
345
+ monetary_amounts.each_with_index do |amount, index|
346
+ next unless index == items.size - 1
347
+
348
+ monetary_amount = if amount.monetary_mount.nil?
349
+ ''
350
+ else
351
+ amount.monetary_amount
352
+ end
353
+ structure = Eancom.find_structure(tag: 'MOA')
354
+ footer.segment Eancom::Edifact::MOA.new(
355
+ monetary_amount_type_code_qualifier: structure.dictionary_lookup(:monetary_amount_type_code_qualifier,
356
+ amount.monetary_amount_type_code_qualifier),
357
+ monetary_amount: monetary_amount
358
+ )
359
+ end
360
+ end
361
+ end
362
+
363
+ messages = config.body.messages
364
+ messages.each do |message|
365
+ items = message.items
366
+ items.each do |item|
367
+ taxes = item.taxes
368
+ taxes.each_with_index do |tax, index|
369
+ next unless index == 1
370
+ structure = Eancom.find_structure(tag: 'TAX')
371
+ footer.segment Eancom::Edifact::TAX.new(
372
+ duty_or_tax_or_fee_function_code_qualifier: '7',
373
+ duty_or_tax_or_fee_name_code: structure.dictionary_lookup(:duty_or_tax_or_fee_name_code, tax.tax.duty_or_tax_or_fee_name_code)
374
+ )
375
+ end
376
+ end
377
+ end
378
+
379
+ footer.segment Eancom::Edifact::UNT.new(
380
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
381
+ message_reference_number: config.header.message_reference_number
382
+ )
383
+
384
+ footer.segment Eancom::Edifact::UNZ.new(
385
+ interchange_control_count: messages.size.to_s,
386
+ interchange_control_reference: config.header.interchange_control_reference.to_s
387
+ )
388
+ end
389
+ end
@@ -0,0 +1,134 @@
1
+ Eancom::Definition.create(name: 'D01B', type: :invrpt) 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: 'UNOA',
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
+ date_time_messages = message.date_time_messages
39
+ date_time_messages.each_with_index do |dtm, index|
40
+ next unless index == 0
41
+ structure = Eancom.find_structure(tag: 'DTM')
42
+ key = dtm.identifier.intern.to_sym
43
+ body.segment Eancom::Edifact::DTM.new(
44
+ type: structure.dictionary_lookup(:type, dtm.identifier),
45
+ date_time: dtm[key].date_time,
46
+ format: '203'
47
+ )
48
+ end
49
+
50
+ date_time_messages.each_with_index do |dtm, index|
51
+ next unless index == 1
52
+ structure = Eancom.find_structure(tag: 'DTM')
53
+ key = dtm.identifier.intern.to_sym
54
+ body.segment Eancom::Edifact::DTM.new(
55
+ type: structure.dictionary_lookup(:type, dtm.identifier),
56
+ date_time: dtm[key].date_time,
57
+ format: '102'
58
+ )
59
+ end
60
+
61
+ nads = message.nads
62
+ nads.each_with_index do |nad, index|
63
+ next unless index == 0
64
+ structure = Eancom.find_structure(tag: 'NAD')
65
+ key = nad.identifier.intern.to_sym
66
+ body.segment Eancom::Edifact::NAD.new(
67
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
68
+ party_identifier: nad[key].party_identifier,
69
+ code_list_responsible_agency_code_1: '9'
70
+ )
71
+ end
72
+ nads = message.nads
73
+ nads.each_with_index do |nad, index|
74
+ next unless index == 1
75
+ structure = Eancom.find_structure(tag: 'NAD')
76
+ key = nad.identifier.intern.to_sym
77
+ body.segment Eancom::Edifact::NAD.new(
78
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
79
+ party_identifier: nad[key].party_identifier,
80
+ code_list_responsible_agency_code_1: '9'
81
+ )
82
+ end
83
+
84
+ total_quantity = 0
85
+
86
+ items = message.items
87
+
88
+ items.each_with_index do |item, index|
89
+ total_quantity += item.quantity.to_i
90
+
91
+ structure = Eancom.find_structure(tag: 'LIN')
92
+ body.segment Eancom::Edifact::LIN.new(
93
+ line_item_identifier_1: (index + 1).to_s,
94
+ item_identifier: item.ean,
95
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
96
+ )
97
+
98
+ inventories = item.inventory
99
+
100
+ inventories.each do |inventory|
101
+ structure = Eancom.find_structure(tag: 'INV')
102
+ body.segment Eancom::Edifact::INV.new(
103
+ inventory_movement_direction_code: structure.dictionary_lookup(:inventory_movement_direction_code,
104
+ inventory.inventory_movement_direction_code),
105
+ inventory_balance_method_code: inventory.inventory_balance_method_code
106
+ )
107
+ end
108
+
109
+ quantities = item.quantities
110
+ quantities.each_with_index do |qty, index|
111
+ structure = Eancom.find_structure(tag: 'QTY')
112
+ key = qty.identifier.intern.to_sym
113
+ body.segment Eancom::Edifact::QTY.new(
114
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
115
+ quantity: qty[key].quantity
116
+ )
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ document.footer do |footer|
123
+ messages = config.body.messages
124
+
125
+ footer.segment Eancom::Edifact::UNT.new(
126
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
127
+ message_reference_number: config.header.message_reference_number
128
+ )
129
+ footer.segment Eancom::Edifact::UNZ.new(
130
+ interchange_control_count: messages.size.to_s,
131
+ interchange_control_reference: config.header.interchange_control_reference.to_s
132
+ )
133
+ end
134
+ end
@@ -0,0 +1,125 @@
1
+ Eancom::Definition.create(name: 'D96A', type: :invrpt) 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
+ 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
+ structure = Eancom.find_structure(tag: 'DTM')
43
+ key = dtm.identifier.intern.to_sym
44
+ body.segment Eancom::Edifact::DTM.new(
45
+ type: structure.dictionary_lookup(:type, dtm.identifier),
46
+ date_time: dtm[key].date_time,
47
+ format: '102'
48
+ )
49
+ end
50
+
51
+ nads = message.nads
52
+ nads.each_with_index do |nad, index|
53
+ next unless index == 0
54
+ structure = Eancom.find_structure(tag: 'NAD')
55
+ key = nad.identifier.intern.to_sym
56
+ body.segment Eancom::Edifact::NAD.new(
57
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
58
+ party_identifier: nad[key].party_identifier,
59
+ code_list_responsible_agency_code_1: '9',
60
+ name_and_address_description_1: nad[key].name_and_address_description_1
61
+ )
62
+ end
63
+
64
+ total_quantity = 0
65
+
66
+ items = message.items
67
+
68
+ items.each_with_index do |item, index|
69
+ total_quantity += item.quantity.to_i
70
+
71
+ structure = Eancom.find_structure(tag: 'LIN')
72
+ body.segment Eancom::Edifact::LIN.new(
73
+ line_item_identifier_1: (index + 1).to_s,
74
+ item_identifier: item.ean,
75
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
76
+ )
77
+
78
+ if additional_product_id = item.additional_product_id
79
+ additional_product_id.each do |id|
80
+ next unless product_identification = id.product_identification
81
+
82
+ structure = Eancom.find_structure(tag: 'PIA')
83
+ body.segment Eancom::Edifact::PIA.new(
84
+ product_identifier_code_qualifier: structure.dictionary_lookup(:product_identifier_code_qualifier, product_identification.product_identifier_code_qualifier),
85
+ item_identifier_1: product_identification.item_identifier_1,
86
+ item_type_identification_code_1: structure.dictionary_lookup(:item_type_identification_code_1, product_identification.item_type_identification_code_1)
87
+ )
88
+ end
89
+ end
90
+
91
+ quantities = item.quantities
92
+ quantities.each_with_index do |qty, index|
93
+ structure = Eancom.find_structure(tag: 'QTY')
94
+ key = qty.identifier.intern.to_sym
95
+ body.segment Eancom::Edifact::QTY.new(
96
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
97
+ quantity: qty[key].quantity
98
+ )
99
+ end
100
+
101
+ structure = Eancom.find_structure(tag: 'LOC')
102
+ body.segment Eancom::Edifact::LOC.new(
103
+ location_function_qualifier: structure.dictionary_lookup(:location_function_qualifier, item.location.location_function_qualifier),
104
+ location_name_code: item.location.location_name_code,
105
+ code_list_identification_code: item.location.code_list_identification_code,
106
+ code_list_responsible_agency_code: structure.dictionary_lookup(:code_list_responsible_agency_code, item.location.code_list_responsible_agency_code)
107
+ )
108
+ end
109
+
110
+ body.segment Eancom::Edifact::UNT.new(
111
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
112
+ message_reference_number: config.header.message_reference_number
113
+ )
114
+ end
115
+ end
116
+
117
+ document.footer do |footer|
118
+ messages = config.body.messages
119
+
120
+ footer.segment Eancom::Edifact::UNZ.new(
121
+ interchange_control_count: messages.size.to_s,
122
+ interchange_control_reference: config.header.interchange_control_reference.to_s
123
+ )
124
+ end
125
+ end