eancom 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -3
  3. data/.gitlab-ci.yml +11 -13
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -4
  6. data/Gemfile.lock +23 -103
  7. data/README.md +46 -0
  8. data/definitions/desadv/d01b.rb +139 -93
  9. data/definitions/desadv/d96a.rb +187 -101
  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 +128 -0
  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 +85 -1
  32. data/definitions/segments/efi.rb +67 -0
  33. data/definitions/segments/eqd.rb +37 -0
  34. data/definitions/segments/ftx.rb +24 -2
  35. data/definitions/segments/gin.rb +113 -0
  36. data/definitions/segments/imd.rb +5 -1
  37. data/definitions/segments/inv.rb +94 -0
  38. data/definitions/segments/lin.rb +23 -3
  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 +72 -0
  45. data/definitions/segments/pci.rb +110 -0
  46. data/definitions/segments/pgi.rb +6 -2
  47. data/definitions/segments/pia.rb +21 -21
  48. data/definitions/segments/pri.rb +21 -1
  49. data/definitions/segments/qty.rb +219 -5
  50. data/definitions/segments/rff.rb +51 -7
  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 +7 -7
  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 +104 -100
  62. data/definitions/slsrpt/d96a.rb +104 -99
  63. data/eancom.gemspec +5 -8
  64. data/lib/eancom/edifact/document.rb +2 -2
  65. data/lib/eancom/edifact/footer.rb +1 -0
  66. data/lib/eancom/edifact/segment.rb +2 -2
  67. data/lib/eancom/edifact/segments/ajt.rb +32 -0
  68. data/lib/eancom/edifact/segments/ali.rb +2 -4
  69. data/lib/eancom/edifact/segments/bgm.rb +4 -3
  70. data/lib/eancom/edifact/segments/cdi.rb +30 -0
  71. data/lib/eancom/edifact/segments/cnt.rb +8 -1
  72. data/lib/eancom/edifact/segments/cps.rb +4 -1
  73. data/lib/eancom/edifact/segments/cta.rb +30 -0
  74. data/lib/eancom/edifact/segments/cux.rb +1 -1
  75. data/lib/eancom/edifact/segments/dgs.rb +31 -0
  76. data/lib/eancom/edifact/segments/doc.rb +30 -0
  77. data/lib/eancom/edifact/segments/dtm.rb +10 -6
  78. data/lib/eancom/edifact/segments/efi.rb +38 -0
  79. data/lib/eancom/edifact/segments/eqd.rb +30 -0
  80. data/lib/eancom/edifact/segments/ftx.rb +2 -2
  81. data/lib/eancom/edifact/segments/gin.rb +45 -0
  82. data/lib/eancom/edifact/segments/imd.rb +1 -1
  83. data/lib/eancom/edifact/segments/inv.rb +43 -0
  84. data/lib/eancom/edifact/segments/lin.rb +7 -3
  85. data/lib/eancom/edifact/segments/loc.rb +8 -5
  86. data/lib/eancom/edifact/segments/mea.rb +1 -0
  87. data/lib/eancom/edifact/segments/moa.rb +3 -3
  88. data/lib/eancom/edifact/segments/nad.rb +11 -6
  89. data/lib/eancom/edifact/segments/pac.rb +3 -1
  90. data/lib/eancom/edifact/segments/pat.rb +37 -0
  91. data/lib/eancom/edifact/segments/pcd.rb +33 -0
  92. data/lib/eancom/edifact/segments/pci.rb +40 -0
  93. data/lib/eancom/edifact/segments/pia.rb +1 -0
  94. data/lib/eancom/edifact/segments/pri.rb +0 -1
  95. data/lib/eancom/edifact/segments/qty.rb +9 -5
  96. data/lib/eancom/edifact/segments/rff.rb +8 -2
  97. data/lib/eancom/edifact/segments/rte.rb +33 -0
  98. data/lib/eancom/edifact/segments/tax.rb +7 -1
  99. data/lib/eancom/edifact/segments/tdt.rb +4 -1
  100. data/lib/eancom/edifact/segments/tod.rb +33 -0
  101. data/lib/eancom/edifact/segments/tru.rb +31 -0
  102. data/lib/eancom/edifact/segments/una.rb +2 -1
  103. data/lib/eancom/edifact/segments/unb.rb +4 -5
  104. data/lib/eancom/edifact/segments/unh.rb +6 -4
  105. data/lib/eancom/edifact/segments/uns.rb +3 -0
  106. data/lib/eancom/edifact/structure.rb +0 -1
  107. data/lib/eancom/edifact.rb +15 -1
  108. data/lib/eancom/factory.rb +1 -1
  109. data/lib/eancom/parser/document.rb +2 -10
  110. data/lib/eancom/version.rb +1 -1
  111. data/lib/eancom.rb +3 -1
  112. data/pricat.json +1 -0
  113. metadata +51 -52
  114. data/.rspec_status +0 -225
  115. data/.rubocop.yml +0 -2
