0

In making a request via qbXML for importing invoices, I'm using the following snippet:

<InvoiceQueryRq requestID="1">
  <IncludeLineItems>true</IncludeLineItems>
  <OwnerID>0</OwnerID>
</InvoiceQueryRq>

This allows me to grab all line items for all the invoices I'm importing -- which is exactly what I want, as I report on these invoices, their items and quantities (and descriptions).

However, my problem is when the quickbooks user deletes one of the line items, there's no way for me to tell in the response I'm getting. I'll get updates, like updated quantities or descriptions, and of course I get all new line items.

I understand that one solution would be to simply wipe out any data on known invoices and re-insert with new data, however I want to avoid further data manipulation overhead.

Thus, my core question is, is there a way to also include deleted line items on an invoice query?

brazilianldsjaguar
  • 1,409
  • 1
  • 20
  • 45

1 Answers1

1

Thus, my core question is, is there a way to also include deleted line items on an invoice query?

No, there is not.

However, if you're caching this data in your app, it should be pretty trivial to compare the TxnLineID values you got back from QuickBooks, to the cached TxnLineID values you have in your database, and just delete anything from your app that's not present in what you got back from QuickBooks.

Psuedocode for something like that would be something like:

// the main TxnID of the invoice itself
$TxnID = ... 

// this will store the current TxnLineIDs for existing lines
$list_of_current_TxnLineIDs = array();

// loop through the invoice lines that were returned from QuickBooks
foreach ($InvoiceLineRet as $InvoiceLine) 
{
  $list_of_current_TxnLineIDs[] = $InvoiceLine->TxnLineID;
}

// delete anything we have already cached that isn't needed anymore
db_query("DELETE FROM invoice_line WHERE TxnID = $TxnID AND TxnLineID NOT IN ( " . implode(", ", $list_of_current_TxnLineIDs) . " ) ");
Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105
  • Yeah, that was my next idea. How did you do it in the SQL dump? There's the `qb_deleted` column (or something similar), but not sure if you basically did the same thing and instead of a hard delete just marked them? – brazilianldsjaguar Jan 26 '15 at 20:37
  • Added psuedocode -- the above example is basically what the SQL mirror code we distribute does. – Keith Palmer Jr. Jan 27 '15 at 05:05