|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Mail; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
|
6
|
|
|
use Illuminate\Mail\Mailable; |
|
7
|
|
|
use Illuminate\Queue\SerializesModels; |
|
8
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
9
|
|
|
use App\Purchase; |
|
10
|
|
|
use Spipu\Html2Pdf\Html2Pdf; |
|
11
|
|
|
use Spipu\Html2Pdf\Exception\Html2PdfException; |
|
12
|
|
|
use Spipu\Html2Pdf\Exception\ExceptionFormatter; |
|
13
|
|
|
use Illuminate\Support\Facades\Log; |
|
14
|
|
|
|
|
15
|
|
|
class TicketsPaid extends Mailable |
|
16
|
|
|
{ |
|
17
|
|
|
use Queueable, SerializesModels; |
|
18
|
|
|
|
|
19
|
|
|
public $purchase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Create a new message instance. |
|
23
|
|
|
* |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(Purchase $purchase) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->purchase = $purchase; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Build the message. |
|
33
|
|
|
* |
|
34
|
|
|
* @return $this |
|
35
|
|
|
*/ |
|
36
|
|
|
public function build() |
|
37
|
|
|
{ |
|
38
|
|
|
try { |
|
39
|
|
|
$html2pdf = new HTML2PDF('P', 'A4', 'de', true, 'UTF-8', 0); |
|
40
|
|
|
$html2pdf->pdf->SetDisplayMode('fullpage'); |
|
41
|
|
|
$html2pdf->pdf->SetAuthor(config('app.name')); |
|
42
|
|
|
$html2pdf->pdf->SetTitle('Purchase #' . $this->purchase->id); |
|
43
|
|
|
|
|
44
|
|
|
// Generate pdf-content by passing the tickets to the view |
|
45
|
|
|
$content = view('pdfs.ticket-v2', ['tickets' => $this->purchase->tickets])->render(); |
|
46
|
|
|
$html2pdf->writeHTML($content); |
|
47
|
|
|
|
|
48
|
|
|
$pdfContent = $html2pdf->output('tickets-' . $this->purchase->id . '.pdf', 'S'); |
|
49
|
|
|
|
|
50
|
|
|
return $this->markdown('mails.tickets.paid') |
|
51
|
|
|
->attachData($pdfContent, 'tickets-' . $this->purchase->id . '.pdf', [ |
|
52
|
|
|
'mime' => 'application/pdf', |
|
53
|
|
|
]);; |
|
54
|
|
|
} catch (Html2PdfException $e) { |
|
55
|
|
|
$html2pdf->clean(); |
|
56
|
|
|
$formatter = new ExceptionFormatter($e); |
|
57
|
|
|
$errorText = $formatter->getHtmlMessage(); |
|
58
|
|
|
Log::error($errorText); |
|
59
|
|
|
return $this->markdown('mails.tickets.paid'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|