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
|
|
|
|
33
|
|
|
protected $searchableColumns = [ |
34
|
|
|
'invoice_number' => 20, |
35
|
|
|
'total' => 20, |
36
|
|
|
'pending_amount' => 20, |
37
|
|
|
'Member.name' => 15, |
38
|
|
|
'Member.member_code' => 10, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp_start, $drp_end) |
42
|
|
|
{ |
43
|
|
|
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
44
|
|
|
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
45
|
|
|
|
46
|
|
|
if ($drp_start == null or $drp_end == null) { |
47
|
|
|
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); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
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); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function createdBy() |
54
|
|
|
{ |
55
|
|
|
return $this->belongsTo('App\User', 'created_by'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function updatedBy() |
59
|
|
|
{ |
60
|
|
|
return $this->belongsTo('App\User', 'updated_by'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function Member() |
64
|
|
|
{ |
65
|
|
|
return $this->belongsTo('App\Member', 'member_id'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function PaymentDetails() |
69
|
|
|
{ |
70
|
|
|
return $this->hasMany('App\PaymentDetail'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function InvoiceDetails() |
74
|
|
|
{ |
75
|
|
|
return $this->hasMany('App\InvoiceDetail'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function Subscription() |
79
|
|
|
{ |
80
|
|
|
return $this->hasOne('App\Subscription'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|