Support yearly recurrings
MODIFY
app/Jobs/ProcessRecurrings.php
app/Jobs/ProcessRecurrings.php
@@ -37,10 +37,11 @@ class ProcessRecurrings implements ShouldQueue
$this->earningRepository = $earningRepository;
$this->spendingRepository = $spendingRepository;
+ $yearlyRecurrings = $this->recurringRepository->getDueYearly();
$monthtlyRecurrings = $this->recurringRepository->getDueMonthly();
$dailyRecurrings = $this->recurringRepository->getDueDaily();
- $recurrings = $monthtlyRecurrings->combine($dailyRecurrings);
+ $recurrings = $yearlyRecurrings->combine($monthtlyRecurrings->combine($dailyRecurrings));
foreach ($recurrings as $recurring) {
if ($recurring->type !== 'earning' && $recurring->type !== 'spending') {

MODIFY
app/Repositories/RecurringRepository.php
app/Repositories/RecurringRepository.php
@@ -25,11 +25,32 @@ class RecurringRepository
public function getSupportedIntervals(): array
{
return [
+ 'yearly',
'monthly',
'daily'
];
}
+ public function getDueYearly(): Collection
+ {
+ $dateToday = date('Y-m-d');
+ $dateYearAgo = date('Y-m-d', strtotime('-1 year'));
+
+ return Recurring::where('interval', 'yearly')
+ ->where('starts_on', '<=', $dateToday)
+ ->where(function ($query) use ($dateToday) {
+ $query
+ ->where('ends_on', '>=', $dateToday)
+ ->orWhere('ends_on', null);
+ })
+ ->where(function ($query) use ($dateYearAgo) {
+ $query
+ ->where('last_used_on', '<=', $dateYearAgo)
+ ->orWhere('last_used_on', null);
+ })
+ ->get();
+ }
+
/**
* Grabs recurrings that checks all of the following statements
* targeted day is today, or in future if today is last day of the month

Support yearly recurrings