This commit is contained in:
James Cole
2024-11-03 08:16:46 +01:00
parent dc1ecf6a42
commit 7028cb1546
7 changed files with 118 additions and 101 deletions

View File

@@ -46,10 +46,15 @@ class Cron extends Command
protected $signature = 'firefly-iii:cron protected $signature = 'firefly-iii:cron
{--F|force : Force the cron job(s) to execute.} {--F|force : Force the cron job(s) to execute.}
{--date= : Set the date in YYYY-MM-DD to make Firefly III think that\'s the current date.} {--date= : Set the date in YYYY-MM-DD to make Firefly III think that\'s the current date.}
{--download-cer : Download exchange rates. Other tasks will be skipped unless also requested.}
{--create-recurring : Create recurring transactions. Other tasks will be skipped unless also requested.}
{--create-auto-budgets : Create auto budgets. Other tasks will be skipped unless also requested.}
{--send-bill-warnings : Send bill warnings. Other tasks will be skipped unless also requested.}
'; ';
public function handle(): int public function handle(): int
{ {
$doAll = !$this->option('download-cer') && !$this->option('create-recurring') && !$this->option('create-auto-budgets') && !$this->option('send-bill-warnings');
$date = null; $date = null;
try { try {
@@ -60,7 +65,7 @@ class Cron extends Command
$force = (bool)$this->option('force'); // @phpstan-ignore-line $force = (bool)$this->option('force'); // @phpstan-ignore-line
// Fire exchange rates cron job. // Fire exchange rates cron job.
if (true === config('cer.download_enabled')) { if (true === config('cer.download_enabled') && ($doAll || $this->option('download-cer'))) {
try { try {
$this->exchangeRatesCronJob($force, $date); $this->exchangeRatesCronJob($force, $date);
} catch (FireflyException $e) { } catch (FireflyException $e) {
@@ -71,30 +76,36 @@ class Cron extends Command
} }
// Fire recurring transaction cron job. // Fire recurring transaction cron job.
try { if($doAll || $this->option('create-recurring')) {
$this->recurringCronJob($force, $date); try {
} catch (FireflyException $e) { $this->recurringCronJob($force, $date);
app('log')->error($e->getMessage()); } catch (FireflyException $e) {
app('log')->error($e->getTraceAsString()); app('log')->error($e->getMessage());
$this->friendlyError($e->getMessage()); app('log')->error($e->getTraceAsString());
$this->friendlyError($e->getMessage());
}
} }
// Fire auto-budget cron job: // Fire auto-budget cron job:
try { if($doAll || $this->option('create-auto-budgets')) {
$this->autoBudgetCronJob($force, $date); try {
} catch (FireflyException $e) { $this->autoBudgetCronJob($force, $date);
app('log')->error($e->getMessage()); } catch (FireflyException $e) {
app('log')->error($e->getTraceAsString()); app('log')->error($e->getMessage());
$this->friendlyError($e->getMessage()); app('log')->error($e->getTraceAsString());
$this->friendlyError($e->getMessage());
}
} }
// Fire bill warning cron job // Fire bill warning cron job
try { if($doAll || $this->option('send-bill-warnings')) {
$this->billWarningCronJob($force, $date); try {
} catch (FireflyException $e) { $this->billWarningCronJob($force, $date);
app('log')->error($e->getMessage()); } catch (FireflyException $e) {
app('log')->error($e->getTraceAsString()); app('log')->error($e->getMessage());
$this->friendlyError($e->getMessage()); app('log')->error($e->getTraceAsString());
$this->friendlyError($e->getMessage());
}
} }
$this->friendlyInfo('More feedback on the cron jobs can be found in the log files.'); $this->friendlyInfo('More feedback on the cron jobs can be found in the log files.');

View File

@@ -88,6 +88,7 @@ class ShowController extends Controller
$groups = $this->recurring->getTransactions($recurrence); $groups = $this->recurring->getTransactions($recurrence);
$today = today(config('app.timezone')); $today = today(config('app.timezone'));
$array['repeat_until'] = null !== $array['repeat_until'] ? new Carbon($array['repeat_until']) : null; $array['repeat_until'] = null !== $array['repeat_until'] ? new Carbon($array['repeat_until']) : null;
$array['journal_count'] = $this->recurring->getJournalCount($recurrence);
// transform dates back to Carbon objects and expand information // transform dates back to Carbon objects and expand information
foreach ($array['repetitions'] as $index => $repetition) { foreach ($array['repetitions'] as $index => $repetition) {

View File

@@ -177,10 +177,11 @@ class CreateRecurringTransactions implements ShouldQueue
// has repeated X times. // has repeated X times.
$journalCount = $this->repository->getJournalCount($recurrence); $journalCount = $this->repository->getJournalCount($recurrence);
if (0 !== $recurrence->repetitions && $journalCount >= $recurrence->repetitions && false === $this->force) { if (0 !== $recurrence->repetitions && $journalCount >= $recurrence->repetitions && false === $this->force) {
app('log')->info(sprintf('Recurrence #%d has run %d times, so will run no longer.', $recurrence->id, $recurrence->repetitions)); app('log')->info(sprintf('Recurrence #%d has run %d times, so will run no longer.', $recurrence->id, $journalCount));
return false; return false;
} }
app('log')->debug(sprintf('Recurrence #%d has run %d times, max is %d times.', $recurrence->id, $journalCount, $recurrence->repetitions));
// is no longer running // is no longer running
if ($this->repeatUntilHasPassed($recurrence)) { if ($this->repeatUntilHasPassed($recurrence)) {
@@ -202,8 +203,8 @@ class CreateRecurringTransactions implements ShouldQueue
sprintf( sprintf(
'Recurrence #%d is set to run on %s, and today\'s date is %s. Skipped.', 'Recurrence #%d is set to run on %s, and today\'s date is %s. Skipped.',
$recurrence->id, $recurrence->id,
$recurrence->first_date->format('Y-m-d'), $recurrence->first_date->format('Y-m-d H:i:s'),
$this->date->format('Y-m-d') $this->date->format('Y-m-d H:i:s')
) )
); );
@@ -244,9 +245,10 @@ class CreateRecurringTransactions implements ShouldQueue
private function hasNotStartedYet(Recurrence $recurrence): bool private function hasNotStartedYet(Recurrence $recurrence): bool
{ {
$startDate = $this->getStartDate($recurrence); $startDate = $this->getStartDate($recurrence);
app('log')->debug(sprintf('Start date is %s', $startDate->format('Y-m-d'))); app('log')->debug(sprintf('Start date is %s', $startDate->format('Y-m-d H:i:s')));
app('log')->debug(sprintf('Ask date is %s', $this->date->format('Y-m-d H:i:s')));
return $startDate->gt($this->date); return $startDate->gte($this->date);
} }
/** /**

View File

@@ -66,21 +66,20 @@ class RecurringRepository implements RecurringRepositoryInterface
// if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well. // if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well.
$set $set
= TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence): void { = TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence): void {
$q1->where('name', 'recurrence_id'); $q1->where('name', 'recurrence_id');
$q1->where('data', json_encode((string)$recurrence->id)); $q1->where('data', json_encode((string) $recurrence->id));
})->get(['journal_meta.transaction_journal_id']); })->get(['journal_meta.transaction_journal_id']);
// there are X journals made for this recurrence. Any of them meant for today? // there are X journals made for this recurrence. Any of them meant for today?
foreach ($set as $journalMeta) { foreach ($set as $journalMeta) {
$count = TransactionJournalMeta::where(static function (Builder $q2) use ($date): void { $count = TransactionJournalMeta::where(static function (Builder $q2) use ($date): void {
$string = (string)$date; $string = (string) $date;
app('log')->debug(sprintf('Search for date: %s', json_encode($string))); app('log')->debug(sprintf('Search for date: %s', json_encode($string)));
$q2->where('name', 'recurrence_date'); $q2->where('name', 'recurrence_date');
$q2->where('data', json_encode($string)); $q2->where('data', json_encode($string));
}) })
->where('transaction_journal_id', $journalMeta->transaction_journal_id) ->where('transaction_journal_id', $journalMeta->transaction_journal_id)
->count() ->count();
;
if ($count > 0) { if ($count > 0) {
app('log')->debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id)); app('log')->debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id));
@@ -97,12 +96,11 @@ class RecurringRepository implements RecurringRepositoryInterface
public function get(): Collection public function get(): Collection
{ {
return $this->user->recurrences() return $this->user->recurrences()
->with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions']) ->with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('transaction_type_id', 'ASC') ->orderBy('transaction_type_id', 'ASC')
->orderBy('title', 'ASC') ->orderBy('title', 'ASC')
->get() ->get();
;
} }
/** /**
@@ -128,10 +126,9 @@ class RecurringRepository implements RecurringRepositoryInterface
{ {
// grab ALL recurring transactions: // grab ALL recurring transactions:
return Recurrence::with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions']) return Recurrence::with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('title', 'ASC') ->orderBy('title', 'ASC')
->get() ->get();
;
} }
public function getBillId(RecurrenceTransaction $recTransaction): ?int public function getBillId(RecurrenceTransaction $recTransaction): ?int
@@ -141,7 +138,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var RecurrenceTransactionMeta $meta */ /** @var RecurrenceTransactionMeta $meta */
foreach ($recTransaction->recurrenceTransactionMeta as $meta) { foreach ($recTransaction->recurrenceTransactionMeta as $meta) {
if ('bill_id' === $meta->name) { if ('bill_id' === $meta->name) {
$return = (int)$meta->value; $return = (int) $meta->value;
} }
} }
@@ -158,7 +155,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var RecurrenceTransactionMeta $meta */ /** @var RecurrenceTransactionMeta $meta */
foreach ($recTransaction->recurrenceTransactionMeta as $meta) { foreach ($recTransaction->recurrenceTransactionMeta as $meta) {
if ('budget_id' === $meta->name) { if ('budget_id' === $meta->name) {
$return = (int)$meta->value; $return = (int) $meta->value;
} }
} }
@@ -175,7 +172,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var RecurrenceTransactionMeta $meta */ /** @var RecurrenceTransactionMeta $meta */
foreach ($recTransaction->recurrenceTransactionMeta as $meta) { foreach ($recTransaction->recurrenceTransactionMeta as $meta) {
if ('category_id' === $meta->name) { if ('category_id' === $meta->name) {
$return = (int)$meta->value; $return = (int) $meta->value;
} }
} }
@@ -192,7 +189,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var RecurrenceTransactionMeta $meta */ /** @var RecurrenceTransactionMeta $meta */
foreach ($recTransaction->recurrenceTransactionMeta as $meta) { foreach ($recTransaction->recurrenceTransactionMeta as $meta) {
if ('category_name' === $meta->name) { if ('category_name' === $meta->name) {
$return = (string)$meta->value; $return = (string) $meta->value;
} }
} }
@@ -204,20 +201,21 @@ class RecurringRepository implements RecurringRepositoryInterface
*/ */
public function getJournalCount(Recurrence $recurrence, ?Carbon $start = null, ?Carbon $end = null): int public function getJournalCount(Recurrence $recurrence, ?Carbon $start = null, ?Carbon $end = null): int
{ {
Log::debug(sprintf('Now in getJournalCount(#%d, "%s", "%s")', $recurrence->id, $start?->format('Y-m-d H:i:s'), $end?->format('Y-m-d H:i:s')));
$query = TransactionJournal::leftJoin('journal_meta', 'journal_meta.transaction_journal_id', '=', 'transaction_journals.id') $query = TransactionJournal::leftJoin('journal_meta', 'journal_meta.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.user_id', $recurrence->user_id) ->where('transaction_journals.user_id', $recurrence->user_id)
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->where('journal_meta.name', 'recurrence_id') ->where('journal_meta.name', 'recurrence_id')
->where('journal_meta.data', '"'.$recurrence->id.'"') ->where('journal_meta.data', '"' . $recurrence->id . '"');
;
if (null !== $start) { if (null !== $start) {
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')); $query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'));
} }
if (null !== $end) { if (null !== $end) {
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')); $query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
} }
$count = $query->count('transaction_journals.id');
return $query->count('transaction_journals.id'); Log::debug(sprintf('Count is %d', $count));
return $count;
} }
/** /**
@@ -226,11 +224,10 @@ class RecurringRepository implements RecurringRepositoryInterface
public function getJournalIds(Recurrence $recurrence): array public function getJournalIds(Recurrence $recurrence): array
{ {
return TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id') return TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('journal_meta.name', '=', 'recurrence_id') ->where('journal_meta.name', '=', 'recurrence_id')
->where('journal_meta.data', '=', json_encode((string)$recurrence->id)) ->where('journal_meta.data', '=', json_encode((string) $recurrence->id))
->get(['journal_meta.transaction_journal_id'])->pluck('transaction_journal_id')->toArray() ->get(['journal_meta.transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
;
} }
/** /**
@@ -241,7 +238,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var null|Note $note */ /** @var null|Note $note */
$note = $recurrence->notes()->first(); $note = $recurrence->notes()->first();
return (string)$note?->text; return (string) $note?->text;
} }
public function getPiggyBank(RecurrenceTransaction $transaction): ?int public function getPiggyBank(RecurrenceTransaction $transaction): ?int
@@ -251,7 +248,7 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var RecurrenceTransactionMeta $metaEntry */ /** @var RecurrenceTransactionMeta $metaEntry */
foreach ($meta as $metaEntry) { foreach ($meta as $metaEntry) {
if ('piggy_bank_id' === $metaEntry->name) { if ('piggy_bank_id' === $metaEntry->name) {
return (int)$metaEntry->value; return (int) $metaEntry->value;
} }
} }
@@ -278,30 +275,28 @@ class RecurringRepository implements RecurringRepositoryInterface
public function getTransactionPaginator(Recurrence $recurrence, int $page, int $pageSize): LengthAwarePaginator public function getTransactionPaginator(Recurrence $recurrence, int $page, int $pageSize): LengthAwarePaginator
{ {
$journalMeta = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id') $journalMeta = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('name', 'recurrence_id') ->where('name', 'recurrence_id')
->where('data', json_encode((string)$recurrence->id)) ->where('data', json_encode((string) $recurrence->id))
->get()->pluck('transaction_journal_id')->toArray() ->get()->pluck('transaction_journal_id')->toArray();
;
$search = []; $search = [];
foreach ($journalMeta as $journalId) { foreach ($journalMeta as $journalId) {
$search[] = (int)$journalId; $search[] = (int) $journalId;
} }
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($recurrence->user); $collector->setUser($recurrence->user);
$collector->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page) $collector->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page)
->withAccountInformation() ->withAccountInformation();
;
$collector->setJournalIds($search); $collector->setJournalIds($search);
return $collector->getPaginatedGroups(); return $collector->getPaginatedGroups();
} }
public function setUser(null|Authenticatable|User $user): void public function setUser(null | Authenticatable | User $user): void
{ {
if ($user instanceof User) { if ($user instanceof User) {
$this->user = $user; $this->user = $user;
@@ -311,23 +306,22 @@ class RecurringRepository implements RecurringRepositoryInterface
public function getTransactions(Recurrence $recurrence): Collection public function getTransactions(Recurrence $recurrence): Collection
{ {
$journalMeta = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id') $journalMeta = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('name', 'recurrence_id') ->where('name', 'recurrence_id')
->where('data', json_encode((string)$recurrence->id)) ->where('data', json_encode((string) $recurrence->id))
->get()->pluck('transaction_journal_id')->toArray() ->get()->pluck('transaction_journal_id')->toArray();
;
$search = []; $search = [];
foreach ($journalMeta as $journalId) { foreach ($journalMeta as $journalId) {
$search[] = (int)$journalId; $search[] = (int) $journalId;
} }
if (0 === count($search)) { if (0 === count($search)) {
return new Collection(); return new Collection();
} }
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($recurrence->user); $collector->setUser($recurrence->user);
$collector->withCategoryInformation()->withBudgetInformation()->withAccountInformation(); $collector->withCategoryInformation()->withBudgetInformation()->withAccountInformation();
@@ -442,51 +436,51 @@ class RecurringRepository implements RecurringRepositoryInterface
if (is_array($language)) { if (is_array($language)) {
$language = 'en_US'; $language = 'en_US';
} }
$language = (string)$language; $language = (string) $language;
if ('daily' === $repetition->repetition_type) { if ('daily' === $repetition->repetition_type) {
return (string)trans('firefly.recurring_daily', [], $language); return (string) trans('firefly.recurring_daily', [], $language);
} }
if ('weekly' === $repetition->repetition_type) { if ('weekly' === $repetition->repetition_type) {
$dayOfWeek = trans(sprintf('config.dow_%s', $repetition->repetition_moment), [], $language); $dayOfWeek = trans(sprintf('config.dow_%s', $repetition->repetition_moment), [], $language);
if ($repetition->repetition_skip > 0) { if ($repetition->repetition_skip > 0) {
return (string)trans('firefly.recurring_weekly_skip', ['weekday' => $dayOfWeek, 'skip' => $repetition->repetition_skip + 1], $language); return (string) trans('firefly.recurring_weekly_skip', ['weekday' => $dayOfWeek, 'skip' => $repetition->repetition_skip + 1], $language);
} }
return (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek], $language); return (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek], $language);
} }
if ('monthly' === $repetition->repetition_type) { if ('monthly' === $repetition->repetition_type) {
if ($repetition->repetition_skip > 0) { if ($repetition->repetition_skip > 0) {
return (string)trans( return (string) trans(
'firefly.recurring_monthly_skip', 'firefly.recurring_monthly_skip',
['dayOfMonth' => $repetition->repetition_moment, 'skip' => $repetition->repetition_skip + 1], ['dayOfMonth' => $repetition->repetition_moment, 'skip' => $repetition->repetition_skip + 1],
$language $language
); );
} }
return (string)trans( return (string) trans(
'firefly.recurring_monthly', 'firefly.recurring_monthly',
['dayOfMonth' => $repetition->repetition_moment, 'skip' => $repetition->repetition_skip - 1], ['dayOfMonth' => $repetition->repetition_moment, 'skip' => $repetition->repetition_skip - 1],
$language $language
); );
} }
if ('ndom' === $repetition->repetition_type) { if ('ndom' === $repetition->repetition_type) {
$parts = explode(',', $repetition->repetition_moment); $parts = explode(',', $repetition->repetition_moment);
// first part is number of week, second is weekday. // first part is number of week, second is weekday.
$dayOfWeek = trans(sprintf('config.dow_%s', $parts[1]), [], $language); $dayOfWeek = trans(sprintf('config.dow_%s', $parts[1]), [], $language);
return (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $parts[0]], $language); return (string) trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $parts[0]], $language);
} }
if ('yearly' === $repetition->repetition_type) { if ('yearly' === $repetition->repetition_type) {
$today = today(config('app.timezone'))->endOfYear(); $today = today(config('app.timezone'))->endOfYear();
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment); $repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
if (null === $repDate) { if (null === $repDate) {
$repDate = clone $today; $repDate = clone $today;
} }
$diffInYears = (int)$today->diffInYears($repDate, true); $diffInYears = (int) $today->diffInYears($repDate, true);
$repDate->addYears($diffInYears); // technically not necessary. $repDate->addYears($diffInYears); // technically not necessary.
$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js')); $string = $repDate->isoFormat((string) trans('config.month_and_day_no_year_js'));
return (string)trans('firefly.recurring_yearly', ['date' => $string], $language); return (string) trans('firefly.recurring_yearly', ['date' => $string], $language);
} }
return ''; return '';
@@ -499,8 +493,7 @@ class RecurringRepository implements RecurringRepositoryInterface
$search->whereLike('recurrences.title', sprintf('%%%s%%', $query)); $search->whereLike('recurrences.title', sprintf('%%%s%%', $query));
} }
$search $search
->orderBy('recurrences.title', 'ASC') ->orderBy('recurrences.title', 'ASC');
;
return $search->take($limit)->get(['id', 'title', 'description']); return $search->take($limit)->get(['id', 'title', 'description']);
} }
@@ -520,16 +513,16 @@ class RecurringRepository implements RecurringRepositoryInterface
public function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int public function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int
{ {
// if repeat = null just return 0. // if repeat = null just return 0.
if (null === $recurrence->repeat_until && 0 === (int)$recurrence->repetitions) { if (null === $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) {
return 0; return 0;
} }
// expect X transactions then stop. Return that number // expect X transactions then stop. Return that number
if (null === $recurrence->repeat_until && 0 !== (int)$recurrence->repetitions) { if (null === $recurrence->repeat_until && 0 !== (int) $recurrence->repetitions) {
return (int)$recurrence->repetitions; return (int) $recurrence->repetitions;
} }
// need to calculate, this depends on the repetition: // need to calculate, this depends on the repetition:
if (null !== $recurrence->repeat_until && 0 === (int)$recurrence->repetitions) { if (null !== $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) {
$occurrences = $this->getOccurrencesInRange($repetition, $recurrence->first_date ?? today(), $recurrence->repeat_until); $occurrences = $this->getOccurrencesInRange($repetition, $recurrence->first_date ?? today(), $recurrence->repeat_until);
return count($occurrences); return count($occurrences);
@@ -546,7 +539,7 @@ class RecurringRepository implements RecurringRepositoryInterface
$occurrences = []; $occurrences = [];
$mutator = clone $start; $mutator = clone $start;
$mutator->startOfDay(); $mutator->startOfDay();
$skipMod = $repetition->repetition_skip + 1; $skipMod = $repetition->repetition_skip + 1;
app('log')->debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type)); app('log')->debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
app('log')->debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d'))); app('log')->debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));

View File

@@ -77,9 +77,7 @@ class RecurringCronjob extends AbstractCronjob
{ {
app('log')->info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d H:i:s'))); app('log')->info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d H:i:s')));
/** @var CreateRecurringTransactions $job */ $job = new CreateRecurringTransactions($this->date);
$job = app(CreateRecurringTransactions::class);
$job->setDate($this->date);
$job->setForce($this->force); $job->setForce($this->force);
$job->handle(); $job->handle();

View File

@@ -2627,6 +2627,7 @@ return [
'no_bills_create_default' => 'Create a bill', 'no_bills_create_default' => 'Create a bill',
// recurring transactions // recurring transactions
'recurrence_max_count' => 'This recurring transactions will be created at most :max time(s), and has been created :count time(s) already.',
'create_right_now' => 'Create right now', 'create_right_now' => 'Create right now',
'no_new_transaction_in_recurrence' => 'No new transaction was created. Perhaps it was already fired for this date?', 'no_new_transaction_in_recurrence' => 'No new transaction was created. Perhaps it was already fired for this date?',
'recurrences' => 'Recurring transactions', 'recurrences' => 'Recurring transactions',

View File

@@ -22,6 +22,17 @@
</div> </div>
<div class="box-body"> <div class="box-body">
<h4>{{ 'transaction_journal_meta'|_ }}</h4> <h4>{{ 'transaction_journal_meta'|_ }}</h4>
{% if array.nr_of_repetitions > 0 %}
<p>
{% if array.journal_count >= array.nr_of_repetitions %}
<span class="text-danger">{{ trans('firefly.recurrence_max_count', {count: array.journal_count, max: array.nr_of_repetitions}) }}</span>
{% endif %}
{% if array.journal_count < array.nr_of_repetitions %}
{{ trans('firefly.recurrence_max_count', {count: array.journal_count, max: array.nr_of_repetitions}) }}
{% endif %}
</p>
{% endif %}
<p>{{ 'description'|_ }}: <em>{{ array.description }}</em></p> <p>{{ 'description'|_ }}: <em>{{ array.description }}</em></p>
{% if array.active == false %} {% if array.active == false %}