From 6a873e0f4930b493f83e1810cc7948cd7cb12b85 Mon Sep 17 00:00:00 2001 From: chadzink Date: Thu, 17 Jan 2019 11:49:24 -0800 Subject: [PATCH] Implement PorTii business object (#17) --- lib/syspro.rb | 3 +++ lib/syspro/business_objects/models/inventory_inspection.rb | 15 +++++++++++++++ lib/syspro/business_objects/parsers/portii_parser.rb | 27 +++++++++++++++++++++++++++ lib/syspro/business_objects/portii.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/syspro/business_objects/schemas/portii.xml.erb | 8 ++++++++ lib/syspro/business_objects/schemas/portii_doc.xml.erb | 11 +++++++++++ test/portii_test.rb | 30 ++++++++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 0 deletions(-) create mode 100644 lib/syspro/business_objects/models/inventory_inspection.rb create mode 100644 lib/syspro/business_objects/parsers/portii_parser.rb create mode 100644 lib/syspro/business_objects/portii.rb create mode 100644 lib/syspro/business_objects/schemas/portii.xml.erb create mode 100644 lib/syspro/business_objects/schemas/portii_doc.xml.erb create mode 100644 test/portii_test.rb diff --git a/lib/syspro.rb b/lib/syspro.rb index 1cdd3fc..8af8aba 100644 --- a/lib/syspro.rb +++ b/lib/syspro.rb @@ -36,6 +36,7 @@ require 'syspro/business_objects/porqry' require 'syspro/business_objects/comsfm' require 'syspro/business_objects/invsws' require 'syspro/business_objects/invqry' +require 'syspro/business_objects/portii' require 'syspro/business_objects/models/sor' require 'syspro/business_objects/models/sor_detail' @@ -52,6 +53,7 @@ require 'syspro/business_objects/models/comsfm_item' require 'syspro/business_objects/models/invsws_item' require 'syspro/business_objects/models/inv' require 'syspro/business_objects/models/receipt_interospection' +require 'syspro/business_objects/models/inventory_inspection' require 'syspro/business_objects/parsers/combrw_parser' require 'syspro/business_objects/parsers/comfch_parser' @@ -62,6 +64,7 @@ require 'syspro/business_objects/parsers/portoi_parser' require 'syspro/business_objects/parsers/comsfm_parser' require 'syspro/business_objects/parsers/invsws_parser' require 'syspro/business_objects/parsers/invqry_parser' +require 'syspro/business_objects/parsers/portii_parser' # Main Module module Syspro diff --git a/lib/syspro/business_objects/models/inventory_inspection.rb b/lib/syspro/business_objects/models/inventory_inspection.rb new file mode 100644 index 0000000..3928874 --- /dev/null +++ b/lib/syspro/business_objects/models/inventory_inspection.rb @@ -0,0 +1,15 @@ +module Syspro + module BusinessObjects + module Models + class InventoryInspection + attr_accessor :grn_number, + :quantity, + :unit_of_measure, + :units, + :pieces, + :document, + :inspection_completed + end + end + end +end \ No newline at end of file diff --git a/lib/syspro/business_objects/parsers/portii_parser.rb b/lib/syspro/business_objects/parsers/portii_parser.rb new file mode 100644 index 0000000..7b65a7f --- /dev/null +++ b/lib/syspro/business_objects/parsers/portii_parser.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Syspro + module BusinessObjects + module Parsers + class PorTiiParser + attr_reader :doc + + def initialize(doc) + @doc = doc + end + + def parse + { + error_numbers: doc.xpath("//ErrorNumber").map{|e| e.text}, + grn_numbers: doc.xpath("//Item/Key/GRNNumber").map{|e| e.text}, + items_processed: doc.xpath("//StatusOfItems/ItemsProcessed").first.text, + items_invalid: doc.xpath("//StatusOfItems/ItemsInvalid").first.text + } + end + + PorToiObject = Struct.new(:key, :receipts) + end + end + end +end + diff --git a/lib/syspro/business_objects/portii.rb b/lib/syspro/business_objects/portii.rb new file mode 100644 index 0000000..2de86ac --- /dev/null +++ b/lib/syspro/business_objects/portii.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'syspro/business_objects/parsers/portii_parser' +require 'erb' + +module Syspro + module BusinessObjects + class PorTii < ApiResource + include Syspro::ApiOperations::Transaction + include Syspro::BusinessObjects::Parsers + + # input params + attr_accessor :transaction_date, + :ignore_warnings, + :apply_if_entire_document_valid, + :validate_only, + :item_inspected + + def call(user_id) + xml_parameters = params_template.result(binding) + xml_in = template.result(binding) + business_object = 'PORTII' + params = { 'UserId' => user_id, + 'BusinessObject' => business_object, + 'XmlParameters' => xml_parameters, + 'XmlIn' => xml_in } + resp = PorTii.post(params) + + parse_response(resp) + end + + def template + ERB.new File.read(File.expand_path('schemas/portii_doc.xml.erb', File.dirname(__FILE__))), nil, '%' + end + + def params_template + ERB.new File.read(File.expand_path('schemas/portii.xml.erb', File.dirname(__FILE__))), nil, '%' + end + + def parse_response(resp) + handle_errors(resp) + parser = PorTiiParser.new(resp[0].data) + parser.parse + end + + def render_xml(inner_text, dflt_value = "") + inner_text ? inner_text.to_s : dflt_value + end + end + end +end + diff --git a/lib/syspro/business_objects/schemas/portii.xml.erb b/lib/syspro/business_objects/schemas/portii.xml.erb new file mode 100644 index 0000000..555a601 --- /dev/null +++ b/lib/syspro/business_objects/schemas/portii.xml.erb @@ -0,0 +1,8 @@ + + + <%= render_xml(@transaction_date, Time.now.strftime("%Y-%m-%d"))%> + <%= render_xml(@ignore_warnings, "N")%> + <%= render_xml(@apply_if_entire_document_valid, "Y")%> + <%= render_xml(@validate_only, "N")%> + + \ No newline at end of file diff --git a/lib/syspro/business_objects/schemas/portii_doc.xml.erb b/lib/syspro/business_objects/schemas/portii_doc.xml.erb new file mode 100644 index 0000000..983fabd --- /dev/null +++ b/lib/syspro/business_objects/schemas/portii_doc.xml.erb @@ -0,0 +1,11 @@ + + + <%= render_xml(@item_inspected.grn_number)%> + <%= render_xml(@item_inspected.quantity)%> + <%= render_xml(@item_inspected.unit_of_measure)%> + <%= render_xml(@item_inspected.units)%> + <%= render_xml(@item_inspected.pieces)%> + <%= render_xml(@item_inspected.document)%> + <%= render_xml(@item_inspected.inspection_completed)%> + + \ No newline at end of file diff --git a/test/portii_test.rb b/test/portii_test.rb new file mode 100644 index 0000000..545acbd --- /dev/null +++ b/test/portii_test.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'test_helper' + +class PorTiiTest < Minitest::Test + extend Minitest::Spec::DSL + + let(:username) { ENV['SYSPRO_USERNAME'] } + let(:password) { ENV['SYSPRO_PASSWORD'] } + let(:company) { ENV['SYSPRO_COMPANY'] } + let(:company_password) { '' } + let(:user_id) do + Syspro::Logon.logon(username, password, company, company_password) + end + + def test_portii + req = Syspro::BusinessObjects::PorTii.new + + req.item_inspected = Syspro::BusinessObjects::Models::InventoryInspection.new + req.item_inspected.grn_number = "P00012509" + req.item_inspected.quantity = 12.312 + req.item_inspected.inspection_completed = "Y" + + resp = req.call(user_id.guid) + + assert_equal resp.has_key?(:grn_numbers), true + assert_equal resp.has_key?(:items_processed), true + assert_equal resp.has_key?(:items_invalid), true + end +end \ No newline at end of file -- libgit2 0.21.4