Fixed a bug where the target date and start date could not be null [skip ci]

This commit is contained in:
James Cole 2014-08-17 08:57:08 +02:00
parent e4f04583a3
commit 372189a107
2 changed files with 13 additions and 4 deletions

View File

@ -129,6 +129,9 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
if ($data['reminder'] == 'none') {
unset($data['reminder']);
}
if($data['startdate'] == '') {
unset($data['startdate']);
}
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');

View File

@ -53,12 +53,18 @@ class EloquentPiggybankTrigger
/** @var \PiggybankRepetition $rep */
foreach ($reps as $rep) {
if ($rep->currentamount == 0) {
$sum = \Transaction::where('piggybank_id', $piggy->id)->leftJoin(
$query = \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(
);
if (!is_null($rep->startdate)) {
$query->where('transaction_journals.date', '>=', $rep->startdate->format('Y-m-d'));
}
if (!is_null($rep->targetdate)) {
$query->where(
'transaction_journals.date', '<=', $rep->targetdate->format('Y-m-d')
)->sum('transactions.amount');
);
}
$sum = $query->sum('transactions.amount');
$rep->currentamount = floatval($sum);
}
$rep->save();