Update piggy banks repetitions when the piggy bank is edited.

This commit is contained in:
James Cole 2014-11-20 11:19:35 +01:00
parent d758f72393
commit 61eb5b341d
3 changed files with 20 additions and 9 deletions

View File

@ -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') {

View File

@ -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)
{

View File

@ -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).