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:
@@ -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
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,5 @@ class EventServiceProvider extends ServiceProvider
|
||||
public function boot(): void
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,10 +159,10 @@ public function getTodos()
|
||||
$todo->type_id = 2;
|
||||
$todo->url = $href;
|
||||
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->PRIORITY)) $todo->priority = $vcalendar->VTODO->PRIORITY->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->RRULE)) $todo->recurring = $vcalendar->VTODO->RRULE->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->{'RELATED-TO'})) $todo->parent = $vcalendar->VTODO->{'RELATED-TO'}->getValue();
|
||||
$todo->created_at = $vcalendar->VTODO->CREATED->getDateTime();
|
||||
$todo->last_modified = $vcalendar->VTODO->{'LAST-MODIFIED'}->getDateTime();
|
||||
|
||||
|
||||
+10
-2
@@ -7,7 +7,7 @@
|
||||
use Illuminate\Foundation\Configuration\Middleware;
|
||||
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
|
||||
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
$app = Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
web: __DIR__ . '/../routes/web.php',
|
||||
commands: __DIR__ . '/../routes/console.php',
|
||||
@@ -26,4 +26,12 @@
|
||||
})
|
||||
->withExceptions(function (Exceptions $exceptions) {
|
||||
//
|
||||
})->create();
|
||||
})->withKernels()->create();
|
||||
|
||||
$app->singleton(
|
||||
\Illuminate\Contracts\Console\Kernel::class,
|
||||
\App\Console\Kernel::class
|
||||
);
|
||||
|
||||
return $app;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
use App\Http\Controllers\TodoController;
|
||||
use App\Http\Controllers\UnitController;
|
||||
use App\Mail\OrderConfirmation;
|
||||
use App\Services\CaldavService;
|
||||
use App\Http\Controllers\TimesheetController;
|
||||
use App\Http\Controllers\TimesheetEntryController;
|
||||
use App\Http\Controllers\PipelineController;
|
||||
|
||||
Reference in New Issue
Block a user