1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Sofa\Eloquence\Eloquence; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
|
8
|
|
|
class PaymentDetail 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
|
|
|
return $query->leftJoin('trn_invoice', 'trn_payment_details.invoice_id', '=', 'trn_invoice.id') |
37
|
|
|
->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id') |
38
|
|
|
->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') |
39
|
|
|
->orderBy($sorting_field, $sorting_direction); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $query->leftJoin('trn_invoice', 'trn_payment_details.invoice_id', '=', 'trn_invoice.id') |
43
|
|
|
->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id') |
44
|
|
|
->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') |
45
|
|
|
->whereBetween('trn_payment_details.created_at', [$drp_start, $drp_end]) |
46
|
|
|
->orderBy($sorting_field, $sorting_direction); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function createdBy() |
50
|
|
|
{ |
51
|
|
|
return $this->belongsTo('App\User', 'created_by'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function updatedBy() |
55
|
|
|
{ |
56
|
|
|
return $this->belongsTo('App\User', 'updated_by'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function Invoice() |
60
|
|
|
{ |
61
|
|
|
return $this->belongsTo('App\Invoice', 'invoice_id'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function Cheque() |
65
|
|
|
{ |
66
|
|
|
return $this->hasOne('App\ChequeDetail', 'payment_id'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|