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

MODIFY
app/Repositories/RecurringRepository.php
app/Repositories/RecurringRepository.php
@@ -4,6 +4,7 @@ namespace App\Repositories;
use App\Models\Recurring;
use Exception;
+use Illuminate\Database\Eloquent\Collection;
class RecurringRepository
{
@@ -28,7 +29,7 @@ class RecurringRepository
* has no expiration date, or one that is in the future
* has not been used yet, or prior to today
*/
- public function getDueByDayOfMonth(): iterable
+ public function getDueMonthly(): Collection
{
$dayOfMonth = (int) date('j');
@@ -55,6 +56,25 @@ class RecurringRepository
->get();
}
+ public function getDueDaily(): Collection
+ {
+ $dateToday = date('Y-m-d');
+
+ return Recurring::where('interval', 'daily')
+ ->where('starts_on', '<=', $dateToday)
+ ->where(function ($query) use ($dateToday) {
+ $query
+ ->where('ends_on', '>=', $dateToday)
+ ->orWhere('ends_on', null);
+ })
+ ->where(function ($query) use ($dateToday) {
+ $query
+ ->where('last_used_on', '<', $dateToday)
+ ->orWhere('last_used_on', null);
+ })
+ ->get();
+ }
+
public function create(
int $spaceId,
string $type,

Support processing of daily recurrings