diff --git a/lib/syspro.rb b/lib/syspro.rb index ee4cc4e..dfa2a8d 100644 --- a/lib/syspro.rb +++ b/lib/syspro.rb @@ -34,6 +34,7 @@ require 'syspro/business_objects/portor' require 'syspro/business_objects/portoi' require 'syspro/business_objects/porqry' require 'syspro/business_objects/comsfm' +require 'syspro/business_objects/invsws' require 'syspro/business_objects/invqry' require 'syspro/business_objects/models/sor' @@ -48,6 +49,7 @@ require 'syspro/business_objects/models/purchase_orders/freight_line' require 'syspro/business_objects/models/purchase_orders/misc_charge_line' require 'syspro/business_objects/models/purchase_orders/comment_line' require 'syspro/business_objects/models/comsfm_item' +require 'syspro/business_objects/models/invsws_item' require 'syspro/business_objects/models/inv' require 'syspro/business_objects/parsers/combrw_parser' @@ -57,6 +59,7 @@ require 'syspro/business_objects/parsers/sorqry_parser' require 'syspro/business_objects/parsers/portor_parser' 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' # Main Module diff --git a/lib/syspro/business_objects/comsfm.rb b/lib/syspro/business_objects/comsfm.rb index 8d337fc..158e2f5 100644 --- a/lib/syspro/business_objects/comsfm.rb +++ b/lib/syspro/business_objects/comsfm.rb @@ -12,7 +12,7 @@ module Syspro attr_accessor :validate_only, :items - def call(user_id) + def add(user_id) xml_parameters = params_template.result(binding) xml_in = template.result(binding) business_object = 'COMSFM' diff --git a/lib/syspro/business_objects/invsws.rb b/lib/syspro/business_objects/invsws.rb new file mode 100644 index 0000000..765d46d --- /dev/null +++ b/lib/syspro/business_objects/invsws.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'syspro/business_objects/parsers/invsws_parser' +require 'erb' + +module Syspro + module BusinessObjects + class InvSws < ApiResource + include Syspro::ApiOperations::Setup + include Syspro::BusinessObjects::Parsers + + attr_accessor :validate_only, + :apply_product_class_default, + :ignore_warnings, + :apply_if_entire_document_valid, + :item + + def add(user_id) + xml_parameters = params_template.result(binding) + xml_in = template.result(binding) + business_object = 'INVSWS' + params = { 'UserId' => user_id, + 'BusinessObject' => business_object, + 'XmlParameters' => xml_parameters, + 'XmlIn' => xml_in } + resp = InvSws.add(params) + + parse_response(resp) + end + + def template + ERB.new File.read(File.expand_path('schemas/invsws_doc.xml.erb', File.dirname(__FILE__))), nil, '%' + end + + def params_template + ERB.new File.read(File.expand_path('schemas/invsws.xml.erb', File.dirname(__FILE__))), nil, '%' + end + + def parse_response(resp) + handle_errors(resp) + parser = InvSwsParser.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/models/invsws_item.rb b/lib/syspro/business_objects/models/invsws_item.rb new file mode 100644 index 0000000..30367a8 --- /dev/null +++ b/lib/syspro/business_objects/models/invsws_item.rb @@ -0,0 +1,47 @@ +module Syspro + module BusinessObjects + module Models + class InvSwsItem + attr_accessor :key_stock_code, + :key_warehouse, + :cost_multiplier, + :minimum_qty, + :maximum_qty, + :unit_cost, + :default_bin, + :safety_stock_qty, + :re_order_qty, + :pallet_qty, + :user_field1, + :user_field2, + :user_field3, + :order_policy, + :major_order_mult, + :minor_order_mult, + :order_minimum, + :order_maximum, + :order_fix_period, + :trf_supplied_item, + :default_source_wh, + :trf_lead_time, + :trf_cost_gl_code, + :trf_cost_multiply, + :trf_replenish_wh, + :trf_buying_rule, + :trf_dock_to_stock, + :trf_fix_time_period, + :labour_cost, + :material_cost, + :fixed_overhead, + :variable_overhead, + :sub_contract_cost, + :manual_cost_flag, + :e_signature + end + + class InvSwsItemKey + attr_accessor + end + end + end +end \ No newline at end of file diff --git a/lib/syspro/business_objects/parsers/invsws_parser.rb b/lib/syspro/business_objects/parsers/invsws_parser.rb new file mode 100644 index 0000000..ee00298 --- /dev/null +++ b/lib/syspro/business_objects/parsers/invsws_parser.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Syspro + module BusinessObjects + module Parsers + class InvSwsParser + attr_reader :doc + + def initialize(doc) + @doc = doc + end + + def parse + { + "key": { + "stock_code": doc.xpath("//item/key/stockcode").map{|e| e.text}.first, + "warehouse": doc.xpath("//item/key/stockcode").map{|e| e.text}.first + }, + "reacords_read": doc.xpath("//StatusOfItems/RecordsRead").map{|e| e.text}.first, + "reacords_invalid": doc.xpath("//StatusOfItems/RecordsInvalid").map{|e| e.text}.first, + "error_numbers": doc.xpath("//ErrorNumber").map{|e| e.text} + } + end + end + end + end +end + diff --git a/lib/syspro/business_objects/schemas/invsws.xml.erb b/lib/syspro/business_objects/schemas/invsws.xml.erb new file mode 100644 index 0000000..e9ee74d --- /dev/null +++ b/lib/syspro/business_objects/schemas/invsws.xml.erb @@ -0,0 +1,8 @@ + + + <%= render_xml(@apply_product_class_default, "BA") %> + <%= render_xml(@ignore_warnings, "N") %> + <%= render_xml(@apply_if_entire_document_valid, "Y") %> + <%= render_xml(@validate_only, "N") %> + + diff --git a/lib/syspro/business_objects/schemas/invsws_doc.xml.erb b/lib/syspro/business_objects/schemas/invsws_doc.xml.erb new file mode 100644 index 0000000..b4a6c37 --- /dev/null +++ b/lib/syspro/business_objects/schemas/invsws_doc.xml.erb @@ -0,0 +1,43 @@ + + + + <%= render_xml(@item.key_stock_code) %> + <%= render_xml(@item.key_warehouse) %> + + <%= render_xml(@item.cost_multiplier, "1.0") %> + <%= render_xml(@item.minimum_qty) %> + <%= render_xml(@item.maximum_qty) %> + <%= render_xml(@item.unit_cost) %> + <%= render_xml(@item.default_bin, "FG") %> + <%= render_xml(@item.safety_stock_qty) %> + <%= render_xml(@item.re_order_qty) %> + <%= render_xml(@item.pallet_qty) %> + <%= render_xml(@item.user_field1) %> + <%= render_xml(@item.user_field2) %> + <%= render_xml(@item.user_field3) %> + <%= render_xml(@item.order_policy, "C") %> + <%= render_xml(@item.major_order_mult) %> + <%= render_xml(@item.minor_order_mult) %> + <%= render_xml(@item.order_minimum) %> + <%= render_xml(@item.order_maximum) %> + <%= render_xml(@item.order_fix_period, "01") %> + <%= render_xml(@item.trf_supplied_item, "N") %> + <%= render_xml(@item.default_source_wh) %> + <%= render_xml(@item.trf_lead_time, "0") %> + <%= render_xml(@item.trf_cost_gl_code) %> + <%= render_xml(@item.trf_cost_multiply) %> + <%= render_xml(@item.trf_replenish_wh, "0") %> + <%= render_xml(@item.trf_buying_rule, "A") %> + <%= render_xml(@item.trf_dock_to_stock) %> + <%= render_xml(@item.trf_fix_time_period) %> + <%= render_xml(@item.labour_cost) %> + <%= render_xml(@item.material_cost) %> + <%= render_xml(@item.fixed_overhead) %> + <%= render_xml(@item.variable_overhead) %> + <%= render_xml(@item.sub_contract_cost) %> + <%= render_xml(@item.manual_cost_flag, "N") %> + <% if @item.e_signature %> + <%= render_xml(@item.e_signature) %> + <% end %> + + \ No newline at end of file diff --git a/test/comsfm_test.rb b/test/comsfm_test.rb index 32e1708..c969b6c 100644 --- a/test/comsfm_test.rb +++ b/test/comsfm_test.rb @@ -24,7 +24,7 @@ class ComsFmTest < Minitest::Test cust_form.validate_only = "Y" cust_form.items = [cust_item] - errors = cust_form.call(user_id.guid) + errors = cust_form.add(user_id.guid) assert_equal errors.length, 0 end diff --git a/test/invsws_test.rb b/test/invsws_test.rb new file mode 100644 index 0000000..ff6becf --- /dev/null +++ b/test/invsws_test.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ComsFmTest < 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_comsfm + invsws_item = Syspro::BusinessObjects::Models::InvSwsItem.new + invsws_item.key_stock_code = "1003" + invsws_item.key_warehouse = "P0" + invsws_item.default_bin = "P0" + + invsws_req = Syspro::BusinessObjects::InvSws.new + invsws_req.validate_only = "Y" + invsws_req.apply_product_class_default = "BA" + invsws_req.ignore_warnings = "N" + invsws_req.apply_if_entire_document_valid = "Y" + invsws_req.item = invsws_item + + invsws_resp = invsws_req.add(user_id.guid) + + assert_equal invsws_resp[:error_numbers].length, 0 + end +end \ No newline at end of file -- libgit2 0.21.4