BillView   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A session() 0 3 1
A scopeOfTypeSession() 0 4 1
A round() 0 3 1
A bill() 0 3 1
A charge() 0 3 1
A member() 0 3 1
A scopeOfTypeNotSession() 0 12 1
1
<?php
2
3
namespace Siak\Tontine\Model;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Casts\Attribute;
7
8
class BillView extends Base
9
{
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'v_bills';
16
17
    /**
18
     * Indicates if the model should be timestamped.
19
     *
20
     * @var bool
21
     */
22
    public $timestamps = false;
23
24
    public function round()
25
    {
26
        return $this->belongsTo(Round::class);
27
    }
28
29
    public function session()
30
    {
31
        return $this->belongsTo(Session::class);
32
    }
33
34
    public function charge()
35
    {
36
        return $this->belongsTo(Charge::class);
37
    }
38
39
    public function member()
40
    {
41
        return $this->belongsTo(Member::class);
42
    }
43
44
    public function bill()
45
    {
46
        return $this->belongsTo(Bill::class);
47
    }
48
49
    /**
50
     * @param  Builder  $query
51
     * @param  Session $session
52
     *
53
     * @return Builder
54
     */
55
    public function scopeOfTypeSession(Builder $query, Session $session): Builder
56
    {
57
        return $query->where('v_bills.bill_type', Bill::TYPE_SESSION)
58
            ->where('v_bills.session_id', $session->id);
59
    }
60
61
    /**
62
     * @param  Builder  $query
63
     * @param  Session $session
64
     *
65
     * @return Builder
66
     */
67
    public function scopeOfTypeNotSession(Builder $query, Session $session): Builder
68
    {
69
        return $query->where('v_bills.bill_type', '!=', Bill::TYPE_SESSION)
70
            ->where('v_bills.round_id', $session->round_id)
71
            ->whereHas('session', fn(Builder $qs) =>
72
                $qs->where('day_date', '<=', $session->day_date))
73
            ->whereHas('bill', fn(Builder $qb) =>
74
                // Take unsettled bills, or bills settled on this session..
75
                $qb->where(fn(Builder $qs) => $qs
76
                    ->orWhereDoesntHave('settlement')
77
                    ->orWhereHas('settlement', fn(Builder $qt) =>
78
                        $qt->where('session_id', $session->id))));
79
    }
80
}
81