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

MODIFY
app/Repositories/RecurringRepository.php
app/Repositories/RecurringRepository.php
@@ -27,6 +27,7 @@ class RecurringRepository
return [
'yearly',
'monthly',
+ 'weekly',
'daily'
];
}
@@ -85,6 +86,26 @@ class RecurringRepository
->get();
}
+ public function getDueWeekly(): Collection
+ {
+ $dateToday = date('Y-m-d');
+ $dateWeekAgo = date('Y-m-d', strtotime('-1 week'));
+
+ return Recurring::where('interval', 'weekly')
+ ->where('starts_on', '<=', $dateToday)
+ ->where(function ($query) use ($dateToday) {
+ $query
+ ->where('ends_on', '>=', $dateToday)
+ ->orWhere('ends_on', null);
+ })
+ ->where(function ($query) use ($dateWeekAgo) {
+ $query
+ ->where('last_used_on', '<=', $dateWeekAgo)
+ ->orWhere('last_used_on', null);
+ })
+ ->get();
+ }
+
public function getDueDaily(): Collection
{
$dateToday = date('Y-m-d');

Support weekly recurrings