Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SendApprovedEmail
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
20
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 / 16
0.00% covered (danger)
0.00%
0 / 1
6
 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 "your quote was approved" notification.
9 * Replaces the inline SendGrid call in Quotations::send_approved_notification
10 * (Quotations.php:799-…).
11 *
12 * The controller does the synchronous work (approval recording, in-app
13 * notification creation, audit log) BEFORE dispatching this job — see the
14 * FIRE-1092 ordering comment in the controller. This job just delivers
15 * the email.
16 */
17class SendApprovedEmail extends AbstractSendgridJob
18{
19    public function __construct(
20        public readonly string $toEmail,
21        public readonly string $subject,
22        public readonly string $html,
23        public readonly ?string $quoteId = null,
24    ) {}
25
26    protected function buildMail(): ?Mail
27    {
28        if ($this->toEmail === '') {
29            return null;
30        }
31
32        $email = new Mail;
33        $email->setFrom('fire@fire.es', 'Fire Service Titan');
34        $email->setSubject($this->subject);
35        $email->addTo($this->toEmail);
36        $email->addContent('text/html', $this->html);
37
38        $imgpath = file_get_contents(public_path('fireservicetitan.png'));
39        $email->addAttachment(
40            $imgpath,
41            'image/png',
42            'fireservicetitan.png',
43            'inline',
44            'fireservicetitan'
45        );
46
47        return $email;
48    }
49
50    protected function logLabel(): string
51    {
52        return 'Quotations::send_approved_notification';
53    }
54}