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

@@ -146,7 +146,7 @@ class CorporateBenefit extends Model
'max_frequency'
];
public function setAreaLimitAttribute($value)
{
$this->attributes['area_limit'] = empty($value) ? null : $value;
@@ -170,31 +170,31 @@ class CorporateBenefit extends Model
public function getMaxFrequencyAttribute()
{
switch ($this->max_frequency_period) {
// case(0) :
// // TODO Fix This
// return null;
// break;
case(1) :
// case(0) :
// // TODO Fix This
// return null;
// break;
case (1):
return empty($this->daily_frequency) ? 1 : $this->daily_frequency;
break;
case(2) :
case (2):
return empty($this->weekly_frequency) ? 1 : $this->weekly_frequency;
break;
case(3) :
case (3):
return empty($this->monthly_frequency) ? 1 : $this->monthly_frequency;
break;
case(4) :
case (4):
return empty($this->yearly_frequency) ? 1 : $this->yearly_frequency;
break;
case(5) :
case (5):
// TODO Fix This
return empty($this->max_period_for_disability) ? 1 : $this->max_period_for_disability;
break;
case(6) :
case (6):
// TODO Fix This
return 1;
break;
default :
default:
return null;
break;
}
@@ -214,13 +214,19 @@ class CorporateBenefit extends Model
{
return $this->belongsTo(Plan::class);
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? false, function ($query, $search) {
return $query
->where('code', 'like', "%" . $search . "%")
->orWhere('name', 'like', "%" . $search . "%");
->whereHas('benefit', function ($query) use ($search) {
$query->where('code', 'like', "%" . $search . "%")
->orWhere('service_code', 'like', "%" . $search . "%");
})->orWhereHas('plan', function ($query) use ($search) {
$query->where('code', 'like', "%" . $search . "%");
});
// ->where('code', 'like', "%" . $search . "%")
// ->orWhere('name', 'like', "%" . $search . "%");
});
}
}

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 . "%");
// });

View File

@@ -107,4 +107,27 @@ class Person extends Model
{
return $this->morphMany(AppointmentParticipant::class, 'participantable');
}
public function setGenderAttribute($value)
{
if ($value == "M" || $value == "L") {
return $this->attributes['gender'] = "male";
} else if ($value == "F" || $value == "P") {
return $this->attributes['gender'] = "female";
} else {
return $this->attributes['gender'] = $value;
}
}
public function getGenderAttribute()
{
if ($this->attributes['gender'] == "male" || $this->attributes['gender'] == "L") {
return "male";
} else if ($this->attributes['gender'] == "female" || $this->attributes['gender'] == "P") {
return "female";
} else {
return "other";
}
}
}

View File

@@ -11,6 +11,8 @@ class Plan extends Model
{
use HasFactory, SoftDeletes, Blameable;
protected $table = "plans";
protected $fillable = [
"service_code",
"corporate_id",
@@ -138,7 +140,7 @@ class Plan extends Model
{
$this->attributes['max_surgery_reinstatement_days'] = empty($value) ? null : $value;
}
public function setMaxSurgeryPeriodeDaysAttribute($value)
{
$this->attributes['max_surgery_periode_days'] = empty($value) ? null : $value;
@@ -148,11 +150,11 @@ class Plan extends Model
{
$query->when($filters['search'] ?? false, function ($query, $search) {
return $query
->where('service_code', 'like', "%" . $search . "%")
->orWhere('code', 'like', "%" . $search . "%")
->orWhereHas('corporatePlan', function ($query) use ($search) {
$query->where('code', 'like', "%" . $search . "%");
});
->where('service_code', 'like', "%" . $search . "%")
->orWhere('code', 'like', "%" . $search . "%")
->orWhereHas('corporatePlan', function ($query) use ($search) {
$query->where('code', 'like', "%" . $search . "%");
});
});
}
@@ -169,12 +171,12 @@ class Plan extends Model
public function benefits()
{
return $this->belongsToMany(Benefit::class, 'corporate_benefits', 'benefit_id', 'id')
->withTimestamps()
->withPivot([
// TODO corporate_benefits pivot
]);
->withTimestamps()
->withPivot([
// TODO corporate_benefits pivot
]);
}
public function corporateBeneftis()
{
return $this->hasMany(CorporateBenefit::class, 'benefit_id', 'id');