dongpigui8898 2014-01-16 17:54
浏览 38
已采纳

如何使用QuickBooks_IPP显示发票中的每个项目?

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(' &nbsp; &nbsp; 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?

  • 写回答

1条回答 默认 最新

  • duanmi3476 2014-01-16 18:45
    关注

    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 . "
    ");
    
                // 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() . "
    ");
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn