diff --git a/lib/syspro.rb b/lib/syspro.rb index dfa2a8d..1cdd3fc 100644 --- a/lib/syspro.rb +++ b/lib/syspro.rb @@ -51,6 +51,7 @@ 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/models/receipt_interospection' require 'syspro/business_objects/parsers/combrw_parser' require 'syspro/business_objects/parsers/comfch_parser' diff --git a/lib/syspro/business_objects/models/receipt_interospection.rb b/lib/syspro/business_objects/models/receipt_interospection.rb new file mode 100644 index 0000000..ad9484c --- /dev/null +++ b/lib/syspro/business_objects/models/receipt_interospection.rb @@ -0,0 +1,16 @@ +module Syspro + module BusinessObjects + module Models + class ReceiptInterospection + attr_accessor :purchase_order, + :warehouse, + :stock_code, + :quantity, + :counted_quantity_complete, + :delivery_note, + :certificate, + :lot + end + end + end +end \ No newline at end of file diff --git a/lib/syspro/business_objects/parsers/portor_parser.rb b/lib/syspro/business_objects/parsers/portor_parser.rb index 44371e0..f00affa 100644 --- a/lib/syspro/business_objects/parsers/portor_parser.rb +++ b/lib/syspro/business_objects/parsers/portor_parser.rb @@ -11,6 +11,8 @@ module Syspro end def parse + error_numbers = doc.xpath("//ErrorNumber").map{|e| e.text} + gl_journal = doc.first_element_child.xpath('GlJournal') gl_journal_obj = gl_journal.children.map do |el| next if el.name == 'text' @@ -27,7 +29,7 @@ module Syspro key[:entry_number] = doc.first_element_child.xpath('EntryNumber') key[:warehouse] = doc.first_element_child.xpath('Warehouse') key[:gl_journal] = gl_journal_obj - + receipts = doc.first_element_child.xpath('Receipt') receipts_obj = receipts.flat_map do |el| el.elements.map do |inner| @@ -45,13 +47,15 @@ module Syspro ) end - PorTorObject.new( - key, - receipt_models - ) + grns = doc.xpath("//Grn").map{|e| e.text} + + { + error_numbers: error_numbers, + key: key, + receipt: receipt_models, + grns: grns + } end - - PorTorObject = Struct.new(:key, :receipts) end end end diff --git a/lib/syspro/business_objects/portor.rb b/lib/syspro/business_objects/portor.rb index 05914ab..5a17d90 100644 --- a/lib/syspro/business_objects/portor.rb +++ b/lib/syspro/business_objects/portor.rb @@ -9,30 +9,36 @@ module Syspro include Syspro::ApiOperations::Transaction include Syspro::BusinessObjects::Parsers - attr_accessor :transaction_date, :ignore_warnings, :non_stocked_wh_to_use, :grn_matching_action, - :allow_blank_supplier, :apply_if_entire_document_valid, :validate_only, - :manual_serial_transfers_allowed, :ignore_analysis + attr_accessor :transaction_date, + :ignore_warnings, + :non_stocked_wh_to_use, + :grn_matching_action, + :allow_blank_supplier, + :apply_if_entire_document_valid, + :validate_only, + :manual_serial_transfers_allowed, + :ignore_analysis, + # :receipts # NOT implemented yet + :receipt_interospections def call(user_id) - raise NotImplementedError.new("PORTOR not implemented yet.") - #xml_parameters = params_template.result(binding) - #xml_in = template.result(binding) - #business_object = 'PORTOR' - #params = { 'UserId' => user_id, - #'BusinessObject' => business_object, - #'XmlParameters' => xml_parameters, - #'XmlIn' => xml_in } - #resp = PorTor.post(params) - - #parse_response(resp) + xml_parameters = params_template.result(binding) + xml_in = template.result(binding) + business_object = 'PORTOR' + params = { 'UserId' => user_id, + 'BusinessObject' => business_object, + 'XmlParameters' => xml_parameters, + 'XmlIn' => xml_in } + resp = PorTor.post(params) + parse_response(resp) end def template - ERB.new File.read(File.expand_path('schemas/portor.xml.erb', File.dirname(__FILE__))), nil, '%' + ERB.new File.read(File.expand_path('schemas/portor_doc.xml.erb', File.dirname(__FILE__))), nil, '%' end def params_template - ERB.new File.read(File.expand_path('schemas/portor_doc.xml.erb', File.dirname(__FILE__))), nil, '%' + ERB.new File.read(File.expand_path('schemas/portor.xml.erb', File.dirname(__FILE__))), nil, '%' end def parse_response(resp) @@ -40,6 +46,10 @@ module Syspro parser = PorTorParser.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/portor.xml.erb b/lib/syspro/business_objects/schemas/portor.xml.erb index 0ed2c23..f7ed985 100644 --- a/lib/syspro/business_objects/schemas/portor.xml.erb +++ b/lib/syspro/business_objects/schemas/portor.xml.erb @@ -1,227 +1,14 @@ - - - - - - - 436 - 1 - - - 750.000 - - - - - - P - N - 311 - - 1 - N - - - - - - A1 - 750.000 - - - - - 0205 - 1 - - - - - - - 999 - 1 - - 8 - - - - N - N - N - Y - - 150.00 - - Cost Ref - 00-1170 - 0000026 - 150.00 - - - Air - Conf - East - - - - - 100 - Analysis entry details - - - - Air - Conf - East - - - - - 100 - Analysis entry details - - - P/O Receipt note - 00-1540 - - - - - - - - - - - N - - - - Air - Conf - East - - - - - 100 - Analysis entry details - - - - Air - Conf - East - - - - - 100 - Analysis entry details - - - - - - - - 436 - 2 - - - 50.000 - - - - N - - - - - N - 301 - - - N - - 0205 - 50 - - - - - - - 98 - 1 - - 8 - - - - - - - - - - 312 - 10.000 - - - - - - P - - 1 - N - - A1 - 10.000 - - - - N - - 0205 - 1 - - - - - - N - N - Y - - 150.00 - - Cost Ref - 30-4400 - - 150.00 - - P/O Receipt note - 00-1540 - - - - - - - - - - - N - - - - - + + + <%= render_xml(@transaction_date) %> + <%= render_xml(@ignore_warnings, "N") %> + <%= render_xml(@non_stocked_wh_to_use) %> + <%= render_xml(@grn_matching_action, "A") %> + <%= render_xml(@allow_blank_supplier, "N")%> + <%= render_xml(@apply_if_entire_document_valid, "N")%> + <%= render_xml(@validate_only, "N")%> + <%= render_xml(@manual_serial_transfers_allowed, "N")%> + <%= render_xml(@ignore_analysis, "N")%> + + \ No newline at end of file diff --git a/lib/syspro/business_objects/schemas/portor_doc.xml.erb b/lib/syspro/business_objects/schemas/portor_doc.xml.erb index 21687fa..67554d4 100644 --- a/lib/syspro/business_objects/schemas/portor_doc.xml.erb +++ b/lib/syspro/business_objects/schemas/portor_doc.xml.erb @@ -1,15 +1,23 @@ - - - <%= @transaction_date %> - <%= @ignore_warnings ? "N" : "Y"%> - <%= @non_stocked_wh_to_use %> - <%= @grn_matching_action %> - <%= @allow_blank_supplier ? "N" : "Y" %> - <%= @apply_if_entire_document_valid ? "N" : "Y" %> - <%= @validate_only ? "N" : "Y" %> - <%= @manual_serial_transfers_allowed ? "N" : "Y" %> - <%= @ignore_analysis ? "N" : "Y" %> - - - + + <% + if receipt_interospections + @receipt_interospections.each do |interospection_item| + %> + + + <%= render_xml(interospection_item.purchase_order)%> + <%= render_xml(interospection_item.warehouse)%> + <%= render_xml(interospection_item.stock_code)%> + <%= render_xml(interospection_item.quantity)%> + <%= render_xml(interospection_item.counted_quantity_complete, "Y")%> + <%= render_xml(interospection_item.delivery_note)%> + <%= render_xml(interospection_item.certificate)%> + <%= render_xml(interospection_item.lot)%> + + + <% + end + end + %> + \ No newline at end of file diff --git a/test/invsws_test.rb b/test/invsws_test.rb index ff6becf..c422872 100644 --- a/test/invsws_test.rb +++ b/test/invsws_test.rb @@ -13,7 +13,7 @@ class ComsFmTest < Minitest::Test Syspro::Logon.logon(username, password, company, company_password) end - def test_comsfm + def test_invsws invsws_item = Syspro::BusinessObjects::Models::InvSwsItem.new invsws_item.key_stock_code = "1003" invsws_item.key_warehouse = "P0" diff --git a/test/portor_test.rb b/test/portor_test.rb new file mode 100644 index 0000000..0507c3e --- /dev/null +++ b/test/portor_test.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'test_helper' + +class PorTorTest < 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_portor + receipt_intero = Syspro::BusinessObjects::Models::ReceiptInterospection.new + receipt_intero.purchase_order = "Z01310" + receipt_intero.warehouse = "P0" + receipt_intero.stock_code = "8801" + receipt_intero.quantity = 10.21 + receipt_intero.delivery_note = "DELIVER NOTE HERE-WL" + receipt_intero.certificate = "8/45-3" + receipt_intero.lot = "7097505" + + req = Syspro::BusinessObjects::PorTor.new + req.transaction_date = Time.now.strftime("%Y-%m-%d") + req.ignore_warnings = "N" + + req.receipt_interospections = [receipt_intero] + resp = req.call(user_id.guid) + + assert_equal resp[:error_numbers].length, 0 + end +end \ No newline at end of file -- libgit2 0.21.4