Passed
Push — main ( c89920...e11349 )
by Thierry
05:00
created

Fee::addAllSettlements()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 15
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
17
/**
18
 * @databag meeting
19
 * @before getCharge
20
 */
21
class Fee extends CallableClass
22
{
23
    /**
24
     * @di
25
     * @var BillService
26
     */
27
    protected BillService $billService;
28
29
    /**
30
     * @di
31
     * @var SettlementService
32
     */
33
    protected SettlementService $settlementService;
34
35
    /**
36
     * @var SessionModel|null
37
     */
38
    protected ?SessionModel $session;
39
40
    /**
41
     * @var ChargeModel|null
42
     */
43
    protected ?ChargeModel $charge;
44
45
    protected function getCharge()
46
    {
47
        $sessionId = $this->bag('meeting')->get('session.id');
48
        $chargeId = $this->target()->method() === 'home' ?
49
            $this->target()->args()[0] : $this->bag('meeting')->get('charge.f.id');
50
        $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

50
        $this->session = $this->settlementService->getSession(/** @scrutinizer ignore-type */ $sessionId);
Loading history...
51
        $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

51
        $this->charge = $this->settlementService->getCharge(/** @scrutinizer ignore-type */ $chargeId);
Loading history...
52
    }
53
54
    /**
55
     * @param int $chargeId
56
     *
57
     * @return mixed
58
     */
59
    public function home(int $chargeId)
60
    {
61
        $this->bag('meeting')->set('charge.f.id', $chargeId);
62
        $this->bag('meeting')->set('settlement.filter', null);
63
64
        $html = $this->view()->render('tontine.pages.meeting.settlement.home', [
65
            'charge' => $this->charge,
66
            'type' => 'fee',
67
        ]);
68
        $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

68
        $this->response->html('meeting-fees', /** @scrutinizer ignore-type */ $html);
Loading history...
69
        $this->jq('#btn-fee-settlements-back')->click($this->cl(Charge::class)->rq()->home());
70
        $this->jq('#btn-fee-settlements-filter')->click($this->rq()->toggleFilter());
71
72
        return $this->page(1);
73
    }
74
75
    /**
76
     * @param int $pageNumber
77
     *
78
     * @return mixed
79
     */
80
    public function page(int $pageNumber = 0)
81
    {
82
        $onlyUnpaid = $this->bag('meeting')->get('settlement.filter', null);
83
        $billCount = $this->billService->getBillCount($this->charge, $this->session, $onlyUnpaid);
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

83
        $billCount = $this->billService->getBillCount(/** @scrutinizer ignore-type */ $this->charge, $this->session, $onlyUnpaid);
Loading history...
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

83
        $billCount = $this->billService->getBillCount($this->charge, /** @scrutinizer ignore-type */ $this->session, $onlyUnpaid);
Loading history...
84
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber, $billCount, 'meeting', 'settlement.page');
85
        $bills = $this->billService->getBills($this->charge, $this->session, $onlyUnpaid, $pageNumber);
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...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

85
        $bills = $this->billService->getBills($this->charge, /** @scrutinizer ignore-type */ $this->session, $onlyUnpaid, $pageNumber);
Loading history...
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

85
        $bills = $this->billService->getBills(/** @scrutinizer ignore-type */ $this->charge, $this->session, $onlyUnpaid, $pageNumber);
Loading history...
86
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount);
87
88
        $html = $this->view()->render('tontine.pages.meeting.settlement.page', [
89
            'session' => $this->session,
90
            'charge' => $this->charge,
91
            'billCount' => $billCount,
92
            '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

92
            '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

92
            'settlement' => $this->settlementService->getSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session),
Loading history...
93
            'bills' => $bills,
94
            'pagination' => $pagination,
95
        ]);
96
        $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

96
        $this->response->html('meeting-fee-bills', /** @scrutinizer ignore-type */ $html);
Loading history...
97
98
        $this->jq('.btn-add-all-settlements')->click($this->rq()->addAllSettlements());
99
        $this->jq('.btn-del-all-settlements')->click($this->rq()->delAllSettlements());
100
        $billId = jq()->parent()->attr('data-bill-id')->toInt();
101
        $this->jq('.btn-add-settlement')->click($this->rq()->addSettlement($billId));
102
        $this->jq('.btn-del-settlement')->click($this->rq()->delSettlement($billId));
103
        $this->jq('.btn-edit-notes')->click($this->rq()->editNotes($billId));
104
105
        return $this->response;
106
    }
107
108
    public function toggleFilter()
109
    {
110
        $onlyUnpaid = $this->bag('meeting')->get('settlement.filter', null);
111
        // Switch between null, true and false
112
        $onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null);
113
        $this->bag('meeting')->set('settlement.filter', $onlyUnpaid);
114
115
        return $this->page();
116
    }
117
118
    /**
119
     * @param int $billId
120
     *
121
     * @return mixed
122
     */
123
    public function addSettlement(int $billId)
124
    {
125
        if($this->session->closed)
126
        {
127
            $this->notify->warning(trans('meeting.warnings.session.closed'));
128
            return $this->response;
129
        }
130
131
        $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

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

131
        $this->settlementService->createSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session, $billId);
Loading history...
132
133
        // Refresh the amounts available
134
        $this->cl(Loan::class)->refreshAmount($this->session);
135
        $this->cl(Disbursement::class)->refreshAmount($this->session);
136
137
        return $this->page();
138
    }
139
140
    /**
141
     * @param int $billId
142
     *
143
     * @return mixed
144
     */
145
    public function delSettlement(int $billId)
146
    {
147
        if($this->session->closed)
148
        {
149
            $this->notify->warning(trans('meeting.warnings.session.closed'));
150
            return $this->response;
151
        }
152
153
        $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

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

153
        $this->settlementService->deleteSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
154
155
        // Refresh the amounts available
156
        $this->cl(Loan::class)->refreshAmount($this->session);
157
        $this->cl(Disbursement::class)->refreshAmount($this->session);
158
159
        return $this->page();
160
    }
161
162
    /**
163
     * @return mixed
164
     */
165
    public function addAllSettlements()
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->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

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

173
        $this->settlementService->createAllSettlements($this->charge, /** @scrutinizer ignore-type */ $this->session);
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 delAllSettlements()
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->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

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

193
        $this->settlementService->deleteAllSettlements(/** @scrutinizer ignore-type */ $this->charge, $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