Passed
Pull Request — main (#49)
by Thierry
14:14
created

Settlement::getCharge()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
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);
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('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);
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-fixed', /** @scrutinizer ignore-type */ $html);
Loading history...
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,
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->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...
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...
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);
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-fixed-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', '#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);
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::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

151
        $this->settlementService->createSettlement($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::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

151
        $this->settlementService->createSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
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);
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

173
        $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

173
        $this->settlementService->deleteSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
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);
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...: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

193
        $this->settlementService->createAllSettlements(/** @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...: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

193
        $this->settlementService->createAllSettlements($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
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);
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...: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

213
        $this->settlementService->deleteAllSettlements(/** @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...: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

213
        $this->settlementService->deleteAllSettlements($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
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