diff --git a/app/Jobs/CheckInvoiceDueDatesJob.php b/app/Jobs/CheckInvoiceDueDatesJob.php new file mode 100644 index 0000000..e21afa6 --- /dev/null +++ b/app/Jobs/CheckInvoiceDueDatesJob.php @@ -0,0 +1,41 @@ +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()); + } + } +} \ No newline at end of file diff --git a/app/Listeners/CheckInvoiceDueDatesListener.php b/app/Listeners/CheckInvoiceDueDatesListener.php new file mode 100644 index 0000000..dbce4c7 --- /dev/null +++ b/app/Listeners/CheckInvoiceDueDatesListener.php @@ -0,0 +1,27 @@ +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()); + } + } +} \ No newline at end of file diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php new file mode 100644 index 0000000..e7720c1 --- /dev/null +++ b/app/Providers/EventServiceProvider.php @@ -0,0 +1,22 @@ + [ + \App\Listeners\CheckInvoiceDueDatesListener::class, + ], + ]; + + /** + * Bootstrap services. + */ + public function boot(): void + { + parent::boot(); + } +} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 0ad9c57..20485e5 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -2,5 +2,6 @@ return [ App\Providers\AppServiceProvider::class, + App\Providers\EventServiceProvider::class, App\Providers\FortifyServiceProvider::class, ]; diff --git a/config/logging.php b/config/logging.php index da723c4..d8bf92d 100644 --- a/config/logging.php +++ b/config/logging.php @@ -62,6 +62,7 @@ 'path' => storage_path('logs/laravel.log'), 'level' => env('LOG_LEVEL', 'debug'), ], + // 'stack' => [ // 'driver' => 'stack', // 'channels' => explode(',', env('LOG_STACK', 'single')), @@ -84,26 +85,26 @@ 'replace_placeholders' => true, ], - 'slack' => [ - 'driver' => 'slack', - 'url' => env('LOG_SLACK_WEBHOOK_URL'), - 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), - 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), - 'level' => env('LOG_LEVEL', 'critical'), - 'replace_placeholders' => true, - ], + // 'slack' => [ + // 'driver' => 'slack', + // 'url' => env('LOG_SLACK_WEBHOOK_URL'), + // 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), + // 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), + // 'level' => env('LOG_LEVEL', 'critical'), + // 'replace_placeholders' => true, + // ], - 'papertrail' => [ - 'driver' => 'monolog', - 'level' => env('LOG_LEVEL', 'debug'), - 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), - 'handler_with' => [ - 'host' => env('PAPERTRAIL_URL'), - 'port' => env('PAPERTRAIL_PORT'), - 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'), - ], - 'processors' => [PsrLogMessageProcessor::class], - ], + // 'papertrail' => [ + // 'driver' => 'monolog', + // 'level' => env('LOG_LEVEL', 'debug'), + // 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), + // 'handler_with' => [ + // 'host' => env('PAPERTRAIL_URL'), + // 'port' => env('PAPERTRAIL_PORT'), + // 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'), + // ], + // 'processors' => [PsrLogMessageProcessor::class], + // ], 'stderr' => [ 'driver' => 'monolog', diff --git a/routes/web.php b/routes/web.php index fc7bb47..01fdc8c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,10 +3,7 @@ use Illuminate\Support\Facades\Route; use Inertia\Inertia; use App\Http\Controllers\InvoiceController; - -Route::get('/welcome', function () { - return Inertia::render('Welcome'); -})->name('welcome'); +use Illuminate\Support\Facades\Log; Route::get('/', function () { return Inertia::render('Dashboard'); diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/private/.gitignore b/storage/app/private/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755