Passed
Push — main ( 936852...10149e )
by Thierry
15:09
created

Settlement::getCharge()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Ajax\Web\Meeting\Charge\Fixed;
4
5
use App\Ajax\CallableSessionClass;
6
use App\Ajax\Web\Meeting\Charge\FixedFee as Charge;
7
use Siak\Tontine\Model\Charge as ChargeModel;
8
use Siak\Tontine\Service\Meeting\Charge\BillService;
9
use Siak\Tontine\Service\Meeting\Charge\SettlementService;
10
use Siak\Tontine\Service\Tontine\ChargeService;
11
12
use function Jaxon\jq;
13
use function trans;
14
use function trim;
15
16
/**
17
 * @before getCharge
18
 */
19
class Settlement extends CallableSessionClass
20
{
21
    /**
22
     * @var ChargeModel|null
23
     */
24
    protected ?ChargeModel $charge;
25
26
    /**
27
     * The constructor
28
     *
29
     * @param SettlementService $settlementService
30
     * @param ChargeService $chargeService
31
     * @param BillService $billService
32
     */
33
    public function __construct(protected SettlementService $settlementService,
34
        protected ChargeService $chargeService, protected BillService $billService)
35
    {}
36
37
    protected function getCharge()
38
    {
39
        $chargeId = $this->target()->method() === 'home' ?
40
            $this->target()->args()[0] : $this->bag('meeting')->get('fee.fixed.id');
41
        $this->charge = $this->chargeService->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\Ton...rgeService::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

41
        $this->charge = $this->chargeService->getCharge(/** @scrutinizer ignore-type */ $chargeId);
Loading history...
42
    }
43
44
    /**
45
     * @param int $chargeId
46
     *
47
     * @return mixed
48
     */
49
    public function home(int $chargeId)
50
    {
51
        $this->bag('meeting')->set('fee.fixed.id', $chargeId);
52
        $this->bag('meeting')->set('settlement.fixed.filter', null);
53
54
        $html = $this->render('pages.meeting.settlement.home', [
55
            'type' => 'fixed',
56
            'charge' => $this->charge,
57
        ]);
58
        $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

58
        $this->response->html('meeting-fees-fixed', /** @scrutinizer ignore-type */ $html);
Loading history...
59
        $this->jq('#btn-fee-fixed-settlements-back')
60
            ->click($this->cl(Charge::class)->rq()->home());
61
        $this->jq('#btn-fee-fixed-settlements-filter')->click($this->rq()->toggleFilter());
62
63
        return $this->page(1);
64
    }
65
66
    /**
67
     * @param int $pageNumber
68
     *
69
     * @return mixed
70
     */
71
    public function page(int $pageNumber = 0)
72
    {
73
        $search = trim($this->bag('meeting')->get('settlement.fixed.search', ''));
74
        $onlyUnpaid = $this->bag('meeting')->get('settlement.fixed.filter', null);
75
        $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

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

76
            /** @scrutinizer ignore-type */ $this->session, $search, $onlyUnpaid);
Loading history...
77
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber,
78
            $billCount, 'meeting', 'settlement.page');
79
        $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

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

79
        $bills = $this->billService->getBills($this->charge, /** @scrutinizer ignore-type */ $this->session,
Loading history...
80
            $search, $onlyUnpaid, $pageNumber);
81
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount);
82
        $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

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

82
        $settlement = $this->settlementService->getSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
83
84
        $html = $this->render('pages.meeting.settlement.page', [
85
            'type' => 'fixed',
86
            'search' => $search,
87
            'session' => $this->session,
88
            'charge' => $this->charge,
89
            'billCount' => $billCount,
90
            'settlement' => $settlement,
91
            'bills' => $bills,
92
            'pagination' => $pagination,
93
        ]);
94
        $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

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

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

142
        $this->settlementService->createSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
143
144
        return $this->page();
145
    }
146
147
    /**
148
     * @param int $billId
149
     *
150
     * @return mixed
151
     * @after showBalanceAmounts
152
     */
153
    public function delSettlement(int $billId)
154
    {
155
        if($this->session->closed)
156
        {
157
            $this->notify->warning(trans('meeting.warnings.session.closed'));
158
            return $this->response;
159
        }
160
161
        $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

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

161
        $this->settlementService->deleteSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session, $billId);
Loading history...
162
163
        return $this->page();
164
    }
165
166
    /**
167
     * @return mixed
168
     * @after showBalanceAmounts
169
     */
170
    public function addAllSettlements()
171
    {
172
        if($this->session->closed)
173
        {
174
            $this->notify->warning(trans('meeting.warnings.session.closed'));
175
            return $this->response;
176
        }
177
178
        $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

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

178
        $this->settlementService->createAllSettlements(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
179
180
        return $this->page();
181
    }
182
183
    /**
184
     * @return mixed
185
     * @after showBalanceAmounts
186
     */
187
    public function delAllSettlements()
188
    {
189
        if($this->session->closed)
190
        {
191
            $this->notify->warning(trans('meeting.warnings.session.closed'));
192
            return $this->response;
193
        }
194
195
        $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

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

195
        $this->settlementService->deleteAllSettlements(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
196
197
        return $this->page();
198
    }
199
}
200