Skip to content

Firefly III: a personal finances manager

These routines fix #477

James Cole116e19ec064a
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 2372e7e101..78eb0ccac2 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -124,17 +124,24 @@ class AccountController extends Controller
*/
public function destroy(ARI $repository, Account $account)
{
- $type = $account->accountType->type;
- $typeName = config('firefly.shortNamesByFullName.' . $type);
- $name = $account->name;
- $moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
+ $type = $account->accountType->type;
+ $typeName = config('firefly.shortNamesByFullName.' . $type);
+ $name = $account->name;
+ $accountId = $account->id;
+ $moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
$repository->destroy($account, $moveTo);
Session::flash('success', strval(trans('firefly.' . $typeName . '_deleted', ['name' => $name])));
Preferences::mark();
- return redirect(session('accounts.delete.url'));
+ $uri = session('accounts.delete.url');
+ if (!(strpos($uri, sprintf('accounts/show/%s', $accountId)) === false)) {
+ // uri would point back to account
+ $uri = route('accounts.index', [$typeName]);
+ }
+
+ return redirect($uri);
}
/**
@@ -236,11 +243,11 @@ class AccountController extends Controller
$subTitle = $account->name;
$range = Preferences::get('viewRange', '1M')->data;
- $start = session('start', Navigation::startOfPeriod(new Carbon, $range));
- $end = session('end', Navigation::endOfPeriod(new Carbon, $range));
- $page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
- $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
- $chartUri = route('chart.account.single', [$account->id]);
+ $start = session('start', Navigation::startOfPeriod(new Carbon, $range));
+ $end = session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
+ $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
+ $chartUri = route('chart.account.single', [$account->id]);
// grab those journals:
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
$journals = $collector->getPaginatedJournals();
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index 4cccbdeba3..5e3b3a09ef 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -99,13 +99,20 @@ class BillController extends Controller
*/
public function destroy(BillRepositoryInterface $repository, Bill $bill)
{
- $name = $bill->name;
+ $name = $bill->name;
+ $billId = $bill->id;
$repository->destroy($bill);
Session::flash('success', strval(trans('firefly.deleted_bill', ['name' => $name])));
Preferences::mark();
- return redirect(session('bills.delete.url'));
+ $uri = session('bills.delete.url');
+ if (!(strpos($uri, sprintf('bills/show/%s', $billId)) === false)) {
+ // uri would point back to bill
+ $uri = route('bills.index');
+ }
+
+ return redirect($uri);
}
/**
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index 9605e0b8c6..a1ef39d63c 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -134,15 +134,21 @@ class BudgetController extends Controller
public function destroy(Budget $budget, BudgetRepositoryInterface $repository)
{
- $name = $budget->name;
+ $name = $budget->name;
+ $budgetId = $budget->id;
$repository->destroy($budget);
Session::flash('success', strval(trans('firefly.deleted_budget', ['name' => e($name)])));
Preferences::mark();
+ $uri = session('budgets.delete.url');
+ if (!(strpos($uri, sprintf('budgets/show/%s', $budgetId)) === false)) {
+ // uri would point back to budget
+ $uri = route('budgets.index');
+ }
- return redirect(session('budgets.delete.url'));
+ return redirect($uri);
}
/**
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index 835ab48c09..4d7a67e64c 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -98,13 +98,20 @@ class CategoryController extends Controller
public function destroy(CRI $repository, Category $category)
{
- $name = $category->name;
+ $name = $category->name;
+ $categoryId = $category->id;
$repository->destroy($category);
Session::flash('success', strval(trans('firefly.deleted_category', ['name' => e($name)])));
Preferences::mark();
- return redirect(session('categories.delete.url'));
+ $uri = session('categories.delete.url');
+ if (!(strpos($uri, sprintf('categories/show/%s', $categoryId)) === false)) {
+ // uri would point back to category
+ $uri = route('categories.index');
+ }
+
+ return redirect($uri);
}
/**
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php
index d1feb427eb..5d494b5985 100644
--- a/app/Http/Controllers/PiggyBankController.php
+++ b/app/Http/Controllers/PiggyBankController.php
@@ -150,13 +150,18 @@ class PiggyBankController extends Controller
*/
public function destroy(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
{
-
-
Session::flash('success', strval(trans('firefly.deleted_piggy_bank', ['name' => e($piggyBank->name)])));
Preferences::mark();
+ $piggyBankId = $piggyBank->id;
$repository->destroy($piggyBank);
- return redirect(session('piggy-banks.delete.url'));
+ $uri = session('piggy-banks.delete.url');
+ if (!(strpos($uri, sprintf('piggy-banks/show/%s', $piggyBankId)) === false)) {
+ // uri would point back to piggy bank
+ $uri = route('piggy-banks.index');
+ }
+
+ return redirect($uri);
}
/**
@@ -260,6 +265,7 @@ class PiggyBankController extends Controller
$repository->setOrder(intval($id), ($order + 1));
}
}
+
return Response::json(['result' => 'ok']);
}
diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.php
index 98ba1458de..96915dae35 100644
--- a/app/Http/Controllers/Transaction/SingleController.php
+++ b/app/Http/Controllers/Transaction/SingleController.php
@@ -153,16 +153,21 @@ class SingleController extends Controller
if ($this->isOpeningBalance($transactionJournal)) {
return $this->redirectToAccount($transactionJournal);
}
-
- $type = TransactionJournal::transactionTypeStr($transactionJournal);
+ $journalId = $transactionJournal->id;
+ $type = TransactionJournal::transactionTypeStr($transactionJournal);
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));
$repository->delete($transactionJournal);
Preferences::mark();
- // redirect to previous URL:
- return redirect(session('transactions.delete.url'));
+ $uri = session('transactions.delete.url');
+ if (!(strpos($uri, sprintf('transactions/show/%s', $journalId)) === false)) {
+ // uri would point back to transaction
+ $uri = route('transactions.index', [strtolower($type)]);
+ }
+
+ return redirect($uri);
}
/**