Not sure that it will matter, I looked over this script and while I follow it - I think I forgot that the client is not using SOP. (1) all the sales documents are generated 3rd party and imported to Sales Invoices (2) not all the items are inventory, some are non-inventory that are added to the Sales Invoice from the 3rd party application. The non-inventory details are being stored in the GP database - so there is a consistent use of Vendor, Price, Purchase Cost and such - just not counting inventory items.
Hope this clears up the SOP / Sales Invoice matter.