【问题标题】:Quickbooks SDK Create Invoice will not add second line to invoice PHPQuickbooks SDK 创建发票不会在发票 PHP 中添加第二行
【发布时间】:2017-06-30 17:31:40
【问题描述】:

我正在使用示例代码并在沙盒中进行测试,以更好地了解 CreateInvoice。我的代码将第二行写入发票的第一行。 另外我在哪里可以找到更好的“如何”文档? $IPPId->value = "4"; 是什么意思?代表?当我给项目一个 id 时,描述和单价不会显示在发票上,但是项目名称会显示。

    // Create a new Invoice
$invoice = new IPPInvoice();
//$invoice->DocNumber="1234"; //You assign the Invoice Number
$invoice->AutoDocNumber="1"; //Invoice number generated by QB 

//Assign Customer to the invoice
$customerRef = new IPPReferenceType();
$customerRef->value = "3"; //CustomerID
$invoice->CustomerRef = $customerRef;

//New Invoice Line
$IPPLine = new IPPLine();
    $IPPId = new IPPReferenceType(); //Reference type of all IDs that are taken as input or output
    $IPPId->value = "4";
    $IPPLine->Id = $IPPId;

    $IPPLine->LineNum = "1";
    $IPPLine->Description = "DP2OrderID - Sitting Reference - CustomerRef Goes Here"; //Invoice Title
    $IPPLine->Amount = 25.0; //Price - Order Sum

    $enum = new IPPLineDetailTypeEnum();
    $enum->value = "DescriptionOnly";
    $IPPLine->DetailType = $enum;

$invoice->Line = $IPPLine; //Add line to invoice


//New Invoice Line
$IPPLine = new IPPLine();
    $IPPId = new IPPReferenceType(); //Reference type of all IDs that are taken as input or output
    $IPPId->value = "4";
    $IPPLine->Id = $IPPId;

    $IPPLine->LineNum = "2";
    $IPPLine->Description = "Line two"; //Invoice Title
    $IPPLine->Amount = 25.0; //Price - Order Sum

    $enum = new IPPLineDetailTypeEnum();
    $enum->value = "SalesItemLineDetail";
    $IPPLine->DetailType = $enum;

    $SalesItemLineDetail = new IPPSalesItemLineDetail();
    $SalesItemLineDetail->ItemRef = "21";
    $SalesItemLineDetail->Qty= 4;
    $IPPLine->SalesItemLineDetail = $SalesItemLineDetail;
$invoice->Line = $IPPLine; //Add line to invoice


//Add Invoice to quickbooks
$resultingInvoiceObj = $dataService->Add($invoice);

【问题讨论】:

    标签: php sdk quickbooks-online


    【解决方案1】:

    您需要在一个临时数组中添加 IPPLine 对象,然后将该临时数组引用到 Invoice。请修改您的代码如下,它应该可以工作。

    $temparr = []; //create one new temp array
    
    $invoice = new IPPInvoice();
    //$invoice->DocNumber="1234"; //You assign the Invoice Number
    $invoice->AutoDocNumber="1"; //Invoice number generated by QB 
    
    //Assign Customer to the invoice
    $customerRef = new IPPReferenceType();
    $customerRef->value = "3"; //CustomerID
    $invoice->CustomerRef = $customerRef;
    
    //New Invoice Line
    $IPPLine = new IPPLine();
    $IPPId = new IPPReferenceType(); //Reference type of all IDs that are taken as input or output
    $IPPId->value = "4";
    $IPPLine->Id = $IPPId;
    
    $IPPLine->LineNum = "1";
    $IPPLine->Description = "DP2OrderID - Sitting Reference - CustomerRef Goes Here"; //Invoice Title
    $IPPLine->Amount = 25.0; //Price - Order Sum
    
    $enum = new IPPLineDetailTypeEnum();
    $enum->value = "DescriptionOnly";
    $IPPLine->DetailType = $enum;
    
    array_push($temparr,$IPPLine); //add line object in temp array
    
    
    //New Invoice Line
    $IPPLine = new IPPLine();
    $IPPId = new IPPReferenceType(); //Reference type of all IDs that are taken as input or output
    $IPPId->value = "4";
    $IPPLine->Id = $IPPId;
    
    $IPPLine->LineNum = "2";
    $IPPLine->Description = "Line two"; //Invoice Title
    $IPPLine->Amount = 25.0; //Price - Order Sum
    
    $enum = new IPPLineDetailTypeEnum();
    $enum->value = "SalesItemLineDetail";
    $IPPLine->DetailType = $enum;
    
    $SalesItemLineDetail = new IPPSalesItemLineDetail();
    $SalesItemLineDetail->ItemRef = "21";
    $SalesItemLineDetail->Qty= 4;
    $IPPLine->SalesItemLineDetail = $SalesItemLineDetail;
    
    array_push($temparr,$IPPLine); //add line object in temp array
    
    $invoice->Line = $temparr; //Add line to invoice
    
    
    //Add Invoice to quickbooks
    $resultingInvoiceObj = $dataService->Add($invoice);
    

    【讨论】:

      【解决方案2】:

      您使用的是哪个 SDK?如果您只是使用 QuickBooks Online,我们有一个提供 Facade 支持的 SDK:https://github.com/intuit/QuickBooks-V3-PHP-SDK

      在其中,创建发票很简单:

      $myInvoiceObj = Invoice::create([
        "DocNumber" => "1070",
        "LinkedTxn" => [],
        "Line" => [[
            "Id" => "1",
            "LineNum" => 1,
            "Amount" => 150.0,
            "DetailType" => "SalesItemLineDetail",
            "SalesItemLineDetail" => [
                "ItemRef" => [
                    "value" => "1",
                    "name" => "Services"
                ],
                "TaxCodeRef" => [
                    "value" => "NON"
                ]
            ]
        ], [
            "Amount" => 150.0,
            "DetailType" => "SubTotalLineDetail",
            "SubTotalLineDetail" => []
        ]],
        "CustomerRef" => [
            "value" => "1",
            "name" => "Amy's Bird Sanctuary"
        ]
      ]);
      $resultingInvoiceObj = $dataService->Add($myInvoiceObj);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-05
        • 1970-01-01
        相关资源
        最近更新 更多