|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Planning; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
|
6
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
7
|
|
|
use Siak\Tontine\Service\Planning\PoolService; |
|
8
|
|
|
use Siak\Tontine\Service\LocaleService; |
|
9
|
|
|
use Siak\Tontine\Validation\Planning\PoolValidator; |
|
10
|
|
|
|
|
11
|
|
|
use function Jaxon\jq; |
|
12
|
|
|
use function Jaxon\pm; |
|
13
|
|
|
use function trans; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @databag pool |
|
17
|
|
|
*/ |
|
18
|
|
|
class Pool extends CallableClass |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var LocaleService |
|
22
|
|
|
*/ |
|
23
|
|
|
protected LocaleService $localeService; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var PoolValidator |
|
27
|
|
|
*/ |
|
28
|
|
|
protected PoolValidator $validator; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(private PoolService $poolService) |
|
31
|
|
|
{} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @databag subscription |
|
35
|
|
|
* @before checkRoundSessions |
|
36
|
|
|
* @after hideMenuOnMobile |
|
37
|
|
|
*/ |
|
38
|
|
|
public function home() |
|
39
|
|
|
{ |
|
40
|
|
|
$html = $this->render('pages.planning.pool.home', [ |
|
41
|
|
|
'tontine' => $this->tenantService->tontine(), |
|
42
|
|
|
]); |
|
43
|
|
|
$this->response->html('section-title', trans('tontine.menus.planning')); |
|
44
|
|
|
$this->response->html('content-home', $html); |
|
|
|
|
|
|
45
|
|
|
$this->jq('#btn-refresh')->click($this->rq()->home()); |
|
46
|
|
|
$this->jq('#btn-create')->click($this->rq()->showIntro()); |
|
47
|
|
|
|
|
48
|
|
|
return $this->page(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function page(int $pageNumber = 0) |
|
52
|
|
|
{ |
|
53
|
|
|
$poolCount = $this->poolService->getPoolCount(); |
|
54
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $poolCount, 'pool', 'page'); |
|
55
|
|
|
$pools = $this->poolService->getPools($pageNumber); |
|
56
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $poolCount); |
|
57
|
|
|
|
|
58
|
|
|
$html = $this->render('pages.planning.pool.page') |
|
59
|
|
|
->with('round', $this->tenantService->round()) |
|
60
|
|
|
->with('pools', $pools) |
|
61
|
|
|
->with('pagination', $pagination); |
|
62
|
|
|
$this->response->html('content-page', $html); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$poolId = jq()->parent()->attr('data-pool-id')->toInt(); |
|
65
|
|
|
$this->jq('.btn-pool-edit')->click($this->rq()->edit($poolId)); |
|
66
|
|
|
$this->jq('.btn-pool-sessions')->click($this->cl(PoolRound::class)->rq()->home($poolId)); |
|
67
|
|
|
$this->jq('.btn-pool-delete')->click($this->rq()->delete($poolId) |
|
68
|
|
|
->confirm(trans('tontine.pool.questions.delete'))); |
|
69
|
|
|
|
|
70
|
|
|
return $this->response; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function showIntro() |
|
74
|
|
|
{ |
|
75
|
|
|
$title = trans('tontine.pool.titles.add'); |
|
76
|
|
|
$content = $this->render('pages.planning.pool.add_intro'); |
|
77
|
|
|
$buttons = [[ |
|
78
|
|
|
'title' => trans('common.actions.cancel'), |
|
79
|
|
|
'class' => 'btn btn-tertiary', |
|
80
|
|
|
'click' => 'close', |
|
81
|
|
|
],[ |
|
82
|
|
|
'title' => trans('common.actions.next'), |
|
83
|
|
|
'class' => 'btn btn-primary', |
|
84
|
|
|
'click' => $this->rq()->showDepositFixed(), |
|
85
|
|
|
]]; |
|
86
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
87
|
|
|
$this->bag('pool')->set('add', []); |
|
88
|
|
|
|
|
89
|
|
|
return $this->response; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function showDepositFixed() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->dialog->hide(); |
|
95
|
|
|
|
|
96
|
|
|
$title = trans('tontine.pool.titles.deposits'); |
|
97
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
98
|
|
|
$content = $this->render('pages.planning.pool.deposit_fixed') |
|
99
|
|
|
->with('fixed', $properties['deposit']['fixed'] ?? true); |
|
100
|
|
|
$buttons = [[ |
|
101
|
|
|
'title' => trans('common.actions.cancel'), |
|
102
|
|
|
'class' => 'btn btn-tertiary', |
|
103
|
|
|
'click' => 'close', |
|
104
|
|
|
],[ |
|
105
|
|
|
'title' => trans('common.actions.next'), |
|
106
|
|
|
'class' => 'btn btn-primary', |
|
107
|
|
|
'click' => $this->rq()->saveDepositFixed(pm()->checked('pool_deposit_fixed')), |
|
108
|
|
|
]]; |
|
109
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
return $this->response; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function saveDepositFixed(bool $fixed) |
|
115
|
|
|
{ |
|
116
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
117
|
|
|
$properties['deposit']['fixed'] = $fixed; |
|
118
|
|
|
$this->bag('pool')->set('add', $properties); |
|
119
|
|
|
|
|
120
|
|
|
if($fixed) |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->showDepositLendable(); |
|
123
|
|
|
} |
|
124
|
|
|
// Pools with libre deposits are not lendable. |
|
125
|
|
|
return $this->saveDepositLendable(false); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function showDepositLendable() |
|
129
|
|
|
{ |
|
130
|
|
|
$this->dialog->hide(); |
|
131
|
|
|
|
|
132
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
133
|
|
|
$title = trans('tontine.pool.titles.deposits'); |
|
134
|
|
|
$content = $this->render('pages.planning.pool.deposit_lendable') |
|
135
|
|
|
->with('lendable', $properties['deposit']['lendable'] ?? false); |
|
136
|
|
|
$buttons = [[ |
|
137
|
|
|
'title' => trans('common.actions.cancel'), |
|
138
|
|
|
'class' => 'btn btn-tertiary', |
|
139
|
|
|
'click' => 'close', |
|
140
|
|
|
],[ |
|
141
|
|
|
'title' => trans('common.actions.prev'), |
|
142
|
|
|
'class' => 'btn btn-primary', |
|
143
|
|
|
'click' => $this->rq()->showDepositFixed(), |
|
144
|
|
|
],[ |
|
145
|
|
|
'title' => trans('common.actions.next'), |
|
146
|
|
|
'class' => 'btn btn-primary', |
|
147
|
|
|
'click' => $this->rq()->saveDepositLendable(pm()->checked('pool_deposit_lendable')), |
|
148
|
|
|
]]; |
|
149
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
return $this->response; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function saveDepositLendable(bool $lendable) |
|
155
|
|
|
{ |
|
156
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
157
|
|
|
$properties['deposit']['lendable'] = $lendable; |
|
158
|
|
|
$this->bag('pool')->set('add', $properties); |
|
159
|
|
|
|
|
160
|
|
|
return $this->showRemitPlanned(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function showRemitPlanned() |
|
164
|
|
|
{ |
|
165
|
|
|
$this->dialog->hide(); |
|
166
|
|
|
|
|
167
|
|
|
$title = trans('tontine.pool.titles.remitments'); |
|
168
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
169
|
|
|
$fixed = $properties['deposit']['fixed'] ?? true; |
|
170
|
|
|
$prevAction = $fixed ? $this->rq()->showDepositLendable() : $this->rq()->showDepositFixed(); |
|
171
|
|
|
|
|
172
|
|
|
$content = $this->render('pages.planning.pool.remit_planned') |
|
173
|
|
|
->with('planned', $properties['remit']['planned'] ?? true); |
|
174
|
|
|
$buttons = [[ |
|
175
|
|
|
'title' => trans('common.actions.cancel'), |
|
176
|
|
|
'class' => 'btn btn-tertiary', |
|
177
|
|
|
'click' => 'close', |
|
178
|
|
|
],[ |
|
179
|
|
|
'title' => trans('common.actions.prev'), |
|
180
|
|
|
'class' => 'btn btn-primary', |
|
181
|
|
|
'click' => $prevAction, |
|
182
|
|
|
],[ |
|
183
|
|
|
'title' => trans('common.actions.next'), |
|
184
|
|
|
'class' => 'btn btn-primary', |
|
185
|
|
|
'click' => $this->rq()->saveRemitPlanned(pm()->checked('pool_remit_planned')), |
|
186
|
|
|
]]; |
|
187
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
return $this->response; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function saveRemitPlanned(bool $planned) |
|
193
|
|
|
{ |
|
194
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
195
|
|
|
$properties['remit']['planned'] = $planned; |
|
196
|
|
|
$this->bag('pool')->set('add', $properties); |
|
197
|
|
|
|
|
198
|
|
|
return $this->showRemitAuction(); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function showRemitAuction() |
|
202
|
|
|
{ |
|
203
|
|
|
$this->dialog->hide(); |
|
204
|
|
|
|
|
205
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
206
|
|
|
|
|
207
|
|
|
$title = trans('tontine.pool.titles.remitments'); |
|
208
|
|
|
$content = $this->render('pages.planning.pool.remit_auction') |
|
209
|
|
|
->with('auction', $properties['remit']['auction'] ?? false); |
|
210
|
|
|
$buttons = [[ |
|
211
|
|
|
'title' => trans('common.actions.cancel'), |
|
212
|
|
|
'class' => 'btn btn-tertiary', |
|
213
|
|
|
'click' => 'close', |
|
214
|
|
|
],[ |
|
215
|
|
|
'title' => trans('common.actions.prev'), |
|
216
|
|
|
'class' => 'btn btn-primary', |
|
217
|
|
|
'click' => $this->rq()->showRemitPlanned(), |
|
218
|
|
|
],[ |
|
219
|
|
|
'title' => trans('common.actions.next'), |
|
220
|
|
|
'class' => 'btn btn-primary', |
|
221
|
|
|
'click' => $this->rq()->saveRemitAuction(pm()->checked('pool_remit_auction')), |
|
222
|
|
|
]]; |
|
223
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
return $this->response; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function saveRemitAuction(bool $auction) |
|
229
|
|
|
{ |
|
230
|
|
|
$properties = $this->bag('pool')->get('add', []); |
|
231
|
|
|
$properties['remit']['auction'] = $auction; |
|
232
|
|
|
$this->bag('pool')->set('add', $properties); |
|
233
|
|
|
|
|
234
|
|
|
return $this->add(); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function add() |
|
238
|
|
|
{ |
|
239
|
|
|
$this->dialog->hide(); |
|
240
|
|
|
|
|
241
|
|
|
$title = trans('tontine.pool.titles.add'); |
|
242
|
|
|
$content = $this->render('pages.planning.pool.add', [ |
|
243
|
|
|
'properties' => $this->bag('pool')->get('add', []), |
|
244
|
|
|
]); |
|
245
|
|
|
$buttons = [[ |
|
246
|
|
|
'title' => trans('common.actions.cancel'), |
|
247
|
|
|
'class' => 'btn btn-tertiary', |
|
248
|
|
|
'click' => 'close', |
|
249
|
|
|
],[ |
|
250
|
|
|
'title' => trans('common.actions.save'), |
|
251
|
|
|
'class' => 'btn btn-primary', |
|
252
|
|
|
'click' => $this->rq()->create(pm()->form('pool-form')), |
|
253
|
|
|
]]; |
|
254
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
255
|
|
|
|
|
256
|
|
|
return $this->response; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @databag subscription |
|
261
|
|
|
* @di $validator |
|
262
|
|
|
*/ |
|
263
|
|
|
public function create(array $formValues) |
|
264
|
|
|
{ |
|
265
|
|
|
$formValues['properties'] = $this->bag('pool')->get('add', []); |
|
266
|
|
|
$values = $this->validator->validateItem($formValues); |
|
267
|
|
|
$this->poolService->createPool($values); |
|
268
|
|
|
|
|
269
|
|
|
$this->dialog->hide(); |
|
270
|
|
|
$this->notify->success(trans('tontine.pool.messages.created'), trans('common.titles.success')); |
|
271
|
|
|
|
|
272
|
|
|
return $this->page(); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
public function edit(int $poolId) |
|
276
|
|
|
{ |
|
277
|
|
|
$pool = $this->poolService->getPool($poolId); |
|
278
|
|
|
$title = trans('tontine.pool.titles.edit'); |
|
279
|
|
|
$content = $this->render('pages.planning.pool.edit') |
|
280
|
|
|
->with('pool', $pool) |
|
281
|
|
|
->with('locales', LaravelLocalization::getSupportedLocales()); |
|
282
|
|
|
$buttons = [[ |
|
283
|
|
|
'title' => trans('common.actions.cancel'), |
|
284
|
|
|
'class' => 'btn btn-tertiary', |
|
285
|
|
|
'click' => 'close', |
|
286
|
|
|
],[ |
|
287
|
|
|
'title' => trans('common.actions.save'), |
|
288
|
|
|
'class' => 'btn btn-primary', |
|
289
|
|
|
'click' => $this->rq()->update($pool->id, pm()->form('pool-form')), |
|
290
|
|
|
]]; |
|
291
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
return $this->response; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* @di $validator |
|
298
|
|
|
*/ |
|
299
|
|
|
public function update(int $poolId, array $formValues) |
|
300
|
|
|
{ |
|
301
|
|
|
$pool = $this->poolService->getPool($poolId); |
|
302
|
|
|
// The properties field cannot be changed. |
|
303
|
|
|
$formValues['properties'] = $pool->properties; |
|
304
|
|
|
$values = $this->validator->validateItem($formValues); |
|
305
|
|
|
$this->poolService->updatePool($pool, $values); |
|
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
$this->dialog->hide(); |
|
308
|
|
|
$this->notify->success(trans('tontine.pool.messages.updated'), trans('common.titles.success')); |
|
309
|
|
|
|
|
310
|
|
|
return $this->page(); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
public function delete(int $poolId) |
|
314
|
|
|
{ |
|
315
|
|
|
$pool = $this->poolService->getPool($poolId); |
|
316
|
|
|
$this->poolService->deletePool($pool); |
|
|
|
|
|
|
317
|
|
|
$this->notify->success(trans('tontine.pool.messages.deleted'), trans('common.titles.success')); |
|
318
|
|
|
|
|
319
|
|
|
return $this->page(); |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
|