@@ -1,6 +1,6 @@
1
1
  Eancom::Definition.create(name: 'D96A', type: :desadv) do |document, config|
2
2
  document.header do |header|
3
- header.segment Eancom::Edifact::UNA.new()
3
+ header.segment Eancom::Edifact::UNA.new
4
4
 
5
5
  header.segment Eancom::Edifact::UNB.new(
6
6
  syntax_identifier: 'UNOC',
@@ -12,8 +12,8 @@ Eancom::Definition.create(name: 'D96A', type: :desadv) do |document, config|
12
12
  date: config.header.date,
13
13
  time: config.header.time,
14
14
  interchange_control_reference: config.header.interchange_control_reference,
15
- application_reference: 'DESADV',
16
- interchange_agreement_identifier: 'EANCOM'
15
+ application_reference: config.header.application_reference,
16
+ interchange_agreement_identifier: config.header.interchange_agreement_identifier
17
17
  )
18
18
 
19
19
  header.segment Eancom::Edifact::UNH.new(
@@ -27,115 +27,201 @@ Eancom::Definition.create(name: 'D96A', type: :desadv) do |document, config|
27
27
  end
28
28
 
29
29
  document.body do |body|
30
- body.segment Eancom::Edifact::BGM.new(
31
- document_name_code: '351',
32
- document_identifier: config.body.document_identifier,
33
- message_function_code: '9'
34
- )
35
-
36
- # Document Date
37
- body.segment Eancom::Edifact::DTM.new(
38
- type: '137',
39
- date_time: config.body.document_message_date_time,
40
- format: '102'
41
- )
42
-
43
- # Shipping Date
44
- body.segment Eancom::Edifact::DTM.new(
45
- type: '11',
46
- date_time: config.body.despatch_date_and_or_time,
47
- format: '102'
48
- )
49
-
50
- # Order Reference
51
- body.segment Eancom::Edifact::RFF.new(
52
- reference_code_qualifier: 'VN',
53
- reference_identifier: config.body.document_identifier
54
- )
55
-
56
- # Sender ILN
57
- body.segment Eancom::Edifact::NAD.new(
58
- party_function_code_qualifier: 'SU',
59
- party_identifier: config.header.interchange_sender_identification,
60
- code_list_responsible_agancy_code_1: '9'
61
- )
62
-
63
- # Manufacturer ILN
64
- body.segment Eancom::Edifact::NAD.new(
65
- party_function_code_qualifier: 'MF',
66
- party_identifier: config.header.interchange_sender_identification,
67
- code_list_responsible_agancy_code_1: '9'
68
- )
69
-
70
- # Reciver ILN
71
- body.segment Eancom::Edifact::NAD.new(
72
- party_function_code_qualifier: 'BY',
73
- party_identifier: config.header.interchange_recipient_identification,
74
- code_list_responsible_agancy_code_1: '9'
75
- )
76
-
77
- # Destination ILN
78
- body.segment Eancom::Edifact::NAD.new(
79
- party_function_code_qualifier: 'DP',
80
- party_identifier: config.header.interchange_recipient_identification,
81
- code_list_responsible_agancy_code_1: '9'
82
- )
83
-
84
- # Final Recipient ILN
85
- body.segment Eancom::Edifact::NAD.new(
86
- party_function_code_qualifier: 'UC',
87
- party_identifier: config.header.interchange_recipient_identification,
88
- code_list_responsible_agancy_code_1: '9'
89
- )
90
-
91
- # Delivery Note Mode
92
- body.segment Eancom::Edifact::CPS.new(
93
- hierarchical_structure_level_identifier: '1'
94
- )
95
-
96
- # Items
97
- total_quantity = 0
98
-
99
- items = config.body.items
100
-
101
- items.each_with_index do |item, index|
102
- total_quantity += item.quantity.to_i
103
-
104
- body.segment Eancom::Edifact::LIN.new(
105
- line_item_identifier_1: "#{index + 1}",
106
- item_identifier: item.ean,
107
- item_type_identification_code: 'SRV'
30
+ messages = config.body.messages
31
+ messages.each do |message|
32
+ body.segment Eancom::Edifact::BGM.new(
33
+ document_name_code: message.document_name_code,
34
+ document_identifier: message.document_identifier,
35
+ message_function_code: message.message_function_code
108
36
  )
109
37
 
110
- body.segment Eancom::Edifact::QTY.new(
111
- quantity_type_code_qualifier: '12',
112
- quantity: "#{item.quantity}"
38
+ date_time_messages = message.date_time_messages
39
+ date_time_messages.each_with_index do |dtm, index|
40
+ next unless index == 0
41
+
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 = 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'
61
+ )
62
+ end
63
+
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
70
+ body.segment Eancom::Edifact::RFF.new(
71
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
72
+ reference_identifier: rff[key].reference_identifier
73
+ )
74
+ end
75
+
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
83
+ body.segment Eancom::Edifact::NAD.new(
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'
87
+ )
88
+ end
89
+
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
97
+ body.segment Eancom::Edifact::NAD.new(
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'
101
+ )
102
+ end
103
+
104
+ # Reciver ILN
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
111
+ body.segment Eancom::Edifact::NAD.new(
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'
115
+ )
116
+ end
117
+
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
125
+ body.segment Eancom::Edifact::NAD.new(
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'
129
+ )
130
+ end
131
+
132
+ # Final Recipient ILN
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
139
+ body.segment Eancom::Edifact::NAD.new(
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'
143
+ )
144
+ end
145
+
146
+ # Delivery Note Mode
147
+ body.segment Eancom::Edifact::CPS.new(
148
+ hierarchical_structure_level_identifier: message.hierarchical_structure_level_identifier
113
149
  )
114
- end
115
150
 
116
- # Total Quantity
117
- body.segment Eancom::Edifact::CNT.new(
118
- control_total_type_code_quantifier: '1',
119
- control_total_value: "#{total_quantity}"
120
- )
121
-
122
- # Position Count
123
- body.segment Eancom::Edifact::CNT.new(
124
- control_total_type_code_quantifier: '2',
125
- control_total_value: "#{items.count}"
126
- )
151
+ # Items
152
+ total_quantity = 0
153
+
154
+ items = message.items
155
+
156
+ items.each_with_index do |item, index|
157
+ total_quantity += item.quantity.to_i
158
+
159
+ structure = Eancom.find_structure(tag: 'LIN')
160
+ body.segment Eancom::Edifact::LIN.new(
161
+ line_item_identifier_1: (index + 1).to_s,
162
+ item_identifier: item.ean,
163
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code,
164
+ item.item_type_identification_code)
165
+ )
166
+
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
176
+ end
177
+ end
127
178
  end
128
179
 
129
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
215
+ end
216
+
130
217
  footer.segment Eancom::Edifact::UNT.new(
131
- number_of_segments_in_message: "#{document.total_segments}",
132
- message_reference_number: '1'
218
+ number_of_segments_in_message: document.total_segments.to_s,
219
+ message_reference_number: config.header.message_reference_number
133
220
  )
134
221
 
135
222
  footer.segment Eancom::Edifact::UNZ.new(
136
- interchange_control_count: '1',
137
- interchange_control_reference: "#{config.body.document_identifier}"
223
+ interchange_control_count: messages.size.to_s,
224
+ interchange_control_reference: config.header.interchange_control_reference.to_s
138
225
  )
139
226
  end
140
-
141
227
  end