Half-Penny For Your Thoughts

rounded down to the nearest cent



Categories


Recent Articles




Computing

QBFC and Ruby

I discovered how to use QBFC with Ruby. QBFC is part of the Quickbooks SDK and is a fairly basic wrapper around QBXML. To me, it’s not the simplest interface, but it’s a nice not to bother with the XML, as I’ve been doing. Whereas when using QBXML, you would call WIN32OLE.new(“QBXMLRP2.RequestProcessor”), use WIN32OLE.new(“QBFC6.QBSessionManager”) instead.

Here’s quick example:

require 'win32ole'

qb = WIN32OLE.new("QBFC6.QBSessionManager")

qb.OpenConnection2 "", "Ruby Test", 1 # 1 is ctLocalQBD
qb.BeginSession("", 2) # 2 is omDontCare

request_set = qb.CreateMsgSetRequest("US", 6, 0)
customer_query = request_set.AppendCustomerQueryRq

response = qb.DoRequests(request_set)
customer_set = response.ResponseList.GetAt(0)
first_customer = customer_set.Detail.GetAt(0)
puts first_customer.FullName.GetValue

qb.EndSession
qb.CloseConnection
qb = nil 

Now, I like to wrap all that opening and closing connection stuff in a block, so here’s a version I like a bit better:

require 'win32ole'

OPEN_MODES = {
  :single => 0,
  :multi  => 1,
  :either => 2
}

def session(app_name, options = {})
  com_obj = WIN32OLE.new("QBFC6.QBSessionManager")
  com_obj.OpenConnection2(options[:app_id].to_s, app_name, 1) # 1 is ctLocalQBD

      open_mode = OPEN_MODES[options[:open_mode].to_s] || 2 # :either is default
  com_obj.BeginSession(options[:filename].to_s, open_mode)
  
  begin
    yield(com_obj)
  ensure
    com_obj.EndSession
    com_obj.CloseConnection
    com_obj = nil
  end
end

session("Test Application") do | qb |
  request_set = qb.CreateMsgSetRequest("US", 6, 0)
  customer_query = request_set.AppendCustomerQueryRq

  response = qb.DoRequests(request_set)
  customer_set = response.ResponseList.GetAt(0)
  first_customer = customer_set.Detail.GetAt(0)
  puts first_customer.FullName.GetValue
end

And, finally, a bit of playing with WIN32OLE (risky, most likely):

require 'win32ole'

unless Object.const_defined?(:ActiveSupport)
  gem 'activesupport'
  require 'active_support'
end

class WIN32OLE

  alias_method :old_array_selector, :[]
  
  def [](idx)
    if idx.kind_of? Integer
      self.GetAt(idx)
    else
      old_array_selector(idx)
    end
  end
  
  alias_method :old_method_missing, :method_missing
  
  def method_missing(symbol, *params)
    if (('a'..'z') === symbol.to_s[0].chr)
      obj = old_method_missing(symbol.to_s.camelize.to_sym, *params)

      if obj.ole_methods.detect{|m| m.to_s == 'GetValue'}
        obj.GetValue
      end
    else
      old_method_missing(symbol, *params)
    end
  end
end

The new definition of [] checks if an integer was passed. If so, and if self responds to “GetAt”, go ahead and send the integer value to self#GetAt . This allows me to use response.ResponseList[0] instead response.ResponseList.GetAt(0).

The method_missing stuff allows does a similar shortcut for GetValue . Instead of first_customer.FullName.GetValue, I can call first_customer.full_name.

This is not at all tested, so I can’t say what these changes might mess up.


Computing

Quickbooks Multiuser Setup

First off, here’s what worked for me:

Edit the file C:\WINDOWS\system32\drivers\etc\hosts (that’s the path in XP), and add a line matching the IP address of the server (computer that is hosting the multiuser access and files) with the Windows’ computer name of the server. For example, if the server’s name is my-serv and the IP address is 192.168.1.10, add the line:

192.168.1.10  my-serv

Now, to the background and other (hopefully useful) information.

I’ve been trying to setup Quickbooks for multiuser access, and it’s been a pain, but along the way, I’ve found some useful information and tools available from Intuit. Apparently, setting up multiuser access works fine often enough, but when it doesn’t, it’s a bit of a hunt to find out why.

Read the Guide

The first thing–which I wish I would have known about and done before any installation–is go to the Network/Multi-User Setups page on Intuit’s site, and read the Network Installation Guide for your version of Quickbooks. It gives useful information, such as that client computers should be installed as “One User” (at least in 2009 Premier), because apparently adding the line “Or this will be a client computer on a networked setup” was too much work. The Guide is very helpful.

But what if it doesn’t work? For me, I could open a file in Single User mode from the client, but to open it in multiuser mode from the client, I had to open the file on the server, switch to multiuser mode, and leave it open. Then I could open multiuser on the client (I think, in essence, it was defaulting to the “Alternative Setup”). Not optimal.

Download the Network Diagnostic Tool

Intuit has a Network Diagnostic Tool. It’s actually linked to on the above referenced page, but I missed it there and it’s not highlighted in the various searches I did. Download it and then click (on the download page) the “How to Use the Tool” tab. There’s not much in the way of “how do I fix this” information, or even explanations of what exactly some of the tests are checking for. But it’s a nice starting point.

What Worked for Me

The router at my office, for which I am responsible, is a Cisco DSL router, which apparently does weird things to DNS. I’ll admit that my being responsible for a router that I don’t understand is a WTF and obviously part of the problem, but is one of those unfortunate realities. Anyway, it occurred to me that maybe if I define the host name - IP address matching directly, that could help (some of the information in the console tab of the Network Diagnostic Tool got me thinking along these lines). In XP, that can be done by editing C:\WINDOWS\system32\drivers\etc\hosts (see the start of this entry). And it worked.