Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SendApprovalEmail
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 buildMail
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
30
 logLabel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Jobs\Email;
4
5use SendGrid\Mail\Mail;
6
7/**
8 * FIRE-1147: async wrapper for the "needs approval" notification sent when
9 * a quote crosses an approval threshold. Replaces the inline SendGrid call
10 * in Quotations::send_approval_notification (Quotations.php:247-…).
11 *
12 * The controller still does the DB queries + template rendering + records
13 * the approval-pending state synchronously (FIRE-1092 ordering: record
14 * first, send second). This job just delivers the pre-rendered email so
15 * the user's HTTP response can return in < 200 ms.
16 */
17class SendApprovalEmail extends AbstractSendgridJob
18{
19    public function __construct(
20        public readonly string $toEmail,
21        public readonly string $subject,
22        public readonly string $html,
23        /** Optional BCC addresses (commercial / creator copies). */
24        public readonly array $bcc = [],
25        public readonly ?string $quoteId = null,
26    ) {}
27
28    protected function buildMail(): ?Mail
29    {
30        if ($this->toEmail === '') {
31            return null;
32        }
33
34        $email = new Mail;
35        $email->setFrom('fire@fire.es', 'Fire Service Titan');
36        $email->setSubject($this->subject);
37        $email->addTo($this->toEmail);
38        $email->addContent('text/html', $this->html);
39
40        foreach ($this->bcc as $address) {
41            if ($address && $address !== $this->toEmail) {
42                $email->addBcc($address);
43            }
44        }
45
46        $imgpath = file_get_contents(public_path('fireservicetitan.png'));
47        $email->addAttachment(
48            $imgpath,
49            'image/png',
50            'fireservicetitan.png',
51            'inline',
52            'fireservicetitan'
53        );
54
55        return $email;
56    }
57
58    protected function logLabel(): string
59    {
60        return 'Quotations::send_approval_notification';
61    }
62}