eancom 0.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +190 -5
- data/.gitlab-ci.yml +25 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +22 -18
- data/README.md +46 -0
- data/bin/console +3 -2
- data/definitions/desadv/d01b.rb +251 -0
- data/definitions/desadv/d96a.rb +208 -87
- data/definitions/invoic/d01b.rb +559 -0
- data/definitions/invoic/d96a.rb +389 -0
- data/definitions/invrpt/d01b.rb +134 -0
- data/definitions/invrpt/d96a.rb +125 -0
- data/definitions/orders/d01b.rb +182 -0
- data/definitions/orders/d96b.rb +198 -0
- data/definitions/ordrsp/d01b.rb +251 -0
- data/definitions/ordrsp/d96b.rb +226 -0
- data/definitions/pricat/d01b.rb +225 -0
- data/definitions/pricat/d96b.rb +207 -0
- data/definitions/retann/d01b.rb +172 -0
- data/definitions/retann/d96b.rb +221 -0
- data/definitions/segments/ajt.rb +47 -0
- data/definitions/segments/alc.rb +328 -0
- data/definitions/segments/ali.rb +93 -0
- data/definitions/segments/bgm.rb +395 -0
- data/definitions/segments/cav.rb +122 -0
- data/definitions/segments/cci.rb +136 -0
- data/definitions/segments/cdi.rb +39 -0
- data/definitions/segments/cnt.rb +82 -0
- data/definitions/segments/cps.rb +76 -0
- data/definitions/segments/cta.rb +89 -0
- data/definitions/segments/cux.rb +174 -0
- data/definitions/segments/dgs.rb +34 -0
- data/definitions/segments/doc.rb +45 -0
- data/definitions/segments/dtm.rb +243 -0
- data/definitions/segments/efi.rb +67 -0
- data/definitions/segments/eqd.rb +37 -0
- data/definitions/segments/ftx.rb +165 -0
- data/definitions/segments/gin.rb +113 -0
- data/definitions/segments/imd.rb +360 -0
- data/definitions/segments/inv.rb +94 -0
- data/definitions/segments/lin.rb +133 -0
- data/definitions/segments/loc.rb +137 -0
- data/definitions/segments/mea.rb +189 -0
- data/definitions/segments/moa.rb +228 -0
- data/definitions/segments/nad.rb +314 -0
- data/definitions/segments/pac.rb +262 -0
- data/definitions/segments/pat.rb +171 -0
- data/definitions/segments/pcd.rb +72 -0
- data/definitions/segments/pci.rb +110 -0
- data/definitions/segments/pgi.rb +152 -0
- data/definitions/segments/pia.rb +501 -0
- data/definitions/segments/pri.rb +208 -0
- data/definitions/segments/qty.rb +293 -0
- data/definitions/segments/rff.rb +210 -0
- data/definitions/segments/rte.rb +52 -0
- data/definitions/segments/tax.rb +266 -0
- data/definitions/segments/tdt.rb +278 -0
- data/definitions/segments/tod.rb +64 -0
- data/definitions/segments/tru.rb +34 -0
- data/definitions/segments/una.rb +85 -0
- data/definitions/segments/unb.rb +284 -0
- data/definitions/segments/unh.rb +183 -0
- data/definitions/segments/uns.rb +40 -0
- data/definitions/segments/unt.rb +48 -0
- data/definitions/segments/unz.rb +48 -0
- data/definitions/slsrpt/d01b.rb +206 -0
- data/definitions/slsrpt/d96a.rb +199 -0
- data/eancom.gemspec +2 -1
- data/lib/eancom.rb +61 -16
- data/lib/eancom/definition.rb +1 -1
- data/lib/eancom/edifact.rb +60 -13
- data/lib/eancom/edifact/body.rb +63 -0
- data/lib/eancom/edifact/composite.rb +38 -0
- data/lib/eancom/edifact/data.rb +108 -0
- data/lib/eancom/edifact/document.rb +43 -11
- data/lib/eancom/edifact/document_element.rb +26 -0
- data/lib/eancom/edifact/footer.rb +7 -0
- data/lib/eancom/edifact/header.rb +15 -0
- data/lib/eancom/edifact/item.rb +40 -0
- data/lib/eancom/edifact/message.rb +24 -16
- data/lib/eancom/edifact/segment.rb +131 -12
- data/lib/eancom/edifact/segments/ajt.rb +32 -0
- data/lib/eancom/edifact/segments/alc.rb +61 -0
- data/lib/eancom/edifact/segments/ali.rb +50 -0
- data/lib/eancom/edifact/segments/bgm.rb +46 -0
- data/lib/eancom/edifact/segments/cav.rb +47 -0
- data/lib/eancom/edifact/segments/cci.rb +53 -0
- data/lib/eancom/edifact/segments/cdi.rb +30 -0
- data/lib/eancom/edifact/segments/cnt.rb +40 -0
- data/lib/eancom/edifact/segments/cps.rb +33 -0
- data/lib/eancom/edifact/segments/cta.rb +30 -0
- data/lib/eancom/edifact/segments/cux.rb +60 -0
- data/lib/eancom/edifact/segments/dgs.rb +31 -0
- data/lib/eancom/edifact/segments/doc.rb +30 -0
- data/lib/eancom/edifact/segments/dtm.rb +47 -0
- data/lib/eancom/edifact/segments/efi.rb +38 -0
- data/lib/eancom/edifact/segments/eqd.rb +30 -0
- data/lib/eancom/edifact/segments/ftx.rb +63 -0
- data/lib/eancom/edifact/segments/gin.rb +45 -0
- data/lib/eancom/edifact/segments/imd.rb +69 -0
- data/lib/eancom/edifact/segments/inv.rb +43 -0
- data/lib/eancom/edifact/segments/lin.rb +47 -0
- data/lib/eancom/edifact/segments/loc.rb +46 -0
- data/lib/eancom/edifact/segments/mea.rb +54 -0
- data/lib/eancom/edifact/segments/moa.rb +45 -0
- data/lib/eancom/edifact/segments/nad.rb +112 -0
- data/lib/eancom/edifact/segments/pac.rb +56 -0
- data/lib/eancom/edifact/segments/pat.rb +37 -0
- data/lib/eancom/edifact/segments/pcd.rb +33 -0
- data/lib/eancom/edifact/segments/pci.rb +40 -0
- data/lib/eancom/edifact/segments/pgi.rb +45 -0
- data/lib/eancom/edifact/segments/pia.rb +108 -0
- data/lib/eancom/edifact/segments/pri.rb +53 -0
- data/lib/eancom/edifact/segments/qty.rb +44 -0
- data/lib/eancom/edifact/segments/rff.rb +47 -0
- data/lib/eancom/edifact/segments/rte.rb +33 -0
- data/lib/eancom/edifact/segments/tax.rb +78 -0
- data/lib/eancom/edifact/segments/tdt.rb +57 -0
- data/lib/eancom/edifact/segments/tod.rb +33 -0
- data/lib/eancom/edifact/segments/tru.rb +31 -0
- data/lib/eancom/edifact/segments/una.rb +52 -0
- data/lib/eancom/edifact/segments/unb.rb +68 -0
- data/lib/eancom/edifact/segments/unh.rb +50 -0
- data/lib/eancom/edifact/segments/uns.rb +32 -0
- data/lib/eancom/edifact/segments/unt.rb +28 -0
- data/lib/eancom/edifact/segments/unz.rb +28 -0
- data/lib/eancom/edifact/structure.rb +90 -0
- data/lib/eancom/factory.rb +9 -8
- data/lib/eancom/parser.rb +7 -0
- data/lib/eancom/parser/document.rb +60 -0
- data/lib/eancom/parser/segment.rb +71 -0
- data/lib/eancom/version.rb +1 -1
- data/pricat.json +1 -0
- metadata +141 -9
- data/lib/eancom/edifact/element.rb +0 -16
- data/lib/eancom/edifact/envelope.rb +0 -24
@@ -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
|
@@ -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
|