public function update($mIds, array $aData = []): bool
    {
        //  @todo (Pablo - 2019-03-06) - Support passing in multiple IDs so as to be compatible with parent

        $oDb = Factory::service('Database');

        try {

            $sKeyExistsCustomerId = array_key_exists('customer_id', $aData);
            $sKeyExistsEmail      = array_key_exists('email', $aData);

            if ($sKeyExistsCustomerId && $sKeyExistsEmail) {
                throw new InvoiceException('An invoice cannot be assigned to both an email and a customer.', 1);
            }

            if ($sKeyExistsCustomerId && empty($aData['customer_id'])) {
                throw new InvoiceException('If supplied, "customer_id" cannot be empty.', 1);
            } elseif ($sKeyExistsCustomerId && $sKeyExistsEmail) {
                //  Ensure the email field is empty if it has been supplied
                $aData['email'] = null;
            }

            if ($sKeyExistsEmail && empty($aData['email'])) {
                throw new InvoiceException('If supplied, "email" cannot be empty.', 1);
            } elseif ($sKeyExistsEmail && $sKeyExistsCustomerId) {
                //  Ensure the customer_id field is empty if it has been supplied
                $aData['customer_id'] = null;
            }

            $oDb->trans_begin();

            $this->prepareInvoice($aData, $mIds);

            if (array_key_exists('items', $aData)) {
                $aItems = $aData['items'];
                unset($aData['items']);
            }

            unset($aData['ref']);
            unset($aData['token']);

            $bResult = parent::update($mIds, $aData);

            if (!$bResult) {
                throw new InvoiceException('Failed to update invoice.', 1);
            }

            if (!empty($aItems)) {
                $this->updateLineItems($mIds, $aItems);
            }

            $oDb->trans_commit();
            $this->triggerEvent(
                Events::INVOICE_UPDATED,
                [$this->getInvoiceForEvent($mIds)]
            );

            return $bResult;

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $this->setError($e->getMessage());
            return false;
        }
    }