mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Updated API code.
This commit is contained in:
@@ -53,6 +53,7 @@ use Log;
|
||||
class RecurringRepository implements RecurringRepositoryInterface
|
||||
{
|
||||
use CalculateRangeOccurrences, CalculateXOccurrences, CalculateXOccurrencesSince, FiltersWeekends;
|
||||
|
||||
private User $user;
|
||||
|
||||
|
||||
@@ -522,6 +523,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
// filter out everything if "repeat_until" is set.
|
||||
$repeatUntil = $repetition->recurrence->repeat_until;
|
||||
|
||||
return $this->filterMaxDate($repeatUntil, $occurrences);
|
||||
}
|
||||
|
||||
@@ -560,16 +562,16 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
public function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
// expect X transactions then stop. Return that number
|
||||
if (null === $recurrence->repeat_until && 0 !== (int) $recurrence->repetitions) {
|
||||
return (int) $recurrence->repetitions;
|
||||
if (null === $recurrence->repeat_until && 0 !== (int)$recurrence->repetitions) {
|
||||
return (int)$recurrence->repetitions;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
return count($occurrences);
|
||||
@@ -577,4 +579,19 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function searchRecurrence(string $query, int $limit): Collection
|
||||
{
|
||||
$search = $this->user->recurrences();
|
||||
if ('' !== $query) {
|
||||
$search->where('recurrences.title', 'LIKE', sprintf('%%%s%%', $query));
|
||||
}
|
||||
$search
|
||||
->orderBy('recurrences.title', 'ASC');
|
||||
|
||||
return $search->take($limit)->get(['id', 'title', 'description']);
|
||||
}
|
||||
}
|
||||
|
@@ -44,6 +44,14 @@ interface RecurringRepositoryInterface
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchRecurrence(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* Calculate how many transactions are to be expected from this recurrence.
|
||||
*
|
||||
|
Reference in New Issue
Block a user