|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Saving; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableSessionClass; |
|
6
|
|
|
use App\Ajax\Web\Report\Session\Saving; |
|
|
|
|
|
|
7
|
|
|
use Siak\Tontine\Model\Session as SessionModel; |
|
8
|
|
|
use Siak\Tontine\Service\Meeting\Saving\SavingService; |
|
9
|
|
|
use Siak\Tontine\Service\Tontine\FundService; |
|
10
|
|
|
use Siak\Tontine\Validation\Meeting\ClosingValidator; |
|
11
|
|
|
|
|
12
|
|
|
use function Jaxon\jq; |
|
13
|
|
|
use function Jaxon\pm; |
|
14
|
|
|
use function Jaxon\rq; |
|
15
|
|
|
use function trans; |
|
16
|
|
|
|
|
17
|
|
|
class Closing extends CallableSessionClass |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var ClosingValidator |
|
21
|
|
|
*/ |
|
22
|
|
|
protected ClosingValidator $validator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The constructor |
|
26
|
|
|
* |
|
27
|
|
|
* @param SavingService $savingService |
|
28
|
|
|
* @param FundService $fundService |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(protected SavingService $savingService, |
|
31
|
|
|
protected FundService $fundService) |
|
32
|
|
|
{} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @exclude |
|
36
|
|
|
*/ |
|
37
|
|
|
public function show(SessionModel $session) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->session = $session; |
|
40
|
|
|
|
|
41
|
|
|
return $this->home(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @databag report |
|
46
|
|
|
*/ |
|
47
|
|
|
public function home() |
|
48
|
|
|
{ |
|
49
|
|
|
$html = $this->render('pages.meeting.closing.home', [ |
|
50
|
|
|
'session' => $this->session, |
|
51
|
|
|
'closings' => $this->savingService->getSessionClosings($this->session), |
|
|
|
|
|
|
52
|
|
|
'funds' => $this->fundService->getFundList(), |
|
53
|
|
|
]); |
|
54
|
|
|
$this->response->html('meeting-closings', $html); |
|
|
|
|
|
|
55
|
|
|
$this->response->call('makeTableResponsive', 'meeting-closings'); |
|
56
|
|
|
|
|
57
|
|
|
// Sending an Ajax request to the Saving class needs to set |
|
58
|
|
|
// the session id in the report databag. |
|
59
|
|
|
$this->bag('report')->set('session.id', $this->session->id); |
|
60
|
|
|
|
|
61
|
|
|
$this->jq('#btn-closings-refresh')->click($this->rq()->home()); |
|
62
|
|
|
|
|
63
|
|
|
$fundId = pm()->select('closings-fund-id')->toInt(); |
|
64
|
|
|
$this->jq('#btn-closing-edit')->click($this->rq()->editClosing($fundId)); |
|
65
|
|
|
$this->jq('#btn-fund-savings-show')->click($this->rq()->showSavings($fundId)); |
|
66
|
|
|
|
|
67
|
|
|
$fundId = jq()->parent()->attr('data-fund-id')->toInt(); |
|
68
|
|
|
$this->jq('.btn-closing-edit')->click($this->rq()->editClosing($fundId)); |
|
69
|
|
|
$this->jq('.btn-fund-savings-show')->click($this->rq()->showSavings($fundId)); |
|
70
|
|
|
$this->jq('.btn-closing-delete')->click($this->rq()->deleteClosing($fundId) |
|
71
|
|
|
->confirm(trans('meeting.closing.questions.delete'))); |
|
72
|
|
|
|
|
73
|
|
|
return $this->response; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @databag report |
|
78
|
|
|
*/ |
|
79
|
|
|
public function showSavings(int $fundId) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->cl(Saving::class)->show($this->session, $fundId); |
|
82
|
|
|
|
|
83
|
|
|
$this->response->call('showSmScreen', 'report-fund-savings', 'session-savings'); |
|
84
|
|
|
$this->jq('#btn-presence-sessions-back')->click(rq('.') |
|
85
|
|
|
->showSmScreen('meeting-closings', 'session-savings')); |
|
86
|
|
|
|
|
87
|
|
|
return $this->response; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function editClosing(int $fundId) |
|
91
|
|
|
{ |
|
92
|
|
|
if($this->session->closed) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
|
95
|
|
|
return $this->response; |
|
96
|
|
|
} |
|
97
|
|
|
$funds = $this->fundService->getFundList(); |
|
98
|
|
|
if(!isset($funds[$fundId])) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->response; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$title = trans('meeting.saving.titles.closing', ['fund' => $funds[$fundId]]); |
|
104
|
|
|
$content = $this->render('pages.meeting.closing.edit', [ |
|
105
|
|
|
'hasClosing' => $this->savingService->hasFundClosing($this->session, $fundId), |
|
|
|
|
|
|
106
|
|
|
'profitAmount' => $this->savingService->getProfitAmount($this->session, $fundId), |
|
|
|
|
|
|
107
|
|
|
]); |
|
108
|
|
|
$buttons = [[ |
|
109
|
|
|
'title' => trans('common.actions.close'), |
|
110
|
|
|
'class' => 'btn btn-tertiary', |
|
111
|
|
|
'click' => 'close', |
|
112
|
|
|
], [ |
|
113
|
|
|
'title' => trans('common.actions.save'), |
|
114
|
|
|
'class' => 'btn btn-primary', |
|
115
|
|
|
'click' => $this->rq()->saveClosing($fundId, pm()->form('closing-form')), |
|
116
|
|
|
]]; |
|
117
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
return $this->response; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @di $validator |
|
124
|
|
|
*/ |
|
125
|
|
|
public function saveClosing(int $fundId, array $formValues) |
|
126
|
|
|
{ |
|
127
|
|
|
$funds = $this->fundService->getFundList(); |
|
128
|
|
|
if(!isset($funds[$fundId])) |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->response; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$values = $this->validator->validateItem($formValues); |
|
134
|
|
|
$this->savingService->saveFundClosing($this->session, $fundId, $values['amount']); |
|
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
$this->dialog->hide(); |
|
137
|
|
|
$this->notify->success(trans('meeting.messages.profit.saved'), trans('common.titles.success')); |
|
138
|
|
|
|
|
139
|
|
|
return $this->home(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function deleteClosing(int $fundId) |
|
143
|
|
|
{ |
|
144
|
|
|
$funds = $this->fundService->getFundList(); |
|
145
|
|
|
if(!isset($funds[$fundId])) |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->response; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$this->savingService->deleteFundClosing($this->session, $fundId); |
|
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
$this->dialog->hide(); |
|
153
|
|
|
$this->notify->success(trans('meeting.messages.profit.deleted'), trans('common.titles.success')); |
|
154
|
|
|
|
|
155
|
|
|
return $this->home(); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: