eancom 0.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +190 -5
  3. data/.gitlab-ci.yml +25 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile.lock +22 -18
  6. data/README.md +46 -0
  7. data/bin/console +3 -2
  8. data/definitions/desadv/d01b.rb +251 -0
  9. data/definitions/desadv/d96a.rb +208 -87
  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 +328 -0
  24. data/definitions/segments/ali.rb +93 -0
  25. data/definitions/segments/bgm.rb +395 -0
  26. data/definitions/segments/cav.rb +122 -0
  27. data/definitions/segments/cci.rb +136 -0
  28. data/definitions/segments/cdi.rb +39 -0
  29. data/definitions/segments/cnt.rb +82 -0
  30. data/definitions/segments/cps.rb +76 -0
  31. data/definitions/segments/cta.rb +89 -0
  32. data/definitions/segments/cux.rb +174 -0
  33. data/definitions/segments/dgs.rb +34 -0
  34. data/definitions/segments/doc.rb +45 -0
  35. data/definitions/segments/dtm.rb +243 -0
  36. data/definitions/segments/efi.rb +67 -0
  37. data/definitions/segments/eqd.rb +37 -0
  38. data/definitions/segments/ftx.rb +165 -0
  39. data/definitions/segments/gin.rb +113 -0
  40. data/definitions/segments/imd.rb +360 -0
  41. data/definitions/segments/inv.rb +94 -0
  42. data/definitions/segments/lin.rb +133 -0
  43. data/definitions/segments/loc.rb +137 -0
  44. data/definitions/segments/mea.rb +189 -0
  45. data/definitions/segments/moa.rb +228 -0
  46. data/definitions/segments/nad.rb +314 -0
  47. data/definitions/segments/pac.rb +262 -0
  48. data/definitions/segments/pat.rb +171 -0
  49. data/definitions/segments/pcd.rb +72 -0
  50. data/definitions/segments/pci.rb +110 -0
  51. data/definitions/segments/pgi.rb +152 -0
  52. data/definitions/segments/pia.rb +501 -0
  53. data/definitions/segments/pri.rb +208 -0
  54. data/definitions/segments/qty.rb +293 -0
  55. data/definitions/segments/rff.rb +210 -0
  56. data/definitions/segments/rte.rb +52 -0
  57. data/definitions/segments/tax.rb +266 -0
  58. data/definitions/segments/tdt.rb +278 -0
  59. data/definitions/segments/tod.rb +64 -0
  60. data/definitions/segments/tru.rb +34 -0
  61. data/definitions/segments/una.rb +85 -0
  62. data/definitions/segments/unb.rb +284 -0
  63. data/definitions/segments/unh.rb +183 -0
  64. data/definitions/segments/uns.rb +40 -0
  65. data/definitions/segments/unt.rb +48 -0
  66. data/definitions/segments/unz.rb +48 -0
  67. data/definitions/slsrpt/d01b.rb +206 -0
  68. data/definitions/slsrpt/d96a.rb +199 -0
  69. data/eancom.gemspec +2 -1
  70. data/lib/eancom.rb +61 -16
  71. data/lib/eancom/definition.rb +1 -1
  72. data/lib/eancom/edifact.rb +60 -13
  73. data/lib/eancom/edifact/body.rb +63 -0
  74. data/lib/eancom/edifact/composite.rb +38 -0
  75. data/lib/eancom/edifact/data.rb +108 -0
  76. data/lib/eancom/edifact/document.rb +43 -11
  77. data/lib/eancom/edifact/document_element.rb +26 -0
  78. data/lib/eancom/edifact/footer.rb +7 -0
  79. data/lib/eancom/edifact/header.rb +15 -0
  80. data/lib/eancom/edifact/item.rb +40 -0
  81. data/lib/eancom/edifact/message.rb +24 -16
  82. data/lib/eancom/edifact/segment.rb +131 -12
  83. data/lib/eancom/edifact/segments/ajt.rb +32 -0
  84. data/lib/eancom/edifact/segments/alc.rb +61 -0
  85. data/lib/eancom/edifact/segments/ali.rb +50 -0
  86. data/lib/eancom/edifact/segments/bgm.rb +46 -0
  87. data/lib/eancom/edifact/segments/cav.rb +47 -0
  88. data/lib/eancom/edifact/segments/cci.rb +53 -0
  89. data/lib/eancom/edifact/segments/cdi.rb +30 -0
  90. data/lib/eancom/edifact/segments/cnt.rb +40 -0
  91. data/lib/eancom/edifact/segments/cps.rb +33 -0
  92. data/lib/eancom/edifact/segments/cta.rb +30 -0
  93. data/lib/eancom/edifact/segments/cux.rb +60 -0
  94. data/lib/eancom/edifact/segments/dgs.rb +31 -0
  95. data/lib/eancom/edifact/segments/doc.rb +30 -0
  96. data/lib/eancom/edifact/segments/dtm.rb +47 -0
  97. data/lib/eancom/edifact/segments/efi.rb +38 -0
  98. data/lib/eancom/edifact/segments/eqd.rb +30 -0
  99. data/lib/eancom/edifact/segments/ftx.rb +63 -0
  100. data/lib/eancom/edifact/segments/gin.rb +45 -0
  101. data/lib/eancom/edifact/segments/imd.rb +69 -0
  102. data/lib/eancom/edifact/segments/inv.rb +43 -0
  103. data/lib/eancom/edifact/segments/lin.rb +47 -0
  104. data/lib/eancom/edifact/segments/loc.rb +46 -0
  105. data/lib/eancom/edifact/segments/mea.rb +54 -0
  106. data/lib/eancom/edifact/segments/moa.rb +45 -0
  107. data/lib/eancom/edifact/segments/nad.rb +112 -0
  108. data/lib/eancom/edifact/segments/pac.rb +56 -0
  109. data/lib/eancom/edifact/segments/pat.rb +37 -0
  110. data/lib/eancom/edifact/segments/pcd.rb +33 -0
  111. data/lib/eancom/edifact/segments/pci.rb +40 -0
  112. data/lib/eancom/edifact/segments/pgi.rb +45 -0
  113. data/lib/eancom/edifact/segments/pia.rb +108 -0
  114. data/lib/eancom/edifact/segments/pri.rb +53 -0
  115. data/lib/eancom/edifact/segments/qty.rb +44 -0
  116. data/lib/eancom/edifact/segments/rff.rb +47 -0
  117. data/lib/eancom/edifact/segments/rte.rb +33 -0
  118. data/lib/eancom/edifact/segments/tax.rb +78 -0
  119. data/lib/eancom/edifact/segments/tdt.rb +57 -0
  120. data/lib/eancom/edifact/segments/tod.rb +33 -0
  121. data/lib/eancom/edifact/segments/tru.rb +31 -0
  122. data/lib/eancom/edifact/segments/una.rb +52 -0
  123. data/lib/eancom/edifact/segments/unb.rb +68 -0
  124. data/lib/eancom/edifact/segments/unh.rb +50 -0
  125. data/lib/eancom/edifact/segments/uns.rb +32 -0
  126. data/lib/eancom/edifact/segments/unt.rb +28 -0
  127. data/lib/eancom/edifact/segments/unz.rb +28 -0
  128. data/lib/eancom/edifact/structure.rb +90 -0
  129. data/lib/eancom/factory.rb +9 -8
  130. data/lib/eancom/parser.rb +7 -0
  131. data/lib/eancom/parser/document.rb +60 -0
  132. data/lib/eancom/parser/segment.rb +71 -0
  133. data/lib/eancom/version.rb +1 -1
  134. data/pricat.json +1 -0
  135. metadata +141 -9
  136. data/lib/eancom/edifact/element.rb +0 -16
  137. data/lib/eancom/edifact/envelope.rb +0 -24
