Blame view

lib/syspro/business_objects/parsers/portor_parser.rb 1.76 KB
810ca84b   Isaac Lewis   wip purchase orde...
1
2
3
4
5
6
7
8
9
10
11
12
13
  # frozen_string_literal: true
  
  module Syspro
    module BusinessObjects
      module Parsers
        class PorTorParser
          attr_reader :doc
  
          def initialize(doc)
            @doc = doc
          end
  
          def parse
f1e2e13b   chadzink   Implemented PorTo...
14
15
            error_numbers = doc.xpath("//ErrorNumber").map{|e| e.text}
            
810ca84b   Isaac Lewis   wip purchase orde...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
            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
f1e2e13b   chadzink   Implemented PorTo...
32
            
810ca84b   Isaac Lewis   wip purchase orde...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
            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
  
f1e2e13b   chadzink   Implemented PorTo...
50
51
52
53
54
55
56
57
            grns = doc.xpath("//Grn").map{|e| e.text}
            
            {
              error_numbers: error_numbers,
              key: key,
              receipt: receipt_models,
              grns: grns
            }
810ca84b   Isaac Lewis   wip purchase orde...
58
          end
810ca84b   Isaac Lewis   wip purchase orde...
59
60
61
62
        end
      end
    end
  end