1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Charge\Libre; |
4
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
6
|
|
|
use App\Ajax\Web\Meeting\Charge\LibreFee as Charge; |
7
|
|
|
use Siak\Tontine\Service\LocaleService; |
8
|
|
|
use Siak\Tontine\Service\Meeting\Charge\LibreFeeService; |
9
|
|
|
use Siak\Tontine\Service\Tontine\ChargeService; |
10
|
|
|
use Siak\Tontine\Model\Session as SessionModel; |
11
|
|
|
use Siak\Tontine\Model\Charge as ChargeModel; |
12
|
|
|
|
13
|
|
|
use function filter_var; |
14
|
|
|
use function Jaxon\jq; |
15
|
|
|
use function Jaxon\pm; |
16
|
|
|
use function str_replace; |
17
|
|
|
use function trans; |
18
|
|
|
use function trim; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @databag meeting |
22
|
|
|
* @before getCharge |
23
|
|
|
*/ |
24
|
|
|
class Member extends CallableClass |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var LocaleService |
28
|
|
|
*/ |
29
|
|
|
protected LocaleService $localeService; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @di |
33
|
|
|
* @var ChargeService |
34
|
|
|
*/ |
35
|
|
|
protected ChargeService $chargeService; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @di |
39
|
|
|
* @var LibreFeeService |
40
|
|
|
*/ |
41
|
|
|
protected LibreFeeService $feeService; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var SessionModel|null |
45
|
|
|
*/ |
46
|
|
|
protected ?SessionModel $session; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var ChargeModel|null |
50
|
|
|
*/ |
51
|
|
|
protected ?ChargeModel $charge; |
52
|
|
|
|
53
|
|
|
protected function getCharge() |
54
|
|
|
{ |
55
|
|
|
$sessionId = $this->bag('meeting')->get('session.id'); |
56
|
|
|
$chargeId = $this->target()->method() === 'home' ? |
57
|
|
|
$this->target()->args()[0] : $this->bag('meeting')->get('charge.id'); |
58
|
|
|
$this->session = $this->chargeService->getSession($sessionId); |
|
|
|
|
59
|
|
|
$this->charge = $this->chargeService->getCharge($chargeId); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int $chargeId |
64
|
|
|
* |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
public function home(int $chargeId) |
68
|
|
|
{ |
69
|
|
|
$this->bag('meeting')->set('charge.id', $chargeId); |
70
|
|
|
$this->bag('meeting')->set('fee.member.search', ''); |
71
|
|
|
$this->bag('meeting')->set('fee.member.filter', null); |
72
|
|
|
|
73
|
|
|
$html = $this->view()->render('tontine.pages.meeting.charge.libre.member.home', [ |
74
|
|
|
'charge' => $this->charge, |
75
|
|
|
]); |
76
|
|
|
$this->response->html('meeting-fees-libre', $html); |
|
|
|
|
77
|
|
|
$this->jq('#btn-fee-libre-back')->click($this->cl(Charge::class)->rq()->home()); |
78
|
|
|
$this->jq('#btn-fee-libre-filter')->click($this->rq()->toggleFilter()); |
79
|
|
|
$this->jq('#btn-fee-libre-search') |
80
|
|
|
->click($this->rq()->search(jq('#txt-fee-member-search')->val())); |
81
|
|
|
|
82
|
|
|
return $this->page(1); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param int $pageNumber |
87
|
|
|
* |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
|
|
public function page(int $pageNumber = 0) |
91
|
|
|
{ |
92
|
|
|
$search = trim($this->bag('meeting')->get('fee.member.search', '')); |
93
|
|
|
$filter = $this->bag('meeting')->get('fee.member.filter', null); |
94
|
|
|
$memberCount = $this->feeService->getMemberCount($this->charge, |
|
|
|
|
95
|
|
|
$this->session, $search, $filter); |
|
|
|
|
96
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $memberCount, |
97
|
|
|
'meeting', 'member.page'); |
98
|
|
|
$members = $this->feeService->getMembers($this->charge, $this->session, |
|
|
|
|
99
|
|
|
$search, $filter, $pageNumber); |
100
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $memberCount); |
101
|
|
|
|
102
|
|
|
$html = $this->view()->render('tontine.pages.meeting.charge.libre.member.page', [ |
103
|
|
|
'session' => $this->session, |
104
|
|
|
'charge' => $this->charge, |
105
|
|
|
'members' => $members, |
106
|
|
|
'pagination' => $pagination, |
107
|
|
|
]); |
108
|
|
|
$this->response->html('meeting-fee-libre-members', $html); |
|
|
|
|
109
|
|
|
|
110
|
|
|
$memberId = jq()->parent()->attr('data-member-id')->toInt(); |
111
|
|
|
$paid = pm()->checked('check-fee-libre-paid'); |
112
|
|
|
$amount = jq('input', jq()->parent()->parent())->val()->toInt(); |
113
|
|
|
$this->jq('.btn-add-bill')->click($this->rq()->addBill($memberId, $paid)); |
114
|
|
|
$this->jq('.btn-del-bill')->click($this->rq()->delBill($memberId)); |
115
|
|
|
$this->jq('.btn-save-bill')->click($this->rq()->addBill($memberId, $paid, $amount)); |
116
|
|
|
$this->jq('.btn-edit-bill')->click($this->rq()->editBill($memberId)); |
117
|
|
|
// $this->jq('.btn-edit-notes')->click($this->rq()->editNotes($memberId)); |
118
|
|
|
|
119
|
|
|
return $this->response; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function toggleFilter() |
123
|
|
|
{ |
124
|
|
|
$filter = $this->bag('meeting')->get('fee.member.filter', null); |
125
|
|
|
// Switch between null, true and false |
126
|
|
|
$filter = $filter === null ? true : ($filter === true ? false : null); |
127
|
|
|
$this->bag('meeting')->set('fee.member.filter', $filter); |
128
|
|
|
|
129
|
|
|
return $this->page(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function search(string $search) |
133
|
|
|
{ |
134
|
|
|
$this->bag('meeting')->set('fee.member.search', trim($search)); |
135
|
|
|
|
136
|
|
|
return $this->page(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param int $memberId |
141
|
|
|
* @param bool $paid |
142
|
|
|
* @param string $amount |
143
|
|
|
* |
144
|
|
|
* @return mixed |
145
|
|
|
*/ |
146
|
|
|
public function addBill(int $memberId, bool $paid, string $amount = '') |
147
|
|
|
{ |
148
|
|
|
if($this->session->closed) |
149
|
|
|
{ |
150
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
151
|
|
|
return $this->response; |
152
|
|
|
} |
153
|
|
|
$amount = str_replace(',', '.', trim($amount)); |
154
|
|
|
if($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false) |
155
|
|
|
{ |
156
|
|
|
$this->notify->error(trans('meeting.errors.amount.invalid', ['amount' => $amount])); |
157
|
|
|
return $this->response; |
158
|
|
|
} |
159
|
|
|
$amount = $amount === '' ? 0 : (float)$amount; |
160
|
|
|
|
161
|
|
|
$this->feeService->createBill($this->charge, $this->session, $memberId, $paid, $amount); |
|
|
|
|
162
|
|
|
|
163
|
|
|
return $this->page(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param int $memberId |
168
|
|
|
* |
169
|
|
|
* @return mixed |
170
|
|
|
*/ |
171
|
|
|
public function delBill(int $memberId) |
172
|
|
|
{ |
173
|
|
|
if($this->session->closed) |
174
|
|
|
{ |
175
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
176
|
|
|
return $this->response; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->feeService->deleteBill($this->charge, $this->session, $memberId); |
|
|
|
|
180
|
|
|
|
181
|
|
|
return $this->page(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @di $localeService |
186
|
|
|
* @param int $memberId |
187
|
|
|
* |
188
|
|
|
* @return mixed |
189
|
|
|
*/ |
190
|
|
|
public function editBill(int $memberId) |
191
|
|
|
{ |
192
|
|
|
if($this->session->closed) |
193
|
|
|
{ |
194
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
195
|
|
|
return $this->response; |
196
|
|
|
} |
197
|
|
|
$bill = $this->feeService->getBill($this->charge, $this->session, $memberId); |
|
|
|
|
198
|
|
|
if($bill === null || $bill->bill->settlement !== null) |
199
|
|
|
{ |
200
|
|
|
return $this->page(); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$html = $this->view()->render('tontine.pages.meeting.charge.libre.member.edit', [ |
204
|
|
|
'id' => $memberId, |
205
|
|
|
'amount' => $this->localeService->getMoneyValue($bill->bill->amount), |
206
|
|
|
]); |
207
|
|
|
$fieldId = 'member-' . $memberId; |
208
|
|
|
$this->response->html($fieldId, $html); |
|
|
|
|
209
|
|
|
|
210
|
|
|
$memberId = jq()->parent()->attr('data-member-id')->toInt(); |
211
|
|
|
$amount = jq('input', jq()->parent()->parent())->val(); |
212
|
|
|
$this->jq('.btn-save-bill', "#$fieldId")->click($this->rq()->saveBill($memberId, $amount)); |
213
|
|
|
|
214
|
|
|
return $this->response; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param int $memberId |
219
|
|
|
* @param string $amount |
220
|
|
|
* |
221
|
|
|
* @return mixed |
222
|
|
|
*/ |
223
|
|
|
public function saveBill(int $memberId, string $amount) |
224
|
|
|
{ |
225
|
|
|
if($this->session->closed) |
226
|
|
|
{ |
227
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
228
|
|
|
return $this->response; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
$amount = str_replace(',', '.', trim($amount)); |
232
|
|
|
if($amount !== '' && filter_var($amount, FILTER_VALIDATE_FLOAT) === false) |
233
|
|
|
{ |
234
|
|
|
$this->notify->error(trans('meeting.errors.amount.invalid', ['amount' => $amount])); |
235
|
|
|
return $this->response; |
236
|
|
|
} |
237
|
|
|
$amount = $amount === '' ? 0 : (float)$amount; |
238
|
|
|
|
239
|
|
|
if(!$amount) |
240
|
|
|
{ |
241
|
|
|
$this->feeService->deleteBill($this->charge, $this->session, $memberId); |
|
|
|
|
242
|
|
|
return $this->page(); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$this->feeService->updateBill($this->charge, $this->session, $memberId, $amount); |
|
|
|
|
246
|
|
|
return $this->page(); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|