Passed
Push — master ( be1785...591f13 )
by Ajit
07:10
created

Invoice::member()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App;
4
5
use Sofa\Eloquence\Eloquence;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Invoice extends Model
9
{
10
    protected $table = 'trn_invoice';
11
12
    protected $fillable = [
13
            'total',
14
            'pending_amount',
15
            'member_id',
16
            'note',
17
            'status',
18
            'tax',
19
            'additional_fees',
20
            'invoice_number',
21
            'discount_percent',
22
            'discount_amount',
23
            'discount_note',
24
            'created_by',
25
            'updated_by',
26
     ];
27
28
    protected $dates = ['created_at', 'updated_at'];
29
30
    //Eloquence Search mapping
31
    use Eloquence;
32
    use createdByUser, updatedByUser;
33
34
    protected $searchableColumns = [
35
        'invoice_number' => 20,
36
        'total' => 20,
37
        'pending_amount' => 20,
38
        'Member.name' => 15,
39
        'Member.member_code' => 10,
40
    ];
41
42
    public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp_start, $drp_end)
43
    {
44
        $sorting_field = ($sorting_field != null ? $sorting_field : 'created_at');
45
        $sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc');
46
47
        if ($drp_start == null or $drp_end == null) {
48
            return $query->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')->select('trn_invoice.*', 'mst_members.name as member_name')->orderBy($sorting_field, $sorting_direction);
49
        }
50
51
        return $query->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')->select('trn_invoice.*', 'mst_members.name as member_name')->whereBetween('trn_invoice.created_at', [$drp_start, $drp_end])->orderBy($sorting_field, $sorting_direction);
52
    }
53
54
    public function member()
55
    {
56
        return $this->belongsTo('App\Member', 'member_id');
57
    }
58
59
    public function paymentDetails()
60
    {
61
        return $this->hasMany('App\PaymentDetail');
62
    }
63
64
    public function invoiceDetails()
65
    {
66
        return $this->hasMany('App\InvoiceDetail');
67
    }
68
69
    public function subscription()
70
    {
71
        return $this->hasOne('App\Subscription');
72
    }
73
}
74