Passed
Pull Request — main (#48)
by Thierry
13:20
created

Fee::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Ajax\Web\Meeting\Charge\Settlement;
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\Fee 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 Fee 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('charge.fixed.id');
51
        $this->session = $this->settlementService->getSession($sessionId);
0 ignored issues
show
Bug introduced by
It seems like $sessionId can also be of type null; however, parameter $sessionId of Siak\Tontine\Service\Mee...ntService::getSession() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $this->session = $this->settlementService->getSession(/** @scrutinizer ignore-type */ $sessionId);
Loading history...
52
        $this->charge = $this->settlementService->getCharge($chargeId);
0 ignored issues
show
Bug introduced by
It seems like $chargeId can also be of type null; however, parameter $chargeId of Siak\Tontine\Service\Mee...entService::getCharge() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        $this->charge = $this->settlementService->getCharge(/** @scrutinizer ignore-type */ $chargeId);
Loading history...
53
    }
54
55
    /**
56
     * @param int $chargeId
57
     *
58
     * @return mixed
59
     */
60
    public function home(int $chargeId)
61
    {
62
        $this->bag('meeting')->set('charge.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' => 'fee',
69
        ]);
70
        $this->response->html('meeting-fees', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
        $this->response->html('meeting-fees', /** @scrutinizer ignore-type */ $html);
Loading history...
71
        $this->jq('#btn-fee-settlements-back')
72
            ->click($this->cl(Charge::class)->rq()->home());
73
        $this->jq('#btn-fee-settlements-search')
74
            ->click($this->rq()->search(jq('#txt-fee-settlements-search')->val()));
75
        $this->jq('#btn-fee-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,
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...Service::getBillCount() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
        $billCount = $this->billService->getBillCount(/** @scrutinizer ignore-type */ $this->charge,
Loading history...
90
            $this->session, $search, $onlyUnpaid);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...Service::getBillCount() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
            /** @scrutinizer ignore-type */ $this->session, $search, $onlyUnpaid);
Loading history...
91
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber,
92
            $billCount, 'meeting', 'settlement.page');
93
        $bills = $this->billService->getBills($this->charge, $this->session,
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...BillService::getBills() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
        $bills = $this->billService->getBills(/** @scrutinizer ignore-type */ $this->charge, $this->session,
Loading history...
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...BillService::getBills() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
        $bills = $this->billService->getBills($this->charge, /** @scrutinizer ignore-type */ $this->session,
Loading history...
94
            $search, $onlyUnpaid, $pageNumber);
95
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount);
96
        $settlement = $this->settlementService->getSettlement($this->charge, $this->session);
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...ervice::getSettlement() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

96
        $settlement = $this->settlementService->getSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...ervice::getSettlement() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

96
        $settlement = $this->settlementService->getSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
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-bills', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

106
        $this->response->html('meeting-fee-bills', /** @scrutinizer ignore-type */ $html);
Loading history...
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')->click($this->rq()->addSettlement($billId));
112
        $this->jq('.btn-del-settlement')->click($this->rq()->delSettlement($billId));
113
        $this->jq('.btn-edit-notes')->click($this->rq()->editNotes($billId));
114
115
        return $this->response;
116
    }
117
118
    public function toggleFilter()
119
    {
120
        $onlyUnpaid = $this->bag('meeting')->get('settlement.fixed.filter', null);
121
        // Switch between null, true and false
122
        $onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null);
123
        $this->bag('meeting')->set('settlement.fixed.filter', $onlyUnpaid);
124
125
        return $this->page();
126
    }
127
128
    public function search(string $search)
129
    {
130
        $this->bag('meeting')->set('settlement.fixed.search', trim($search));
131
132
        return $this->page();
133
    }
134
135
    /**
136
     * @param int $billId
137
     *
138
     * @return mixed
139
     */
140
    public function addSettlement(int $billId)
141
    {
142
        if($this->session->closed)
143
        {
144
            $this->notify->warning(trans('meeting.warnings.session.closed'));
145
            return $this->response;
146
        }
147
148
        $this->settlementService->createSettlement($this->charge, $this->session, $billId);
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...ice::createSettlement() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

148
        $this->settlementService->createSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...ice::createSettlement() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

148
        $this->settlementService->createSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session, $billId);
Loading history...
149
150
        // Refresh the amounts available
151
        $this->cl(Loan::class)->refreshAmount($this->session);
152
        $this->cl(Disbursement::class)->refreshAmount($this->session);
153
154
        return $this->page();
155
    }
156
157
    /**
158
     * @param int $billId
159
     *
160
     * @return mixed
161
     */
162
    public function delSettlement(int $billId)
163
    {
164
        if($this->session->closed)
165
        {
166
            $this->notify->warning(trans('meeting.warnings.session.closed'));
167
            return $this->response;
168
        }
169
170
        $this->settlementService->deleteSettlement($this->charge, $this->session, $billId);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...ice::deleteSettlement() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

170
        $this->settlementService->deleteSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session, $billId);
Loading history...
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...ice::deleteSettlement() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

170
        $this->settlementService->deleteSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
171
172
        // Refresh the amounts available
173
        $this->cl(Loan::class)->refreshAmount($this->session);
174
        $this->cl(Disbursement::class)->refreshAmount($this->session);
175
176
        return $this->page();
177
    }
178
179
    /**
180
     * @return mixed
181
     */
182
    public function addAllSettlements()
183
    {
184
        if($this->session->closed)
185
        {
186
            $this->notify->warning(trans('meeting.warnings.session.closed'));
187
            return $this->response;
188
        }
189
190
        $this->settlementService->createAllSettlements($this->charge, $this->session);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...:createAllSettlements() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

190
        $this->settlementService->createAllSettlements($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...:createAllSettlements() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

190
        $this->settlementService->createAllSettlements(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
191
192
        // Refresh the amounts available
193
        $this->cl(Loan::class)->refreshAmount($this->session);
194
        $this->cl(Disbursement::class)->refreshAmount($this->session);
195
196
        return $this->page();
197
    }
198
199
    /**
200
     * @return mixed
201
     */
202
    public function delAllSettlements()
203
    {
204
        if($this->session->closed)
205
        {
206
            $this->notify->warning(trans('meeting.warnings.session.closed'));
207
            return $this->response;
208
        }
209
210
        $this->settlementService->deleteAllSettlements($this->charge, $this->session);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...:deleteAllSettlements() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

210
        $this->settlementService->deleteAllSettlements($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...:deleteAllSettlements() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

210
        $this->settlementService->deleteAllSettlements(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
211
212
        // Refresh the amounts available
213
        $this->cl(Loan::class)->refreshAmount($this->session);
214
        $this->cl(Disbursement::class)->refreshAmount($this->session);
215
216
        return $this->page();
217
    }
218
}
219