There's a few things to watch out for here, and it's a little hard to tell exactly what's going on from just your code... so here are some things to check on:
1. Make sure you're fetching the line items:
By default, some of Intuit's queries do not return line items. This isn't specific really to PHP or anything, it's just how Intuit's APIs work.
If you want the line items, you may have to do a query like this:
SELECT *, Line.* FROM Invoice WHERE Id = '5'
2. Not every line item is going to have a SalesItemLineDetail
node.
Line items can have a variety of different detail nodes. Some line items might have a SalesItemLineDetail
node, while others might have a DiscountLineDetail
node, while still others could have other types.
See the possibilities here:
So, a statement like this is not safe to do:
$Line = $Invoice->getLine(0);
$Item = $Line->getSalesItemLineDetail();
$itemRef = $Item->getItemRef();
Because there's a possibility that the SalesItemLineDetail
node you're trying to get might not exist which then would result in $Item
being NULL
which would cause an error.
3. Debugging!
One thing that might be helpful to you (and certainly would be helpful when you're posting looking for help) would be to look at the actual XML response you got back from Intuit.
You can do this by doing:
print($IPP->lastRequest());
print($IPP->lastResponse());
That will dump some debug output which will be helpful. You can also print out the objects:
print_r($Line);
And that might help you track down problems too.
4. Finally - a working example!
Here's an example which should work for you:
In short, what you want to do is:
$num_lines = $Invoice->countLine(); // How many line items are there?
for ($i = 0; $i < $num_lines; $i++)
{
$Line = $Invoice->getLine(0);
// Let's find out what detail type this uses - only fetching item lines here
if ($Line->getDetailType() == 'SalesItemLineDetail')
{
$Detail = $Line->getSalesItemLineDetail();
$item_id = $Detail->getItemRef();
print('Item id is: ' . $item_id . "\n");
// Query for the item
$items = $ItemService->query($Context, $realm, "SELECT * FROM Item WHERE Id = '" . QuickBooks_IPP_IDS::usableIDType($item_id) . "' ");
print(' That item is named: ' . $items[0]->getName() . "\n");
}
}