mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Code for #3240
This commit is contained in:
@@ -569,4 +569,28 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
{
|
||||
$this->user->recurrences()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int
|
||||
{
|
||||
// if repeat = null just return 0.
|
||||
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;
|
||||
}
|
||||
|
||||
// need to calculate, this depends on the repetition:
|
||||
if (null !== $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) {
|
||||
$occurrences = $this->getOccurrencesInRange($repetition, $recurrence->first_date ?? today(), $recurrence->repeat_until);
|
||||
|
||||
return count($occurrences);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -44,6 +44,15 @@ interface RecurringRepositoryInterface
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* Calculate how many transactions are to be expected from this recurrence.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @return int
|
||||
*/
|
||||
public function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int;
|
||||
|
||||
/**
|
||||
* Destroy a recurring transaction.
|
||||
*
|
||||
|
Reference in New Issue
Block a user