Quickbooks SDK创建发票不会添加第二行来发票PHP

时间:2017-06-30 17:31:40

标签: php sdk quickbooks-online

我正在使用示例代码并在沙箱中进行测试,以便更好地了解CreateInvoice。我的代码将第二行写入发票上的第一行。 还有哪里可以找到更好的"如何"文档? $ IPPId-> value =" 4&#34 ;;代表?当我给项目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);

2 个答案:

答案 0 :(得分:0)

您需要在一个临时数组中添加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);

答案 1 :(得分:0)

您使用的是哪种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);