3

我想为第三方发票软件(即来自 API 的 twinfield)创建发票。我根据其库和文档提供所有参数并从 API 调用,但它会给出错误。

{ "success": false, "error": "未找到商品代码,无法调整商品行的描述。" }

API 是php-twinfield

代码如下。

public function saveInvoice($values)
{
    try 
    {
        $user = $values['user'];
        $password = $values['password'];
        $organization = $values['organisation'];
        $officecode = $values['officecode'];
        $connection = new \PhpTwinfield\Secure\WebservicesAuthentication($user, $password, $organization);
        $customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($connection);
        $office   = Office::fromCode($officecode);
        $customer = $customerApiConnector->get('1008',$office);

        $InvoiceApiConnector = new \PhpTwinfield\ApiConnectors\InvoiceApiConnector($connection);
        //class invoiceline object 
        $line = new \PhpTwinfield\InvoiceLine();
        $line
            ->setArticle(2)
            ->setQuantity(2)
            ->setValueExcl(100)
            ->setUnits(1)
            ->setVatCode('VH')
            ->setUnitsPriceExcl(100)
            ->setDim1(8020)
            ->setDescription("Testinvoice anand")
            ->setAllowDiscountOrPremium(false);
        //class invoice object
        $invoice = new \PhpTwinfield\Invoice();
        $invoice
            ->setCustomer($customer)
            ->setBank('BNK')
            ->setDueDate(\Carbon\Carbon::now()->addMonth())
            ->setPeriod('2018/12')
            ->setCurrency('EUR')
            ->setStatus('concept')
            ->setInvoiceDate('20180606')
            ->addLine($line)
            ->setPaymentMethod('cash')
            ->setInvoiceType('FACTUUR');

        $result = $InvoiceApiConnector->send($invoice);
        print_r($result);
        //$jsonResponse = JsonResponse::success($result);
    }

    catch (SoapFault $e)
    {
        $jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
    }
    //return $jsonResponse;
}

如果在这一行$line->setArticle(0)发生变化,错误就是这样。

{“成功”:假,“错误”:“响应异常”}

4

0 回答 0