Add backend check for due invoices, #54
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user