Passed
Pull Request — main (#57)
by Thierry
15:28 queued 13s
created

Settlement::showTotal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 21
rs 9.7666
c 0
b 0
f 0
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);
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

28
        $this->response->html('meeting-fees-fixed', /** @scrutinizer ignore-type */ $html);
Loading history...
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);
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...e::getSettlementCount() 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

41
        $settlement = $this->settlementService->getSettlementCount($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...e::getSettlementCount() 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

41
        $settlement = $this->settlementService->getSettlementCount(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
42
        $settlementCount = $settlement->total ?? 0;
0 ignored issues
show
Bug introduced by
The property total does not seem to exist on Siak\Tontine\Model\Bill. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
43
        $settlementAmount = $settlement->amount ?? 0;
44
45
        $billCount = $this->billService->getBillCount($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...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

45
        $billCount = $this->billService->getBillCount($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...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

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

51
        $this->response->html('meeting-settlements-total', /** @scrutinizer ignore-type */ $html);
Loading history...
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,
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

71
        $billCount = $this->billService->getBillCount(/** @scrutinizer ignore-type */ $this->charge,
Loading history...
72
            $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

72
            /** @scrutinizer ignore-type */ $this->session, $search, $onlyUnpaid);
Loading history...
73
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber,
74
            $billCount, 'meeting', 'settlement.page');
75
        $bills = $this->billService->getBills($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...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

75
        $bills = $this->billService->getBills($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...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

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

87
        $this->response->html('meeting-fee-fixed-bills', /** @scrutinizer ignore-type */ $html);
Loading history...
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);
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

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

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

143
        $this->settlementService->deleteSettlement(/** @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::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

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

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

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

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

167
        $this->settlementService->deleteAllSettlements(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
168
169
        return $this->page();
170
    }
171
}
172