update
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Invoice;
|
||||
use App\Services\EmailNotificationTemplateRenderer;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -18,18 +19,26 @@ class InvoiceNotificationMail extends Mailable
|
||||
{
|
||||
public function __construct(
|
||||
public readonly Invoice $invoice,
|
||||
public readonly Collection $attachments,
|
||||
public readonly Collection $invoiceAttachments,
|
||||
public readonly string $customerName,
|
||||
public readonly string $message,
|
||||
public readonly string $companyName,
|
||||
public readonly string $type = 'invoice',
|
||||
public readonly ?string $invoicePdf = null,
|
||||
public readonly ?string $invoicePdfFileName = null,
|
||||
public readonly ?string $paymentUrl = null,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$tpl = $this->activeTemplate();
|
||||
$fallbackSubject = $this->type === 'renewal'
|
||||
? "Thông báo gia hạn cước #{$this->invoice->invoice_number} - {$this->companyName}"
|
||||
: "Thông báo hóa đơn #{$this->invoice->invoice_number} - {$this->companyName}";
|
||||
|
||||
$subject = $tpl
|
||||
? $this->resolveSubject($tpl->subject)
|
||||
: "Thông báo hóa đơn #{$this->invoice->invoice_number} - {$this->companyName}";
|
||||
: $fallbackSubject;
|
||||
|
||||
return new Envelope(subject: $subject);
|
||||
}
|
||||
@@ -59,16 +68,25 @@ class InvoiceNotificationMail extends Mailable
|
||||
view: 'emails.invoice-notification',
|
||||
with: [
|
||||
'invoice' => $this->invoice,
|
||||
'attachments' => $this->attachments,
|
||||
'attachments' => $this->invoiceAttachments,
|
||||
'customerName' => $this->customerName,
|
||||
'message' => $this->message,
|
||||
'bodyMessage' => $this->message,
|
||||
'companyName' => $this->companyName,
|
||||
'type' => $this->type,
|
||||
'paymentUrl' => $this->paymentUrl,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function attachments(): array
|
||||
{
|
||||
if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) {
|
||||
return [
|
||||
Attachment::fromData(fn() => $this->invoicePdf, $this->invoicePdfFileName)
|
||||
->withMime('application/pdf'),
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user