1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Siak\Tontine\Service\Report\Pdf; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Siak\Tontine\Model\Guild; |
7
|
|
|
use Siak\Tontine\Model\Round; |
8
|
|
|
use Siak\Tontine\Model\Session; |
9
|
|
|
use Siak\Tontine\Service\Guild\GuildService; |
10
|
|
|
|
11
|
|
|
use function trans; |
12
|
|
|
use function view; |
13
|
|
|
|
14
|
|
|
class PdfPrinterService |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param GuildService $guildService |
18
|
|
|
* @param array $config |
19
|
|
|
*/ |
20
|
|
|
public function __construct(private GuildService $guildService, private array $config) |
21
|
|
|
{} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Guild $guild |
25
|
|
|
* @param string $report |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
private function getViewPath(Guild $guild, string $report): string |
30
|
|
|
{ |
31
|
|
|
$template = $this->guildService->getReportTemplate($guild); |
32
|
|
|
return "tontine.report.$template.$report"; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $templatePath |
37
|
|
|
* @param array $config |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
private function getPdf(string $templatePath, array $config = []): string |
42
|
|
|
{ |
43
|
|
|
$config = [ |
44
|
|
|
...$this->config, |
45
|
|
|
...$config, |
46
|
|
|
'headerTemplate' => (string)view("$templatePath.tpl.header"), |
47
|
|
|
'footerTemplate' => (string)view("$templatePath.tpl.footer"), |
48
|
|
|
]; |
49
|
|
|
return PdfGeneratorFacade::getPdf((string)view($templatePath), $config); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Guild $guild |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getSessionReportPath(Guild $guild): string |
58
|
|
|
{ |
59
|
|
|
return $this->getViewPath($guild, 'session'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param Session $session |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getSessionReportFilename(Session $session): string |
68
|
|
|
{ |
69
|
|
|
return Str::slug(trans('meeting.report.labels.session')) . |
70
|
|
|
'-' . Str::slug($session->title) . '.pdf'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param Guild $guild |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getSessionReport(Guild $guild): string |
79
|
|
|
{ |
80
|
|
|
return $this->getPdf($this->getViewPath($guild, 'session')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param Guild $guild |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getSavingsReportPath(Guild $guild): string |
89
|
|
|
{ |
90
|
|
|
return $this->getViewPath($guild, 'savings'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param Session $session |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getSavingsReportFilename(Session $session): string |
99
|
|
|
{ |
100
|
|
|
return Str::slug(trans('meeting.report.labels.savings')) . |
101
|
|
|
'-' . Str::slug($session->title) . '.pdf'; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param Guild $guild |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getSavingsReport(Guild $guild): string |
110
|
|
|
{ |
111
|
|
|
return $this->getPdf($this->getViewPath($guild, 'savings')); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param Guild $guild |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getCreditReportPath(Guild $guild): string |
120
|
|
|
{ |
121
|
|
|
return $this->getViewPath($guild, 'credit'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param Session $session |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getCreditReportFilename(Session $session): string |
130
|
|
|
{ |
131
|
|
|
return Str::slug(trans('meeting.report.labels.credit')) . |
132
|
|
|
'-' . Str::slug($session->title) . '.pdf'; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param Guild $guild |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getCreditReport(Guild $guild): string |
141
|
|
|
{ |
142
|
|
|
return $this->getPdf($this->getViewPath($guild, 'credit')); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param Guild $guild |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getRoundReportPath(Guild $guild): string |
151
|
|
|
{ |
152
|
|
|
return $this->getViewPath($guild, 'round'); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param Round $round |
157
|
|
|
* |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
|
|
public function getRoundReportFilename(Round $round): string |
161
|
|
|
{ |
162
|
|
|
return Str::slug(trans('meeting.report.labels.round')) . |
163
|
|
|
'-' . Str::slug($round->title) . '.pdf'; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param Guild $guild |
168
|
|
|
* |
169
|
|
|
* @return string |
170
|
|
|
*/ |
171
|
|
|
public function getRoundReport(Guild $guild): string |
172
|
|
|
{ |
173
|
|
|
return $this->getPdf($this->getViewPath($guild, 'round')); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $form |
178
|
|
|
* |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function getFormViewPath(string $form): string |
182
|
|
|
{ |
183
|
|
|
return "tontine.entry.raptor.$form"; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param string $form |
188
|
|
|
* |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
public function getEntryForm(string $form): string |
192
|
|
|
{ |
193
|
|
|
return $this->getPdf($this->getFormViewPath($form)); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param string $form |
198
|
|
|
* |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function getFormFilename(string $form): string |
202
|
|
|
{ |
203
|
|
|
return trans("meeting.entry.files.$form") . '.pdf'; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|