Fix: Job to check invoice due dates was never run

Made it a command so it runs with the scheduler
This commit is contained in:
2026-03-05 10:42:40 +01:00
parent 4ee1d01e38
commit c470240dc0
8 changed files with 82 additions and 63 deletions
+4 -3
View File
@@ -14,7 +14,7 @@ class CaldavSyncCommand extends Command
protected $signature = 'caldav:sync';
protected $description = 'Sync CalDAV VTODOs into local todos table';
public function handle(CaldavService $service)
public function handle(CaldavService $service)
{
// only run every 5 minutes although the task is called every minute
$cacheKey = 'caldav_sync_last_run';
@@ -24,8 +24,8 @@ public function handle(CaldavService $service)
}
Cache::put($cacheKey, true, 300);
Log::info('Running CalDAV sync');
$this->info('Starting CalDAV sync');
Log::info('Synchronizing Todo itmes with CalDAV server');
$this->info('Synchronizing Todo itmes with CalDAV server');
$todos = $service->getTodos();
@@ -106,6 +106,7 @@ public function handle(CaldavService $service)
Log::info("Synced " . count($todos) . " todos.");
$this->info("Synced " . count($todos) . " todos.");
return 0;
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use App\Models\Invoice;
class CheckInvoiceDueDatesCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'invoices:check-due';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check invoices for due dates (runs synchronously)';
/**
* Execute the console command.
*/
public function handle(): int
{
$this->info('Check invoice due dates');
Log::info('Check invoice due dates');
try {
$today = Carbon::today();
// Find invoices with payment_status 'issued' and due_date <= today
$invoices = Invoice::where('payment_status', 'issued')
->whereDate('due_date', '<=', $today)
->get();
foreach ($invoices as $invoice) {
$invoice->update(['payment_status' => 'due']);
$this->info("Updated invoice {$invoice->nr} to 'due' status");
}
$this->info("Checked {$invoices->count()} invoices for due dates.");
} catch (\Exception $e) {
$this->error("Error in CheckInvoiceDueDatesJob: " . $e->getMessage());
}
return 0;
}
}
+10 -1
View File
@@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
\App\Console\Commands\CaldavSyncCommand::class,
\App\Console\Commands\CheckInvoiceDueDatesCommand::class,
];
/**
@@ -21,6 +22,14 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule): void
{
$schedule->command('caldav:sync')
->everyMinute()
->withoutOverlapping();
// Run synchronously on schedule to support environments without queue workers
$schedule->command('invoices:check-due')
->dailyAt('3:00')
->withoutOverlapping();
}
/**
@@ -32,4 +41,4 @@ protected function commands(): void
require base_path('routes/console.php');
}
}
}