Send invoices by email.

This commit is contained in:
2025-01-09 11:18:12 +01:00
parent 8da6da471d
commit 6235112f74
19 changed files with 468 additions and 23 deletions

63
app/Mail/InvoiceMail.php Normal file
View 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'),
];
}
}