static public function calculateDeliveryRemainingQuantity($item)
    {
        if ($item instanceof SupplierOrderItemInterface) {
            return $item->getQuantity() - static::calculateReceivedQuantity($item);
        }

        if (!$item instanceof SupplierDeliveryItemInterface) {
            throw new InvalidArgumentException(
                "Expected instance of " .
                SupplierOrderItemInterface::class . " or " .
                SupplierDeliveryItemInterface::class
            );
        }

        $orderItem = $item->getOrderItem();

        $result = $orderItem->getQuantity() - static::calculateReceivedQuantity($orderItem);

        if (0 < $item->getQuantity()) {
            $result += $item->getQuantity();
        }

        return $result;
    }