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

@ -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'),
],
],

View File

@ -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:

View File

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