|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Credit; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableSessionClass; |
|
6
|
|
|
use Siak\Tontine\Model\Session as SessionModel; |
|
7
|
|
|
use Siak\Tontine\Service\Meeting\Credit\RefundService; |
|
8
|
|
|
use Siak\Tontine\Validation\Meeting\DebtValidator; |
|
9
|
|
|
|
|
10
|
|
|
use function Jaxon\jq; |
|
11
|
|
|
use function Jaxon\pm; |
|
12
|
|
|
use function trans; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @databag partial.refund |
|
16
|
|
|
*/ |
|
17
|
|
|
class PartialRefund extends CallableSessionClass |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var DebtValidator |
|
21
|
|
|
*/ |
|
22
|
|
|
protected DebtValidator $validator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The constructor |
|
26
|
|
|
* |
|
27
|
|
|
* @param RefundService $refundService |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(protected RefundService $refundService) |
|
30
|
|
|
{} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @exclude |
|
34
|
|
|
*/ |
|
35
|
|
|
public function show(SessionModel $session) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->session = $session; |
|
38
|
|
|
|
|
39
|
|
|
return $this->home(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function home() |
|
43
|
|
|
{ |
|
44
|
|
|
$html = $this->renderView('pages.meeting.refund.partial.home') |
|
45
|
|
|
->with('session', $this->session); |
|
46
|
|
|
$this->response->html('meeting-partial-refunds', $html); |
|
|
|
|
|
|
47
|
|
|
$this->jq('#btn-partial-refunds-refresh')->click($this->rq()->home()); |
|
48
|
|
|
$this->jq('#btn-partial-refunds-add')->click($this->rq()->addRefund()); |
|
49
|
|
|
|
|
50
|
|
|
return $this->page(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param int $pageNumber |
|
55
|
|
|
* |
|
56
|
|
|
* @return mixed |
|
57
|
|
|
*/ |
|
58
|
|
|
public function page(int $pageNumber = 0) |
|
59
|
|
|
{ |
|
60
|
|
|
$refundCount = $this->refundService->getPartialRefundCount($this->session); |
|
|
|
|
|
|
61
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, $refundCount, |
|
62
|
|
|
'partial.refund', 'principal.page'); |
|
63
|
|
|
$refunds = $this->refundService->getPartialRefunds($this->session, $pageNumber); |
|
|
|
|
|
|
64
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $refundCount); |
|
65
|
|
|
|
|
66
|
|
|
$html = $this->renderView('pages.meeting.refund.partial.page', [ |
|
67
|
|
|
'session' => $this->session, |
|
68
|
|
|
'refunds' => $refunds, |
|
69
|
|
|
'pagination' => $pagination, |
|
70
|
|
|
]); |
|
71
|
|
|
$this->response->html('meeting-partial-refunds-page', $html); |
|
|
|
|
|
|
72
|
|
|
$this->response->call('makeTableResponsive', 'meeting-partial-refunds-page'); |
|
73
|
|
|
|
|
74
|
|
|
$refundId = jq()->parent()->attr('data-partial-refund-id')->toInt(); |
|
75
|
|
|
$this->jq('.btn-partial-refund-edit')->click($this->rq()->editRefund($refundId)); |
|
76
|
|
|
$this->jq('.btn-partial-refund-delete')->click($this->rq()->deleteRefund($refundId) |
|
77
|
|
|
->confirm(trans('meeting.refund.questions.delete'))); |
|
78
|
|
|
$this->jq('.btn-del-partial-refund')->click($this->rq()->deleteRefund($refundId) |
|
79
|
|
|
->confirm(trans('meeting.refund.questions.delete'))); |
|
80
|
|
|
|
|
81
|
|
|
return $this->response; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function addRefund() |
|
85
|
|
|
{ |
|
86
|
|
|
if($this->session->closed) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
|
89
|
|
|
return $this->response; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$title = trans('meeting.refund.titles.add'); |
|
93
|
|
|
$content = $this->renderView('pages.meeting.refund.partial.add', [ |
|
94
|
|
|
'debts' => $this->refundService->getUnpaidDebtList($this->session), |
|
|
|
|
|
|
95
|
|
|
]); |
|
96
|
|
|
$buttons = [[ |
|
97
|
|
|
'title' => trans('common.actions.cancel'), |
|
98
|
|
|
'class' => 'btn btn-tertiary', |
|
99
|
|
|
'click' => 'close', |
|
100
|
|
|
],[ |
|
101
|
|
|
'title' => trans('common.actions.save'), |
|
102
|
|
|
'class' => 'btn btn-primary', |
|
103
|
|
|
'click' => $this->rq()->createRefund(pm()->form('refund-form')), |
|
104
|
|
|
]]; |
|
105
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
return $this->response; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @di $validator |
|
112
|
|
|
* @after showBalanceAmounts |
|
113
|
|
|
*/ |
|
114
|
|
|
public function createRefund(array $formValues) |
|
115
|
|
|
{ |
|
116
|
|
|
if($this->session->closed) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
|
119
|
|
|
return $this->response; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$values = $this->validator->validateItem($formValues); |
|
123
|
|
|
$debt = $this->refundService->getDebt($values['debt']); |
|
124
|
|
|
if(!$debt) |
|
|
|
|
|
|
125
|
|
|
{ |
|
126
|
|
|
$this->notify->warning(trans('meeting.loan.errors.not_found')); |
|
127
|
|
|
return $this->response; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$this->refundService->createPartialRefund($debt, $this->session, $values['amount']); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
$this->dialog->hide(); |
|
133
|
|
|
|
|
134
|
|
|
// Refresh the refunds pages |
|
135
|
|
|
$this->cl(Refund::class)->show($this->session); |
|
136
|
|
|
|
|
137
|
|
|
return $this->page(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function editRefund(int $refundId) |
|
141
|
|
|
{ |
|
142
|
|
|
if($this->session->closed) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
|
145
|
|
|
return $this->response; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$refund = $this->refundService->getPartialRefund($this->session, $refundId); |
|
|
|
|
|
|
149
|
|
|
$title = trans('meeting.refund.titles.edit'); |
|
150
|
|
|
$content = $this->renderView('pages.meeting.refund.partial.edit', [ |
|
151
|
|
|
'refund' => $refund, |
|
152
|
|
|
'debtLabel' => $this->refundService->getDebtLabel($refund->debt, $this->session), |
|
153
|
|
|
]); |
|
154
|
|
|
$buttons = [[ |
|
155
|
|
|
'title' => trans('common.actions.cancel'), |
|
156
|
|
|
'class' => 'btn btn-tertiary', |
|
157
|
|
|
'click' => 'close', |
|
158
|
|
|
],[ |
|
159
|
|
|
'title' => trans('common.actions.save'), |
|
160
|
|
|
'class' => 'btn btn-primary', |
|
161
|
|
|
'click' => $this->rq()->updateRefund($refundId, pm()->form('refund-form')), |
|
162
|
|
|
]]; |
|
163
|
|
|
$this->dialog->show($title, $content, $buttons); |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
return $this->response; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @di $validator |
|
170
|
|
|
* @after showBalanceAmounts |
|
171
|
|
|
*/ |
|
172
|
|
|
public function updateRefund(int $refundId, array $formValues) |
|
173
|
|
|
{ |
|
174
|
|
|
if($this->session->closed) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
|
177
|
|
|
return $this->response; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$formValues['debt'] = $refundId; |
|
181
|
|
|
$values = $this->validator->validateItem($formValues); |
|
182
|
|
|
|
|
183
|
|
|
$this->refundService->updatePartialRefund($this->session, $refundId, $values['amount']); |
|
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
$this->dialog->hide(); |
|
186
|
|
|
|
|
187
|
|
|
// Refresh the refunds pages |
|
188
|
|
|
$this->cl(Refund::class)->show($this->session); |
|
189
|
|
|
|
|
190
|
|
|
return $this->page(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @after showBalanceAmounts |
|
195
|
|
|
*/ |
|
196
|
|
|
public function deleteRefund(int $refundId) |
|
197
|
|
|
{ |
|
198
|
|
|
if($this->session->closed) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
|
201
|
|
|
return $this->response; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$this->refundService->deletePartialRefund($this->session, $refundId); |
|
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
// Refresh the refunds pages |
|
207
|
|
|
$this->cl(Refund::class)->show($this->session); |
|
208
|
|
|
|
|
209
|
|
|
return $this->page(); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|