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

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

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

            Database::get('money')->beginTransaction();

            //~ Verify account
            $accountId = (int) $post->get('accountId');
            $account   = $this->verifyAccount($accountId);

            //~ Load item
            $itemId = (int) $this->route->getParameterCollection()
                ->getByName('id')
                ->getValue();

            $itemMapper = new BudgetMapper(Database::get('money'));
            $item       = $itemMapper->findById($itemId);

            if ($account->getId() !== $item->getAccountId()) {
                throw new \Exception('Mismatch account ID!');
            }

            //~ Remove budget categories
            $itemCategories = $item->getAllBudgetCategory();
            $itemCategoryMapper = new BudgetCategoryMapper(Database::get('money'));
            foreach ($itemCategories as $itemCategory) {
                $itemCategoryMapper->delete($itemCategory);
            }

            //~ Remove budget months
            $itemMonths = $item->getAllBudgetMonth();
            $itemMonthMapper = new BudgetMonthMapper(Database::get('money'));
            foreach ($itemMonths as $itemMonth) {
                $itemMonthMapper->delete($itemMonth);
            }

            //~ Remove item
            $itemMapper->delete($item);

            Database::get('money')->commit();

        } catch (\Exception $exception) {

            Database::get('money')->rollBack();

            $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();

            Database::get('money')->beginTransaction();

            //~ Verify account
            $accountId = (int) $post->get('accountId');
            $account   = $this->verifyAccount($accountId);

            //~ Load item
            $itemId = (int) $this->route->getParameterCollection()
                ->getByName('id')
                ->getValue();

            $itemMapper = new BudgetMapper(Database::get('money'));
            $item       = $itemMapper->findById($itemId);

            if ($account->getId() !== $item->getAccountId()) {
                throw new \Exception('Mismatch account ID!');
            }

            //~ Remove budget categories
            $itemCategories = $item->getAllBudgetCategory();
            $itemCategoryMapper = new BudgetCategoryMapper(Database::get('money'));
            foreach ($itemCategories as $itemCategory) {
                $itemCategoryMapper->delete($itemCategory);
            }

            //~ Remove budget months
            $itemMonths = $item->getAllBudgetMonth();
            $itemMonthMapper = new BudgetMonthMapper(Database::get('money'));
            foreach ($itemMonths as $itemMonth) {
                $itemMonthMapper->delete($itemMonth);
            }

            //~ Remove item
            $itemMapper->delete($item);

            Database::get('money')->commit();

        } catch (\Exception $exception) {

            Database::get('money')->rollBack();

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

        return $response;
    }
Ajax edit category.

@return ResponseInterface