56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Sales\Infrastructure\Receipts;
|
|
|
|
use App\Modules\Sales\Application\DTOs\QuickSaleSummary;
|
|
use App\Modules\Shared\Application\UseCases\CompanyDetailsStore;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Attachment;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
|
|
/**
|
|
* The email with a quick sale's PDF receipt attached. Always in Finnish,
|
|
* like the receipt itself.
|
|
*/
|
|
class QuickSaleReceiptMail extends Mailable
|
|
{
|
|
public function __construct(public QuickSaleSummary $sale)
|
|
{
|
|
$this->locale('fi');
|
|
}
|
|
|
|
public function envelope(): Envelope
|
|
{
|
|
$company = app(CompanyDetailsStore::class)->get();
|
|
|
|
return new Envelope(
|
|
subject: __($this->sale->isCredit() ? 'sales.receipt_mail.credit_subject' : 'sales.receipt_mail.subject', [
|
|
'number' => $this->sale->id,
|
|
'company' => $company->name ?? config('app.name'),
|
|
]),
|
|
);
|
|
}
|
|
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
view: 'sales-views::receipt-mail',
|
|
with: ['sale' => $this->sale, 'company' => app(CompanyDetailsStore::class)->get()],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return list<Attachment>
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
$pdf = app(ReceiptPdf::class);
|
|
|
|
return [
|
|
Attachment::fromData(fn (): string => $pdf->render($this->sale)->output(), $pdf->fileName($this->sale))
|
|
->withMime('application/pdf'),
|
|
];
|
|
}
|
|
}
|