|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Sofa\Eloquence\Eloquence; |
|
7
|
|
|
use Carbon\Carbon; |
|
8
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait; |
|
9
|
|
|
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions; |
|
10
|
|
|
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMedia; |
|
11
|
|
|
|
|
12
|
|
|
class Member extends Model implements HasMediaConversions |
|
13
|
|
|
{ |
|
14
|
|
|
use HasMediaTrait , Eloquence; |
|
15
|
|
|
|
|
16
|
|
|
protected $table = 'mst_members'; |
|
17
|
|
|
|
|
18
|
|
|
protected $fillable = [ |
|
19
|
|
|
'member_code', |
|
20
|
|
|
'name', |
|
21
|
|
|
'DOB', |
|
22
|
|
|
'email', |
|
23
|
|
|
'address', |
|
24
|
|
|
'status', |
|
25
|
|
|
'proof_name', |
|
26
|
|
|
'gender', |
|
27
|
|
|
'contact', |
|
28
|
|
|
'emergency_contact', |
|
29
|
|
|
'health_issues', |
|
30
|
|
|
'pin_code', |
|
31
|
|
|
'occupation', |
|
32
|
|
|
'aim', |
|
33
|
|
|
'source', |
|
34
|
|
|
'created_by', |
|
35
|
|
|
'updated_by' |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
protected $dates = ['created_at', 'updated_at', 'DOB']; |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
protected $searchableColumns = [ |
|
42
|
|
|
'member_code' => 20, |
|
43
|
|
|
'name' => 20, |
|
44
|
|
|
'email' => 20, |
|
45
|
|
|
'contact' => 20, |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
// Media i.e. Image size conversion |
|
49
|
|
|
public function registerMediaConversions() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->addMediaConversion('thumb') |
|
52
|
|
|
->setManipulations(['w' => 50, 'h' => 50, 'q' => 100, 'fit' => 'crop']) |
|
53
|
|
|
->performOnCollections('profile'); |
|
54
|
|
|
|
|
55
|
|
|
$this->addMediaConversion('form') |
|
56
|
|
|
->setManipulations(['w' => 70, 'h' => 70, 'q' => 100, 'fit' => 'crop']) |
|
57
|
|
|
->performOnCollections('profile','proof'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
//Relationships |
|
61
|
|
|
public function createdBy() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->belongsTo('App\User','created_by'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function updatedBy() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->belongsTo('App\User','updated_by'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function Subscriptions() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->hasMany('App\Subscription'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function Invoices() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->hasMany('App\Invoice'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
//Scope Queries |
|
82
|
|
|
public function scopeIndexQuery($query,$sorting_field,$sorting_direction,$drp_start,$drp_end) |
|
83
|
|
|
{ |
|
84
|
|
|
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
|
85
|
|
|
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
|
86
|
|
|
|
|
87
|
|
|
if ($drp_start == null or $drp_end == null) |
|
88
|
|
|
{ |
|
89
|
|
|
return $query->select('mst_members.id','mst_members.member_code','mst_members.name','mst_members.contact','mst_members.created_at','mst_members.status')->where('mst_members.status','!=', \constStatus::Archive)->orderBy($sorting_field,$sorting_direction); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $query->select('mst_members.id','mst_members.member_code','mst_members.name','mst_members.contact','mst_members.created_at','mst_members.status')->where('mst_members.status','!=', \constStatus::Archive)->whereBetween('mst_members.created_at', [$drp_start, $drp_end])->orderBy($sorting_field,$sorting_direction); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
// public function scopeReportQuery($query,$sorting_field,$sorting_direction,$drp_start,$drp_end) |
|
97
|
|
|
// { |
|
98
|
|
|
// $sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
|
99
|
|
|
// $sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
|
100
|
|
|
|
|
101
|
|
|
// if ($drp_start == null or $drp_end == null) |
|
102
|
|
|
// { |
|
103
|
|
|
// return $query->leftJoin('mst_plans', 'mst_members.plan_id', '=', 'mst_plans.id')->select('mst_members.*','mst_plans.plan_name')->where('mst_members.status','!=', \constStatus::Archive)->orderBy($sorting_field,$sorting_direction); |
|
104
|
|
|
// } |
|
105
|
|
|
|
|
106
|
|
|
// return $query->leftJoin('mst_plans', 'mst_members.plan_id', '=', 'mst_plans.id')->select('mst_members.*','mst_plans.plan_name')->where('mst_members.status','!=', \constStatus::Archive)->whereBetween('mst_members.created_at', [$drp_start, $drp_end])->orderBy($sorting_field,$sorting_direction); |
|
107
|
|
|
// } |
|
108
|
|
|
|
|
109
|
|
|
public function scopeActive($query) |
|
110
|
|
|
{ |
|
111
|
|
|
return $query->where('status','=', \constStatus::Active); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function scopeInactive($query) |
|
115
|
|
|
{ |
|
116
|
|
|
return $query->where('status','=', \constStatus::InActive); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function scopeRecent($query) |
|
120
|
|
|
{ |
|
121
|
|
|
return $query->where('created_at','<=',Carbon::today())->take(10)->orderBy('created_at','desc'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function scopeBirthday($query) |
|
125
|
|
|
{ |
|
126
|
|
|
return $query->whereMonth('DOB','=',Carbon::today()->month)->whereDay('DOB','<',Carbon::today()->addDays(7))->whereDay('DOB','>=',Carbon::today()->day)->where('status','=',\constStatus::Active); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
// Laravel issue: Workaroud Needed |
|
130
|
|
|
public function scopeRegistrations($query,$month,$year) |
|
131
|
|
|
{ |
|
132
|
|
|
return $query->whereMonth('created_at', '=', $month)->whereYear('created_at', '=',$year)->count(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |