Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : Using ClassRefListID when inserting invoice linesSearch Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC SQL Support Forum

 New Topic 
 
 Post Reply 
[1]  
 Using ClassRefListID when inserting invoice lines 
 Author   Message 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-14 08:01:05

When inserting an invoice via a looping SQL procedure, I have invoice lines (InvoiceLine table) items that can potentially be assigned to varying classes.  Using the ClassRefListID field, I class the lines accordingly, and do not address the ClassRefListID in the main Invoice (header/parent) table.  When I examine the invoice in Quickbooks, it seems that ALL invoice line items have been forced to the SAME class (looks like the class that I last defined in the last child InvoiceLine item).  I need to insert invoices with lines that point to DIFFERENT classes as I can manually in Quickbooks, is this possible using QODBC????  Thank you!

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-14 11:30:54

You are correct, when you create or add InvoiceLines, QODBC will always use the last Class referenced in the Invoice (if applicable). For example, this three line invoice:

INSERT INTO "InvoiceLine" ("CustomerRefListID", "ClassRefListID", "RefNumber",
"InvoiceLineItemRefListID", "InvoiceLineDesc", "InvoiceLineRate",
"InvoiceLineAmount", "InvoiceLineSalesTaxCodeRefListID", "FQSaveToCache")
VALUES ('470001-1071525403', '30000-933272658', 'QODBCClass1', '250000-933272656',
'Building permit Additional Room', 100.00000, 100.00, '20000-999022286', 1)

INSERT INTO "InvoiceLine" ("CustomerRefListID", "ClassRefListID", "RefNumber",
"InvoiceLineItemRefListID", "InvoiceLineDesc", "InvoiceLineRate",
"InvoiceLineAmount", "InvoiceLineSalesTaxCodeRefListID", "FQSaveToCache")
VALUES ('470001-1071525403', '60000-933272658', 'QODBCClass1', '250000-933272656',
'Bin Permit Renovations', 200.00000, 200.00, '20000-999022286', 1)

INSERT INTO "InvoiceLine" ("CustomerRefListID", "RefNumber",
"InvoiceLineItemRefListID", "InvoiceLineDesc", "InvoiceLineRate",
"InvoiceLineAmount", "InvoiceLineSalesTaxCodeRefListID", "FQSaveToCache")
VALUES ('470001-1071525403', 'QODBCClass1', '250000-933272656', 'Less Council Rebate',
-50.00000, -50.00, '20000-999022286', 0)

incorrectly appears in QuickBooks with all three invoice lines showing the "Remodel:Referral" Class:

So, you will need to use Plan B:

To get around this you can first create the Invoice and then add invoice lines and specify the Class to use, or not to use, like this:

INSERT INTO "InvoiceLine" ("CustomerRefListID", "ClassRefListID", "RefNumber",
"InvoiceLineItemRefListID", "InvoiceLineDesc", "InvoiceLineRate",
"InvoiceLineAmount", "InvoiceLineSalesTaxCodeRefListID", "FQSaveToCache")
VALUES ('470001-1071525403', '30000-933272658', 'QODBCClass2', '250000-933272656',
'Building permit Additional Room', 100.00000, 100.00, '20000-999022286', 0)

