eancom 1.6.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 +204 -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 -7
  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
@@ -1,17 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
1
  Eancom::Definition.create(name: 'D96A', type: :desadv) do |document, config|
4
2
  document.header do |header|
3
+ header.segment Eancom::Edifact::UNA.new
4
+
5
5
  header.segment Eancom::Edifact::UNB.new(
6
- syntax_identifier: 'UNOA',
7
- syntax_version_number: '2',
6
+ syntax_identifier: 'UNOC',
7
+ syntax_version_number: '3',
8
8
  interchange_sender_identification: config.header.interchange_sender_identification,
9
- sender_identifiction_code_qualifier: config.header.sender_identification_code_qualifier || '14',
9
+ sender_identifiction_code_qualifier: '14',
10
10
  interchange_recipient_identification: config.header.interchange_recipient_identification,
11
- recipient_identifiction_code_qualifier: config.header.recipient_identification_code_qualifier || '14',
11
+ recipient_identifiction_code_qualifier: '14',
12
12
  date: config.header.date,
13
13
  time: config.header.time,
14
- interchange_control_reference: config.header.interchange_control_reference
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
15
17
  )
16
18
 
17
19
  header.segment Eancom::Edifact::UNH.new(
@@ -26,92 +28,124 @@ Eancom::Definition.create(name: 'D96A', type: :desadv) do |document, config|
26
28
 
27
29
  document.body do |body|
28
30
  messages = config.body.messages
29
-
30
31
  messages.each do |message|
31
32
  body.segment Eancom::Edifact::BGM.new(
32
- document_name_code: '351',
33
+ document_name_code: message.document_name_code,
33
34
  document_identifier: message.document_identifier,
34
- message_function_code: '9'
35
+ message_function_code: message.message_function_code
35
36
  )
36
37
 
37
- # Document Date
38
- body.segment Eancom::Edifact::DTM.new(
39
- type: '137',
40
- date_time: message.document_message_date_time.date_time,
41
- format: '102'
42
- )
38
+ date_time_messages = message.date_time_messages
39
+ date_time_messages.each_with_index do |dtm, index|
40
+ next unless index == 0
43
41
 
44
- # Shipping Date
45
- body.segment Eancom::Edifact::DTM.new(
46
- type: '11',
47
- date_time: message.despatch_date_and_or_time.date_time,
48
- format: '102'
49
- )
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
50
 
51
- # Order Reference
52
- if order_number_buyer = message.order_number_buyer
53
- body.segment Eancom::Edifact::RFF.new(
54
- reference_code_qualifier: 'ON',
55
- reference_identifier: order_number_buyer.reference_identifier
51
+ date_time_messages = message.date_time_messages
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'
56
61
  )
57
62
  end
58
63
 
59
- if order_number_supplier = message.order_number_supplier
64
+ references = message.references
65
+ references.each_with_index do |rff, index|
66
+ next unless index == 0
67
+
68
+ structure = Eancom.find_structure(tag: 'RFF')
69
+ key = rff.identifier.intern.to_sym
60
70
  body.segment Eancom::Edifact::RFF.new(
61
- reference_code_qualifier: 'VN',
62
- reference_identifier: order_number_supplier.reference_identifier
71
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
72
+ reference_identifier: rff[key].reference_identifier
63
73
  )
64
74
  end
65
75
 
66
- if (supplier = message.supplier)
67
- # Sender ILN
76
+ # Sender ILN
77
+ nads = message.nads
78
+ nads.each_with_index do |nad, index|
79
+ next unless index == 0
80
+
81
+ structure = Eancom.find_structure(tag: 'NAD')
82
+ key = nad.identifier.intern.to_sym
68
83
  body.segment Eancom::Edifact::NAD.new(
69
- party_function_code_qualifier: 'SU',
70
- party_identifier: supplier.party_identifier,
71
- code_list_responsible_agancy_code_1: '9'
84
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
85
+ party_identifier: nad[key].party_identifier,
86
+ code_list_responsible_agency_code_1: '9'
72
87
  )
73
-
74
88
  end
75
89
 
76
- if (manufacturer = message.manufacturer)
77
- # Manufacturer ILN
90
+ # Manufacturer ILN
91
+ nads = message.nads
92
+ nads.each_with_index do |nad, index|
93
+ next unless index == 1
94
+
95
+ structure = Eancom.find_structure(tag: 'NAD')
96
+ key = nad.identifier.intern.to_sym
78
97
  body.segment Eancom::Edifact::NAD.new(
79
- party_function_code_qualifier: 'MF',
80
- party_identifier: manufacturer.party_identifier,
81
- code_list_responsible_agancy_code_1: '9'
98
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
99
+ party_identifier: nad[key].party_identifier,
100
+ code_list_responsible_agency_code_1: '9'
82
101
  )
83
102
  end
84
103
 
85
104
  # Reciver ILN
86
- if (buyer = message.buyer)
105
+ nads = message.nads
106
+ nads.each_with_index do |nad, index|
107
+ next unless index == 2
108
+
109
+ structure = Eancom.find_structure(tag: 'NAD')
110
+ key = nad.identifier.intern.to_sym
87
111
  body.segment Eancom::Edifact::NAD.new(
88
- party_function_code_qualifier: 'BY',
89
- party_identifier: buyer.party_identifier,
90
- code_list_responsible_agancy_code_1: '9'
112
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
113
+ party_identifier: nad[key].party_identifier,
114
+ code_list_responsible_agency_code_1: '9'
91
115
  )
92
116
  end
93
117
 
94
- # Delivery Party ILN
95
- if (delivery_party = message.delivery_party)
118
+ # Destination ILN
119
+ nads = message.nads
120
+ nads.each_with_index do |nad, index|
121
+ next unless index == 3
122
+
123
+ structure = Eancom.find_structure(tag: 'NAD')
124
+ key = nad.identifier.intern.to_sym
96
125
  body.segment Eancom::Edifact::NAD.new(
97
- party_function_code_qualifier: 'DP',
98
- party_identifier: delivery_party.party_identifier,
99
- code_list_responsible_agancy_code_1: '9'
126
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
127
+ party_identifier: nad[key].party_identifier,
128
+ code_list_responsible_agency_code_1: '9'
100
129
  )
101
130
  end
102
131
 
103
132
  # Final Recipient ILN
104
- if (ultimate_consignee = message.ultimate_consignee)
133
+ nads = message.nads
134
+ nads.each_with_index do |nad, index|
135
+ next unless index == 4
136
+
137
+ structure = Eancom.find_structure(tag: 'NAD')
138
+ key = nad.identifier.intern.to_sym
105
139
  body.segment Eancom::Edifact::NAD.new(
106
- party_function_code_qualifier: 'UC',
107
- party_identifier: ultimate_consignee.party_identifier,
108
- code_list_responsible_agancy_code_1: '9'
140
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
141
+ party_identifier: nad[key].party_identifier,
142
+ code_list_responsible_agency_code_1: '9'
109
143
  )
110
144
  end
111
145
 
112
146
  # Delivery Note Mode
113
147
  body.segment Eancom::Edifact::CPS.new(
114
- hierarchical_structure_level_identifier: '1'
148
+ hierarchical_structure_level_identifier: message.hierarchical_structure_level_identifier
115
149
  )
116
150
 
117
151
  # Items
@@ -119,45 +153,74 @@ Eancom::Definition.create(name: 'D96A', type: :desadv) do |document, config|
119
153
 
120
154
  items = message.items
121
155
 
122
- items.each_with_index do |item, _index|
123
- dispatch_quantity = item.despatch_quantity
124
- total_quantity += dispatch_quantity.quantity.to_i
156
+ items.each_with_index do |item, index|
157
+ total_quantity += item.quantity.to_i
125
158
 
159
+ structure = Eancom.find_structure(tag: 'LIN')
126
160
  body.segment Eancom::Edifact::LIN.new(
127
- line_item_identifier_1: item.line_item_identifier_1.to_s,
161
+ line_item_identifier_1: (index + 1).to_s,
128
162
  item_identifier: item.ean,
129
- item_type_identification_code: 'EN'
163
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code,
164
+ item.item_type_identification_code)
130
165
  )
