I'm using the QuickBooks PHP DevKit to get the Invoice for each Customer. This works fine, but I need to get each Item from each Line in the invoice to simply display it and I am having difficulty getting this information for some reason.
I can get the ItemRef with
$Item = $Line->getSalesItemLineDetail();
$itemRef = $Item->getItemRef();
But it throws a fatal error: "Call to a member function getItemRef() on a non-object" and kills the script.
This is the code I have.
//get QuickBooks customer ID
$customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer WHERE id = '18' ");
if (count($customers))
{
foreach ($customers as $Customer)
{
$invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE CustomerRef = '" . QuickBooks_IPP_IDS::usableIDType($Customer->getId()) . "' ");
if (count($invoices))
{
foreach ($invoices as $Invoice)
{
echo $Invoice->getTotalAmt();
$line_count = $Invoice->countLine();
for ($i = 0; $i < $line_count; $i++)
{
$Line = $Invoice->getLine($i);
//print_r($Line);
$Item = $Line->getSalesItemLineDetail();
$itemRef = $Item->getItemRef();
$item = $ItemService->query($Context, $realm, "SELECT * FROM Item WHERE id = '" . QuickBooks_IPP_IDS::usableIDType($itemRef) . "' ");
foreach($item as $Item){
echo $Item->getName();
}
}
}
}
else
{
print(' This customer has no invoices.<br>');
}
}
}
else
{
print('There are no customers with the provided ID');
}
In short, what is the proper way to query for the Item in each Line of an Invoice?