2026-05-09 12:51:32 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Mail;
|
|
|
|
|
|
|
|
|
|
use App\Models\Tenant;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
|
use Illuminate\Mail\Mailable;
|
2026-06-29 11:25:16 +03:00
|
|
|
use Illuminate\Mail\Mailables\Attachment;
|
2026-05-09 12:51:32 +03:00
|
|
|
use Illuminate\Mail\Mailables\Content;
|
|
|
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2026-06-29 11:25:16 +03:00
|
|
|
use Illuminate\Support\Str;
|
2026-05-09 12:51:32 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Email-уведомление об оплате тарифного счёта (ТЗ §18.5, событие
|
|
|
|
|
* invoice_paid).
|
|
|
|
|
*
|
|
|
|
|
* Триггер: после смены статуса saas_invoice на 'paid'. Endpoint
|
|
|
|
|
* биллинга / webhook ЮKassa — отдельный коммит; этот Mailable готов
|
|
|
|
|
* к подключению.
|
|
|
|
|
*/
|
|
|
|
|
class InvoicePaidNotification extends Mailable
|
|
|
|
|
{
|
|
|
|
|
use Queueable;
|
|
|
|
|
use SerializesModels;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
public User $recipient,
|
|
|
|
|
public Tenant $tenant,
|
|
|
|
|
public string $amountRub,
|
|
|
|
|
public ?string $invoiceNumber,
|
|
|
|
|
public ?string $tariffName,
|
2026-06-29 11:25:16 +03:00
|
|
|
/** Относительный путь PDF-акта на диске 'local' (для вложения). */
|
|
|
|
|
public ?string $actPdfPath = null,
|
|
|
|
|
/** Номер акта — для имени файла вложения. */
|
|
|
|
|
public ?string $actNumber = null,
|
2026-05-09 12:51:32 +03:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
public function envelope(): Envelope
|
|
|
|
|
{
|
|
|
|
|
return new Envelope(
|
|
|
|
|
subject: 'Лидерра. Счёт оплачен',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function content(): Content
|
|
|
|
|
{
|
|
|
|
|
return new Content(
|
|
|
|
|
view: 'emails.invoice_paid',
|
|
|
|
|
with: [
|
|
|
|
|
'recipient' => $this->recipient,
|
|
|
|
|
'tenant' => $this->tenant,
|
|
|
|
|
'amountRub' => $this->amountRub,
|
|
|
|
|
'invoiceNumber' => $this->invoiceNumber,
|
|
|
|
|
'tariffName' => $this->tariffName,
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-29 11:25:16 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Вложение: PDF закрывающего документа (Акт), если он сформирован.
|
|
|
|
|
*
|
|
|
|
|
* @return array<int, Attachment>
|
|
|
|
|
*/
|
|
|
|
|
public function attachments(): array
|
|
|
|
|
{
|
|
|
|
|
if ($this->actPdfPath === null) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = 'Akt-'.Str::ascii((string) $this->actNumber).'.pdf';
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
Attachment::fromStorageDisk('local', $this->actPdfPath)
|
|
|
|
|
->as($name)
|
|
|
|
|
->withMime('application/pdf'),
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-05-09 12:51:32 +03:00
|
|
|
}
|