如何使用php api访问Quickbooks发票行项目

时间:2013-04-03 11:56:04

标签: php quickbooks quickbooks-online

我正在尝试使用php api,

访问quickbooks中的发票行项目

所以我可以对它做一些操作......

当我这样做时能够获得发票数据......

<?php
$Invoice = $InvoiceService->findById($Context, $realmID, $InvoiceID);
pr($Invoice);
?>

结果如下:

QuickBooks_IPP_Object_Invoice Object
(
    [_data:protected] => Array
        (
            [Id] => Array
                (
                    [0] => {QBO-52}
                )

            [SyncToken] => Array
                (
                    [0] => 13
                )

            [MetaData] => Array
                (
                    [0] => QuickBooks_IPP_Object_MetaData Object
                        (
                            [_data:protected] => Array
                                (
                                    [CreateTime] => Array
                                        (
                                            [0] => 2013-04-02T02:55:30-07:00
                                        )

                                    [LastUpdatedTime] => Array
                                        (
                                            [0] => 2013-04-03T04:15:53-07:00
                                        )

                                )

                        )

                )

            [Header] => Array
                (
                    [0] => QuickBooks_IPP_Object_Header Object
                        (
                            [_data:protected] => Array
                                (
                                    [TxnDate] => Array
                                        (
                                            [0] => 2013-03-31-07:00
                                        )

                                    [Msg] => Array
                                        (
                                            [0] => Customer Message update via QB++
                                        )

                                    [CustomerId] => Array
                                        (
                                            [0] => {QBO-35}
                                        )

                                    [SubTotalAmt] => Array
                                        (
                                            [0] => 15.00
                                        )

                                    [TotalAmt] => Array
                                        (
                                            [0] => 15.00
                                        )

                                    [ToBePrinted] => Array
                                        (
                                            [0] => false
                                        )

                                    [ToBeEmailed] => Array
                                        (
                                            [0] => false
                                        )

                                    [DueDate] => Array
                                        (
                                            [0] => 2013-04-29-07:00
                                        )

                                    [BillAddr] => Array
                                        (
                                            [0] => QuickBooks_IPP_Object_BillAddr Object
                                                (
                                                    [_data:protected] => Array
                                                        (
                                                            [Line1] => Array
                                                                (
                                                                    [0] => Jeffery
                                                                )

                                                            [Line2] => Array
                                                                (
                                                                    [0] => Ads India
                                                                )

                                                            [Line3] => Array
                                                                (
                                                                    [0] => Jeffery trading Co Ltd
                                                                )

                                                            [Line4] => Array
                                                                (
                                                                    [0] => Cochin
                                                                )

                                                            [Line5] => Array
                                                                (
                                                                    [0] => Kerala
India
                                                                )

                                                            [GeoCode] => Array
                                                                (
                                                                    [0] => INVALID
                                                                )

                                                        )

                                                )

                                        )

                                    [ShipAddr] => Array
                                        (
                                            [0] => QuickBooks_IPP_Object_ShipAddr Object
                                                (
                                                    [_data:protected] => Array
                                                        (
                                                            [Line1] => Array
                                                                (
                                                                    [0] => Jeffery
                                                                )

                                                            [Line2] => Array
                                                                (
                                                                    [0] => Jeffery trading Co Ltd\\nJeffery traders\\nCochin\\nIndia
                                                                )

                                                            [Line3] => Array
                                                                (
                                                                    [0] => Jeffery
                                                                )

                                                            [Line4] => Array
                                                                (
                                                                    [0] => 0484232425
                                                                )

                                                            [PostalCode] => Array
                                                                (
                                                                    [0] => 0
                                                                )

                                                            [GeoCode] => Array
                                                                (
                                                                    [0] => INVALID
                                                                )

                                                            [Tag] => Array
                                                                (
                                                                    [0] => CUSTOMER
                                                                )

                                                        )

                                                )

                                        )

                                    [ShipMethodId] => Array
                                        (
                                            [0] => {QBO-}
                                        )

                                    [Balance] => Array
                                        (
                                            [0] => 15.00
                                        )

                                    [DiscountTaxable] => Array
                                        (
                                            [0] => true
                                        )

                                )

                        )

                )

            [Line] => Array
                (
                    [0] => QuickBooks_IPP_Object_Line Object
                        (
                            [_data:protected] => Array
                                (
                                    [Desc] => Array
                                        (
                                            [0] => TES15++
                                        )

                                    [Amount] => Array
                                        (
                                            [0] => 15.00
                                        )

                                    [Taxable] => Array
                                        (
                                            [0] => false
                                        )

                                    [ItemId] => Array
                                        (
                                            [0] => {QBO-30}
                                        )

                                )

                        )

                    [1] => QuickBooks_IPP_Object_Line Object
                        (
                            [_data:protected] => Array
                                (
                                    [Amount] => Array
                                        (
                                            [0] => 0.00
                                        )

                                    [Taxable] => Array
                                        (
                                            [0] => false
                                        )

                                    [ItemId] => Array
                                        (
                                            [0] => {QBO-21}
                                        )

                                )

                        )

                )

        )

)

我可以按照以下方式获得发票ID,客户ID

<?php

pr($Invoice->getId());

pr($Invoice->getHeader()->getCustomerId());

?>

我的问题是如何获取订单项的数量并将其提取到正常数组

我累了pr($Invoice->getLine());它不会给我整个数组但只是该数组中的第一项......

我发现很难实现这个目标....

1 个答案:

答案 0 :(得分:5)

$Invoice->getLine(0);
$Invoice->getLine(1);
$Invoice->getLine(2);
$Invoice->getLine(3);
etc.

OR

$count = $Invoice->countLine();
for ($i = 0; $i < $count; $i++)
{
  $Line = $Invoice->getLine($i);
}