Files
hqland-app/app/Notifications/PaymentDueNotification.php

44 lines
1.3 KiB
PHP

<?php
namespace App\Notifications;
use App\Models\PaymentScheduleItem;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class PaymentDueNotification extends Notification
{
use Queueable;
public function __construct(
public PaymentScheduleItem $scheduleItem
) {}
public function via(object $notifiable): array
{
return ['database'];
}
public function toDatabase(object $notifiable): array
{
$contract = $this->scheduleItem->schedule?->contract;
$remaining = (float) $this->scheduleItem->remaining_amount;
return [
'title' => 'Cảnh báo đợt thanh toán sắp đến hạn',
'message' => sprintf(
'HĐ %s - Đợt %d (%s) sẽ đến hạn vào %s. Còn thiếu: %s VNĐ.',
$contract?->contract_number ?? 'N/A',
$this->scheduleItem->installment_no,
$this->scheduleItem->type?->getLabel() ?? 'N/A',
$this->scheduleItem->due_date?->format('d/m/Y') ?? 'N/A',
number_format($remaining)
),
'contract_id' => $contract?->id,
'schedule_item_id' => $this->scheduleItem->id,
'due_date' => $this->scheduleItem->due_date?->toDateString(),
'remaining_amount' => $remaining,
];
}
}