Blame view

lib/syspro/business_objects/portoi.rb 1.89 KB
d9a9cb5d   chadzink   Add portoi and co...
1
2
3
4
5
6
7
8
9
10
11
12
13
  # frozen_string_literal: true
  
  require 'syspro/business_objects/parsers/portoi_parser'
  require 'erb'
  
  module Syspro
    module BusinessObjects
      class PorToi < ApiResource
        include Syspro::ApiOperations::Transaction
        include Syspro::BusinessObjects::Parsers
  
        # input params
        attr_accessor :purchase_order_header,
b1c0def6   Samuel J Clopton   rubocop violation...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
                      :order_details,
                      :validate_only,
                      :ignore_warnings,
                      :allow_non_stock_items,
                      :allow_zero_price,
                      :validate_working_days,
                      :allow_po_when_blanket_po,
                      :default_memo_code,
                      :fixed_exchange_rate,
                      :default_memo_days,
                      :allow_blank_ledger_code,
                      :calc_due_date,
                      :default_delivery_address,
                      :insert_dangerous_goods_text,
                      :insert_additional_po_text,
                      :status
d9a9cb5d   chadzink   Add portoi and co...
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
61
62
63
  
        def call(user_id)
          xml_parameters = params_template.result(binding)
          xml_in = template.result(binding)
          business_object = 'PORTOI'
          params = { 'UserId' => user_id,
                     'BusinessObject' => business_object,
                     'XmlParameters' => xml_parameters,
                     'XmlIn' => xml_in }
          resp = PorToi.post(params)
  
          parse_response(resp)
        end
  
        def template
          ERB.new File.read(File.expand_path('schemas/portoi_doc.xml.erb', File.dirname(__FILE__))), nil, '%'
        end
  
        def params_template
          ERB.new File.read(File.expand_path('schemas/portoi.xml.erb', File.dirname(__FILE__))), nil, '%'
        end
  
        def parse_response(resp)
          handle_errors(resp)
          parser = PorToiParser.new(resp[0].data)
          parser.parse
        end
  
        def render_xml(inner_text)
          inner_text ? inner_text.to_s : ''
        end
      end
    end
  end