1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Report; |
4
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
6
|
|
|
use Siak\Tontine\Model\Session as SessionModel; |
7
|
|
|
use Siak\Tontine\Service\Report\ReportService; |
8
|
|
|
use Siak\Tontine\Service\TenantService; |
9
|
|
|
use Siak\Tontine\Service\Tontine\TontineService; |
10
|
|
|
|
11
|
|
|
use function compact; |
12
|
|
|
use function count; |
13
|
|
|
use function Jaxon\pm; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @databag report |
17
|
|
|
*/ |
18
|
|
|
class Session extends CallableClass |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param TenantService $tenantService |
22
|
|
|
* @param TontineService $tontineService |
23
|
|
|
* @param ReportService $reportService |
24
|
|
|
*/ |
25
|
|
|
public function __construct(protected TenantService $tenantService, |
26
|
|
|
protected TontineService $tontineService, protected ReportService $reportService) |
27
|
|
|
{} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @after hideMenuOnMobile |
31
|
|
|
*/ |
32
|
|
|
public function home() |
33
|
|
|
{ |
34
|
|
|
// Don't show the page if there is no session or no member. |
35
|
|
|
$sessions = $this->tenantService->getSessions(orderAsc: false) |
36
|
|
|
->filter(fn($session) => $session->opened || $session->closed); |
37
|
|
|
if($sessions->count() === 0) |
38
|
|
|
{ |
39
|
|
|
return $this->response; |
40
|
|
|
} |
41
|
|
|
$members = $this->tontineService->getMembers(); |
42
|
|
|
if($members->count() === 0) |
43
|
|
|
{ |
44
|
|
|
return $this->response; |
45
|
|
|
} |
46
|
|
|
$members->prepend('', 0); |
47
|
|
|
|
48
|
|
|
$this->response->html('section-title', trans('tontine.menus.report')); |
49
|
|
|
$html = $this->render('pages.report.session.home', |
50
|
|
|
['sessions' => $sessions->pluck('title', 'id'), 'members' => $members]); |
51
|
|
|
$this->response->html('content-home', $html); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->jq('#btn-members-refresh')->click($this->rq()->home()); |
54
|
|
|
$sessionId = pm()->select('select-session')->toInt(); |
55
|
|
|
$memberId = pm()->select('select-member')->toInt(); |
56
|
|
|
$this->jq('#btn-session-select')->click($this->rq()->showSession($sessionId)); |
57
|
|
|
$this->jq('#btn-member-select')->click($this->rq()->showMember($sessionId, $memberId)); |
58
|
|
|
|
59
|
|
|
return $this->_showSession($sessions->first()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function showReportButtons(SessionModel $session) |
63
|
|
|
{ |
64
|
|
|
$closings = $this->reportService->getClosings($session); |
65
|
|
|
$html = $this->render('pages.report.session.exports', |
66
|
|
|
['sessionId' => $session->id, 'hasClosing' => count($closings) > 0]); |
67
|
|
|
$this->response->html('session-reports-export', $html); |
|
|
|
|
68
|
|
|
|
69
|
|
|
return $this->response; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function _showSession(SessionModel $session) |
73
|
|
|
{ |
74
|
|
|
$this->response->html('session-report-title', $session->title); |
75
|
|
|
$this->cl(Session\Session::class)->show($session); |
76
|
|
|
|
77
|
|
|
return $this->showReportButtons($session); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function showSession(int $sessionId) |
81
|
|
|
{ |
82
|
|
|
if(!($session = $this->tenantService->getSession($sessionId))) |
83
|
|
|
{ |
84
|
|
|
return $this->response; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->_showSession($session); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function showMember(int $sessionId, int $memberId) |
91
|
|
|
{ |
92
|
|
|
if(!($session = $this->tenantService->getSession($sessionId))) |
93
|
|
|
{ |
94
|
|
|
return $this->response; |
95
|
|
|
} |
96
|
|
|
if(!($member = $this->tontineService->getMember($memberId))) |
97
|
|
|
{ |
98
|
|
|
return $this->response; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->response->html('session-report-title', $session->title . ' - ' . $member->name); |
102
|
|
|
$this->cl(Session\Member::class)->show($session, $member); |
103
|
|
|
|
104
|
|
|
return $this->showReportButtons($session); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|