|
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 Subscription extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
protected $table = 'trn_subscriptions'; |
|
12
|
|
|
|
|
13
|
|
|
protected $fillable = [ |
|
14
|
|
|
'member_id', |
|
15
|
|
|
'invoice_id', |
|
16
|
|
|
'plan_id', |
|
17
|
|
|
'status', |
|
18
|
|
|
'is_renewal', |
|
19
|
|
|
'start_date', |
|
20
|
|
|
'end_date', |
|
21
|
|
|
'created_by', |
|
22
|
|
|
'updated_by', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
protected $dates = ['created_at', 'updated_at', 'start_date', 'end_date']; |
|
26
|
|
|
|
|
27
|
|
|
//Eloquence Search mapping |
|
28
|
|
|
use Eloquence; |
|
29
|
|
|
|
|
30
|
|
|
protected $searchableColumns = [ |
|
31
|
|
|
'Member.member_code' => 20, |
|
32
|
|
|
'start_date' => 20, |
|
33
|
|
|
'end_date' => 20, |
|
34
|
|
|
'Member.name' => 20, |
|
35
|
|
|
'Plan.plan_name' => 20, |
|
36
|
|
|
'Invoice.invoice_number' => 20, |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
public function scopeDashboardExpiring($query) |
|
40
|
|
|
{ |
|
41
|
|
|
return $query->where('end_date','<',Carbon::today()->addDays(7))->where('status','=',\constSubscription::onGoing); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function scopeDashboardExpired($query) |
|
45
|
|
|
{ |
|
46
|
|
|
return $query->where('status','=',\constSubscription::Expired); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function scopeIndexQuery($query,$sorting_field,$sorting_direction,$drp_start,$drp_end) |
|
50
|
|
|
{ |
|
51
|
|
|
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
|
52
|
|
|
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
|
53
|
|
|
|
|
54
|
|
|
if ($drp_start == null or $drp_end == null) |
|
55
|
|
|
{ |
|
56
|
|
|
return $query->leftJoin('mst_plans', 'trn_subscriptions.plan_id', '=', 'mst_plans.id')->select('trn_subscriptions.*','mst_plans.plan_name')->orderBy($sorting_field,$sorting_direction); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $query->leftJoin('mst_plans', 'trn_subscriptions.plan_id', '=', 'mst_plans.id')->select('trn_subscriptions.*','mst_plans.plan_name')->whereBetween('trn_subscriptions.created_at', [$drp_start, $drp_end])->orderBy($sorting_field,$sorting_direction); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function scopeExpiring($query,$sorting_field,$sorting_direction,$drp_start,$drp_end) |
|
63
|
|
|
{ |
|
64
|
|
|
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
|
65
|
|
|
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
|
66
|
|
|
|
|
67
|
|
|
if ($drp_start == null or $drp_end == null) |
|
68
|
|
|
{ |
|
69
|
|
|
return $query->leftJoin('mst_plans', 'trn_subscriptions.plan_id', '=', 'mst_plans.id')->select('trn_subscriptions.*','mst_plans.plan_name')->where('trn_subscriptions.end_date','<',Carbon::today()->addDays(7))->where('trn_subscriptions.status','=',\constSubscription::onGoing)->orderBy($sorting_field,$sorting_direction); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $query->leftJoin('mst_plans', 'trn_subscriptions.plan_id', '=', 'mst_plans.id')->select('trn_subscriptions.*','mst_plans.plan_name')->where('trn_subscriptions.end_date','<',Carbon::today()->addDays(7))->where('trn_subscriptions.status','=',\constSubscription::onGoing)->whereBetween('trn_subscriptions.created_at', [$drp_start, $drp_end])->orderBy($sorting_field,$sorting_direction); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function scopeExpired($query,$sorting_field,$sorting_direction,$drp_start,$drp_end) |
|
76
|
|
|
{ |
|
77
|
|
|
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
|
78
|
|
|
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
|
79
|
|
|
|
|
80
|
|
|
if ($drp_start == null or $drp_end == null) |
|
81
|
|
|
{ |
|
82
|
|
|
return $query->leftJoin('mst_plans', 'trn_subscriptions.plan_id', '=', 'mst_plans.id')->select('trn_subscriptions.*','mst_plans.plan_name')->where('trn_subscriptions.status','=',\constSubscription::Expired)->where('trn_subscriptions.status','!=',\constSubscription::renewed)->orderBy($sorting_field,$sorting_direction); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $query->leftJoin('mst_plans', 'trn_subscriptions.plan_id', '=', 'mst_plans.id')->select('trn_subscriptions.*','mst_plans.plan_name')->where('trn_subscriptions.status','=',\constSubscription::Expired)->where('trn_subscriptions.status','!=',\constSubscription::renewed)->whereBetween('trn_subscriptions.created_at', [$drp_start, $drp_end])->orderBy($sorting_field,$sorting_direction); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function createdBy() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->belongsTo('App\User','created_by'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function updatedBy() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->belongsTo('App\User','updated_by'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function Member() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->belongsTo('App\Member','member_id'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function Plan() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->belongsTo('App\Plan','plan_id'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function Invoice() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->belongsTo('App\Invoice','invoice_id'); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|