mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 02:45:58 +00:00
chore: reformat code.
This commit is contained in:
@@ -68,8 +68,8 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
public function createdPreviously(Recurrence $recurrence, Carbon $date): bool
|
||||
{
|
||||
// if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well.
|
||||
$set =
|
||||
TransactionJournalMeta::where(function (Builder $q1) use ($recurrence) {
|
||||
$set
|
||||
= TransactionJournalMeta::where(function (Builder $q1) use ($recurrence) {
|
||||
$q1->where('name', 'recurrence_id');
|
||||
$q1->where('data', json_encode((string)$recurrence->id));
|
||||
})->get(['journal_meta.transaction_journal_id']);
|
||||
@@ -92,10 +92,25 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the user's recurring transactions.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->recurrences()
|
||||
->with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('transaction_type_id', 'ASC')
|
||||
->orderBy('title', 'ASC')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*/
|
||||
public function destroy(Recurrence $recurrence): void
|
||||
{
|
||||
@@ -112,21 +127,6 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
$this->user->recurrences()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the user's recurring transactions.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->recurrences()
|
||||
->with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('transaction_type_id', 'ASC')
|
||||
->orderBy('title', 'ASC')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ALL recurring transactions.
|
||||
*
|
||||
@@ -160,7 +160,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the budget ID from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -200,7 +200,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -220,9 +220,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Returns the journals created for this recurrence, possibly limited by time.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -232,7 +232,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
->where('transaction_journals.user_id', $recurrence->user_id)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('journal_meta.name', 'recurrence_id')
|
||||
->where('journal_meta.data', '"'.$recurrence->id.'"');
|
||||
->where('journal_meta.data', '"' . $recurrence->id . '"');
|
||||
if (null !== $start) {
|
||||
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
@@ -245,7 +245,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get journal ID's for journals created by this recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -261,7 +261,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the notes.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -277,46 +277,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate events in the date range.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$occurrences = [];
|
||||
$mutator = clone $start;
|
||||
$mutator->startOfDay();
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
|
||||
if ('daily' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getDailyInRange($mutator, $end, $skipMod);
|
||||
}
|
||||
if ('weekly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getWeeklyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('monthly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getMonthlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('ndom' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getNdomInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getYearlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
|
||||
// filter out all the weekend days:
|
||||
return $this->filterWeekends($repetition, $occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurrenceTransaction $transaction
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
@@ -336,7 +297,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the tags from the recurring transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $transaction
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return array
|
||||
* @throws JsonException
|
||||
@@ -355,9 +316,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
@@ -385,7 +346,17 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -420,9 +391,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Calculate the next X iterations starting on the date given in $date.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
@@ -457,10 +428,10 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
*
|
||||
* Only returns them of they are after $afterDate
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param Carbon $afterDate
|
||||
* @param int $count
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param Carbon $afterDate
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -494,10 +465,31 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
return $this->filterMaxDate($repeatUntil, $occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon|null $max
|
||||
* @param array $occurrences
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterMaxDate(?Carbon $max, array $occurrences): array
|
||||
{
|
||||
if (null === $max) {
|
||||
return $occurrences;
|
||||
}
|
||||
$filtered = [];
|
||||
foreach ($occurrences as $date) {
|
||||
if ($date->lte($max)) {
|
||||
$filtered[] = $date;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the repetition in a string that is user readable.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param RecurrenceRepetition $repetition
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
@@ -571,17 +563,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
@@ -623,11 +605,50 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate events in the date range.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$occurrences = [];
|
||||
$mutator = clone $start;
|
||||
$mutator->startOfDay();
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
|
||||
if ('daily' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getDailyInRange($mutator, $end, $skipMod);
|
||||
}
|
||||
if ('weekly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getWeeklyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('monthly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getMonthlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('ndom' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getNdomInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getYearlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
|
||||
// filter out all the weekend days:
|
||||
return $this->filterWeekends($repetition, $occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
@@ -639,25 +660,4 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
return $service->update($recurrence, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon|null $max
|
||||
* @param array $occurrences
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterMaxDate(?Carbon $max, array $occurrences): array
|
||||
{
|
||||
if (null === $max) {
|
||||
return $occurrences;
|
||||
}
|
||||
$filtered = [];
|
||||
foreach ($occurrences as $date) {
|
||||
if ($date->lte($max)) {
|
||||
$filtered[] = $date;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user