我正在使用QuickBooks PHP DevKit爲每個客戶獲取發票。這工作正常,但我需要從發票中的每一行中獲取每個項目以簡單顯示它,並且由於某種原因我很難獲取此信息。如何使用QuickBooks_IPP從發票中顯示一行中的每個項目?
我可以
$Item = $Line->getSalesItemLineDetail();
$itemRef = $Item->getItemRef();
得到的itemref但它拋出一個致命的錯誤:「調用一個非對象的成員函數getItemRef()」,並殺死了腳本。
這是我的代碼。
//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');
}
總之,在發票的每一行中查詢項目的正確方法是什麼?
非常感謝你,基思,爲您的快速解決方案!這絕對有助於理解我想要做的事情。我查看了示例文件(example_invoice_w_lines_query.php),但它只包含了$ Line = $ Invoice-> getLine(0),我已經擁有這個文件,並且不確定如何獲取對象的更深層數據,儘管我是在我的select語句中缺少「Line。*」,這可能是它的很大一部分。無論如何,非常感謝您的幫助! – cellen
NP。我更新了GitHub上的例子,專門回答你的問題,這就是爲什麼它之前沒有展示過這些東西。 –