Once the invoice is created, we can locate the TxnID using the QODBC stored procedure (as long as we haven't broken our QODBC connection):

SP_LASTINSERTID InvoiceLine

The TxnID for the new invoice is 5CA9-1197764583, so we can now add additional lines to the Invoice by doing:

INSERT INTO "InvoiceLine" ("TxnID", "ClassRefListID", 
"InvoiceLineItemRefListID", "InvoiceLineDesc", "InvoiceLineRate",
"InvoiceLineAmount", "InvoiceLineSalesTaxCodeRefListID")
VALUES ('5CA9-1197764583', '60000-933272658', '250000-933272656',
'Bin Permit Renovations', 200.00000, 200.00, '20000-999022286')

INSERT INTO "InvoiceLine" ("TxnID", "ClassRefListID",
"InvoiceLineItemRefListID", "InvoiceLineDesc", "InvoiceLineRate",
"InvoiceLineAmount", "InvoiceLineSalesTaxCodeRefListID")
VALUES ('5CA9-1197764583', '', '250000-933272656', 'Less Council Rebate',
-50.00000, -50.00, '20000-999022286')

The invoice now appears in QuickBooks with different Class values for each line:

 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-15 00:04:17
Thanks, Tom.  This makes sense.  I understand that you are suggesting I create the main invoice record first, then insert the child (InvoiceLine) items, however I don't see you ever actually inserting to the "INVOICE" table below.  Is the INVOICE table record automatically created or something when you insert to InvoiceLine as you did below?  Thanks! 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-15 01:37:53
Tom, I've run into a big problem.  It appears that TxnID is NOT an INSERTABLE field.  I received the QODBC error regarding the field not being allowed in the INSERT list, and so I checked out the field's attributes using "SP_COLUMNS InvoiceLine".  TxnID appears to be NOT insertable, so using the method you laid out below doesn't work.  Any help?  Thanks! 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-15 08:30:01

The Invoice is the Main Invoice Table and contains a header record for each invoice, while InvoiceLine provides all the line item detail for a customer invoice and contains all the information included in the Main Invoice Table. So you don't need to use the Invoice table if you don't want too. For multi-line invoices, some may find it easier to not include all the header information with each line item, but rather to have seperate smaller commands for the Invoice Lines and a final big INSERT for the Invoice header.

To insert a new Invoice line into the InvoiceLine table for an existing invoice we just need to supply the TxnID as the first column. It's that simple. sp_columns doesn't have an insertable on add column, but if it did, TxnID would be true.

If you are getting a field not being allowed in insert when you try to add the second line, then your FQSaveToCache caching flag is still set true (1) on the first insert, it need's to be set false (0).

 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-16 01:31:46

Tom, I am in fact setting FQSaveToCache = 0 in the first statement, and then not using this field all together in the second statement.  The procedure fails on the second statement...  Here is the exact SQL that is being executed:

1.

INSERT INTO InvoiceLine
 (Memo, BillAddressAddr1, IsToBePrinted, CustomerSalesTaxCodeRefListID,
 DueDate, ShipDate, IsPending, TxnDate, ARAccountRefListID,
 CustomerRefListID, ClassRefListID, InvoiceLineItemRefListID,
 InvoiceLineDesc, InvoiceLineRate, InvoiceLineAmount, InvoiceLineSalesTaxCodeRefListID,
 FQSaveToCache)
VALUES
 ('[PE] - ', 'KARLA FOUNTAIN', 0, '20000-1012341377',
 {d'2006-06-24'}, {d'2006-06-24'}, 0, {d'2006-06-08'}, '4C0000-979674056',
 '4E160000-1150227958', '1FF0000-1104418069', '30000-979670045',
 '', 0.00, 75.00, '20000-1012341377',
 0)

2.

INSERT INTO InvoiceLine
 (TxnID, ClassRefListID, InvoiceLineItemRefListID, InvoiceLineDesc,
 InvoiceLineRate, InvoiceLineAmount, InvoiceLineSalesTaxCodeRefListID)
VALUES
 ('14B6DC-1150298902', '18C0000-1085753034', 'E0000-980263422', '',
 0.00, 500, '20000-1012341377')

-----

Fails upon executing #2.  Error: "Field not allowed in insert."  I also tried removing FQSaveToCache from the first statement all together, but I get the same experience.  What am I missing here?

Thanks!

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-16 08:48:06

Check that the first line did create an invoice and that your TxnID is for the invoice. I am already using QODBC v6.00.00.172 which has changes to make TxnID work correctly when adding lines to Sales Receipts. So you could have a broken InvoiceLine revision of QODBC. You will need to update QODBC to v6.00.00.174 (or later) when it get's released.

You can check when the release is available by looking at the QODBC Updates and Bug Fixes topic in this forum.

 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-20 06:07:43
Tom,

FYI: I ran the debugger on my procedure and checked everything as I stepped-through line by line.  After the first query was executed, both the InvoiceLine AND Invoice records WERE sucsessfully created in Quickbooks.  I noted the TxnID and verified that the same TxnID was being used on the second insert.  The procedure fails on the 2nd procedure with the error I've been experiencing all along.  I'm using QODBC 6.00.00.134; how do I go about obtaining updates?

Thanks! 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-20 09:37:07
See: How can I get the latest version of QODBC?  

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-21 03:48:06

This is interesting.  After upgrading to version 6.00.00.155, I have a new and different problem.  Now all of the sudden when I execute the "sp_LastInserID InvoiceLine" statement -- nothing is returned.  I haven't modified this section of the code at all, and it was working fine with 6.00.00.134.  I noticed that running this stored procedure doesn't even work using the "VB Demo," application.  Nothing errors, but null values are returned.  Because I can't get by this part now I can't see if upgrading solved my issue with the second insert using the TxnID....  Thanks!

 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-24 05:48:15
Tom, anything on this?  Please help!  Thanks! 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-24 10:44:51

You can get around

SP_LASTINSERTID InvoiceLine

not working in QODBC v6.00.00.155 by locating the TxnID yourself, like in my example by using the RefNumber:

SELECT TxnID FROM Invoice unoptimized where RefNumber = 'QODBCClass2'

 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-27 02:02:55
Well I'm leaving the RefNumber out of the insert because I wish to have Quickbooks automatically assign me the next available RefNumber.  So if I don't know the RefNumber at the time of insert -- then how can I "SELECT TxnID FROM Invoice WHERE RefNumber = '???'"  ??

Is there a bug with QODBC v.6.00.00.155 that is causing SP_LASTINSERTID to not work or am I doing something wrong?  Like I said the exact same code worked fine with my previous version of QODBC.

I'm stuck and don't know how I should proceed on this.... 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-27 08:26:22

Yes, there's a bug in QODBC v6.00.00.155, that's been fixed in v6.00.00.172. Try using:

SELECT  TOP 1 TxnID FROM Invoice WHERE CustomerRefListID = '470001-1071525403' ORDER BY TimeModified DESC

for now.

 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-28 06:12:21
Tom, so sorry but one last thing on this...  Everything seems to be working now -- however now all of the sudden we get an error when trying to insert a negative line item in a given invoice (which is unavoidable for our business.)  We get a message that states, "TRANSACTION AMOUNT MUST BE POSITIVE."  The total invoice amount itself will be positive -- but we may have individual lines that are negative amounts.

This has always worked for us in the past... and I'm not sure if this behavior started after the upgrade to the latest QODBC version OR after we started inserting invoices in "plan B" fashion as per your recommendation (inserting invoice lines individually rather than using the invoice header record method...)  Unfortunately I'm really stuck now...  Any advice for me?

Thanks so much! 

  Top 
  Kyle Shea 
  
 Group: Members 
 Posts: 19 
 Joined: 2006-04-19 
 Profile
 Posted : 2006-06-28 08:00:51
Tom, disregard the last post.  By ordering my DataTable with the negative items at the bottom (last) -- I can get around this issue.  It looks like if any one InvoiceLine insert makes your total invoice amount < 0, the insert errors... however by handling the negative lines last -- there is no chance the total invoice amount will ever become negative.  Thanks! 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-28 08:13:15
Yes, the rule for negative numbers has always been that you can use negiative amounts providing that the Invoice itself is not made negative at that point of time (because it would be a credit memo, not a invoice). So inserting negative amounts must be done last. 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to