1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Saving; |
4
|
|
|
|
5
|
|
|
use App\Ajax\CallableSessionClass; |
6
|
|
|
use Siak\Tontine\Model\Session as SessionModel; |
7
|
|
|
use Siak\Tontine\Service\Meeting\Saving\SavingService; |
8
|
|
|
use Siak\Tontine\Service\Tontine\FundService; |
9
|
|
|
use Siak\Tontine\Service\Tontine\MemberService; |
10
|
|
|
use Siak\Tontine\Validation\Meeting\SavingValidator; |
11
|
|
|
|
12
|
|
|
use function Jaxon\jq; |
13
|
|
|
use function Jaxon\pm; |
14
|
|
|
use function trans; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @databag meeting.saving |
18
|
|
|
*/ |
19
|
|
|
class Saving extends CallableSessionClass |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var SavingValidator |
23
|
|
|
*/ |
24
|
|
|
protected SavingValidator $validator; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The constructor |
28
|
|
|
* |
29
|
|
|
* @param SavingService $savingService |
30
|
|
|
* @param FundService $fundService |
31
|
|
|
* @param MemberService $memberService |
32
|
|
|
*/ |
33
|
|
|
public function __construct(protected SavingService $savingService, |
34
|
|
|
protected FundService $fundService, protected MemberService $memberService) |
35
|
|
|
{} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @exclude |
39
|
|
|
*/ |
40
|
|
|
public function show(SessionModel $session) |
41
|
|
|
{ |
42
|
|
|
$this->session = $session; |
43
|
|
|
|
44
|
|
|
return $this->home(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function home() |
48
|
|
|
{ |
49
|
|
|
$html = $this->render('pages.meeting.saving.home', [ |
50
|
|
|
'session' => $this->session, |
51
|
|
|
'fundId' => (int)$this->bag('meeting.saving')->get('fund.id', -1), |
52
|
|
|
'funds' => $this->fundService->getFundList()->prepend('', -1), |
53
|
|
|
]); |
54
|
|
|
$this->response->html('meeting-savings', $html); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->jq('#btn-savings-refresh')->click($this->rq()->home()); |
57
|
|
|
$fundId = pm()->select('savings-fund-id')->toInt(); |
58
|
|
|
$this->jq('#btn-savings-edit')->click($this->rq(Member::class)->home($fundId)); |
59
|
|
|
$this->jq('#btn-savings-fund')->click($this->rq()->filter($fundId)); |
60
|
|
|
|
61
|
|
|
return $this->page(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function showTotal(int $fundId, int $savingCount) |
65
|
|
|
{ |
66
|
|
|
$savingTotal = $this->savingService->getSavingTotal($this->session, $fundId); |
|
|
|
|
67
|
|
|
$html = $this->render('pages.meeting.saving.total', [ |
68
|
|
|
'savingCount' => $savingCount, |
69
|
|
|
'savingTotal' => $savingTotal, |
70
|
|
|
]); |
71
|
|
|
$this->response->html('meeting-savings-total', $html); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function page(int $pageNumber = 0) |
75
|
|
|
{ |
76
|
|
|
$fundId = (int)$this->bag('meeting.saving')->get('fund.id', -1); |
77
|
|
|
$savingCount = $this->savingService->getSavingCount($this->session, $fundId); |
|
|
|
|
78
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $savingCount, |
79
|
|
|
'meeting.saving', 'page'); |
80
|
|
|
$savings = $this->savingService->getSavings($this->session, $fundId, $pageNumber); |
|
|
|
|
81
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $savingCount); |
82
|
|
|
|
83
|
|
|
$this->showTotal($fundId, $savingCount); |
84
|
|
|
|
85
|
|
|
$html = $this->render('pages.meeting.saving.page', [ |
86
|
|
|
'session' => $this->session, |
87
|
|
|
'savings' => $savings, |
88
|
|
|
'pagination' => $pagination, |
89
|
|
|
]); |
90
|
|
|
$this->response->html('meeting-savings-page', $html); |
|
|
|
|
91
|
|
|
$this->response->call('makeTableResponsive', 'meeting-savings-page'); |
92
|
|
|
|
93
|
|
|
$savingId = jq()->parent()->attr('data-saving-id')->toInt(); |
94
|
|
|
$this->jq('.btn-saving-edit')->click($this->rq()->editSaving($savingId)); |
95
|
|
|
$this->jq('.btn-saving-delete')->click($this->rq()->deleteSaving($savingId) |
96
|
|
|
->confirm(trans('meeting.saving.questions.delete'))); |
97
|
|
|
|
98
|
|
|
return $this->response; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function filter(int $fundId) |
102
|
|
|
{ |
103
|
|
|
$this->bag('meeting.saving')->set('fund.id', $fundId); |
104
|
|
|
|
105
|
|
|
return $this->page(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function editSaving(int $savingId) |
109
|
|
|
{ |
110
|
|
|
if($this->session->closed) |
111
|
|
|
{ |
112
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
113
|
|
|
return $this->response; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$saving = $this->savingService->getSaving($this->session, $savingId); |
|
|
|
|
117
|
|
|
$title = trans('meeting.saving.titles.edit'); |
118
|
|
|
$content = $this->render('pages.meeting.saving.edit', [ |
119
|
|
|
'saving' => $saving, |
120
|
|
|
'members' => $this->memberService->getMemberList(), |
121
|
|
|
'funds' => $this->fundService->getFundList(), |
122
|
|
|
]); |
123
|
|
|
$buttons = [[ |
124
|
|
|
'title' => trans('common.actions.cancel'), |
125
|
|
|
'class' => 'btn btn-tertiary', |
126
|
|
|
'click' => 'close', |
127
|
|
|
],[ |
128
|
|
|
'title' => trans('common.actions.save'), |
129
|
|
|
'class' => 'btn btn-primary', |
130
|
|
|
'click' => $this->rq()->updateSaving($savingId, pm()->form('saving-form')), |
131
|
|
|
]]; |
132
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
133
|
|
|
|
134
|
|
|
return $this->response; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @di $validator |
139
|
|
|
* @after showBalanceAmounts |
140
|
|
|
*/ |
141
|
|
|
public function updateSaving(int $savingId, array $formValues) |
142
|
|
|
{ |
143
|
|
|
if($this->session->closed) |
144
|
|
|
{ |
145
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
146
|
|
|
return $this->response; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$values = $this->validator->validateItem($formValues); |
150
|
|
|
$this->savingService->updateSaving($this->session, $savingId, $values); |
|
|
|
|
151
|
|
|
|
152
|
|
|
$this->dialog->hide(); |
153
|
|
|
|
154
|
|
|
return $this->home(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @after showBalanceAmounts |
159
|
|
|
*/ |
160
|
|
|
public function deleteSaving(int $savingId) |
161
|
|
|
{ |
162
|
|
|
if($this->session->closed) |
163
|
|
|
{ |
164
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
165
|
|
|
return $this->response; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$this->savingService->deleteSaving($this->session, $savingId); |
|
|
|
|
169
|
|
|
|
170
|
|
|
return $this->home(); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|