1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Sofa\Eloquence\Eloquence; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait; |
9
|
|
|
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions; |
10
|
|
|
|
11
|
|
|
class Member extends Model implements HasMediaConversions |
12
|
|
|
{ |
13
|
|
|
use HasMediaTrait, Eloquence; |
|
|
|
|
14
|
|
|
use createdByUser, updatedByUser; |
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
|
|
|
protected $searchableColumns = [ |
41
|
|
|
'member_code' => 20, |
42
|
|
|
'name' => 20, |
43
|
|
|
'email' => 20, |
44
|
|
|
'contact' => 20, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
public function getDobAttribute($value) |
48
|
|
|
{ |
49
|
|
|
return (new Carbon($value))->format('Y-m-d'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Media i.e. Image size conversion |
53
|
|
|
public function registerMediaConversions() |
54
|
|
|
{ |
55
|
|
|
$this->addMediaConversion('thumb')->setManipulations(['w' => 50, 'h' => 50, 'q' => 100, 'fit' => 'crop'])->performOnCollections('profile'); |
56
|
|
|
|
57
|
|
|
$this->addMediaConversion('form')->setManipulations(['w' => 70, 'h' => 70, 'q' => 100, 'fit' => 'crop'])->performOnCollections('profile', 'proof'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
//Relationships |
61
|
|
|
public function subscriptions() |
62
|
|
|
{ |
63
|
|
|
return $this->hasMany('App\Subscription'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function invoices() |
67
|
|
|
{ |
68
|
|
|
return $this->hasMany('App\Invoice'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
//Scope Queries |
72
|
|
|
public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp_start, $drp_end) |
73
|
|
|
{ |
74
|
|
|
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at'); |
75
|
|
|
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc'); |
76
|
|
|
|
77
|
|
|
if ($drp_start == null or $drp_end == null) { |
78
|
|
|
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); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
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', [ |
82
|
|
|
$drp_start, |
83
|
|
|
$drp_end, |
84
|
|
|
])->orderBy($sorting_field, $sorting_direction); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function scopeActive($query) |
88
|
|
|
{ |
89
|
|
|
return $query->where('status', '=', \constStatus::Active); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function scopeInactive($query) |
93
|
|
|
{ |
94
|
|
|
return $query->where('status', '=', \constStatus::InActive); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function scopeRecent($query) |
98
|
|
|
{ |
99
|
|
|
return $query->where('created_at', '<=', Carbon::today())->take(10)->orderBy('created_at', 'desc'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function scopeBirthday($query) |
103
|
|
|
{ |
104
|
|
|
return $query->whereMonth('DOB', '=', Carbon::today()->month)->whereDay('DOB', '<', Carbon::today()->addDays(7))->whereDay('DOB', '>=', Carbon::today()->day)->where('status', '=', \constStatus::Active); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// Laravel issue: Workaroud Needed |
108
|
|
|
public function scopeRegistrations($query, $month, $year) |
109
|
|
|
{ |
110
|
|
|
return $query->whereMonth('created_at', '=', $month)->whereYear('created_at', '=', $year)->count(); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|