1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Http\Response; |
7
|
|
|
use Illuminate\View\View; |
8
|
|
|
use Siak\Tontine\Service\Report\Pdf\PrinterService; |
9
|
|
|
use Siak\Tontine\Service\Report\ReportService; |
10
|
|
|
use Siak\Tontine\Service\TenantService; |
11
|
|
|
use Siak\Tontine\Service\Tontine\TontineService; |
12
|
|
|
use Sqids\SqidsInterface; |
13
|
|
|
|
14
|
|
|
use function base64_decode; |
15
|
|
|
use function response; |
16
|
|
|
use function view; |
17
|
|
|
|
18
|
|
|
class ReportController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param TenantService $tenantService |
22
|
|
|
* @param ReportService $reportService |
23
|
|
|
* @param PrinterService $printerService |
24
|
|
|
*/ |
25
|
|
|
public function __construct(private TenantService $tenantService, |
26
|
|
|
private ReportService $reportService, private TontineService $tontineService, |
27
|
|
|
private PrinterService $printerService) |
28
|
|
|
{} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Request $request |
32
|
|
|
* @param int $sessionId |
33
|
|
|
* |
34
|
|
|
* @return View|Response |
35
|
|
|
*/ |
36
|
|
|
public function sessionById(Request $request, int $sessionId) |
37
|
|
|
{ |
38
|
|
|
$template = $this->tontineService->getReportTemplate(); |
39
|
|
|
$session = $this->tenantService->getSession($sessionId); |
40
|
|
|
view()->share($this->reportService->getSessionReport($session)); |
|
|
|
|
41
|
|
|
// Show the html page |
42
|
|
|
if($request->has('html')) |
43
|
|
|
{ |
44
|
|
|
return view("tontine.report.$template.session"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Print the pdf |
48
|
|
|
$filename = $this->reportService->getSessionReportFilename($session); |
|
|
|
|
49
|
|
|
return response(base64_decode($this->printerService->getSessionReport($template)), 200) |
50
|
|
|
->header('Content-Description', 'Session Report') |
51
|
|
|
->header('Content-Type', 'application/pdf') |
52
|
|
|
->header('Content-Disposition', "inline; filename=$filename") |
53
|
|
|
->header('Content-Transfer-Encoding', 'binary') |
54
|
|
|
->header('Expires', '0') |
55
|
|
|
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') |
56
|
|
|
->header('Pragma', 'public'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Request $request |
61
|
|
|
* @param SqidsInterface $sqids |
62
|
|
|
* @param string $sessionId |
63
|
|
|
* |
64
|
|
|
* @return View|Response |
65
|
|
|
*/ |
66
|
|
|
public function session(Request $request, SqidsInterface $sqids, string $sessionSqid) |
67
|
|
|
{ |
68
|
|
|
[$sessionId] = $sqids->decode($sessionSqid); |
69
|
|
|
return $this->sessionById($request, $sessionId); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param Request $request |
74
|
|
|
* @param SqidsInterface $sqids |
75
|
|
|
* @param string $sessionId |
76
|
|
|
* |
77
|
|
|
* @return View|Response |
78
|
|
|
*/ |
79
|
|
|
public function profits(Request $request, SqidsInterface $sqids, string $sessionSqid) |
80
|
|
|
{ |
81
|
|
|
[$sessionId] = $sqids->decode($sessionSqid); |
82
|
|
|
$template = $this->tontineService->getReportTemplate(); |
83
|
|
|
$session = $this->tenantService->getSession($sessionId); |
84
|
|
|
view()->share($this->reportService->getProfitsReport($session)); |
|
|
|
|
85
|
|
|
// Show the html page |
86
|
|
|
if($request->has('html')) |
87
|
|
|
{ |
88
|
|
|
return view("tontine.report.$template.profits"); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Print the pdf |
92
|
|
|
$filename = $this->reportService->getProfitsReportFilename($session); |
|
|
|
|
93
|
|
|
return response(base64_decode($this->printerService->getProfitsReport($template)), 200) |
94
|
|
|
->header('Content-Description', 'Profits Report') |
95
|
|
|
->header('Content-Type', 'application/pdf') |
96
|
|
|
->header('Content-Disposition', "inline; filename=$filename") |
97
|
|
|
->header('Content-Transfer-Encoding', 'binary') |
98
|
|
|
->header('Expires', '0') |
99
|
|
|
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') |
100
|
|
|
->header('Pragma', 'public'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param Request $request |
105
|
|
|
* @param int $roundId |
106
|
|
|
* |
107
|
|
|
* @return View|Response |
108
|
|
|
*/ |
109
|
|
|
public function roundById(Request $request, int $roundId) |
110
|
|
|
{ |
111
|
|
|
$template = $this->tontineService->getReportTemplate(); |
112
|
|
|
$round = $this->tenantService->getRound($roundId); |
113
|
|
|
view()->share($this->reportService->getRoundReport($round)); |
|
|
|
|
114
|
|
|
// Show the html page |
115
|
|
|
if($request->has('html')) |
116
|
|
|
{ |
117
|
|
|
return view("tontine.report.$template.round"); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// Print the pdf |
121
|
|
|
$filename = $this->reportService->getRoundReportFilename($round); |
|
|
|
|
122
|
|
|
return response(base64_decode($this->printerService->getRoundReport($template)), 200) |
123
|
|
|
->header('Content-Description', 'Round Report') |
124
|
|
|
->header('Content-Type', 'application/pdf') |
125
|
|
|
->header('Content-Disposition', "inline; filename=$filename") |
126
|
|
|
->header('Content-Transfer-Encoding', 'binary') |
127
|
|
|
->header('Expires', '0') |
128
|
|
|
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') |
129
|
|
|
->header('Pragma', 'public'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param Request $request |
134
|
|
|
* @param SqidsInterface $sqids |
135
|
|
|
* @param string $roundSqid |
136
|
|
|
* |
137
|
|
|
* @return View|Response |
138
|
|
|
*/ |
139
|
|
|
public function round(Request $request, SqidsInterface $sqids, string $roundSqid) |
140
|
|
|
{ |
141
|
|
|
[$roundId] = $sqids->decode($roundSqid); |
142
|
|
|
return $this->roundById($request, $roundId); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|