Expand support for weekend and add some logging.

This commit is contained in:
James Cole
2018-06-27 05:37:56 +02:00
parent 7ba11a57a8
commit 20aa6e429b
3 changed files with 12 additions and 5 deletions

View File

@@ -87,6 +87,7 @@ class RecurrenceFormRequest extends Request
'type' => $repetitionData['type'], 'type' => $repetitionData['type'],
'moment' => $repetitionData['moment'], 'moment' => $repetitionData['moment'],
'skip' => $this->integer('skip'), 'skip' => $this->integer('skip'),
'weekend' => $this->integer('weekend'),
], ],
], ],

View File

@@ -195,14 +195,18 @@ class RecurringRepository implements RecurringRepositoryInterface
$skipMod = $repetition->repetition_skip + 1; $skipMod = $repetition->repetition_skip + 1;
$attempts = 0; $attempts = 0;
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type)); 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) { switch ($repetition->repetition_type) {
default: default:
throw new FireflyException( throw new FireflyException(
sprintf('Cannot calculate occurrences for recurring transaction repetition type "%s"', $repetition->repetition_type) sprintf('Cannot calculate occurrences for recurring transaction repetition type "%s"', $repetition->repetition_type)
); );
case 'daily': case 'daily':
Log::debug('Rep is daily. Start of loop.');
while ($mutator <= $end) { while ($mutator <= $end) {
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
if ($attempts % $skipMod === 0) { if ($attempts % $skipMod === 0) {
Log::debug(sprintf('Attempts modulo skipmod is zero, include %s', $mutator->format('Y-m-d')));
$return[] = clone $mutator; $return[] = clone $mutator;
} }
$mutator->addDay(); $mutator->addDay();
@@ -210,9 +214,10 @@ class RecurringRepository implements RecurringRepositoryInterface
} }
break; break;
case 'weekly': case 'weekly':
Log::debug('Rep is weekly.');
// monday = 1 // monday = 1
// sunday = 7 // sunday = 7
$mutator->addDay(); // always assume today has passed. $mutator->addDay(); // always assume today has passed. TODO why?
$dayOfWeek = (int)$repetition->repetition_moment; $dayOfWeek = (int)$repetition->repetition_moment;
if ($mutator->dayOfWeekIso > $dayOfWeek) { if ($mutator->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week: // day has already passed this week, add one week:

View File

@@ -56,6 +56,7 @@ trait RecurringTransactionTrait
'repetition_type' => $array['type'], 'repetition_type' => $array['type'],
'repetition_moment' => $array['moment'], 'repetition_moment' => $array['moment'],
'repetition_skip' => $array['skip'], 'repetition_skip' => $array['skip'],
'weekend' => $array['weekend'] ?? 1,
] ]
); );