mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-24 15:26:33 -06:00
Expand support for weekend and add some logging.
This commit is contained in:
parent
7ba11a57a8
commit
20aa6e429b
@ -79,14 +79,15 @@ class RecurrenceFormRequest extends Request
|
||||
],
|
||||
'meta' => [
|
||||
// tags and piggy bank ID.
|
||||
'tags' => '' !== $this->string('tags') ? explode(',', $this->string('tags')): [],
|
||||
'tags' => '' !== $this->string('tags') ? explode(',', $this->string('tags')) : [],
|
||||
'piggy_bank_id' => $this->integer('piggy_bank_id'),
|
||||
],
|
||||
'repetitions' => [
|
||||
[
|
||||
'type' => $repetitionData['type'],
|
||||
'moment' => $repetitionData['moment'],
|
||||
'skip' => $this->integer('skip'),
|
||||
'type' => $repetitionData['type'],
|
||||
'moment' => $repetitionData['moment'],
|
||||
'skip' => $this->integer('skip'),
|
||||
'weekend' => $this->integer('weekend'),
|
||||
],
|
||||
],
|
||||
|
||||
|
@ -195,14 +195,18 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
$attempts = 0;
|
||||
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
switch ($repetition->repetition_type) {
|
||||
default:
|
||||
throw new FireflyException(
|
||||
sprintf('Cannot calculate occurrences for recurring transaction repetition type "%s"', $repetition->repetition_type)
|
||||
);
|
||||
case 'daily':
|
||||
Log::debug('Rep is daily. Start of loop.');
|
||||
while ($mutator <= $end) {
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
if ($attempts % $skipMod === 0) {
|
||||
Log::debug(sprintf('Attempts modulo skipmod is zero, include %s', $mutator->format('Y-m-d')));
|
||||
$return[] = clone $mutator;
|
||||
}
|
||||
$mutator->addDay();
|
||||
@ -210,9 +214,10 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
break;
|
||||
case 'weekly':
|
||||
Log::debug('Rep is weekly.');
|
||||
// monday = 1
|
||||
// sunday = 7
|
||||
$mutator->addDay(); // always assume today has passed.
|
||||
$mutator->addDay(); // always assume today has passed. TODO why?
|
||||
$dayOfWeek = (int)$repetition->repetition_moment;
|
||||
if ($mutator->dayOfWeekIso > $dayOfWeek) {
|
||||
// day has already passed this week, add one week:
|
||||
|
@ -56,6 +56,7 @@ trait RecurringTransactionTrait
|
||||
'repetition_type' => $array['type'],
|
||||
'repetition_moment' => $array['moment'],
|
||||
'repetition_skip' => $array['skip'],
|
||||
'weekend' => $array['weekend'] ?? 1,
|
||||
]
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user