diff --git a/lib/syspro.rb b/lib/syspro.rb index 46e947d..2228d96 100644 --- a/lib/syspro.rb +++ b/lib/syspro.rb @@ -25,10 +25,12 @@ require 'syspro/api_operations/query' require 'syspro/business_objects/combrw' require 'syspro/business_objects/comfch' require 'syspro/business_objects/comfnd' +require 'syspro/business_objects/sorqbs' require 'syspro/business_objects/parsers/combrw_parser' require 'syspro/business_objects/parsers/comfch_parser' require 'syspro/business_objects/parsers/comfnd_parser' +require 'syspro/business_objects/parsers/sorqbs_parser' # Main Module module Syspro diff --git a/lib/syspro/api_operations/query.rb b/lib/syspro/api_operations/query.rb index ab8af04..fc54287 100644 --- a/lib/syspro/api_operations/query.rb +++ b/lib/syspro/api_operations/query.rb @@ -16,8 +16,6 @@ module Syspro request(:get, '/Query/Query', params) end - def find; end - private def warn_on_opts_in_params(params) diff --git a/lib/syspro/business_objects/models/sor.rb b/lib/syspro/business_objects/models/sor.rb new file mode 100644 index 0000000..e970e32 --- /dev/null +++ b/lib/syspro/business_objects/models/sor.rb @@ -0,0 +1,16 @@ +module Syspro + module BusinessObjects + module Models + class Sor + attr_accessor :customer, :name, :customer_po_number, :cust_stock_code, :stock_code, :description, + :supply_wh, :release_manager, :release_status, :purchase_order, :shipment_days, + :num_day_drops, :num_week_drops, :day_in_week, :num_month_drops, :day_in_month, + :price_contract_num, :stock_uom, :contract_qty, :total_delivered, :total_received, + :opening_cume, :data_last_inv, :base_date, :expiry_date, :last_invoice, :buying_group, + :last_dispatch_note, :confirmed_release_details, :unconfirmed_release_details, :release_details, + :delivery_history_details, :release_history_details, :sor_detail, :contract_item + end + end + end +end + diff --git a/lib/syspro/business_objects/parsers/sorqbs_parser.rb b/lib/syspro/business_objects/parsers/sorqbs_parser.rb new file mode 100644 index 0000000..6cbe183 --- /dev/null +++ b/lib/syspro/business_objects/parsers/sorqbs_parser.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Syspro + module BusinessObjects + module Parsers + class SorQbs + attr_reader :doc + + def initialize(doc) + @doc = doc + end + + def parse + binding.pry + sor = Syspro::BusinessObjects::Models::Sor.new() + end + end + end + end +end + diff --git a/lib/syspro/business_objects/schemas/sorqbs.xml.erb b/lib/syspro/business_objects/schemas/sorqbs.xml.erb new file mode 100644 index 0000000..15e5ae7 --- /dev/null +++ b/lib/syspro/business_objects/schemas/sorqbs.xml.erb @@ -0,0 +1,20 @@ + + + + <% unless @filters.empty? %> + + <% for filter in @filters %> + <<%= filter[:name] %> FilterType="<% filter[:type] %>" FilterValue="<% filter[:value] %>"/> + <% end %> + + <% end %> + + diff --git a/lib/syspro/business_objects/sorqbs.rb b/lib/syspro/business_objects/sorqbs.rb new file mode 100644 index 0000000..fba668b --- /dev/null +++ b/lib/syspro/business_objects/sorqbs.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'syspro/business_objects/parsers/sorqbs_parser' +require 'erb' + +module Syspro + module BusinessObjects + class SorQbs < ApiResource + include Syspro::ApiOperations::Query + include Syspro::BusinessObjects::Parsers + + attr_accessor :include_sales_order_details, :include_contact_details, :include_delivery_history, + :include_unconfirmed_releases, :include_confirmed_releases, :include_release_details, + :include_release_history, :filters + + def call(user_id) + xml_in = template.result(binding) + business_object = 'SORQBS' + params = { 'UserId' => user_id, 'BusinessObject' => business_object, 'XmlIn' => xml_in } + resp = SorQbs.query(params) + parse_response(resp) + end + + def template + ERB.new File.read(File.expand_path('schemas/sorqbs.xml.erb', File.dirname(__FILE__))), nil, '%' + end + + def parse_response(resp) + handle_errors(resp) + parser = SorQbsParser.new(respo[0].data) + parser.parse + end + + def handle_errors(resp) + body = resp[0].http_body + raise SysproError, body if body =~ /^(ERROR)/ + end + end + end +end + diff --git a/test/cassettes/test_sor_query.yml b/test/cassettes/test_sor_query.yml new file mode 100644 index 0000000..969c0b8 --- /dev/null +++ b/test/cassettes/test_sor_query.yml @@ -0,0 +1,70 @@ +--- +http_interactions: +- request: + method: get + uri: http://syspro.wildlandlabs.com:90/SYSPROWCFService/Rest/logon?CompanyId=L&CompanyPassword=&Operator=wland&OperatorPassword=piperita2016 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Syspro/7 RubyBindings/1.0.0.alpha.1 + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Length: + - '36' + Content-Type: + - application/octet-stream + Server: + - Microsoft-HTTPAPI/2.0 + Date: + - Wed, 11 Apr 2018 19:00:49 GMT + body: + encoding: UTF-8 + string: 'E621DED6B5E98C4783D130230F6B29E700 ' + http_version: + recorded_at: Wed, 11 Apr 2018 19:00:49 GMT +- request: + method: get + uri: http://syspro.wildlandlabs.com:90/SYSPROWCFService/Rest/Query/Query?BusinessObject=SORQBS&UserId=E621DED6B5E98C4783D130230F6B29E700%20%20&XmlIn=%3C?xml%20version=%221.0%22%20encoding=%22Windows-1252%22?%3E%0A%3CQuery%20xmlns:xsd=%22http://www.w3.org/2001/XMLSchema-instance%22%20xsd:noNamespaceSchemaLocation=%22SORQBS.XSD%22%3E%0A%20%20%3COption%3E%0A%20%20%20%20%3CIncludeSalesOrderDetails%3Etrue%3C/IncludeSalesOrderDetails%3E%0A%20%20%20%20%3CIncludeContractDetails%3Etrue%3C/IncludeContractDetails%3E%0A%20%20%20%20%3CIncludeDeliveryHistory%3Etrue%3C/IncludeDeliveryHistory%3E%0A%20%20%20%20%3CIncludeUnconfirmedReleases%3Etrue%3C/IncludeUnconfirmedReleases%3E%0A%20%20%20%20%3CIncludeConfirmedReleases%3Etrue%3C/IncludeConfirmedReleases%3E%0A%20%20%20%20%3CIncludeReleaseDetails%3Etrue%3C/IncludeReleaseDetails%3E%0A%20%20%20%20%3CIncludeReleaseHistory%3Etrue%3C/IncludeReleaseHistory%3E%0A%20%20%3C/Option%3E%0A%20%20%20%0A%20%20%20%20%3CFilter%3E%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%3CCustomer%20FilterType=%22%22%20FilterValue=%22%22/%3E%0A%20%20%20%20%20%20%0A%20%20%20%20%3C/Filter%3E%0A%20%20%0A%3C/Query%3E%0A%0A + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Syspro/7 RubyBindings/1.0.0.alpha.1 + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Length: + - '102' + Content-Type: + - application/octet-stream + Server: + - Microsoft-HTTPAPI/2.0 + Date: + - Wed, 11 Apr 2018 19:00:53 GMT + body: + encoding: UTF-8 + string: 'ERROR: Access denied to Functional Area ''SorBlanketSo'' for operator + ''WLAND'' (Business Object ''SORQBS'')' + http_version: + recorded_at: Wed, 11 Apr 2018 19:00:53 GMT +recorded_with: VCR 4.0.0 diff --git a/test/sor_test.rb b/test/sor_test.rb new file mode 100644 index 0000000..0c91657 --- /dev/null +++ b/test/sor_test.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'test_helper' + +class SorTest < Minitest::Test + extend Minitest::Spec::DSL + before { VCR.insert_cassette name } + after { VCR.eject_cassette } + + let(:username) { 'wland' } + let(:password) { 'piperita2016' } + let(:company) { 'L' } + let(:company_password) { '' } + let(:user_id) do + Syspro::Logon.logon(username, password, company, company_password) + end + + def test_sor_query + sorqbs = Syspro::BusinessObjects::SorQbs.new + + sorqbs.include_sales_order_details = true + sorqbs.include_contact_details = true + sorqbs.include_delivery_history = true + sorqbs.include_unconfirmed_releases = true + sorqbs.include_confirmed_releases = true + sorqbs.include_release_details = true + sorqbs.include_release_history = true + sorqbs.filters = [ + { name: 'Customer', type: 'A', value: 'JJJ001' } + ] + + sor_result = sorqbs.call(user_id.guid) + refute_nil sor_result + end +end + -- libgit2 0.21.4