Twinfield gives error when I tried to create new invoice

540 views Asked by At

I want to create an invoice to third party invoice software i.e. twinfield from API. I give all the param according to its library and doc and call from API but it will give error.

{ "success": false, "error": "Item code not found., The description of an item line cannot be adjusted." }

The API is php-twinfield.

The code is given below.

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;
}

if change in this line $line->setArticle(0) the error is like that.

{ "success": false, "error": "ResponseException" }

0

There are 0 answers