|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Ajax\Web\Meeting\Charge\Libre; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\CallableChargeClass; |
|
6
|
|
|
use App\Ajax\Web\Meeting\Charge\LibreFee 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.libre.search', ''); |
|
22
|
|
|
$this->bag('meeting')->set('settlement.libre.filter', null); |
|
23
|
|
|
|
|
24
|
|
|
$html = $this->render('pages.meeting.settlement.home', [ |
|
25
|
|
|
'type' => 'libre', |
|
26
|
|
|
'charge' => $this->charge, |
|
27
|
|
|
]); |
|
28
|
|
|
$this->response->html('meeting-fees-libre', $html); |
|
|
|
|
|
|
29
|
|
|
$this->jq('#btn-fee-libre-settlements-back')->click($this->rq(Charge::class)->home()); |
|
30
|
|
|
$this->jq('#btn-fee-libre-settlements-filter')->click($this->rq()->toggleFilter()); |
|
31
|
|
|
|
|
32
|
|
|
return $this->page(1); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
private function showTotal() |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$settlement = $this->settlementService->getSettlementCount($this->charge, $this->session); |
|
|
|
|
|
|
38
|
|
|
$settlementCount = $settlement->total ?? 0; |
|
|
|
|
|
|
39
|
|
|
$settlementAmount = $settlement->amount ?? 0; |
|
40
|
|
|
|
|
41
|
|
|
$billCount = $this->billService->getBillCount($this->charge, $this->session); |
|
|
|
|
|
|
42
|
|
|
$html = $this->render('pages.meeting.settlement.total', [ |
|
43
|
|
|
'billCount' => $billCount, |
|
44
|
|
|
'settlementCount' => $settlementCount, |
|
45
|
|
|
'settlementAmount' => $settlementAmount, |
|
46
|
|
|
]); |
|
47
|
|
|
$this->response->html('meeting-settlements-total', $html); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$html = $this->render('pages.meeting.settlement.action', [ |
|
50
|
|
|
'session' => $this->session, |
|
51
|
|
|
'charge' => $this->charge, |
|
52
|
|
|
'billCount' => $billCount, |
|
53
|
|
|
'settlementCount' => $settlementCount, |
|
54
|
|
|
]); |
|
55
|
|
|
$this->response->html('meeting-settlements-action', $html); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param int $pageNumber |
|
60
|
|
|
* |
|
61
|
|
|
* @return mixed |
|
62
|
|
|
*/ |
|
63
|
|
|
public function page(int $pageNumber = 0) |
|
64
|
|
|
{ |
|
65
|
|
|
$search = trim($this->bag('meeting')->get('settlement.libre.search', '')); |
|
66
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.libre.filter', null); |
|
67
|
|
|
$billCount = $this->billService->getBillCount($this->charge, |
|
|
|
|
|
|
68
|
|
|
$this->session, $search, $onlyUnpaid); |
|
|
|
|
|
|
69
|
|
|
[$pageNumber, $perPage] = $this->pageNumber($pageNumber, |
|
70
|
|
|
$billCount, 'meeting', 'settlement.page'); |
|
71
|
|
|
$bills = $this->billService->getBills($this->charge, $this->session, |
|
|
|
|
|
|
72
|
|
|
$search, $onlyUnpaid, $pageNumber); |
|
73
|
|
|
$pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount); |
|
74
|
|
|
|
|
75
|
|
|
$html = $this->render('pages.meeting.settlement.page', [ |
|
76
|
|
|
'session' => $this->session, |
|
77
|
|
|
'charge' => $this->charge, |
|
78
|
|
|
'bills' => $bills, |
|
79
|
|
|
'pagination' => $pagination, |
|
80
|
|
|
]); |
|
81
|
|
|
$this->response->html('meeting-fee-libre-bills', $html); |
|
|
|
|
|
|
82
|
|
|
$this->response->call('makeTableResponsive', 'meeting-fee-libre-bills'); |
|
83
|
|
|
|
|
84
|
|
|
$billId = jq()->parent()->attr('data-bill-id')->toInt(); |
|
85
|
|
|
$this->jq('.btn-add-settlement', '#meeting-fee-libre-bills') |
|
86
|
|
|
->click($this->rq()->addSettlement($billId)); |
|
87
|
|
|
$this->jq('.btn-del-settlement', '#meeting-fee-libre-bills') |
|
88
|
|
|
->click($this->rq()->delSettlement($billId)); |
|
89
|
|
|
$this->jq('.btn-edit-notes', '#meeting-fee-libre-bills') |
|
90
|
|
|
->click($this->rq()->editNotes($billId)); |
|
91
|
|
|
|
|
92
|
|
|
return $this->response; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function toggleFilter() |
|
96
|
|
|
{ |
|
97
|
|
|
$onlyUnpaid = $this->bag('meeting')->get('settlement.libre.filter', null); |
|
98
|
|
|
// Switch between null, true and false |
|
99
|
|
|
$onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null); |
|
100
|
|
|
$this->bag('meeting')->set('settlement.libre.filter', $onlyUnpaid); |
|
101
|
|
|
|
|
102
|
|
|
return $this->page(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @before checkChargeEdit |
|
107
|
|
|
* @after showBalanceAmounts |
|
108
|
|
|
* @param int $billId |
|
109
|
|
|
* |
|
110
|
|
|
* @return mixed |
|
111
|
|
|
*/ |
|
112
|
|
|
public function addSettlement(int $billId) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->settlementService->createSettlement($this->charge, $this->session, $billId); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
return $this->page(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @before checkChargeEdit |
|
121
|
|
|
* @after showBalanceAmounts |
|
122
|
|
|
* @param int $billId |
|
123
|
|
|
* |
|
124
|
|
|
* @return mixed |
|
125
|
|
|
*/ |
|
126
|
|
|
public function delSettlement(int $billId) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->settlementService->deleteSettlement($this->charge, $this->session, $billId); |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
return $this->page(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|