Invoice   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 74
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A updatedBy() 0 3 1
A Member() 0 3 1
B scopeIndexQuery() 0 11 5
A Invoice_details() 0 3 1
A Subscription() 0 3 1
A Payment_details() 0 3 1
A createdBy() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sofa\Eloquence\Eloquence;
7
use Carbon\Carbon;
8
9
class Invoice extends Model
10
{
11
	 protected $table = 'trn_invoice';
12
13
	 protected $fillable = [
14
	 		'total',
15
            'pending_amount',
16
	 		'member_id',
17
	 		'note',
18
            'status',
19
			'tax',
20
            'additional_fees',
21
	 		'invoice_number',
22
            'discount_percent',
23
            'discount_amount',
24
            'discount_note',
25
	 		'created_by',
26
    		'updated_by',
27
	 ];  
28
29
     protected $dates = ['created_at','updated_at'];
30
31
    //Eloquence Search mapping
32
    use Eloquence;
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
        {
49
            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);
50
        }
51
52
        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);
53
    }
54
55
	public function createdBy()
56
    {
57
        return $this->belongsTo('App\User','created_by');
58
    }
59
60
    public function updatedBy()
61
    {
62
        return $this->belongsTo('App\User','updated_by');
63
    }  
64
65
    public function Member()
66
    {
67
    	return $this->belongsTo('App\Member','member_id');
68
    }
69
70
    public function Payment_details()
71
    {
72
        return $this->hasMany('App\Payment_detail');
73
    }
74
75
    public function Invoice_details()
76
    {
77
        return $this->hasMany('App\Invoice_detail');
78
    }
79
80
    public function Subscription()
81
    {
82
        return $this->hasOne('App\Subscription');
83
    }
84
85
}
86