1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Charge\Fixed; |
4
|
|
|
|
5
|
|
|
use App\Ajax\CallableClass; |
6
|
|
|
use App\Ajax\Web\Meeting\Cash\Disbursement; |
7
|
|
|
use App\Ajax\Web\Meeting\Credit\Loan; |
8
|
|
|
use App\Ajax\Web\Meeting\Charge\FixedFee as Charge; |
9
|
|
|
use Siak\Tontine\Service\Meeting\Charge\BillService; |
10
|
|
|
use Siak\Tontine\Service\Meeting\Charge\SettlementService; |
11
|
|
|
use Siak\Tontine\Model\Session as SessionModel; |
12
|
|
|
use Siak\Tontine\Model\Charge as ChargeModel; |
13
|
|
|
|
14
|
|
|
use function Jaxon\jq; |
15
|
|
|
use function trans; |
16
|
|
|
use function trim; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @databag meeting |
20
|
|
|
* @before getCharge |
21
|
|
|
*/ |
22
|
|
|
class Settlement extends CallableClass |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @di |
26
|
|
|
* @var BillService |
27
|
|
|
*/ |
28
|
|
|
protected BillService $billService; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @di |
32
|
|
|
* @var SettlementService |
33
|
|
|
*/ |
34
|
|
|
protected SettlementService $settlementService; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var SessionModel|null |
38
|
|
|
*/ |
39
|
|
|
protected ?SessionModel $session; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ChargeModel|null |
43
|
|
|
*/ |
44
|
|
|
protected ?ChargeModel $charge; |
45
|
|
|
|
46
|
|
|
protected function getCharge() |
47
|
|
|
{ |
48
|
|
|
$sessionId = $this->bag('meeting')->get('session.id'); |
49
|
|
|
$chargeId = $this->target()->method() === 'home' ? |
50
|
|
|
$this->target()->args()[0] : $this->bag('meeting')->get('fee.fixed.id'); |
51
|
|
|
$this->session = $this->settlementService->getSession($sessionId); |
|
|
|
|
52
|
|
|
$this->charge = $this->settlementService->getCharge($chargeId); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param int $chargeId |
57
|
|
|
* |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
|
|
public function home(int $chargeId) |
61
|
|
|
{ |
62
|
|
|
$this->bag('meeting')->set('fee.fixed.id', $chargeId); |
63
|
|
|
$this->bag('meeting')->set('settlement.fixed.search', ''); |
64
|
|
|
$this->bag('meeting')->set('settlement.fixed.filter', null); |
65
|
|
|
|
66
|
|
|
$html = $this->view()->render('tontine.pages.meeting.settlement.home', [ |
67
|
|
|
'charge' => $this->charge, |
68
|
|
|
'type' => 'fixed', |
69
|
|
|
]); |
70
|
|
|
$this->response->html('meeting-fees-fixed', $html); |
|
|
|
|
71
|
|
|
$this->jq('#btn-fee-fixed-settlements-back') |
72
|
|
|
->click($this->cl(Charge::class)->rq()->home()); |
73
|
|
|
$this->jq('#btn-fee-fixed-settlements-search') |
74
|
|
|
->click($this->rq()->search(jq('#txt-fee-settlements-search')->val())); |
75
|
|
|
$this->jq('#btn-fee-fixed-settlements-filter')->click($this->rq()->toggleFilter()); |
76
|
|
|
|
77
|
|
|
return $this->page(1); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param int $pageNumber |
82
|
|
|
* |
83
|
|
|
* @return mixed |
84
|
|
|
*/ |
85
|
|
|
public function page(int $pageNumber = 0) |
86
|
|
|
{ |
87
|
|
|
$search = trim($this->bag('meeting')->get('settlement.fixed.search', '')); |
88
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.fixed.filter', null); |
89
|
|
|
$billCount = $this->billService->getBillCount($this->charge, |
|
|
|
|
90
|
|
|
$this->session, $search, $onlyUnpaid); |
|
|
|
|
91
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, |
92
|
|
|
$billCount, 'meeting', 'settlement.page'); |
93
|
|
|
$bills = $this->billService->getBills($this->charge, $this->session, |
|
|
|
|
94
|
|
|
$search, $onlyUnpaid, $pageNumber); |
95
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount); |
96
|
|
|
$settlement = $this->settlementService->getSettlement($this->charge, $this->session); |
|
|
|
|
97
|
|
|
|
98
|
|
|
$html = $this->view()->render('tontine.pages.meeting.settlement.page', [ |
99
|
|
|
'session' => $this->session, |
100
|
|
|
'charge' => $this->charge, |
101
|
|
|
'billCount' => $billCount, |
102
|
|
|
'settlement' => $settlement, |
103
|
|
|
'bills' => $bills, |
104
|
|
|
'pagination' => $pagination, |
105
|
|
|
]); |
106
|
|
|
$this->response->html('meeting-fee-fixed-bills', $html); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$this->jq('.btn-add-all-settlements')->click($this->rq()->addAllSettlements()); |
109
|
|
|
$this->jq('.btn-del-all-settlements')->click($this->rq()->delAllSettlements()); |
110
|
|
|
$billId = jq()->parent()->attr('data-bill-id')->toInt(); |
111
|
|
|
$this->jq('.btn-add-settlement', '#meeting-fee-fixed-bills') |
112
|
|
|
->click($this->rq()->addSettlement($billId)); |
113
|
|
|
$this->jq('.btn-del-settlement', '#meeting-fee-fixed-bills') |
114
|
|
|
->click($this->rq()->delSettlement($billId)); |
115
|
|
|
$this->jq('.btn-edit-notes', '#meeting-fee-fixed-bills') |
116
|
|
|
->click($this->rq()->editNotes($billId)); |
117
|
|
|
|
118
|
|
|
return $this->response; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function toggleFilter() |
122
|
|
|
{ |
123
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.fixed.filter', null); |
124
|
|
|
// Switch between null, true and false |
125
|
|
|
$onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null); |
126
|
|
|
$this->bag('meeting')->set('settlement.fixed.filter', $onlyUnpaid); |
127
|
|
|
|
128
|
|
|
return $this->page(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function search(string $search) |
132
|
|
|
{ |
133
|
|
|
$this->bag('meeting')->set('settlement.fixed.search', trim($search)); |
134
|
|
|
|
135
|
|
|
return $this->page(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param int $billId |
140
|
|
|
* |
141
|
|
|
* @return mixed |
142
|
|
|
*/ |
143
|
|
|
public function addSettlement(int $billId) |
144
|
|
|
{ |
145
|
|
|
if($this->session->closed) |
146
|
|
|
{ |
147
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
148
|
|
|
return $this->response; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$this->settlementService->createSettlement($this->charge, $this->session, $billId); |
|
|
|
|
152
|
|
|
|
153
|
|
|
// Refresh the amounts available |
154
|
|
|
$this->cl(Loan::class)->refreshAmount($this->session); |
155
|
|
|
$this->cl(Disbursement::class)->refreshAmount($this->session); |
156
|
|
|
|
157
|
|
|
return $this->page(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param int $billId |
162
|
|
|
* |
163
|
|
|
* @return mixed |
164
|
|
|
*/ |
165
|
|
|
public function delSettlement(int $billId) |
166
|
|
|
{ |
167
|
|
|
if($this->session->closed) |
168
|
|
|
{ |
169
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
170
|
|
|
return $this->response; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->settlementService->deleteSettlement($this->charge, $this->session, $billId); |
|
|
|
|
174
|
|
|
|
175
|
|
|
// Refresh the amounts available |
176
|
|
|
$this->cl(Loan::class)->refreshAmount($this->session); |
177
|
|
|
$this->cl(Disbursement::class)->refreshAmount($this->session); |
178
|
|
|
|
179
|
|
|
return $this->page(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return mixed |
184
|
|
|
*/ |
185
|
|
|
public function addAllSettlements() |
186
|
|
|
{ |
187
|
|
|
if($this->session->closed) |
188
|
|
|
{ |
189
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
190
|
|
|
return $this->response; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$this->settlementService->createAllSettlements($this->charge, $this->session); |
|
|
|
|
194
|
|
|
|
195
|
|
|
// Refresh the amounts available |
196
|
|
|
$this->cl(Loan::class)->refreshAmount($this->session); |
197
|
|
|
$this->cl(Disbursement::class)->refreshAmount($this->session); |
198
|
|
|
|
199
|
|
|
return $this->page(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return mixed |
204
|
|
|
*/ |
205
|
|
|
public function delAllSettlements() |
206
|
|
|
{ |
207
|
|
|
if($this->session->closed) |
208
|
|
|
{ |
209
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
210
|
|
|
return $this->response; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$this->settlementService->deleteAllSettlements($this->charge, $this->session); |
|
|
|
|
214
|
|
|
|
215
|
|
|
// Refresh the amounts available |
216
|
|
|
$this->cl(Loan::class)->refreshAmount($this->session); |
217
|
|
|
$this->cl(Disbursement::class)->refreshAmount($this->session); |
218
|
|
|
|
219
|
|
|
return $this->page(); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|