Send invoices by email.
This commit is contained in:
63
app/Mail/InvoiceMail.php
Normal file
63
app/Mail/InvoiceMail.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Http\Controllers\EController;
|
||||
use App\Http\Controllers\PdfController;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Attachment;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class InvoiceMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public string $body {
|
||||
set {
|
||||
$this->body = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public string $pdf;
|
||||
|
||||
public string $xml;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(protected Invoice $invoice)
|
||||
{
|
||||
$pdf = new PdfController();
|
||||
$this->pdf = $pdf->attachInvoice($invoice->id);
|
||||
|
||||
$xml = new EController();
|
||||
$this->xml = $xml->attachInvoice($invoice->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
html: 'mail.invoice.sent',
|
||||
with: ['html' => $this->body],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [
|
||||
Attachment::fromData(fn() => $this->pdf, __('invoice.Invoice') . '_' . $this->invoice->number . '.pdf')
|
||||
->withMime('application/pdf'),
|
||||
Attachment::fromData(fn() => $this->xml, __('invoice.Invoice') . '_' . $this->invoice->number . '.xml')
|
||||
->withMime('application/xml'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user