Blame view

lib/syspro/business_objects/parsers/portor_parser.rb 1.72 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
b1c0def6   Samuel J Clopton   rubocop violation...
14
            error_numbers = doc.xpath('//ErrorNumber').map(&:text)
f4259c1e   Samuel J Clopton   fix tests and add...
15
  
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
f4259c1e   Samuel J Clopton   fix tests and add...
32
  
810ca84b   Isaac Lewis   wip purchase orde...
33
34
35
36
            receipts = doc.first_element_child.xpath('Receipt')
            receipts_obj = receipts.flat_map do |el|
              el.elements.map do |inner|
                [inner.name,
b1c0def6   Samuel J Clopton   rubocop violation...
37
                 inner.value]
810ca84b   Isaac Lewis   wip purchase orde...
38
39
40
41
42
43
44
45
46
47
48
49
              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
  
b1c0def6   Samuel J Clopton   rubocop violation...
50
            grns = doc.xpath('//Grn').map(&:text)
f4259c1e   Samuel J Clopton   fix tests and add...
51
  
f1e2e13b   chadzink   Implemented PorTo...
52
53
54
55
56
57
            {
              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