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,182 @@
1
+ Eancom::Definition.create(name: 'D01B', type: :orders) 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
+ 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: '102'
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
+ date_time_messages.each_with_index do |dtm, index|
62
+ next unless index == 2
63
+ structure = Eancom.find_structure(tag: 'DTM')
64
+ key = dtm.identifier.intern.to_sym
65
+ body.segment Eancom::Edifact::DTM.new(
66
+ type: structure.dictionary_lookup(:type, dtm.identifier),
67
+ date_time: dtm[key].date_time,
68
+ format: '102'
69
+ )
70
+ end
71
+
72
+ nads = message.nads
73
+ nads.each_with_index do |nad, index|
74
+ next unless index == 0
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
+ nads.each_with_index do |nad, index|
85
+ next unless index == 1
86
+ structure = Eancom.find_structure(tag: 'NAD')
87
+ key = nad.identifier.intern.to_sym
88
+ body.segment Eancom::Edifact::NAD.new(
89
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
90
+ party_identifier: nad[key].party_identifier,
91
+ code_list_responsible_agency_code_1: '9'
92
+ )
93
+ end
94
+
95
+ nads.each_with_index do |nad, index|
96
+ next unless index == 2
97
+ structure = Eancom.find_structure(tag: 'NAD')
98
+ key = nad.identifier.intern.to_sym
99
+ body.segment Eancom::Edifact::NAD.new(
100
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
101
+ party_identifier: nad[key].party_identifier,
102
+ code_list_responsible_agency_code_1: '9'
103
+ )
104
+ end
105
+
106
+ nads.each_with_index do |nad, index|
107
+ next unless index == 3
108
+ structure = Eancom.find_structure(tag: 'NAD')
109
+ key = nad.identifier.intern.to_sym
110
+ body.segment Eancom::Edifact::NAD.new(
111
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
112
+ party_identifier: nad[key].party_identifier,
113
+ code_list_responsible_agency_code_1: '9'
114
+ )
115
+ end
116
+
117
+ structure = Eancom.find_structure(tag: 'CUX')
118
+ body.segment Eancom::Edifact::CUX.new(
119
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, message.currency.currency_usage_code_qualifier_1),
120
+ currency_identification_code_1: message.currency.currency_identification_code_1,
121
+ currency_type_code_qualifier_1: structure.dictionary_lookup(:currency_type_code_qualifier_1,
122
+ message.currency.currency_type_code_qualifier_1)
123
+ )
124
+
125
+ total_quantity = 0
126
+
127
+ items = message.items
128
+
129
+ items.each_with_index do |item, index|
130
+
131
+ structure = Eancom.find_structure(tag: 'LIN')
132
+ body.segment Eancom::Edifact::LIN.new(
133
+ line_item_identifier_1: (index + 1).to_s,
134
+ item_identifier: item.ean,
135
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code
136
+ )
137
+ )
138
+ quantities = item.quantities
139
+ quantities.each_with_index do |qty, index|
140
+ structure = Eancom.find_structure(tag: 'QTY')
141
+ key = qty.identifier.intern.to_sym
142
+ body.segment Eancom::Edifact::QTY.new(
143
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
144
+ quantity: qty[key].quantity,
145
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
146
+ )
147
+ end
148
+ end
149
+
150
+ body.segment Eancom::Edifact::UNS.new(
151
+ section_identification: 'S'
152
+ )
153
+ items = message.items
154
+ items.each_with_index do |item, index|
155
+ next unless index == items.size - 1
156
+ item_count = items.size - 1
157
+
158
+ counts = item.counts
159
+ counts.each_with_index do |cnt, index|
160
+ structure = Eancom.find_structure(tag: 'CNT')
161
+ body.segment Eancom::Edifact::CNT.new(
162
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier, cnt.control_total_type_code_quantifier),
163
+ control_total_value: (item_count + 1).to_s
164
+ )
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ document.footer do |footer|
171
+ messages = config.body.messages
172
+
173
+ footer.segment Eancom::Edifact::UNT.new(
174
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
175
+ message_reference_number: config.header.message_reference_number
176
+ )
177
+ footer.segment Eancom::Edifact::UNZ.new(
178
+ interchange_control_count: messages.size.to_s,
179
+ interchange_control_reference: config.header.interchange_control_reference
180
+ )
181
+ end
182
+ end
@@ -0,0 +1,198 @@
1
+ Eancom::Definition.create(name: 'D96A', type: :orders) 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
+ nads = message.nads
63
+ nads.each_with_index do |nad, index|
64
+ next unless index == 0
65
+ structure = Eancom.find_structure(tag: 'NAD')
66
+ key = nad.identifier.intern.to_sym
67
+ body.segment Eancom::Edifact::NAD.new(
68
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
69
+ party_identifier: nad[key].party_identifier,
70
+ code_list_responsible_agency_code_1: '9'
71
+ )
72
+ end
73
+
74
+ nads.each_with_index do |nad, index|
75
+ next unless index == 1
76
+ structure = Eancom.find_structure(tag: 'NAD')
77
+ key = nad.identifier.intern.to_sym
78
+ body.segment Eancom::Edifact::NAD.new(
79
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
80
+ party_identifier: nad[key].party_identifier,
81
+ code_list_responsible_agency_code_1: '9'
82
+ )
83
+ end
84
+
85
+ nads.each_with_index do |nad, index|
86
+ next unless index == 2
87
+ structure = Eancom.find_structure(tag: 'NAD')
88
+ key = nad.identifier.intern.to_sym
89
+ body.segment Eancom::Edifact::NAD.new(
90
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
91
+ party_identifier: nad[key].party_identifier,
92
+ code_list_responsible_agency_code_1: '9'
93
+ )
94
+ end
95
+
96
+ nads.each_with_index do |nad, index|
97
+ next unless index == 3
98
+ structure = Eancom.find_structure(tag: 'NAD')
99
+ key = nad.identifier.intern.to_sym
100
+ body.segment Eancom::Edifact::NAD.new(
101
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
102
+ party_identifier: nad[key].party_identifier,
103
+ code_list_responsible_agency_code_1: '9'
104
+ )
105
+ end
106
+
107
+ structure = Eancom.find_structure(tag: 'CTA')
108
+ body.segment Eancom::Edifact::CTA.new(
109
+ contact_function_code: structure.dictionary_lookup(:contact_function_code, message.contact_function_code)
110
+ )
111
+
112
+ structure = Eancom.find_structure(tag: 'CUX')
113
+ body.segment Eancom::Edifact::CUX.new(
114
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, message.currency.currency_usage_code_qualifier_1),
115
+ currency_identification_code_1: message.currency.currency_identification_code_1,
116
+ currency_type_code_qualifier_1: '10'
117
+ )
118
+
119
+ total_quantity = 0
120
+
121
+ items = message.items
122
+
123
+ items.each_with_index do |item, index|
124
+ total_quantity += item.quantity.to_i
125
+
126
+ structure = Eancom.find_structure(tag: 'LIN')
127
+ body.segment Eancom::Edifact::LIN.new(
128
+ line_item_identifier_1: (index + 1).to_s,
129
+ item_identifier: item.ean,
130
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
131
+ )
132
+
133
+
134
+ references = item.references
135
+ references.each_with_index do |rff, index|
136
+ structure = Eancom.find_structure(tag: 'RFF')
137
+ key = rff.identifier.intern.to_sym
138
+ body.segment Eancom::Edifact::RFF.new(
139
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
140
+ reference_identifier: rff[key].reference_identifier
141
+ )
142
+ end
143
+
144
+ quantities = item.quantities
145
+ quantities.each_with_index do |qty, index|
146
+ next unless index == 0
147
+ structure = Eancom.find_structure(tag: 'QTY')
148
+ key = qty.identifier.intern.to_sym
149
+ body.segment Eancom::Edifact::QTY.new(
150
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
151
+ quantity: qty[key].quantity,
152
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
153
+ )
154
+ end
155
+
156
+ quantities.each_with_index do |qty, index|
157
+ next unless index == 1
158
+ structure = Eancom.find_structure(tag: 'QTY')
159
+ key = qty.identifier.intern.to_sym
160
+ body.segment Eancom::Edifact::QTY.new(
161
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
162
+ quantity: qty[key].quantity,
163
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
164
+ )
165
+ end
166
+
167
+ prices = item.prices
168
+ prices.each do |price|
169
+ next unless price = price.price
170
+
171
+ structure = Eancom.find_structure(tag: 'PRI')
172
+ body.segment Eancom::Edifact::PRI.new(
173
+ price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
174
+ price_amount: price.price_amount
175
+ )
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ document.footer do |footer|
182
+ messages = config.body.messages
183
+
184
+ footer.segment Eancom::Edifact::UNS.new(
185
+ section_identification: 'S'
186
+ )
187
+
188
+ footer.segment Eancom::Edifact::UNT.new(
189
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
190
+ message_reference_number: config.header.message_reference_number
191
+ )
192
+
193
+ footer.segment Eancom::Edifact::UNZ.new(
194
+ interchange_control_count: messages.size.to_s,
195
+ interchange_control_reference: config.header.interchange_control_reference.to_s
196
+ )
197
+ end
198
+ end
@@ -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