Blame view

lib/syspro/business_objects/portor.rb 1.68 KB
810ca84b   Isaac Lewis   wip purchase orde...
1
2
3
4
5
6
7
8
9
10
11
  # frozen_string_literal: true
  
  require 'syspro/business_objects/parsers/portor_parser'
  require 'erb'
  
  module Syspro
    module BusinessObjects
      class PorTor < ApiResource
        include Syspro::ApiOperations::Transaction
        include Syspro::BusinessObjects::Parsers
  
f1e2e13b   chadzink   Implemented PorTo...
12
13
14
15
16
17
18
19
20
21
22
        attr_accessor :transaction_date,
                      :ignore_warnings,
                      :non_stocked_wh_to_use,
                      :grn_matching_action,
                      :allow_blank_supplier,
                      :apply_if_entire_document_valid,
                      :validate_only,
                      :manual_serial_transfers_allowed,
                      :ignore_analysis,
                      # :receipts # NOT implemented yet
                      :receipt_interospections
810ca84b   Isaac Lewis   wip purchase orde...
23
24
  
        def call(user_id)
f1e2e13b   chadzink   Implemented PorTo...
25
26
27
28
29
30
31
32
33
          xml_parameters = params_template.result(binding)
          xml_in = template.result(binding)
          business_object = 'PORTOR'
          params = { 'UserId' => user_id,
                     'BusinessObject' => business_object,
                     'XmlParameters' => xml_parameters,
                     'XmlIn' => xml_in }
          resp = PorTor.post(params)
          parse_response(resp)
810ca84b   Isaac Lewis   wip purchase orde...
34
35
36
        end
  
        def template
f1e2e13b   chadzink   Implemented PorTo...
37
          ERB.new File.read(File.expand_path('schemas/portor_doc.xml.erb', File.dirname(__FILE__))), nil, '%'
810ca84b   Isaac Lewis   wip purchase orde...
38
39
40
        end
  
        def params_template
f1e2e13b   chadzink   Implemented PorTo...
41
          ERB.new File.read(File.expand_path('schemas/portor.xml.erb', File.dirname(__FILE__))), nil, '%'
810ca84b   Isaac Lewis   wip purchase orde...
42
43
44
45
46
47
48
        end
  
        def parse_response(resp)
          handle_errors(resp)
          parser = PorTorParser.new(resp[0].data)
          parser.parse
        end
f1e2e13b   chadzink   Implemented PorTo...
49
50
51
52
  
        def render_xml(inner_text, dflt_value = "")
          inner_text ? inner_text.to_s : dflt_value
        end
810ca84b   Isaac Lewis   wip purchase orde...
53
54
55
      end
    end
  end