更新发票时Quickbooks Online +清空行

时间:2016-07-31 15:24:35

标签: php quickbooks-online

查看此图片:http://i.stack.imgur.com/hFjO1.png

由于一些非常奇怪的原因,每次我使用此功能更新发票时,我都会在QBO中收到空白。

当我创建发票时,没关系。但每当我更新它时,就会出现问题。

请帮忙。

static function _update_invoice($data) {

    require(quickbooks_functions::$quickbooks_configuration_file);

    $InvoiceService = new QuickBooks_IPP_Service_Invoice();

    $Invoice = new QuickBooks_IPP_Object_Invoice();

    $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE Id = '" . $data['id'] . "'");
    $Invoice = $invoices[0];

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

    if ($data['shipping']) {
        $ShipAddr = new QuickBooks_IPP_Object_ShipAddr();
        $ShipAddr->setLine1($data['shipping']['address_line1']);
        $ShipAddr->setLine2($data['shipping']['address_line2']);
        $ShipAddr->setCity($data['shipping']['city']);
        $ShipAddr->setCountrySubDivisionCode($data['shipping']['state']);
        $ShipAddr->setPostalCode($data['shipping']['zipcode']);
        $ShipAddr->setCountry($data['shipping']['country']);
        $Invoice->setShipAddr($ShipAddr);
    }

    if ($data['discountPercent']) {
        $Line = new QuickBooks_IPP_Object_Line();
        $Line->setDetailType('DiscountLineDetail');

        $DiscountLineDetail = new QuickBooks_IPP_Object_DiscountLineDetail();
        $DiscountLineDetail->setPercentBased(true);
        $DiscountLineDetail->setDiscountPercent($data['discountPercent']);

        $Line->addDiscountLineDetail($DiscountLineDetail);
        $Invoice->addLine($Line);
    }

    if ($data['shippingCost']) {
        $Line = new QuickBooks_IPP_Object_Line();
        $Line->setDetailType('SalesItemLineDetail');
        $Line->setAmount($data['shippingCost']);

        $SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
        $SalesItemLineDetail->setItemRef('SHIPPING_ITEM_ID');
        $SalesItemLineDetail->setTaxCodeRef($data['shippingTaxCode']);

        $Line->addSalesItemLineDetail($SalesItemLineDetail);
        $Invoice->addLine($Line);
    }

    foreach ($data['items'] as $item) {
        if (!empty($item['quantity'])) {
            $Line = new QuickBooks_IPP_Object_Line();
            $Line->setDetailType('SalesItemLineDetail');
            $Line->setAmount($item['price'] * $item['quantity']);
            $Line->setDescription($item['description']);

            $SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
            $SalesItemLineDetail->setUnitPrice($item['price']);
            $SalesItemLineDetail->setQty($item['quantity']);
            $SalesItemLineDetail->setTaxCodeRef($item['taxCode']);

            $Line->addSalesItemLineDetail($SalesItemLineDetail);
            $Invoice->addLine($Line);
        }
    }

    $TxnTaxDetail = new QuickBooks_IPP_Object_TxnTaxDetail();
    $TxnTaxDetail->setTxnTaxCodeRef(2);
    $Invoice->addTxnTaxDetail($TxnTaxDetail);

    $BillEmail = new QuickBooks_IPP_Object_BillEmail();
    $BillEmail->setAddress($data['billingEmailAddress']);
    $Invoice->setBillEmail($BillEmail);

    $CustomField = new QuickBooks_IPP_Object_CustomField();
    $CustomField->setName('PO Number');
    $CustomField->setType('StringType');
    $CustomField->setDefinitionId(1);
    $CustomField->setStringValue($data['purchaseOrderNumber']);
    $Invoice->addCustomField($CustomField);

    $CustomField = new QuickBooks_IPP_Object_CustomField();
    $CustomField->setName('Order ID');
    $CustomField->setType('StringType');
    $CustomField->setDefinitionId(2);
    $CustomField->setStringValue($data['orderId']);
    $Invoice->addCustomField($CustomField);

    $Invoice->setTxnDate($data['invoiceDate']);
    $Invoice->setDueDate($data['dueDate']);
    $Invoice->setCustomerRef($data['customerId']);
    $Invoice->setSalesTermRef($data['salesTerms']);
    $Invoice->setCustomerMemo($data['customerMemo']);
    $Invoice->setPrivateNote($data['statementMemo']);
    $Invoice->setShipMethodRef($data['shipVia']);
    $Invoice->setShipDate($data['shipDate']);
    $Invoice->setTrackingNum($data['trackingNumber']);

    if ($resp = $InvoiceService->update($Context, $realm, $Invoice->getId(), $Invoice)) {
        return true;
    } else {
        print($InvoiceService->lastError());
    }
}

0 个答案:

没有答案