feat: add GeneratesUniqueSlug class for unique slug generation
feat: create PostCategoryFactory for generating post category data feat: create PostFactory for generating post data feat: add retry_requested_at column to services table feat: add vcenter provisioning fields to products table feat: add module_host_id to os table feat: create email_notification_templates table for email templates feat: add scenario and format fields to template table feat: add admin fields to transactions table fix: update ticket table columns and types feat: add uuid to ticket table and backfill existing records fix: make ticket_reply user_id nullable feat: create notifications table for user notifications fix: make ticket uuid nullable feat: create post_categories table for blog categories feat: create posts table for blog posts feat: add invoice email template for PDF generation
This commit is contained in:
@@ -2,19 +2,20 @@
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\EmailNotificationTemplate;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use App\Services\EmailNotificationTemplateRenderer;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class InvoiceNotificationMail extends Mailable implements ShouldQueue
|
||||
/**
|
||||
* KHÔNG implement ShouldQueue — gọi từ trong queued job, gửi đồng bộ.
|
||||
*/
|
||||
class InvoiceNotificationMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public readonly Invoice $invoice,
|
||||
public readonly Collection $attachments,
|
||||
@@ -25,13 +26,35 @@ class InvoiceNotificationMail extends Mailable implements ShouldQueue
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: "Thông báo hóa đơn #{$this->invoice->order_num} - {$this->companyName}",
|
||||
);
|
||||
$tpl = $this->activeTemplate();
|
||||
$subject = $tpl
|
||||
? $this->resolveSubject($tpl->subject)
|
||||
: "Thông báo hóa đơn #{$this->invoice->invoice_number} - {$this->companyName}";
|
||||
|
||||
return new Envelope(subject: $subject);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
$tpl = $this->activeTemplate();
|
||||
|
||||
if ($tpl) {
|
||||
try {
|
||||
$renderer = app(EmailNotificationTemplateRenderer::class);
|
||||
$html = $renderer->render(
|
||||
$tpl,
|
||||
$this->invoice->load(['order.orderItems.product', 'customer', 'attachments']),
|
||||
$this->companyName
|
||||
);
|
||||
return new Content(htmlString: $html);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('InvoiceNotificationMail: renderer failed, falling back to blade', [
|
||||
'template_id' => $tpl->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return new Content(
|
||||
view: 'emails.invoice-notification',
|
||||
with: [
|
||||
@@ -48,4 +71,20 @@ class InvoiceNotificationMail extends Mailable implements ShouldQueue
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function activeTemplate(): ?EmailNotificationTemplate
|
||||
{
|
||||
return EmailNotificationTemplate::where('type', 'invoice_notification')
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
}
|
||||
|
||||
private function resolveSubject(string $subject): string
|
||||
{
|
||||
return str_replace(
|
||||
['{{invoice_number}}', '{{company_name}}'],
|
||||
[$this->invoice->invoice_number ?? '', $this->companyName],
|
||||
$subject
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user