This commit is contained in:
James Cole
2019-09-26 19:16:17 +02:00
parent f370a1b486
commit 3ff8aa7509
4 changed files with 284 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ use FireflyIII\Services\Internal\Destroy\RecurrenceDestroyService;
use FireflyIII\Services\Internal\Update\RecurrenceUpdateService;
use FireflyIII\Support\Repositories\Recurring\CalculateRangeOccurrences;
use FireflyIII\Support\Repositories\Recurring\CalculateXOccurrences;
use FireflyIII\Support\Repositories\Recurring\CalculateXOccurrencesSince;
use FireflyIII\Support\Repositories\Recurring\FiltersWeekends;
use FireflyIII\User;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -52,7 +53,7 @@ use Log;
*/
class RecurringRepository implements RecurringRepositoryInterface
{
use CalculateRangeOccurrences, CalculateXOccurrences, FiltersWeekends;
use CalculateRangeOccurrences, CalculateXOccurrences, CalculateXOccurrencesSince, FiltersWeekends;
/** @var User */
private $user;
@@ -496,4 +497,44 @@ class RecurringRepository implements RecurringRepositoryInterface
return $service->update($recurrence, $data);
}
/**
* Calculate the next X iterations starting on the date given in $date.
* Returns an array of Carbon objects.
*
* Only returns them of they are after $afterDate
*
* @param RecurrenceRepetition $repetition
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
*
* @return array
* @throws FireflyException
*/
public function getXOccurrencesSince(RecurrenceRepetition $repetition, Carbon $date, Carbon $afterDate, int $count): array
{
$skipMod = $repetition->repetition_skip + 1;
$occurrences = [];
if ('daily' === $repetition->repetition_type) {
$occurrences = $this->getXDailyOccurrencesSince($date, $afterDate, $count, $skipMod);
}
if ('weekly' === $repetition->repetition_type) {
$occurrences = $this->getXWeeklyOccurrencesSince($date, $afterDate, $count, $skipMod, $repetition->repetition_moment);
}
if ('monthly' === $repetition->repetition_type) {
$occurrences = $this->getXMonthlyOccurrencesSince($date, $afterDate, $count, $skipMod, $repetition->repetition_moment);
}
if ('ndom' === $repetition->repetition_type) {
$occurrences = $this->getXNDomOccurrencesSince($date, $afterDate, $count, $skipMod, $repetition->repetition_moment);
}
if ('yearly' === $repetition->repetition_type) {
$occurrences = $this->getXYearlyOccurrencesSince($date, $afterDate, $count, $skipMod, $repetition->repetition_moment);
}
// filter out all the weekend days:
$occurrences = $this->filterWeekends($repetition, $occurrences);
return $occurrences;
}
}

View File

@@ -163,6 +163,22 @@ interface RecurringRepositoryInterface
*/
public function getXOccurrences(RecurrenceRepetition $repetition, Carbon $date, int $count): array;
/**
* Calculate the next X iterations starting on the date given in $date.
* Returns an array of Carbon objects.
*
* Only returns them of they are after $afterDate
*
* @param RecurrenceRepetition $repetition
* @param Carbon $date
* @param Carbon $afterDate
* @param int $count
*
* @throws FireflyException
* @return array
*/
public function getXOccurrencesSince(RecurrenceRepetition $repetition, Carbon $date,Carbon $afterDate, int $count): array;
/**
* Parse the repetition in a string that is user readable.
*