Added the ability to manually add or remove money from piggy banks (issue #6) [skip ci]

This commit is contained in:
James Cole
2014-08-17 08:45:22 +02:00
parent d645a38aec
commit e4f04583a3
10 changed files with 245 additions and 32 deletions

View File

@@ -52,12 +52,15 @@ class EloquentPiggybankTrigger
$reps = $piggy->piggybankrepetitions()->get();
/** @var \PiggybankRepetition $rep */
foreach ($reps as $rep) {
$sum = \Transaction::where('piggybank_id', $piggy->id)->leftJoin(
if ($rep->currentamount == 0) {
$sum = \Transaction::where('piggybank_id', $piggy->id)->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '>=', $rep->startdate->format('Y-m-d'))->where(
'transaction_journals.date', '<=', $rep->targetdate->format('Y-m-d')
)->sum('transactions.amount');
$rep->currentamount = floatval($sum);
'transaction_journals.date', '<=', $rep->targetdate->format('Y-m-d')
)->sum('transactions.amount');
$rep->currentamount = floatval($sum);
}
$rep->save();