Do not update when no event connected.

This commit is contained in:
James Cole 2015-03-03 08:46:14 +01:00
parent f0316f09ed
commit fa344d5308
2 changed files with 9 additions and 0 deletions

View File

@ -32,6 +32,9 @@ class UpdateJournalConnection
// get the event connected to this journal: // get the event connected to this journal:
/** @var PiggyBankEvent $event */ /** @var PiggyBankEvent $event */
$event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first(); $event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first();
if(is_null($event)) {
return;
}
$piggyBank = $event->piggyBank()->first(); $piggyBank = $event->piggyBank()->first();
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first();

View File

@ -9,6 +9,7 @@ use FireflyIII\Http\Requests;
use FireflyIII\Http\Requests\PiggyBankFormRequest; use FireflyIII\Http\Requests\PiggyBankFormRequest;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@ -191,6 +192,9 @@ class PiggyBankController extends Controller
$repetition->currentamount += $amount; $repetition->currentamount += $amount;
$repetition->save(); $repetition->save();
// create event.
PiggyBankEvent::create(['date' => Carbon::now(), 'amount' => $amount, 'piggy_bank_id' => $piggyBank->id]);
/* /*
* Create event! * Create event!
*/ */
@ -220,6 +224,8 @@ class PiggyBankController extends Controller
$repetition->currentamount -= $amount; $repetition->currentamount -= $amount;
$repetition->save(); $repetition->save();
PiggyBankEvent::create(['date' => Carbon::now(), 'amount' => $amount * -1, 'piggy_bank_id' => $piggyBank->id]);
/* /*
* Create event! * Create event!
*/ */