table member dan table benefit

This commit is contained in:
pajri
2022-12-20 17:48:28 +07:00
parent da14589328
commit 88ad144921
17 changed files with 1365 additions and 499 deletions

View File

@@ -14,6 +14,7 @@ class Member extends Model
protected $fillable = [
"id",
"person_id",
"member_id",
"record_type",
"payor_id",
@@ -73,11 +74,18 @@ class Member extends Model
'deleted_by',
];
public function claims()
{
return $this->hasMany(Claim::class, 'member_id', 'id');
}
public function person()
{
return $this->belongsTo(Person::class, 'person_id', 'id');
}
public function employeds()
{
return $this->hasMany(CorporateEmployee::class, 'member_id');
@@ -110,13 +118,13 @@ class Member extends Model
// // ])
// ->where('start', '<', now())
// ->where('end', '>', now());
return $this->hasOneThrough(Corporate::class, CorporateEmployee::class, 'member_id', 'id', 'id', 'corporate_id');
// ->where('corporate_policies.start', '<', now())
// ->where('corporate_policies.end', '>', now())
// ->where('member_policies.start', '<', now())
// ->where('member_policies.end', '>', now());
// ->where('corporate_policies.start', '<', now())
// ->where('corporate_policies.end', '>', now())
// ->where('member_policies.start', '<', now())
// ->where('member_policies.end', '>', now());
}
public function memberPlans()
@@ -160,13 +168,16 @@ class Member extends Model
public function getFullNameAttribute()
{
$arr = [];
if (!empty($this->name_prefix)) {
$arr[] = $this->name_prefix;
if (!$this->person) {
return null;
}
$arr[] = $this->name;
if (!empty($this->name_suffix)) {
$arr[] = $this->name_suffix;
$arr = [];
if (!empty($this->person->name_prefix)) {
$arr[] = $this->person->name_prefix;
}
$arr[] = $this->person->name;
if (!empty($this->person->name_suffix)) {
$arr[] = $this->person->name_suffix;
}
return implode(' ', $arr);
@@ -177,13 +188,35 @@ class Member extends Model
return $this->gender ? ($this->gender == 'female' ? 'F' : 'M') : $this->gender;
}
public function getNameAttribute()
{
return $this->person->name ?? null;
}
public function getBirthDateAttribute()
{
return Carbon::parse($this->person->birth_date ?? null)->format('Y-m-d') ?? null;
}
public function getGenderAttribute()
{
return $this->person->gender ?? null;
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? false, function ($query, $search) {
return $query
->where('member_id', 'like', "%" . $search . "%")
->orWhere('payor_id', 'like', "%" . $search . "%")
->orWhere('name', 'like', "%" . $search . "%");
->orWhere('email', 'like', "%" . $search . "%")
->orWhereHas('person', function ($query) use ($search) {
$query->where('name', 'like', "%" . $search . "%");
$query->orWhere('phone', 'like', "%" . $search . "%");
})
->orWhereHas('currentPlan', function ($query) use ($search) {
$query->where('code', 'like', "%" . $search . "%");
});
// ->orWhereHas('corporatePlan', function ($query) use ($search) {
// $query->where('code', 'like', "%" . $search . "%");
// });