Module: Twinfield::Helpers::TransactionMatch
- Included in:
- Browse::Transaction::CostCenter, Browse::Transaction::Customer, Browse::Transaction::GeneralLedger, Transaction
- Defined in:
- lib/twinfield/helpers/transaction_match.rb
Instance Method Summary collapse
- #match!(other_transaction) ⇒ Object
- #to_match_xml(other_transaction) ⇒ Object
- #to_transaction_match_line_xml(transline) ⇒ Object
Instance Method Details
#match!(other_transaction) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/twinfield/helpers/transaction_match.rb', line 25 def match! other_transaction response = Twinfield::Api::Process.request do to_match_xml(other_transaction) end xml = Nokogiri::XML(response.body[:process_xml_string_response][:process_xml_string_result]) if xml.at_css("match").attributes["result"].value == "1" self else raise Twinfield::TransactionMatchError.new(xml.css("[msg]").map { |x| x.attributes["msg"].value }.join(" ") + "(possibly a non-matching invoice number)") end end |
#to_match_xml(other_transaction) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/twinfield/helpers/transaction_match.rb', line 10 def to_match_xml other_transaction raise Twinfield::TransactionMatchError.new("This transaction and the other transaction don't add up to 0") if (value + other_transaction.value) != 0 "<match> <set> <matchcode>170</matchcode> <office>#{Twinfield.configuration.company}</office> <matchdate>#{Date.today.strftime("%Y%m%d")}</matchdate> <lines> #{to_transaction_match_line_xml(1)} #{other_transaction.to_transaction_match_line_xml(2)} </lines> </set> </match>" end |
#to_transaction_match_line_xml(transline) ⇒ Object
6 7 8 |
# File 'lib/twinfield/helpers/transaction_match.rb', line 6 def to_transaction_match_line_xml(transline) "<line><transcode>#{code}</transcode><transnumber>#{number}</transnumber><transline>#{transline}</transline></line>" end |