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
+3 -2
View File
@@ -24,8 +24,8 @@ public function handle(CaldavService $service)
} }
Cache::put($cacheKey, true, 300); Cache::put($cacheKey, true, 300);
Log::info('Running CalDAV sync'); Log::info('Synchronizing Todo itmes with CalDAV server');
$this->info('Starting CalDAV sync'); $this->info('Synchronizing Todo itmes with CalDAV server');
$todos = $service->getTodos(); $todos = $service->getTodos();
@@ -106,6 +106,7 @@ public function handle(CaldavService $service)
Log::info("Synced " . count($todos) . " todos."); Log::info("Synced " . count($todos) . " todos.");
$this->info("Synced " . count($todos) . " todos."); $this->info("Synced " . count($todos) . " todos.");
return 0; 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;
}
}
+9
View File
@@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel
*/ */
protected $commands = [ protected $commands = [
\App\Console\Commands\CaldavSyncCommand::class, \App\Console\Commands\CaldavSyncCommand::class,
\App\Console\Commands\CheckInvoiceDueDatesCommand::class,
]; ];
/** /**
@@ -21,6 +22,14 @@ class Kernel extends ConsoleKernel
*/ */
protected function schedule(Schedule $schedule): void 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();
} }
/** /**
-41
View File
@@ -1,41 +0,0 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\Invoice;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class CheckInvoiceDueDatesJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Execute the job.
*/
public function handle(): void
{
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']);
Log::info("Updated invoice {$invoice->nr} to 'due' status");
}
Log::info("Checked {$invoices->count()} invoices for due dates.");
} catch (\Exception $e) {
Log::error("Error in CheckInvoiceDueDatesJob: " . $e->getMessage());
}
}
}
-11
View File
@@ -16,16 +16,5 @@ class EventServiceProvider extends ServiceProvider
public function boot(): void public function boot(): void
{ {
parent::boot(); parent::boot();
// // TODO: read where to put these or ask in the forums
// // it seems to work here, but where is the apropriate place?
// // Kernel::schedule did not work
Schedule::command('caldav:sync')
->everyMinute()
->withoutOverlapping();
Schedule::job(new CheckInvoiceDueDatesJob())
->daily()
->withoutOverlapping();
} }
} }
+4 -4
View File
@@ -159,10 +159,10 @@ public function getTodos()
$todo->type_id = 2; $todo->type_id = 2;
$todo->url = $href; $todo->url = $href;
if (isset($vcalendar->VTODO->DUE)) $todo->due_date = $vcalendar->VTODO->DUE->getDateTime(); if (isset($vcalendar->VTODO->DUE)) $todo->due_date = $vcalendar->VTODO->DUE->getDateTime();
if(isset($vcalendar->VTODO->RRULE)) $todo->recurring = $vcalendar->VTODO->RRULE->getValue(); if (isset($vcalendar->VTODO->RRULE)) $todo->recurring = $vcalendar->VTODO->RRULE->getValue();
if(isset($vcalendar->VTODO->PRIORITY)) $todo->priority = $vcalendar->VTODO->PRIORITY->getValue(); if (isset($vcalendar->VTODO->PRIORITY)) $todo->priority = $vcalendar->VTODO->PRIORITY->getValue();
if(isset($vcalendar->VTODO->STATUS)) $todo->status = $vcalendar->VTODO->STATUS->getValue(); if (isset($vcalendar->VTODO->STATUS)) $todo->status = $vcalendar->VTODO->STATUS->getValue();
if(isset($vcalendar->VTODO->{'RELATED-TO'})) $todo->parent = $vcalendar->VTODO->{'RELATED-TO'}->getValue(); if (isset($vcalendar->VTODO->{'RELATED-TO'})) $todo->parent = $vcalendar->VTODO->{'RELATED-TO'}->getValue();
$todo->created_at = $vcalendar->VTODO->CREATED->getDateTime(); $todo->created_at = $vcalendar->VTODO->CREATED->getDateTime();
$todo->last_modified = $vcalendar->VTODO->{'LAST-MODIFIED'}->getDateTime(); $todo->last_modified = $vcalendar->VTODO->{'LAST-MODIFIED'}->getDateTime();
+10 -2
View File
@@ -7,7 +7,7 @@
use Illuminate\Foundation\Configuration\Middleware; use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets; use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
return Application::configure(basePath: dirname(__DIR__)) $app = Application::configure(basePath: dirname(__DIR__))
->withRouting( ->withRouting(
web: __DIR__ . '/../routes/web.php', web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php', commands: __DIR__ . '/../routes/console.php',
@@ -26,4 +26,12 @@
}) })
->withExceptions(function (Exceptions $exceptions) { ->withExceptions(function (Exceptions $exceptions) {
// //
})->create(); })->withKernels()->create();
$app->singleton(
\Illuminate\Contracts\Console\Kernel::class,
\App\Console\Kernel::class
);
return $app;
-1
View File
@@ -11,7 +11,6 @@
use App\Http\Controllers\TodoController; use App\Http\Controllers\TodoController;
use App\Http\Controllers\UnitController; use App\Http\Controllers\UnitController;
use App\Mail\OrderConfirmation; use App\Mail\OrderConfirmation;
use App\Services\CaldavService;
use App\Http\Controllers\TimesheetController; use App\Http\Controllers\TimesheetController;
use App\Http\Controllers\TimesheetEntryController; use App\Http\Controllers\TimesheetEntryController;
use App\Http\Controllers\PipelineController; use App\Http\Controllers\PipelineController;