Payment_detail   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 60
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B scopeIndexQuery() 0 18 5
A createdBy() 0 3 1
A Cheque() 0 3 1
A updatedBy() 0 3 1
A Invoice() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sofa\Eloquence\Eloquence;
7
8
class Payment_detail extends Model
9
{
10
	 protected $table = 'trn_payment_details';
11
12
	 protected $fillable = [
13
	 		'payment_amount',
14
	 		'note',
15
	 		'mode',
16
	 		'invoice_id',
17
	 		'created_by',
18
    		'updated_by',
19
	 ];
20
21
     //Eloquence Search mapping
22
    use Eloquence;
23
24
    protected $searchableColumns = [
25
        'payment_amount' => 20,
26
        'Invoice.invoice_number' => 20,
27
        'Invoice.member.name' => 20,
28
    ];  
29
30
    public function scopeIndexQuery($query,$sorting_field,$sorting_direction,$drp_start,$drp_end)
31
    {
32
        $sorting_field = ($sorting_field != null ? $sorting_field : 'created_at');
33
        $sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc');
34
35
        if ($drp_start == null or $drp_end == null) 
36
        {
37
            return $query->leftJoin('trn_invoice','trn_payment_details.invoice_id','=','trn_invoice.id')
38
                         ->leftJoin('mst_members','trn_invoice.member_id','=','mst_members.id')
39
                         ->select('trn_payment_details.id','trn_payment_details.created_at','trn_payment_details.payment_amount','trn_payment_details.mode','trn_payment_details.invoice_id','trn_invoice.invoice_number','mst_members.id as member_id','mst_members.name as member_name','mst_members.member_code')
40
                         ->orderBy($sorting_field,$sorting_direction);
41
        }
42
43
        return $query->leftJoin('trn_invoice','trn_payment_details.invoice_id','=','trn_invoice.id')
44
                     ->leftJoin('mst_members','trn_invoice.member_id','=','mst_members.id')
45
                     ->select('trn_payment_details.id','trn_payment_details.created_at','trn_payment_details.payment_amount','trn_payment_details.mode','trn_invoice.invoice_number','mst_members.name as member_name','mst_members.member_code')
46
                     ->whereBetween('trn_payment_details.created_at', [$drp_start, $drp_end])
47
                     ->orderBy($sorting_field,$sorting_direction);
48
    }
49
50
	public function createdBy()
51
    {
52
        return $this->belongsTo('App\User','created_by');
53
    }
54
55
    public function updatedBy()
56
    {
57
        return $this->belongsTo('App\User','updated_by');
58
    }  
59
60
    public function Invoice()
61
    {
62
    	return $this->belongsTo('App\Invoice','invoice_id');
63
    }    
64
	
65
	public function Cheque()
66
    {
67
        return $this->hasOne('App\Cheque_detail','payment_id');
68
    }
69
}