810ca84b
Isaac Lewis
wip purchase orde...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# frozen_string_literal: true
module Syspro
module BusinessObjects
module Parsers
class PorTorParser
attr_reader :doc
def initialize(doc)
@doc = doc
end
def parse
gl_journal = doc.first_element_child.xpath('GlJournal')
gl_journal_obj = gl_journal.children.map do |el|
next if el.name == 'text'
{
name: el.name,
text: el.text
}
end.compact
key = {}
key[:jnl_year] = doc.first_element_child.xpath('JnlYear')
key[:jnl_month] = doc.first_element_child.xpath('JnlMonth')
key[:journal] = doc.first_element_child.xpath('Journal')
key[:entry_number] = doc.first_element_child.xpath('EntryNumber')
key[:warehouse] = doc.first_element_child.xpath('Warehouse')
key[:gl_journal] = gl_journal_obj
binding.pry
receipts = doc.first_element_child.xpath('Receipt')
receipts_obj = receipts.flat_map do |el|
el.elements.map do |inner|
[inner.name,
inner.value]
end
end.compact.to_h
receipt_models = receipts_obj.map do |receipt|
Por.new(
grn: receipt.grn,
lot_number: receipt.lot_number,
purchase_order: receipt.purchase_order,
purchase_order_line: receipt.purchase_order_line
)
end
PorTorObject.new(
key,
receipt_models
)
end
PorTorObject = Struct.new(:key, :receipts)
end
end
end
end
|