1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Charge\Libre; |
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\LibreFee 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.libre.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.libre.id', $chargeId); |
63
|
|
|
$this->bag('meeting')->set('settlement.libre.search', ''); |
64
|
|
|
$this->bag('meeting')->set('settlement.libre.filter', null); |
65
|
|
|
|
66
|
|
|
$html = $this->view()->render('tontine.pages.meeting.settlement.home', [ |
67
|
|
|
'charge' => $this->charge, |
68
|
|
|
'type' => 'libre', |
69
|
|
|
]); |
70
|
|
|
$this->response->html('meeting-fees-libre', $html); |
|
|
|
|
71
|
|
|
$this->jq('#btn-fee-libre-settlements-back')->click($this->cl(Charge::class)->rq()->home()); |
72
|
|
|
$this->jq('#btn-fee-libre-settlements-filter')->click($this->rq()->toggleFilter()); |
73
|
|
|
|
74
|
|
|
return $this->page(1); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param int $pageNumber |
79
|
|
|
* |
80
|
|
|
* @return mixed |
81
|
|
|
*/ |
82
|
|
|
public function page(int $pageNumber = 0) |
83
|
|
|
{ |
84
|
|
|
$search = trim($this->bag('meeting')->get('settlement.libre.search', '')); |
85
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.libre.filter', null); |
86
|
|
|
$billCount = $this->billService->getBillCount($this->charge, |
|
|
|
|
87
|
|
|
$this->session, $search, $onlyUnpaid); |
|
|
|
|
88
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, |
89
|
|
|
$billCount, 'meeting', 'settlement.page'); |
90
|
|
|
$bills = $this->billService->getBills($this->charge, $this->session, |
|
|
|
|
91
|
|
|
$search, $onlyUnpaid, $pageNumber); |
92
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount); |
93
|
|
|
$settlement = $this->settlementService->getSettlement($this->charge, $this->session); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$html = $this->view()->render('tontine.pages.meeting.settlement.page', [ |
96
|
|
|
'session' => $this->session, |
97
|
|
|
'charge' => $this->charge, |
98
|
|
|
'billCount' => $billCount, |
99
|
|
|
'settlement' => $settlement, |
100
|
|
|
'bills' => $bills, |
101
|
|
|
'pagination' => $pagination, |
102
|
|
|
]); |
103
|
|
|
$this->response->html('meeting-fee-libre-bills', $html); |
|
|
|
|
104
|
|
|
|
105
|
|
|
$billId = jq()->parent()->attr('data-bill-id')->toInt(); |
106
|
|
|
$this->jq('.btn-add-settlement', '#meeting-fee-libre-bills') |
107
|
|
|
->click($this->rq()->addSettlement($billId)); |
108
|
|
|
$this->jq('.btn-del-settlement', '#meeting-fee-libre-bills') |
109
|
|
|
->click($this->rq()->delSettlement($billId)); |
110
|
|
|
$this->jq('.btn-edit-notes', '#meeting-fee-libre-bills') |
111
|
|
|
->click($this->rq()->editNotes($billId)); |
112
|
|
|
|
113
|
|
|
return $this->response; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function toggleFilter() |
117
|
|
|
{ |
118
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.libre.filter', null); |
119
|
|
|
// Switch between null, true and false |
120
|
|
|
$onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null); |
121
|
|
|
$this->bag('meeting')->set('settlement.libre.filter', $onlyUnpaid); |
122
|
|
|
|
123
|
|
|
return $this->page(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param int $billId |
128
|
|
|
* |
129
|
|
|
* @return mixed |
130
|
|
|
*/ |
131
|
|
|
public function addSettlement(int $billId) |
132
|
|
|
{ |
133
|
|
|
if($this->session->closed) |
134
|
|
|
{ |
135
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
136
|
|
|
return $this->response; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$this->settlementService->createSettlement($this->charge, $this->session, $billId); |
|
|
|
|
140
|
|
|
|
141
|
|
|
// Refresh the amounts available |
142
|
|
|
$this->cl(Loan::class)->refreshAmount($this->session); |
143
|
|
|
$this->cl(Disbursement::class)->refreshAmount($this->session); |
144
|
|
|
|
145
|
|
|
return $this->page(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param int $billId |
150
|
|
|
* |
151
|
|
|
* @return mixed |
152
|
|
|
*/ |
153
|
|
|
public function delSettlement(int $billId) |
154
|
|
|
{ |
155
|
|
|
if($this->session->closed) |
156
|
|
|
{ |
157
|
|
|
$this->notify->warning(trans('meeting.warnings.session.closed')); |
158
|
|
|
return $this->response; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$this->settlementService->deleteSettlement($this->charge, $this->session, $billId); |
|
|
|
|
162
|
|
|
|
163
|
|
|
// Refresh the amounts available |
164
|
|
|
$this->cl(Loan::class)->refreshAmount($this->session); |
165
|
|
|
$this->cl(Disbursement::class)->refreshAmount($this->session); |
166
|
|
|
|
167
|
|
|
return $this->page(); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|