Skip to content

Firefly III: a personal finances manager

Update piggy banks repetitions when the piggy bank is edited.

James Cole61eb5b341dad
diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php
index f94e1368d1..2e9cd7fbfb 100644
--- a/app/controllers/PiggybankController.php
+++ b/app/controllers/PiggybankController.php
@@ -283,7 +283,7 @@ class PiggybankController extends BaseController
/*
* Create the relevant repetition per Event.
*/
- Event::fire('piggybank.storePiggybank', [$piggyBank]); // new and used.
+ Event::fire('piggybank.store', [$piggyBank]); // new and used.
Session::flash('success', 'New piggy bank stored!');
@@ -333,6 +333,7 @@ class PiggybankController extends BaseController
}
// store!
$repos->update($piggyBank, $data);
+ Event::fire('piggybank.update', [$piggyBank]); // new and used.
Session::flash('success', 'Piggy bank updated!');
if ($data['post_submit_action'] == 'return_to_edit') {
diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php
index c856dfba05..f5e24c72f1 100644
--- a/app/lib/FireflyIII/Event/Piggybank.php
+++ b/app/lib/FireflyIII/Event/Piggybank.php
@@ -88,10 +88,6 @@ class Piggybank
}
}
- /*
- *
- */
-
public function storePiggybank(\Piggybank $piggybank)
{
if (intval($piggybank->repeats) == 0) {
@@ -104,6 +100,10 @@ class Piggybank
}
}
+ /*
+ *
+ */
+
/**
* @param \TransactionJournal $journal
* @param int $piggybankId
@@ -182,8 +182,9 @@ class Piggybank
// triggers on piggy bank events:
$events->listen('piggybank.addMoney', 'FireflyIII\Event\Piggybank@addMoney');
$events->listen('piggybank.removeMoney', 'FireflyIII\Event\Piggybank@removeMoney');
+ $events->listen('piggybank.store', 'FireflyIII\Event\Piggybank@storePiggybank');
+ $events->listen('piggybank.update', 'FireflyIII\Event\Piggybank@updatePiggybank');
- $events->listen('piggybank.storePiggybank', 'FireflyIII\Event\Piggybank@storePiggybank');
// triggers when others are updated.
$events->listen('transactionJournal.store', 'FireflyIII\Event\Piggybank@storeTransfer');
@@ -191,6 +192,15 @@ class Piggybank
$events->listen('transactionJournal.destroy', 'FireflyIII\Event\Piggybank@destroyTransfer');
}
+ public function updatePiggybank(\Piggybank $piggybank)
+ {
+ // get the repetition:
+ $repetition = $piggybank->currentRelevantRep();
+ $repetition->startdate = $piggybank->startdate;
+ $repetition->targetdate = $piggybank->targetdate;
+ $repetition->save();
+ }
+
public function updateTransfer(\TransactionJournal $journal)
{
diff --git a/bootstrap/start.php b/bootstrap/start.php
index fc0f6e7441..ac8176b74e 100644
--- a/bootstrap/start.php
+++ b/bootstrap/start.php
@@ -92,14 +92,14 @@ Event::subscribe('FireflyIII\Event\Piggybank');
Event::subscribe('FireflyIII\Event\Budget');
Event::subscribe('FireflyIII\Event\TransactionJournal');
-// TODO event that creates a relationship between transaction journals and recurring events when created.
-// TODO event that updates the relationship between transaction journals and recurring events when edited.
+// event that creates a relationship between transaction journals and recurring events when created.
+// event that updates the relationship between transaction journals and recurring events when edited.
// event that creates a LimitRepetition when a Limit is created.
// event for when a transfer gets created and set an associated piggy bank; save as Piggy bank event.
// when this transfer gets edited, retro-actively edit the event and THUS also the piggy bank.
// event for when a transfer gets deleted; also delete related piggy bank event.
// event to create the first repetition (for non-repeating piggy banks) when the piggy bank is created.
-// TODO event for when the non-repeating piggy bank is updated because the single repetition must also be changed.
+// event for when the non-repeating piggy bank is updated because the single repetition must also be changed.
// (also make piggy bank events "invalid" when they start falling outside of the date-scope of the piggy bank,
// although this not changes the amount in the piggy bank).
// TODO check if recurring transactions are being updated when journals are updated (aka no longer fitting, thus removed).