mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 12:15:55 +00:00
Updated a lot of small things, new triggers for future reminder and some cleanup.
This commit is contained in:
@@ -80,6 +80,14 @@ class EloquentLimitTrigger
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \LimitRepetition $repetition
|
||||
*/
|
||||
public function madeRepetition(\LimitRepetition $repetition)
|
||||
{
|
||||
\Log::info('TRIGGER: Created a limit repetition (#' . $repetition->id . ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Limit $limit
|
||||
*
|
||||
@@ -101,8 +109,10 @@ class EloquentLimitTrigger
|
||||
//$events->listen('budgets.change', 'Firefly\Trigger\Limits\EloquentLimitTrigger@updateLimitRepetitions');
|
||||
$events->listen('limits.destroy', 'Firefly\Trigger\Limits\EloquentLimitTrigger@destroy');
|
||||
$events->listen('limits.store', 'Firefly\Trigger\Limits\EloquentLimitTrigger@store');
|
||||
$events->listen('limits.update', 'Firefly\Trigger\Limits\EloquentLimitTrigger@update');
|
||||
$events->listen('limits.check', 'Firefly\Trigger\Limits\EloquentLimitTrigger@checkRepeatingLimits');
|
||||
$events->listen('limits.update', 'Firefly\Trigger\Limits\EloquentLimitTrigger@update');
|
||||
$events->listen('limits.check', 'Firefly\Trigger\Limits\EloquentLimitTrigger@checkRepeatingLimits');
|
||||
$events->listen('limits.repetition', 'Firefly\Trigger\Limits\EloquentLimitTrigger@madeRepetition');
|
||||
//\Event::fire('limits.repetition', [$repetition]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,112 +12,6 @@ use Illuminate\Events\Dispatcher;
|
||||
*/
|
||||
class EloquentPiggybankTrigger
|
||||
{
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param \TransactionJournal $journal
|
||||
* @param \Transaction $transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createRelatedTransfer(
|
||||
\Piggybank $piggyBank, \TransactionJournal $journal, \Transaction $transaction
|
||||
)
|
||||
{
|
||||
$repetition = $piggyBank->repetitionForDate($journal->date);
|
||||
if (!is_null($repetition)) {
|
||||
// get the amount transferred TO this
|
||||
$amount = floatval($transaction->amount);
|
||||
$repetition->currentamount += $amount;
|
||||
$repetition->save();
|
||||
} else {
|
||||
\Session::flash('warning', 'Cannot add transfer to piggy, outside of scope.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(\Piggybank $piggyBank)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param $amount
|
||||
*/
|
||||
public function modifyAmountAdd(\Piggybank $piggyBank, $amount)
|
||||
{
|
||||
$rep = $piggyBank->currentRelevantRep();
|
||||
$today = new Carbon;
|
||||
|
||||
// create event:
|
||||
$event = new \PiggybankEvent;
|
||||
$event->date = new Carbon;
|
||||
$event->amount = $amount;
|
||||
$event->piggybank()->associate($piggyBank);
|
||||
|
||||
// for future / past repetitions.
|
||||
if (!($rep->startdate >= $today && $rep->targetdate <= $today)) {
|
||||
$event->date = $rep->startdate;
|
||||
}
|
||||
|
||||
|
||||
$event->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param $amount
|
||||
*/
|
||||
public function modifyAmountRemove(\Piggybank $piggyBank, $amount)
|
||||
{
|
||||
// create event:
|
||||
$event = new \PiggybankEvent;
|
||||
$event->date = new Carbon;
|
||||
$event->amount = $amount;
|
||||
$event->piggybank()->associate($piggyBank);
|
||||
$event->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*/
|
||||
public function storePiggy(\Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->createRepetition($piggyBank->startdate, $piggyBank->targetdate);
|
||||
return true;
|
||||
$rep = new \PiggybankRepetition;
|
||||
$rep->piggybank()->associate($piggyBank);
|
||||
$rep->targetdate = $piggyBank->targetdate;
|
||||
$rep->startdate = $piggyBank->startdate;
|
||||
$rep->currentamount = 0;
|
||||
$rep->save();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and creates all repetitions for repeating piggy banks.
|
||||
* This routine is also called whenever Firefly runs, so new repetitions
|
||||
* are created automatically.
|
||||
*
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function storeRepeated(\Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->createRepetition($piggyBank->startdate, $piggyBank->targetdate);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -125,7 +19,7 @@ class EloquentPiggybankTrigger
|
||||
{
|
||||
|
||||
if (\Auth::check()) {
|
||||
$piggies = \Auth::user()->piggybanks()->where('repeats',1)->get();
|
||||
$piggies = \Auth::user()->piggybanks()->where('repeats', 1)->get();
|
||||
} else {
|
||||
$piggies = [];
|
||||
}
|
||||
@@ -184,6 +78,121 @@ class EloquentPiggybankTrigger
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param \TransactionJournal $journal
|
||||
* @param \Transaction $transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createRelatedTransfer(
|
||||
\Piggybank $piggyBank, \TransactionJournal $journal, \Transaction $transaction
|
||||
) {
|
||||
$repetition = $piggyBank->repetitionForDate($journal->date);
|
||||
if (!is_null($repetition)) {
|
||||
// get the amount transferred TO this
|
||||
$amount = floatval($transaction->amount);
|
||||
$repetition->currentamount += $amount;
|
||||
$repetition->save();
|
||||
} else {
|
||||
\Session::flash('warning', 'Cannot add transfer to piggy, outside of scope.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(\Piggybank $piggyBank)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PiggybankRepetition $rep
|
||||
*/
|
||||
public function madeRep(\PiggybankRepetition $rep)
|
||||
{
|
||||
// do something.
|
||||
\Log::info('TRIGGER: Created a piggybank repetition (#' . $rep->id . ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param $amount
|
||||
*/
|
||||
public function modifyAmountAdd(\Piggybank $piggyBank, $amount)
|
||||
{
|
||||
$rep = $piggyBank->currentRelevantRep();
|
||||
$today = new Carbon;
|
||||
|
||||
// create event:
|
||||
$event = new \PiggybankEvent;
|
||||
$event->date = new Carbon;
|
||||
$event->amount = $amount;
|
||||
$event->piggybank()->associate($piggyBank);
|
||||
|
||||
// for future / past repetitions.
|
||||
if (!($rep->startdate >= $today && $rep->targetdate <= $today)) {
|
||||
$event->date = $rep->startdate;
|
||||
}
|
||||
|
||||
|
||||
$event->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
* @param $amount
|
||||
*/
|
||||
public function modifyAmountRemove(\Piggybank $piggyBank, $amount)
|
||||
{
|
||||
// create event:
|
||||
$event = new \PiggybankEvent;
|
||||
$event->date = new Carbon;
|
||||
$event->amount = $amount;
|
||||
$event->piggybank()->associate($piggyBank);
|
||||
$event->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Piggybank $piggyBank
|
||||
*/
|
||||
public function storePiggy(\Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->createRepetition($piggyBank->startdate, $piggyBank->targetdate);
|
||||
|
||||
return true;
|
||||
$rep = new \PiggybankRepetition;
|
||||
$rep->piggybank()->associate($piggyBank);
|
||||
$rep->targetdate = $piggyBank->targetdate;
|
||||
$rep->startdate = $piggyBank->startdate;
|
||||
$rep->currentamount = 0;
|
||||
$rep->save();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and creates all repetitions for repeating piggy banks.
|
||||
* This routine is also called whenever Firefly runs, so new repetitions
|
||||
* are created automatically.
|
||||
*
|
||||
* @param \Piggybank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function storeRepeated(\Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->createRepetition($piggyBank->startdate, $piggyBank->targetdate);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
@@ -210,7 +219,13 @@ class EloquentPiggybankTrigger
|
||||
'piggybanks.updateRelatedTransfer',
|
||||
'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@updateRelatedTransfer'
|
||||
);
|
||||
$events->listen('piggybanks.check', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@checkRepeatingPiggies');
|
||||
$events->listen(
|
||||
'piggybanks.check', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@checkRepeatingPiggies'
|
||||
);
|
||||
|
||||
$events->listen(
|
||||
'piggybanks.repetition', 'Firefly\Trigger\Piggybanks\EloquentPiggybankTrigger@madeRep'
|
||||
);
|
||||
}
|
||||
|
||||
public function update(\Piggybank $piggyBank)
|
||||
|
||||
Reference in New Issue
Block a user