mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
This commit is contained in:
@@ -137,10 +137,16 @@ class AvailableBudgetController extends Controller
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function delete(AvailableBudget $availableBudget)
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$this->abRepository->destroyAvailableBudget($availableBudget);
|
||||
session()->flash('success', trans('firefly.deleted_ab'));
|
||||
$id = (int)$request->get('id');
|
||||
if (0 !== $id) {
|
||||
$availableBudget = $this->abRepository->findById($id);
|
||||
if (null !== $availableBudget) {
|
||||
$this->abRepository->destroyAvailableBudget($availableBudget);
|
||||
session()->flash('success', trans('firefly.deleted_ab'));
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('budgets.index'));
|
||||
}
|
||||
|
@@ -79,6 +79,14 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findById(int $id): ?AvailableBudget
|
||||
{
|
||||
return $this->user->availableBudgets->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all available budgets (in all currencies) (for the selected period).
|
||||
*
|
||||
|
@@ -56,6 +56,13 @@ interface AvailableBudgetRepositoryInterface
|
||||
*/
|
||||
public function find(TransactionCurrency $currency, Carbon $start, Carbon $end): ?AvailableBudget;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return AvailableBudget|null
|
||||
*/
|
||||
public function findById(int $id): ?AvailableBudget;
|
||||
|
||||
/**
|
||||
* Return a list of all available budgets (in all currencies) (for the selected period).
|
||||
*
|
||||
|
@@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -319,7 +320,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
// find the budget:
|
||||
$budget = $this->user->budgets()->find((int)$data['budget_id']);
|
||||
if (null === $budget) {
|
||||
throw new FireflyException('200004: Budget does not exist.');
|
||||
throw new FireflyException('200004: Budget does not exist.');
|
||||
}
|
||||
|
||||
// find limit with same date range and currency.
|
||||
@@ -329,7 +330,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
->where('budget_limits.transaction_currency_id', $currency->id)
|
||||
->first(['budget_limits.*']);
|
||||
if (null !== $limit) {
|
||||
throw new FireflyException('200027: Budget limit already exists.');
|
||||
throw new FireflyException('200027: Budget limit already exists.');
|
||||
}
|
||||
Log::debug('No existing budget limit, create a new one');
|
||||
|
||||
@@ -425,6 +426,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
// update if exists:
|
||||
|
Reference in New Issue
Block a user