Add backend check for due invoices, #54

This commit is contained in:
vollstock committed 2025-11-11 21:20:15 +01:00
1 parent 63202b0845
commit b420aada17
15 files changed
+112 -23

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
<?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());
}
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Listeners;
use Illuminate\Support\Facades\Cache;
use App\Jobs\CheckInvoiceDueDatesJob;
use Illuminate\Support\Facades\Log;
class CheckInvoiceDueDatesListener
{
public function handle($event)
{
try {
$today = now()->toDateString();
$cacheKey = 'invoice_due_dates_checked_' . $today;
if (!Cache::has($cacheKey)) {
// Cache a timestamped key, so we only check once a day
Cache::put($cacheKey, true, now()->endOfDay());
Log::info("Starting daily job to check for due invoices.");
(new CheckInvoiceDueDatesJob())->handle();
}
} catch (\Exception $e) {
Log::error("Error in CheckInvoiceDueDatesListener: " . $e->getMessage());
}
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
'Illuminate\Routing\Events\RouteMatched' => [
\App\Listeners\CheckInvoiceDueDatesListener::class,
],
];
/**
* Bootstrap services.
*/
public function boot(): void
{
parent::boot();
}
}
+1
View File
@@ -2,5 +2,6 @@
return [ return [
App\Providers\AppServiceProvider::class, App\Providers\AppServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\FortifyServiceProvider::class, App\Providers\FortifyServiceProvider::class,
]; ];
+20 -19
View File
@@ -62,6 +62,7 @@
'path' => storage_path('logs/laravel.log'), 'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'), 'level' => env('LOG_LEVEL', 'debug'),
], ],
// 'stack' => [ // 'stack' => [
// 'driver' => 'stack', // 'driver' => 'stack',
// 'channels' => explode(',', env('LOG_STACK', 'single')), // 'channels' => explode(',', env('LOG_STACK', 'single')),
@@ -84,26 +85,26 @@
'replace_placeholders' => true, 'replace_placeholders' => true,
], ],
'slack' => [ // 'slack' => [
'driver' => 'slack', // 'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'), // 'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), // 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'),
'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), // 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'),
'level' => env('LOG_LEVEL', 'critical'), // 'level' => env('LOG_LEVEL', 'critical'),
'replace_placeholders' => true, // 'replace_placeholders' => true,
], // ],
'papertrail' => [ // 'papertrail' => [
'driver' => 'monolog', // 'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'), // 'level' => env('LOG_LEVEL', 'debug'),
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), // 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
'handler_with' => [ // 'handler_with' => [
'host' => env('PAPERTRAIL_URL'), // 'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'), // 'port' => env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'), // 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'),
], // ],
'processors' => [PsrLogMessageProcessor::class], // 'processors' => [PsrLogMessageProcessor::class],
], // ],
'stderr' => [ 'stderr' => [
'driver' => 'monolog', 'driver' => 'monolog',
+1 -4
View File
@@ -3,10 +3,7 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Inertia\Inertia; use Inertia\Inertia;
use App\Http\Controllers\InvoiceController; use App\Http\Controllers\InvoiceController;
use Illuminate\Support\Facades\Log;
Route::get('/welcome', function () {
return Inertia::render('Welcome');
})->name('welcome');
Route::get('/', function () { Route::get('/', function () {
return Inertia::render('Dashboard'); return Inertia::render('Dashboard');
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.