This commit is contained in:
James Cole 2018-12-20 22:32:33 +01:00
parent 297e12f6e4
commit b6c23b8eb3

View File

@ -26,7 +26,9 @@ namespace FireflyIII\Jobs;
use Carbon\Carbon;
use FireflyIII\Events\RequestedReportOnJournals;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Rule;
@ -188,6 +190,24 @@ class CreateRecurringTransactions implements ShouldQueue
return $return;
}
/**
* @param Recurrence $recurrence
*
* @return int
*/
private function getPiggyId(Recurrence $recurrence): int
{
$meta = $recurrence->recurrenceMeta;
/** @var RecurrenceMeta $metaEntry */
foreach ($meta as $metaEntry) {
if ('piggy_bank_id' === $metaEntry->name) {
return (int)$metaEntry->value;
}
}
return 0;
}
/**
* Get the users rules.
*
@ -313,6 +333,12 @@ class CreateRecurringTransactions implements ShouldQueue
$journal = $this->journalRepository->store($array);
Log::info(sprintf('Created new journal #%d', $journal->id));
// get piggy bank ID from meta data:
$piggyBankId = $this->getPiggyId($recurrence);
// trigger event:
event(new StoredTransactionJournal($journal, $piggyBankId));
$collection->push($journal);
// update recurring thing:
$recurrence->latest_date = $date;