|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Planning; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
|
6
|
|
|
use App\Ajax\Web\Tontine\Select; |
|
7
|
|
|
use Siak\Tontine\Service\Planning\RoundService; |
|
8
|
|
|
use Siak\Tontine\Validation\Planning\RoundValidator; |
|
9
|
|
|
|
|
10
|
|
|
use function Jaxon\jq; |
|
11
|
|
|
use function Jaxon\pm; |
|
12
|
|
|
use function trans; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @databag tontine |
|
16
|
|
|
*/ |
|
17
|
|
|
class Round extends CallableClass |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var RoundValidator |
|
21
|
|
|
*/ |
|
22
|
|
|
protected RoundValidator $validator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param RoundService $roundService |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(protected RoundService $roundService) |
|
28
|
|
|
{} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @databag planning |
|
32
|
|
|
* @after hideMenuOnMobile |
|
33
|
|
|
*/ |
|
34
|
|
|
public function home() |
|
35
|
|
|
{ |
|
36
|
|
|
$html = $this->render('pages.planning.round.home'); |
|
37
|
|
|
$this->response->html('content-home', $html); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$this->jq('#btn-show-select')->click($this->cl(Select::class)->rq()->showRounds()); |
|
40
|
|
|
$this->jq('#btn-round-refresh')->click($this->rq()->home()); |
|
41
|
|
|
$this->jq('#btn-round-create')->click($this->rq()->add()); |
|
42
|
|
|
|
|
43
|
|
|
$this->page(); |
|
44
|
|
|
|
|
45
|
|
|
return $this->cl(Session::class)->setTenantService($this->tenantService)->show(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function page(int $pageNumber = 0) |
|
49
|
|
|
{ |
|
50
|
|
|
$roundCount = $this->roundService->getRoundCount(); |
|
51
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $roundCount, 'tontine', 'round.page'); |
|
52
|
|
|
$rounds = $this->roundService->getRounds($pageNumber); |
|
53
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $roundCount); |
|
54
|
|
|
|
|
55
|
|
|
$html = $this->render('pages.planning.round.page') |
|
56
|
|
|
->with('rounds', $rounds) |
|
57
|
|
|
->with('pagination', $pagination); |
|
58
|
|
|
$this->response->html('content-page-rounds', $html); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$roundId = jq()->parent()->attr('data-round-id')->toInt(); |
|
61
|
|
|
$this->jq('.btn-round-edit')->click($this->rq()->edit($roundId)); |
|
62
|
|
|
$this->jq('.btn-round-select')->click($this->cl(Select::class)->rq()->saveRound($roundId)); |
|
63
|
|
|
|
|
64
|
|
|
return $this->response; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function add() |
|
68
|
|
|
{ |
|
69
|
|
|
$title = trans('tontine.round.titles.add'); |
|
70
|
|
|
$content = $this->render('pages.planning.round.add'); |
|
71
|
|
|
$buttons = [[ |
|
72
|
|
|
'title' => trans('common.actions.cancel'), |
|
73
|
|
|
'class' => 'btn btn-tertiary', |
|
74
|
|
|
'click' => 'close', |
|
75
|
|
|
],[ |
|
76
|
|
|
'title' => trans('common.actions.save'), |
|
77
|
|
|
'class' => 'btn btn-primary', |
|
78
|
|
|
'click' => $this->rq()->create(pm()->form('round-form')), |
|
79
|
|
|
]]; |
|
80
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
return $this->response; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @di $validator |
|
87
|
|
|
*/ |
|
88
|
|
|
public function create(array $formValues) |
|
89
|
|
|
{ |
|
90
|
|
|
$values = $this->validator->validateItem($formValues); |
|
91
|
|
|
$this->roundService->createRound($values); |
|
92
|
|
|
$this->page(); // Back to current page |
|
93
|
|
|
|
|
94
|
|
|
$this->dialog->hide(); |
|
95
|
|
|
$this->notify->success(trans('tontine.round.messages.created'), trans('common.titles.success')); |
|
96
|
|
|
|
|
97
|
|
|
return $this->response; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function edit(int $roundId) |
|
101
|
|
|
{ |
|
102
|
|
|
$round = $this->roundService->getRound($roundId); |
|
103
|
|
|
|
|
104
|
|
|
$title = trans('tontine.round.titles.edit'); |
|
105
|
|
|
$content = $this->render('pages.planning.round.edit')->with('round', $round); |
|
106
|
|
|
$buttons = [[ |
|
107
|
|
|
'title' => trans('common.actions.cancel'), |
|
108
|
|
|
'class' => 'btn btn-tertiary', |
|
109
|
|
|
'click' => 'close', |
|
110
|
|
|
],[ |
|
111
|
|
|
'title' => trans('common.actions.save'), |
|
112
|
|
|
'class' => 'btn btn-primary', |
|
113
|
|
|
'click' => $this->rq()->update($round->id, pm()->form('round-form')), |
|
114
|
|
|
]]; |
|
115
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
return $this->response; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @di $validator |
|
122
|
|
|
*/ |
|
123
|
|
|
public function update(int $roundId, array $formValues) |
|
124
|
|
|
{ |
|
125
|
|
|
$values = $this->validator->validateItem($formValues); |
|
126
|
|
|
$this->roundService->updateRound($roundId, $values); |
|
127
|
|
|
$this->page(); // Back to current page |
|
128
|
|
|
|
|
129
|
|
|
$this->dialog->hide(); |
|
130
|
|
|
$this->notify->success(trans('tontine.round.messages.updated'), trans('common.titles.success')); |
|
131
|
|
|
|
|
132
|
|
|
return $this->response; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|