Skip to content

Firefly III: a personal finances manager

Fixed route when removing piggy banks.

James Cole7d2627515fdc
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index c761cbf207..3fb864bfc2 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -15,8 +15,8 @@ use Firefly\Storage\Piggybank\PiggybankRepositoryInterface as PRI;
class PiggybankController extends BaseController
{
- protected $_repository;
protected $_accounts;
+ protected $_repository;
/**
* @param PRI $repository
@@ -91,10 +91,10 @@ class PiggybankController extends BaseController
*/
public function delete(Piggybank $piggyBank)
{
- View::share('subTitle', 'Delete "'.$piggyBank->name.'"');
- if($piggyBank->repeats == 1) {
+ View::share('subTitle', 'Delete "' . $piggyBank->name . '"');
+ if ($piggyBank->repeats == 1) {
View::share('title', 'Repeated expenses');
- View::share('mainTitleIcon', 'fa-rotate-right');
+ View::share('mainTitleIcon', 'fa-rotate-right')
} else {
View::share('title', 'Piggy banks');
View::share('mainTitleIcon', 'fa-sort-amount-asc');
@@ -111,11 +111,18 @@ class PiggybankController extends BaseController
public function destroy(Piggybank $piggyBank)
{
Event::fire('piggybanks.destroy', [$piggyBank]);
+ if ($piggyBank->repeats == 1) {
+ $route = 'piggybanks.index.repeated';
+ $message = 'Repeated expense';
+ } else {
+ $route = 'piggybanks.index.piggybanks';
+ $message = 'Piggybank';
+ }
$this->_repository->destroy($piggyBank);
- Session::flash('success', 'Piggy bank deleted.');
+ Session::flash('success', $message . ' deleted.');
- return Redirect::route('piggybanks.index');
+ return Redirect::route($route);
}
/**
@@ -133,19 +140,18 @@ class PiggybankController extends BaseController
$periods = Config::get('firefly.piggybank_periods');
- View::share('subTitle','Edit "'.$piggyBank->name.'"');
-
+ View::share('subTitle', 'Edit "' . $piggyBank->name . '"');
if ($piggyBank->repeats == 1) {
- View::share('title','Repeated expenses');
+ View::share('title', 'Repeated expenses');
View::share('mainTitleIcon', 'fa-rotate-left');
return View::make('piggybanks.edit-repeated')->with('piggybank', $piggyBank)->with('accounts', $accounts)
->with('periods', $periods);
} else {
// piggy bank.
- View::share('title','Piggy banks');
+ View::share('title', 'Piggy banks');
View::share('mainTitleIcon', 'fa-sort-amount-asc');
return View::make('piggybanks.edit-piggybank')->with('piggybank', $piggyBank)->with('accounts', $accounts)
@@ -155,6 +161,45 @@ class PiggybankController extends BaseController
}
+ /**
+ * @param Piggybank $piggyBank
+ *
+ * @return \Illuminate\Http\RedirectResponse
+ * @throws Firefly\Exception\FireflyException
+ */
+ public function modMoney(Piggybank $piggyBank)
+ {
+ $amount = floatval(Input::get('amount'));
+ switch (Input::get('what')) {
+ default:
+ throw new FireflyException('No such action');
+ break;
+ case 'add':
+ $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
+ if (round($amount, 2) <= round(min($maxAdd, $piggyBank->targetamount), 2)) {
+ Session::flash('success', 'Amount updated!');
+ $this->_repository->modifyAmount($piggyBank, $amount);
+ Event::fire('piggybanks.modifyAmountAdd', [$piggyBank, $amount]);
+ } else {
+ Session::flash('warning', 'Could not!');
+ }
+ break;
+ case 'remove':
+ $rep = $piggyBank->currentRelevantRep();
+ $maxRemove = $rep->currentamount;
+ if (round($amount, 2) <= round($maxRemove, 2)) {
+ Session::flash('success', 'Amount updated!');
+ $this->_repository->modifyAmount($piggyBank, ($amount * -1));
+ Event::fire('piggybanks.modifyAmountRemove', [$piggyBank, ($amount * -1)]);
+ } else {
+ Session::flash('warning', 'Could not!');
+ }
+ break;
+ }
+
+ return Redirect::route('piggybanks.index');
+ }
+
/**
* @return $this
*/
@@ -188,6 +233,22 @@ class PiggybankController extends BaseController
->with('accounts', $accounts);
}
+ /**
+ * @param Piggybank $piggyBank
+ *
+ * @return $this
+ */
+ public function removeMoney(Piggybank $piggyBank)
+ {
+ $what = 'remove';
+ $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
+ $maxRemove = $piggyBank->currentRelevantRep()->currentamount;
+
+ return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with(
+ 'maxRemove', $maxRemove
+ )->with('piggybank', $piggyBank);
+ }
+
/**
* @return $this
*/
@@ -222,61 +283,6 @@ class PiggybankController extends BaseController
->with('accounts', $accounts);
}
- /**
- * @param Piggybank $piggyBank
- *
- * @return \Illuminate\Http\RedirectResponse
- * @throws Firefly\Exception\FireflyException
- */
- public function modMoney(Piggybank $piggyBank)
- {
- $amount = floatval(Input::get('amount'));
- switch (Input::get('what')) {
- default:
- throw new FireflyException('No such action');
- break;
- case 'add':
- $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
- if (round($amount, 2) <= round(min($maxAdd, $piggyBank->targetamount), 2)) {
- Session::flash('success', 'Amount updated!');
- $this->_repository->modifyAmount($piggyBank, $amount);
- Event::fire('piggybanks.modifyAmountAdd', [$piggyBank, $amount]);
- } else {
- Session::flash('warning', 'Could not!');
- }
- break;
- case 'remove':
- $rep = $piggyBank->currentRelevantRep();
- $maxRemove = $rep->currentamount;
- if (round($amount, 2) <= round($maxRemove, 2)) {
- Session::flash('success', 'Amount updated!');
- $this->_repository->modifyAmount($piggyBank, ($amount * -1));
- Event::fire('piggybanks.modifyAmountRemove', [$piggyBank, ($amount * -1)]);
- } else {
- Session::flash('warning', 'Could not!');
- }
- break;
- }
-
- return Redirect::route('piggybanks.index');
- }
-
- /**
- * @param Piggybank $piggyBank
- *
- * @return $this
- */
- public function removeMoney(Piggybank $piggyBank)
- {
- $what = 'remove';
- $maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
- $maxRemove = $piggyBank->currentRelevantRep()->currentamount;
-
- return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with(
- 'maxRemove', $maxRemove
- )->with('piggybank', $piggyBank);
- }
-
/**
*
*/
@@ -285,15 +291,15 @@ class PiggybankController extends BaseController
$leftOnAccount = $this->_repository->leftOnAccount($piggyBank->account);
$balance = $piggyBank->account->balance();
- View::share('subTitle',$piggyBank->name);
+ View::share('subTitle', $piggyBank->name);
- if($piggyBank->repeats == 1) {
+ if ($piggyBank->repeats == 1) {
// repeated expense.
- View::share('title','Repeated expenses');
+ View::share('title', 'Repeated expenses');
View::share('mainTitleIcon', 'fa-rotate-left');
} else {
// piggy bank.
- View::share('title','Piggy banks');
+ View::share('title', 'Piggy banks');
View::share('mainTitleIcon', 'fa-sort-amount-asc');
}