Commit 6a873e0f4930b493f83e1810cc7948cd7cb12b85

Authored by chadzink
Committed by GitHub
1 parent f1e2e13b

Implement PorTii business object (#17)

partial implement to get started
@@ -36,6 +36,7 @@ require 'syspro/business_objects/porqry' @@ -36,6 +36,7 @@ require 'syspro/business_objects/porqry'
36 require 'syspro/business_objects/comsfm' 36 require 'syspro/business_objects/comsfm'
37 require 'syspro/business_objects/invsws' 37 require 'syspro/business_objects/invsws'
38 require 'syspro/business_objects/invqry' 38 require 'syspro/business_objects/invqry'
  39 +require 'syspro/business_objects/portii'
39 40
40 require 'syspro/business_objects/models/sor' 41 require 'syspro/business_objects/models/sor'
41 require 'syspro/business_objects/models/sor_detail' 42 require 'syspro/business_objects/models/sor_detail'
@@ -52,6 +53,7 @@ require 'syspro/business_objects/models/comsfm_item' @@ -52,6 +53,7 @@ require 'syspro/business_objects/models/comsfm_item'
52 require 'syspro/business_objects/models/invsws_item' 53 require 'syspro/business_objects/models/invsws_item'
53 require 'syspro/business_objects/models/inv' 54 require 'syspro/business_objects/models/inv'
54 require 'syspro/business_objects/models/receipt_interospection' 55 require 'syspro/business_objects/models/receipt_interospection'
  56 +require 'syspro/business_objects/models/inventory_inspection'
55 57
56 require 'syspro/business_objects/parsers/combrw_parser' 58 require 'syspro/business_objects/parsers/combrw_parser'
57 require 'syspro/business_objects/parsers/comfch_parser' 59 require 'syspro/business_objects/parsers/comfch_parser'
@@ -62,6 +64,7 @@ require 'syspro/business_objects/parsers/portoi_parser' @@ -62,6 +64,7 @@ require 'syspro/business_objects/parsers/portoi_parser'
62 require 'syspro/business_objects/parsers/comsfm_parser' 64 require 'syspro/business_objects/parsers/comsfm_parser'
63 require 'syspro/business_objects/parsers/invsws_parser' 65 require 'syspro/business_objects/parsers/invsws_parser'
64 require 'syspro/business_objects/parsers/invqry_parser' 66 require 'syspro/business_objects/parsers/invqry_parser'
  67 +require 'syspro/business_objects/parsers/portii_parser'
65 68
66 # Main Module 69 # Main Module
67 module Syspro 70 module Syspro
lib/syspro/business_objects/models/inventory_inspection.rb 0 → 100644
  1 +module Syspro
  2 + module BusinessObjects
  3 + module Models
  4 + class InventoryInspection
  5 + attr_accessor :grn_number,
  6 + :quantity,
  7 + :unit_of_measure,
  8 + :units,
  9 + :pieces,
  10 + :document,
  11 + :inspection_completed
  12 + end
  13 + end
  14 + end
  15 +end
0 \ No newline at end of file 16 \ No newline at end of file
lib/syspro/business_objects/parsers/portii_parser.rb 0 → 100644
  1 +# frozen_string_literal: true
  2 +
  3 +module Syspro
  4 + module BusinessObjects
  5 + module Parsers
  6 + class PorTiiParser
  7 + attr_reader :doc
  8 +
  9 + def initialize(doc)
  10 + @doc = doc
  11 + end
  12 +
  13 + def parse
  14 + {
  15 + error_numbers: doc.xpath("//ErrorNumber").map{|e| e.text},
  16 + grn_numbers: doc.xpath("//Item/Key/GRNNumber").map{|e| e.text},
  17 + items_processed: doc.xpath("//StatusOfItems/ItemsProcessed").first.text,
  18 + items_invalid: doc.xpath("//StatusOfItems/ItemsInvalid").first.text
  19 + }
  20 + end
  21 +
  22 + PorToiObject = Struct.new(:key, :receipts)
  23 + end
  24 + end
  25 + end
  26 +end
  27 +
lib/syspro/business_objects/portii.rb 0 → 100644
  1 +# frozen_string_literal: true
  2 +
  3 +require 'syspro/business_objects/parsers/portii_parser'
  4 +require 'erb'
  5 +
  6 +module Syspro
  7 + module BusinessObjects
  8 + class PorTii < ApiResource
  9 + include Syspro::ApiOperations::Transaction
  10 + include Syspro::BusinessObjects::Parsers
  11 +
  12 + # input params
  13 + attr_accessor :transaction_date,
  14 + :ignore_warnings,
  15 + :apply_if_entire_document_valid,
  16 + :validate_only,
  17 + :item_inspected
  18 +
  19 + def call(user_id)
  20 + xml_parameters = params_template.result(binding)
  21 + xml_in = template.result(binding)
  22 + business_object = 'PORTII'
  23 + params = { 'UserId' => user_id,
  24 + 'BusinessObject' => business_object,
  25 + 'XmlParameters' => xml_parameters,
  26 + 'XmlIn' => xml_in }
  27 + resp = PorTii.post(params)
  28 +
  29 + parse_response(resp)
  30 + end
  31 +
  32 + def template
  33 + ERB.new File.read(File.expand_path('schemas/portii_doc.xml.erb', File.dirname(__FILE__))), nil, '%'
  34 + end
  35 +
  36 + def params_template
  37 + ERB.new File.read(File.expand_path('schemas/portii.xml.erb', File.dirname(__FILE__))), nil, '%'
  38 + end
  39 +
  40 + def parse_response(resp)
  41 + handle_errors(resp)
  42 + parser = PorTiiParser.new(resp[0].data)
  43 + parser.parse
  44 + end
  45 +
  46 + def render_xml(inner_text, dflt_value = "")
  47 + inner_text ? inner_text.to_s : dflt_value
  48 + end
  49 + end
  50 + end
  51 +end
  52 +
lib/syspro/business_objects/schemas/portii.xml.erb 0 → 100644
  1 +<PostInspections xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="PORTII.XSD">
  2 + <Parameters>
  3 + <TransactionDate><%= render_xml(@transaction_date, Time.now.strftime("%Y-%m-%d"))%></TransactionDate>
  4 + <IgnoreWarnings><%= render_xml(@ignore_warnings, "N")%></IgnoreWarnings>
  5 + <ApplyIfEntireDocumentValid><%= render_xml(@apply_if_entire_document_valid, "Y")%></ApplyIfEntireDocumentValid>
  6 + <ValidateOnly><%= render_xml(@validate_only, "N")%></ValidateOnly>
  7 + </Parameters>
  8 +</PostInspections>
0 \ No newline at end of file 9 \ No newline at end of file
lib/syspro/business_objects/schemas/portii_doc.xml.erb 0 → 100644
  1 +<PostInspections xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="PORTIIDOC.XSD">
  2 + <Item>
  3 + <GRNNumber><%= render_xml(@item_inspected.grn_number)%></GRNNumber>
  4 + <Quantity><%= render_xml(@item_inspected.quantity)%></Quantity>
  5 + <UnitOfMeasure><%= render_xml(@item_inspected.unit_of_measure)%></UnitOfMeasure>
  6 + <Units><%= render_xml(@item_inspected.units)%></Units>
  7 + <Pieces><%= render_xml(@item_inspected.pieces)%></Pieces>
  8 + <Document><%= render_xml(@item_inspected.document)%></Document>
  9 + <InspectionCompleted><%= render_xml(@item_inspected.inspection_completed)%></InspectionCompleted>
  10 + </Item>
  11 +</PostInspections>
0 \ No newline at end of file 12 \ No newline at end of file
test/portii_test.rb 0 → 100644
  1 +# frozen_string_literal: true
  2 +
  3 +require 'test_helper'
  4 +
  5 +class PorTiiTest < Minitest::Test
  6 + extend Minitest::Spec::DSL
  7 +
  8 + let(:username) { ENV['SYSPRO_USERNAME'] }
  9 + let(:password) { ENV['SYSPRO_PASSWORD'] }
  10 + let(:company) { ENV['SYSPRO_COMPANY'] }
  11 + let(:company_password) { '' }
  12 + let(:user_id) do
  13 + Syspro::Logon.logon(username, password, company, company_password)
  14 + end
  15 +
  16 + def test_portii
  17 + req = Syspro::BusinessObjects::PorTii.new
  18 +
  19 + req.item_inspected = Syspro::BusinessObjects::Models::InventoryInspection.new
  20 + req.item_inspected.grn_number = "P00012509"
  21 + req.item_inspected.quantity = 12.312
  22 + req.item_inspected.inspection_completed = "Y"
  23 +
  24 + resp = req.call(user_id.guid)
  25 +
  26 + assert_equal resp.has_key?(:grn_numbers), true
  27 + assert_equal resp.has_key?(:items_processed), true
  28 + assert_equal resp.has_key?(:items_invalid), true
  29 + end
  30 +end
0 \ No newline at end of file 31 \ No newline at end of file