1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Charge\Fixed; |
4
|
|
|
|
5
|
|
|
use App\Ajax\CallableChargeClass; |
6
|
|
|
use App\Ajax\Web\Meeting\Charge\FixedFee as Charge; |
7
|
|
|
|
8
|
|
|
use function Jaxon\jq; |
9
|
|
|
use function trim; |
10
|
|
|
|
11
|
|
|
class Settlement extends CallableChargeClass |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param int $chargeId |
15
|
|
|
* |
16
|
|
|
* @return mixed |
17
|
|
|
*/ |
18
|
|
|
public function home(int $chargeId) |
19
|
|
|
{ |
20
|
|
|
$this->bag('meeting')->set('charge.id', $chargeId); |
21
|
|
|
$this->bag('meeting')->set('settlement.fixed.filter', null); |
22
|
|
|
$this->bag('meeting')->set('settlement.fixed.search', ''); |
23
|
|
|
|
24
|
|
|
$html = $this->render('pages.meeting.settlement.home', [ |
25
|
|
|
'type' => 'fixed', |
26
|
|
|
'charge' => $this->charge, |
27
|
|
|
]); |
28
|
|
|
$this->response->html('meeting-fees-fixed', $html); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$this->jq('#btn-fee-fixed-settlements-back') |
31
|
|
|
->click($this->rq(Charge::class)->home()); |
32
|
|
|
$this->jq('#btn-fee-fixed-settlements-filter')->click($this->rq()->toggleFilter()); |
33
|
|
|
$this->jq('#btn-fee-fixed-settlements-search') |
34
|
|
|
->click($this->rq()->search(jq('#txt-fee-settlements-search')->val())); |
35
|
|
|
|
36
|
|
|
return $this->page(1); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private function showTotal() |
40
|
|
|
{ |
41
|
|
|
$settlement = $this->settlementService->getSettlementCount($this->charge, $this->session); |
|
|
|
|
42
|
|
|
$settlementCount = $settlement->total ?? 0; |
|
|
|
|
43
|
|
|
$settlementAmount = $settlement->amount ?? 0; |
44
|
|
|
|
45
|
|
|
$billCount = $this->billService->getBillCount($this->charge, $this->session); |
|
|
|
|
46
|
|
|
$html = $this->render('pages.meeting.settlement.total', [ |
47
|
|
|
'billCount' => $billCount, |
48
|
|
|
'settlementCount' => $settlementCount, |
49
|
|
|
'settlementAmount' => $settlementAmount, |
50
|
|
|
]); |
51
|
|
|
$this->response->html('meeting-settlements-total', $html); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$html = $this->render('pages.meeting.settlement.action', [ |
54
|
|
|
'session' => $this->session, |
55
|
|
|
'charge' => $this->charge, |
56
|
|
|
'billCount' => $billCount, |
57
|
|
|
'settlementCount' => $settlementCount, |
58
|
|
|
]); |
59
|
|
|
$this->response->html('meeting-settlements-action', $html); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int $pageNumber |
64
|
|
|
* |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
public function page(int $pageNumber = 0) |
68
|
|
|
{ |
69
|
|
|
$search = trim($this->bag('meeting')->get('settlement.fixed.search', '')); |
70
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.fixed.filter', null); |
71
|
|
|
$billCount = $this->billService->getBillCount($this->charge, |
|
|
|
|
72
|
|
|
$this->session, $search, $onlyUnpaid); |
|
|
|
|
73
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, |
74
|
|
|
$billCount, 'meeting', 'settlement.page'); |
75
|
|
|
$bills = $this->billService->getBills($this->charge, $this->session, |
|
|
|
|
76
|
|
|
$search, $onlyUnpaid, $pageNumber); |
77
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount); |
78
|
|
|
|
79
|
|
|
$this->showTotal(); |
80
|
|
|
|
81
|
|
|
$html = $this->render('pages.meeting.settlement.page', [ |
82
|
|
|
'session' => $this->session, |
83
|
|
|
'charge' => $this->charge, |
84
|
|
|
'bills' => $bills, |
85
|
|
|
'pagination' => $pagination, |
86
|
|
|
]); |
87
|
|
|
$this->response->html('meeting-fee-fixed-bills', $html); |
|
|
|
|
88
|
|
|
$this->response->call('makeTableResponsive', 'meeting-fee-fixed-bills'); |
89
|
|
|
|
90
|
|
|
$this->jq('.btn-add-all-settlements')->click($this->rq()->addAllSettlements()); |
91
|
|
|
$this->jq('.btn-del-all-settlements')->click($this->rq()->delAllSettlements()); |
92
|
|
|
$billId = jq()->parent()->attr('data-bill-id')->toInt(); |
93
|
|
|
$this->jq('.btn-add-settlement', '#meeting-fee-fixed-bills') |
94
|
|
|
->click($this->rq()->addSettlement($billId)); |
95
|
|
|
$this->jq('.btn-del-settlement', '#meeting-fee-fixed-bills') |
96
|
|
|
->click($this->rq()->delSettlement($billId)); |
97
|
|
|
$this->jq('.btn-edit-notes', '#meeting-fee-fixed-bills') |
98
|
|
|
->click($this->rq()->editNotes($billId)); |
99
|
|
|
|
100
|
|
|
return $this->response; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function toggleFilter() |
104
|
|
|
{ |
105
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.fixed.filter', null); |
106
|
|
|
// Switch between null, true and false |
107
|
|
|
$onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null); |
108
|
|
|
$this->bag('meeting')->set('settlement.fixed.filter', $onlyUnpaid); |
109
|
|
|
|
110
|
|
|
return $this->page(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function search(string $search) |
114
|
|
|
{ |
115
|
|
|
$this->bag('meeting')->set('settlement.fixed.search', trim($search)); |
116
|
|
|
|
117
|
|
|
return $this->page(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @before checkChargeEdit |
122
|
|
|
* @after showBalanceAmounts |
123
|
|
|
* @param int $billId |
124
|
|
|
* |
125
|
|
|
* @return mixed |
126
|
|
|
*/ |
127
|
|
|
public function addSettlement(int $billId) |
128
|
|
|
{ |
129
|
|
|
$this->settlementService->createSettlement($this->charge, $this->session, $billId); |
|
|
|
|
130
|
|
|
|
131
|
|
|
return $this->page(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @before checkChargeEdit |
136
|
|
|
* @after showBalanceAmounts |
137
|
|
|
* @param int $billId |
138
|
|
|
* |
139
|
|
|
* @return mixed |
140
|
|
|
*/ |
141
|
|
|
public function delSettlement(int $billId) |
142
|
|
|
{ |
143
|
|
|
$this->settlementService->deleteSettlement($this->charge, $this->session, $billId); |
|
|
|
|
144
|
|
|
|
145
|
|
|
return $this->page(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @before checkChargeEdit |
150
|
|
|
* @after showBalanceAmounts |
151
|
|
|
* @return mixed |
152
|
|
|
*/ |
153
|
|
|
public function addAllSettlements() |
154
|
|
|
{ |
155
|
|
|
$this->settlementService->createAllSettlements($this->charge, $this->session); |
|
|
|
|
156
|
|
|
|
157
|
|
|
return $this->page(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @before checkChargeEdit |
162
|
|
|
* @after showBalanceAmounts |
163
|
|
|
* @return mixed |
164
|
|
|
*/ |
165
|
|
|
public function delAllSettlements() |
166
|
|
|
{ |
167
|
|
|
$this->settlementService->deleteAllSettlements($this->charge, $this->session); |
|
|
|
|
168
|
|
|
|
169
|
|
|
return $this->page(); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|