43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Jobs\Mail\SendInvoiceMailJob;
|
|
use App\Mail\InvoiceNotificationMail;
|
|
use App\Models\Invoice;
|
|
use App\Models\Notification;
|
|
use App\Models\Service;
|
|
use App\Support\AutoEmailGate;
|
|
|
|
class RenewalInvoiceNotifier
|
|
{
|
|
public function notify(Invoice $invoice, Service $service): void
|
|
{
|
|
$customer = $service->customer;
|
|
if (! $customer) {
|
|
return;
|
|
}
|
|
|
|
$name = $service->server_name ?: $service->orderItem?->product?->name ?: 'Dịch vụ';
|
|
$invoice->setRelation('order', $service->orderItem?->order);
|
|
|
|
Notification::notifyCustomer($customer, [
|
|
'type' => 'renewal_invoice',
|
|
'title' => 'Hóa đơn gia hạn dịch vụ',
|
|
'body' => sprintf(
|
|
'Dịch vụ %s hết hạn ngày %s. Hóa đơn gia hạn #%s (%s VNĐ) đang chờ thanh toán.',
|
|
$name,
|
|
$service->expires_at?->format('d/m/Y') ?? '-',
|
|
$invoice->invoice_number,
|
|
number_format((int) $invoice->total, 0, ',', '.'),
|
|
),
|
|
'link' => $invoice->clientPath(),
|
|
'data' => ['invoice_number' => $invoice->invoice_number, 'service_id' => $service->id],
|
|
]);
|
|
|
|
if ($customer->email && AutoEmailGate::allows(InvoiceNotificationMail::SCENARIO)) {
|
|
SendInvoiceMailJob::dispatch($invoice->id, 'renewal', null, null, null, null)->afterCommit();
|
|
}
|
|
}
|
|
}
|