131
166
 
132
- body.segment Eancom::Edifact::QTY.new(
133
- quantity_type_code_qualifier: '12',
134
- quantity: dispatch_quantity.quantity.to_s,
135
- measurement_unit_code: 'PCE'
136
- )
167
+ quantities = item.quantities
168
+ quantities.each_with_index do |qty, index|
169
+ structure = Eancom.find_structure(tag: 'QTY')
170
+ key = qty.identifier.intern.to_sym
171
+ body.segment Eancom::Edifact::QTY.new(
172
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
173
+ quantity: qty[key].quantity
174
+ )
175
+ end
137
176
  end
177
+ end
178
+ end
138
179
 
139
- # Position Count
140
- body.segment Eancom::Edifact::CNT.new(
141
- control_total_type_code_quantifier: '2',
142
- control_total_value: items.count.to_s
143
- )
144
-
145
- # Total Quantity
146
- body.segment Eancom::Edifact::CNT.new(
147
- control_total_type_code_quantifier: '1',
148
- control_total_value: total_quantity.to_s
149
- )
180
+ document.footer do |footer|
181
+ messages = config.body.messages
182
+ messages.each do |message|
183
+ items = message.items
184
+ control_total_value = 0
185
+
186
+ items.each_with_index do |item, index|
187
+ quantities = item.quantities
188
+ quantities.each do |qty|
189
+ key = qty.identifier.intern.to_sym
190
+ control_total_value += qty[key].quantity.to_i
191
+ end
192
+ next unless index == 1
193
+ counts = item.counts
194
+ counts.each_with_index do |cnt, cnt_index|
195
+ next unless cnt_index == 0
196
+ structure = Eancom.find_structure(tag: 'CNT')
197
+ footer.segment Eancom::Edifact::CNT.new(
198
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier,
199
+ cnt.control_total_type_code_quantifier),
200
+ control_total_value: control_total_value.to_s
201
+ )
202
+ end
203
+
204
+
205
+ counts.each_with_index do |cnt, cnt_index|
206
+ next unless cnt_index == 1
207
+ structure = Eancom.find_structure(tag: 'CNT')
208
+ footer.segment Eancom::Edifact::CNT.new(
209
+ control_total_type_code_quantifier: structure.dictionary_lookup(:control_total_type_code_quantifier,
210
+ cnt.control_total_type_code_quantifier),
211
+ control_total_value: items.count.to_s
212
+ )
213
+ end
214
+ end
150
215
  end
151
216
 
152
- body.segment Eancom::Edifact::UNT.new(
153
- number_of_segments_in_message: (document.total_segments + 2).to_s,
154
- message_reference_number: config.header.interchange_control_reference.to_s
217
+ footer.segment Eancom::Edifact::UNT.new(
218
+ number_of_segments_in_message: document.total_segments.to_s,
219
+ message_reference_number: config.header.message_reference_number
155
220
  )
156
- end
157
221
 
158
- document.footer do |footer|
159
222
  footer.segment Eancom::Edifact::UNZ.new(
160
- interchange_control_count: '1',
223
+ interchange_control_count: messages.size.to_s,
161
224
  interchange_control_reference: config.header.interchange_control_reference.to_s
162
225
  )
163
226
  end