@@ -0,0 +1,40 @@
1
+ tag = 'UNS'
2
+ Eancom.register_segment(tag: tag, klass: Eancom::Edifact::UNS)
3
+
4
+ structure = Eancom::Edifact::Structure.new(tag: tag)
5
+ #==============================================================================
6
+ # Tag #
7
+ #==============================================================================
8
+ tag = Eancom::Edifact::Composite.new()
9
+ data = Eancom::Edifact::Data.new(
10
+ type: String,
11
+ length: 1..3,
12
+ dictionary: nil,
13
+ description: "Message Header",
14
+ required: true
15
+ )
16
+ tag.add(:tag, data)
17
+
18
+ structure << tag
19
+ #==============================================================================
20
+ # Section identification
21
+ #==============================================================================
22
+ section_identification = Eancom::Edifact::Composite.new()
23
+
24
+ data = Eancom::Edifact::Data.new(
25
+ type: String,
26
+ length: 0..1,
27
+ dictionary: {
28
+ 'S' => {
29
+ description: 'Detail/summary section separation',
30
+ identifier: 'detail_summary_section_separation'
31
+ }
32
+ },
33
+ description: "Section identification",
34
+ required: true
35
+ )
36
+ section_identification.add(:section_identification, data)
37
+
38
+ structure << section_identification
39
+ #==============================================================================
40
+ Eancom.register_structure(tag: 'UNS', structure: structure)
@@ -0,0 +1,48 @@
1
+ tag = 'UNT'
2
+ Eancom.register_segment(tag: tag, klass: Eancom::Edifact::UNT)
3
+
4
+ structure = Eancom::Edifact::Structure.new(tag: tag)
5
+ #==============================================================================
6
+ # Tag #
7
+ #==============================================================================
8
+ tag = Eancom::Edifact::Composite.new()
9
+ data = Eancom::Edifact::Data.new(
10
+ type: String,
11
+ length: 1..3,
12
+ dictionary: nil,
13
+ description: "Message Header",
14
+ required: true
15
+ )
16
+ tag.add(:tag, data)
17
+
18
+ structure << tag
19
+ #==============================================================================
20
+ # Number of segments in the message #
21
+ #==============================================================================
22
+ number_of_segments_in_message = Eancom::Edifact::Composite.new()
23
+ data = Eancom::Edifact::Data.new(
24
+ type: String,
25
+ length: 1..10,
26
+ dictionary: nil,
27
+ description: "Number of segments in the message",
28
+ required: true
29
+ )
30
+ number_of_segments_in_message.add(:number_of_segments_in_message, data)
31
+
32
+ structure << number_of_segments_in_message
33
+ #==============================================================================
34
+ # Message reference number #
35
+ #==============================================================================
36
+ message_reference_number = Eancom::Edifact::Composite.new()
37
+ data = Eancom::Edifact::Data.new(
38
+ type: String,
39
+ length: 1..14,
40
+ dictionary: nil,
41
+ description: "Message reference number",
42
+ required: true
43
+ )
44
+ message_reference_number.add(:message_reference_number, data)
45
+
46
+ structure << message_reference_number
47
+ #==============================================================================
48
+ Eancom.register_structure(tag: 'UNT', structure: structure)
@@ -0,0 +1,48 @@
1
+ tag = 'UNZ'
2
+ Eancom.register_segment(tag: tag, klass: Eancom::Edifact::UNZ)
3
+
4
+ structure = Eancom::Edifact::Structure.new(tag: tag)
5
+ #==============================================================================
6
+ # Tag #
7
+ #==============================================================================
8
+ tag = Eancom::Edifact::Composite.new()
9
+ data = Eancom::Edifact::Data.new(
10
+ type: String,
11
+ length: 3,
12
+ dictionary: nil,
13
+ description: "Message Header",
14
+ required: true
15
+ )
16
+ tag.add(:tag, data)
17
+
18
+ structure << tag
19
+ #==============================================================================
20
+ # Interchange control count #
21
+ #==============================================================================
22
+ interchange_control_count = Eancom::Edifact::Composite.new()
23
+ data = Eancom::Edifact::Data.new(
24
+ type: String,
25
+ length: 1..6,
26
+ dictionary: nil,
27
+ description: "Interchange control count",
28
+ required: true
29
+ )
30
+ interchange_control_count.add(:interchange_control_count, data)
31
+
32
+ structure << interchange_control_count
33
+ #==============================================================================
34
+ # Interchange control reference #
35
+ #==============================================================================
36
+ interchange_control_reference = Eancom::Edifact::Composite.new()
37
+ data = Eancom::Edifact::Data.new(
38
+ type: String,
39
+ length: 1..14,
40
+ dictionary: nil,
41
+ description: "Number of segments in the message",
42
+ required: true
43
+ )
44
+ interchange_control_reference.add(:interchange_control_reference, data)
45
+
46
+ structure << interchange_control_reference
47
+ #==============================================================================
48
+ Eancom.register_structure(tag: 'UNZ', structure: structure)
@@ -0,0 +1,206 @@
1
+ Eancom::Definition.create(name: 'D01B', type: :slsrpt) 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
+ )
16
+
17
+ header.segment Eancom::Edifact::UNH.new(
18
+ message_reference_number: config.header.message_reference_number,
19
+ message_type: config.header.message_type,
20
+ message_version_number: config.header.message_version_number,
21
+ message_release_number: config.header.message_release_number,
22
+ controlling_agency: config.header.controlling_agency,
23
+ association_assigned_code: config.header.association_assigned_code
24
+ )
25
+ end
26
+
27
+ document.body do |body|
28
+ messages = config.body.messages
29
+
30
+ messages.each do |message|
31
+ code_list_identification_code = if message.code_list_identification_code.nil?
32
+ ''
33
+ else
34
+ message.code_list_identification_code
35
+ end
36
+ body.segment Eancom::Edifact::BGM.new(
37
+ document_name_code: message.document_name_code,
38
+ code_list_identification_code: code_list_identification_code,
39
+ code_list_responsible_agency_code: '9',
40
+ document_identifier: message.document_identifier,
41
+ message_function_code: message.message_function_code
42
+ )
43
+
44
+ date_time_messages = message.date_time_messages
45
+ date_time_messages.each_with_index do |dtm, index|
46
+ next unless index == 0
47
+
48
+ structure = Eancom.find_structure(tag: 'DTM')
49
+ key = dtm.identifier.intern.to_sym
50
+ body.segment Eancom::Edifact::DTM.new(
51
+ type: structure.dictionary_lookup(:type, dtm.identifier),
52
+ date_time: dtm[key].date_time,
53
+ format: '102'
54
+ )
55
+ end
56
+
57
+ date_time_messages.each_with_index do |dtm, index|
58
+ next unless index == 1
59
+
60
+ structure = Eancom.find_structure(tag: 'DTM')
61
+ key = dtm.identifier.intern.to_sym
62
+ body.segment Eancom::Edifact::DTM.new(
63
+ type: structure.dictionary_lookup(:type, dtm.identifier),
64
+ date_time: dtm[key].date_time,
65
+ format: '102'
66
+ )
67
+ end
68
+
69
+ date_time_messages.each_with_index do |dtm, index|
70
+ next unless index == 2
71
+
72
+ structure = Eancom.find_structure(tag: 'DTM')
73
+ key = dtm.identifier.intern.to_sym
74
+ body.segment Eancom::Edifact::DTM.new(
75
+ type: structure.dictionary_lookup(:type, dtm.identifier),
76
+ date_time: dtm[key].date_time,
77
+ format: '102'
78
+ )
79
+ end
80
+
81
+ nads = message.nads
82
+ nads.each_with_index do |nad, index|
83
+ next unless index == 0
84
+
85
+ structure = Eancom.find_structure(tag: 'NAD')
86
+ key = nad.identifier.intern.to_sym
87
+ body.segment Eancom::Edifact::NAD.new(
88
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
89
+ party_identifier: nad[key].party_identifier,
90
+ code_list_responsible_agency_code_1: '9'
91
+ )
92
+ end
93
+
94
+ nads.each_with_index do |nad, index|
95
+ next unless index == 1
96
+
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
+ # Reference Currency
107
+ if currency = message.currency
108
+ structure = Eancom.find_structure(tag: 'CUX')
109
+ body.segment Eancom::Edifact::CUX.new(
110
+ currency_identification_code_1: currency.currency_identification_code_1,
111
+ currency_type_code_qualifier_1: structure.dictionary_lookup(:currency_type_code_qualifier_1,
112
+ currency.currency_type_code_qualifier_1),
113
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1,
114
+ currency.currency_usage_code_qualifier_1)
115
+ )
116
+ end
117
+
118
+ # Location
119
+ if location = message.location
120
+ structure = Eancom.find_structure(tag: 'LOC')
121
+ body.segment Eancom::Edifact::LOC.new(
122
+ code_list_identification_code: location.code_list_identification_code,
123
+ code_list_responsible_agency_code: structure.dictionary_lookup(:code_list_responsible_agency_code, location.code_list_responsible_agency_code),
124
+ location_function_qualifier: structure.dictionary_lookup(:location_function_qualifier, location.location_function_qualifier),
125
+ location_name_code: location.location_name_code
126
+ )
127
+ end
128
+
129
+ # Sales Date
130
+ date_time_messages.each_with_index do |dtm, index|
131
+ next unless index == 3
132
+
133
+ structure = Eancom.find_structure(tag: 'DTM')
134
+ key = dtm.identifier.intern.to_sym
135
+ body.segment Eancom::Edifact::DTM.new(
136
+ type: structure.dictionary_lookup(:type, dtm.identifier),
137
+ date_time: dtm[key].date_time,
138
+ format: '102'
139
+ )
140
+ end
141
+
142
+ total_quantity = 0
143
+
144
+ items = message.items
145
+
146
+ items.each_with_index do |item, index|
147
+ total_quantity += item.quantity.to_i
148
+
149
+ structure = Eancom.find_structure(tag: 'LIN')
150
+ body.segment Eancom::Edifact::LIN.new(
151
+ line_item_identifier_1: (index + 1).to_s,
152
+ item_identifier: item.ean,
153
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
154
+ )
155
+
156
+ references = item.references
157
+ references.each_with_index do |rff, index|
158
+ structure = Eancom.find_structure(tag: 'RFF')
159
+ key = rff.identifier.intern.to_sym
160
+ body.segment Eancom::Edifact::RFF.new(
161
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
162
+ reference_identifier: rff[key].reference_identifier
163
+ )
164
+ end
165
+
166
+ prices = item.prices
167
+ prices.each do |price|
168
+ next unless price = price.price
169
+
170
+ structure = Eancom.find_structure(tag: 'PRI')
171
+ body.segment Eancom::Edifact::PRI.new(
172
+ price_amount: price.price_amount,
173
+ price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
174
+ price_specification_code: structure.dictionary_lookup(:price_specification_code,
175
+ price.price_specification_code),
176
+ price_type_code: price.price_type_code
177
+ )
178
+ end
179
+
180
+ qty = item.quantities
181
+ qty.each_with_index do |qty, index|
182
+ structure = Eancom.find_structure(tag: 'QTY')
183
+ key = qty.identifier.intern.to_sym
184
+ body.segment Eancom::Edifact::QTY.new(
185
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
186
+ quantity: qty[key].quantity
187
+ )
188
+ end
189
+ end
190
+
191
+ body.segment Eancom::Edifact::UNT.new(
192
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
193
+ message_reference_number: config.header.message_reference_number
194
+ )
195
+ end
196
+ end
197
+
198
+ document.footer do |footer|
199
+ messages = config.body.messages
200
+
201
+ footer.segment Eancom::Edifact::UNZ.new(
202
+ interchange_control_count: messages.size.to_s,
203
+ interchange_control_reference: config.header.interchange_control_reference.to_s
204
+ )
205
+ end
206
+ end
@@ -0,0 +1,199 @@
1
+ Eancom::Definition.create(name: 'D96A', type: :slsrpt) do |document, config|
2
+ # Creates a template for an slsrpt d01b formatted edifact document
3
+ document.header do |header|
4
+ header.segment Eancom::Edifact::UNA.new
5
+
6
+ header.segment Eancom::Edifact::UNB.new(
7
+ syntax_identifier: 'UNOA',
8
+ syntax_version_number: '2',
9
+ interchange_sender_identification: config.header.interchange_sender_identification,
10
+ sender_identifiction_code_qualifier: '14',
11
+ interchange_recipient_identification: config.header.interchange_recipient_identification,
12
+ recipient_identifiction_code_qualifier: '14',
13
+ date: config.header.date,
14
+ time: config.header.time,
15
+ interchange_control_reference: config.header.interchange_control_reference
16
+ )
17
+
18
+ header.segment Eancom::Edifact::UNH.new(
19
+ message_reference_number: config.header.message_reference_number,
20
+ message_type: config.header.message_type,
21
+ message_version_number: config.header.message_version_number,
22
+ message_release_number: config.header.message_release_number,
23
+ controlling_agency: config.header.controlling_agency,
24
+ association_assigned_code: config.header.association_assigned_code
25
+ )
26
+ end
27
+
28
+ document.body do |body|
29
+ # Messages
30
+ messages = config.body.messages
31
+
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
+ )
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
+
73
+ # Supplier
74
+ nads = message.nads
75
+ nads.each_with_index do |nad, index|
76
+ next unless index == 0
77
+
78
+ structure = Eancom.find_structure(tag: 'NAD')
79
+ key = nad.identifier.intern.to_sym
80
+ body.segment Eancom::Edifact::NAD.new(
81
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
82
+ party_identifier: nad[key].party_identifier,
83
+ code_list_responsible_agency_code_1: '9'
84
+ )
85
+ end
86
+
87
+ # Buyer
88
+ nads.each_with_index do |nad, index|
89
+ next unless index == 1
90
+
91
+ structure = Eancom.find_structure(tag: 'NAD')
92
+ key = nad.identifier.intern.to_sym
93
+ body.segment Eancom::Edifact::NAD.new(
94
+ party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
95
+ party_identifier: nad[key].party_identifier,
96
+ code_list_responsible_agency_code_1: '9'
97
+ )
98
+ end
99
+
100
+ # Reference Currency
101
+ if currency = message.currency
102
+ structure = Eancom.find_structure(tag: 'CUX')
103
+ body.segment Eancom::Edifact::CUX.new(
104
+ currency_identification_code_1: currency.currency_identification_code_1,
105
+ currency_type_code_qualifier_1: structure.dictionary_lookup(:currency_type_code_qualifier_1,
106
+ currency.currency_type_code_qualifier_1),
107
+ currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, currency.currency_usage_code_qualifier_1)
108
+ )
109
+ end
110
+
111
+ # Location
112
+ if location = message.location
113
+ structure = Eancom.find_structure(tag: 'LOC')
114
+ body.segment Eancom::Edifact::LOC.new(
115
+ code_list_identification_code: location.code_list_identification_code,
116
+ code_list_responsible_agency_code: structure.dictionary_lookup(:code_list_responsible_agency_code, location.code_list_responsible_agency_code),
117
+ location_function_qualifier: structure.dictionary_lookup(:location_function_qualifier, location.location_function_qualifier),
118
+ location_name_code: location.location_name_code
119
+ )
120
+ end
121
+
122
+ date_time_messages.each_with_index do |dtm, index|
123
+ next unless index == 3
124
+ structure = Eancom.find_structure(tag: 'DTM')
125
+ key = dtm.identifier.intern.to_sym
126
+ body.segment Eancom::Edifact::DTM.new(
127
+ type: structure.dictionary_lookup(:type, dtm.identifier),
128
+ date_time: dtm[key].date_time,
129
+ format: '203'
130
+ )
131
+ end
132
+
133
+ # Items
134
+ total_quantity = 0
135
+
136
+ items = message.items
137
+
138
+ items.each_with_index do |item, index|
139
+ total_quantity += item.quantity.to_i
140
+
141
+ structure = Eancom.find_structure(tag: 'LIN')
142
+ body.segment Eancom::Edifact::LIN.new(
143
+ line_item_identifier_1: (index + 1).to_s,
144
+ item_identifier: item.ean,
145
+ item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
146
+ )
147
+
148
+ references = item.references
149
+ references.each_with_index do |rff, index|
150
+ structure = Eancom.find_structure(tag: 'RFF')
151
+ key = rff.identifier.intern.to_sym
152
+ body.segment Eancom::Edifact::RFF.new(
153
+ reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
154
+ reference_identifier: rff[key].reference_identifier
155
+ )
156
+ end
157
+
158
+ prices = item.prices
159
+ prices.each do |price|
160
+ next unless price = price.price
161
+
162
+ structure = Eancom.find_structure(tag: 'PRI')
163
+ body.segment Eancom::Edifact::PRI.new(
164
+ price_amount: price.price_amount,
165
+ price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
166
+ price_specification_code: structure.dictionary_lookup(:price_specification_code,
167
+ price.price_specification_code),
168
+ price_type_code: price.price_type_code
169
+ )
170
+ end
171
+
172
+ qty = item.quantities
173
+ qty.each_with_index do |qty, index|
174
+ structure = Eancom.find_structure(tag: 'QTY')
175
+ key = qty.identifier.intern.to_sym
176
+ body.segment Eancom::Edifact::QTY.new(
177
+ quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
178
+ quantity: qty[key].quantity,
179
+ measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
180
+ )
181
+ end
182
+ end
183
+
184
+ body.segment Eancom::Edifact::UNT.new(
185
+ number_of_segments_in_message: (document.total_segments + 2).to_s,
186
+ message_reference_number: config.header.message_reference_number
187
+ )
188
+ end
189
+ end
190
+
191
+ document.footer do |footer|
192
+ messages = config.body.messages
193
+
194
+ footer.segment Eancom::Edifact::UNZ.new(
195
+ interchange_control_count: messages.size.to_s,
196
+ interchange_control_reference: config.header.interchange_control_reference.to_s
197
+ )
198
+ end
199
+ end