src/Money/Module/Category/Controller/Category.php
public function ajaxDelete()
    {
        if (!Server::getInstance()->isAjax()) {
            throw new \RuntimeException();
        }

        $response = new Api();
        $response->setHttpCode(200);
        $response->setIsSuccess(true);

        try {
            $post = Post::getInstance();

            $categoryId = (int) $this->route->getParameterCollection()
                ->getByName('id')
                ->getValue();
            $accountId  = (int) $post->get('accountId');

            //~ Retrieve user account / account
            $mapper = new AccountUserMapper(Database::get('money'));
            $accountUser = $mapper->findByKeys(array(
                'user_id'    => Session::getInstance()->get('id'),
                'account_id' => $accountId
            ));
            $account = $accountUser->getAccount();

            //~ Retrieve category
            $categoryMapper = new CategoryMapper(Database::get('money'));
            $category       = $categoryMapper->findById($categoryId);

            if ($category->getAccountId() !== $account->getId()) {
                throw new \RuntimeException();
            }

            if ($category->getParentId() === 0 && $categoryMapper->rowExists('category_parent_id', $category->getId())) {
                throw new \RuntimeException('Current category has children! It cannot be deleted.', 1001);
            }

            $categoryMapper->delete($category);

            //~ Reset category id for each transaction with old category id
            $transactionMapper = new TransactionMapper(Database::get('money'));
            $transactionMapper->addWhere('category_id', (int) $category->getId());
            $transactionMapper->addWhere('account_id',  (int) $account->getId());
            foreach ($transactionMapper->select() as $transaction) {
                $transaction->setCategoryId(0);
                $transactionMapper->update($transaction);
            }

        } catch (\Exception $exception) {
            $response->setIsSuccess(false)
                ->setHttpCode(500)
                ->setErrorCode($exception->getCode())
                ->setErrorMessage($exception->getMessage())
                ->setContent(true);
        }

        return $response;
    }
public function ajaxDelete()
    {
        if (!Server::getInstance()->isAjax()) {
            throw new \RuntimeException();
        }

        $response = new Api();
        $response->setHttpCode(200);
        $response->setIsSuccess(true);

        try {
            $post = Post::getInstance();

            $categoryId = (int) $this->route->getParameterCollection()
                ->getByName('id')
                ->getValue();
            $accountId  = (int) $post->get('accountId');

            //~ Retrieve user account / account
            $mapper = new AccountUserMapper(Database::get('money'));
            $accountUser = $mapper->findByKeys(array(
                'user_id'    => Session::getInstance()->get('id'),
                'account_id' => $accountId
            ));
            $account = $accountUser->getAccount();

            //~ Retrieve category
            $categoryMapper = new CategoryMapper(Database::get('money'));
            $category       = $categoryMapper->findById($categoryId);

            if ($category->getAccountId() !== $account->getId()) {
                throw new \RuntimeException();
            }

            if ($category->getParentId() === 0 && $categoryMapper->rowExists('category_parent_id', $category->getId())) {
                throw new \RuntimeException('Current category has children! It cannot be deleted.', 1001);
            }

            $categoryMapper->delete($category);

            //~ Reset category id for each transaction with old category id
            $transactionMapper = new TransactionMapper(Database::get('money'));
            $transactionMapper->addWhere('category_id', (int) $category->getId());
            $transactionMapper->addWhere('account_id',  (int) $account->getId());
            foreach ($transactionMapper->select() as $transaction) {
                $transaction->setCategoryId(0);
                $transactionMapper->update($transaction);
            }

        } catch (\Exception $exception) {
            $response->setIsSuccess(false)
                ->setHttpCode(500)
                ->setErrorCode($exception->getCode())
                ->setErrorMessage($exception->getMessage())
                ->setContent(true);
        }

        return $response;
    }
Ajax edit category.

@return ResponseInterface