41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?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());
|
|
}
|
|
}
|
|
} |