Search code examples
phpapiexact-online

Exact API - SalesOrderLines (Item Mandatory: Unit) even when the unit is there


We import orders into Exact API which works for UK, NL but now we are trying to import DE orders too. We have everything setted up, but when we are trying to import orders we get an error which looks like this:

Item Mandatory: Unit

Even when we try to import the unit in different ways it shows this

Invalid Reference: Unit

And we can not figure it out why it doesn't work but on UK an NL it works like a charm.

There is a piece of code for DE order import.

/** @var \Picqer\Financials\Exact\Item $item */
$item = ExactItem::getItemByEan($connection, $i->product_ean);

if (isset($item)) {
    $unitPrice = round(doubleval($i->product_item_price_no_vat), 4);
    $unitPriceVat = round(doubleval($i->product_item_price), 4);

    $unitCode = $item->Unit;

    if ($client == ExactController::CLIENT_NL) {
        $item = [
            'Item' => $item->ID,
            'Quantity' => $i->product_quantity,
            'ItemCode' => $i->product_ean,
            'ItemDescription' => $i->product_name
        ];
    } else {
        $item = [
            'Item' => $item->ID,
            'Quantity' => $i->product_quantity,
            'ItemCode' => $i->product_ean,
            'ItemDescription' => $i->product_name
        ];
    }

    if ($client == ExactController::CLIENT_DE) {
        $item["UnitCode"] = $unitCode;
    }


    if ($client == ExactController::CLIENT_NL || $client == ExactController::CLIENT_DE) {
        //$item['NetPrice'] = $unitPrice;
        $item['UnitPrice'] = $unitPriceVat;
    } else {
        $item['UnitPrice'] = $unitPrice;
    }
}

It would definitely help when you had this problem and you know how to fix.

PS: I have tried to set UnitCode to ID, Code and it didn't help.


Solution

  • We have found a solution!

    The problem was when we tried to import shipping as an item and the shipping wasn't defined in Exact DE but at UK and NL was.

    Even now we don't know why it was saying that there was a problem with Units.