Fix Employee Data - Client Portal
This commit is contained in:
@@ -57,7 +57,6 @@ class Member extends Model
|
||||
"endorsement_date",
|
||||
"members_effective_date",
|
||||
"members_expire_date",
|
||||
"employee_status",
|
||||
"activation_date",
|
||||
"terminated_date",
|
||||
"remarks",
|
||||
@@ -94,7 +93,7 @@ class Member extends Model
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* relationship */
|
||||
/* Relationship */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
public function claims()
|
||||
{
|
||||
@@ -154,36 +153,18 @@ class Member extends Model
|
||||
public function currentPlans()
|
||||
{
|
||||
return $this->hasManyThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id');
|
||||
// ->latest(); // TODO Fix This
|
||||
}
|
||||
|
||||
public function currentPlan()
|
||||
{
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id',)
|
||||
->latest();
|
||||
// ->where('plans.service_code', $this->claimRequest->service_code); // TODO Fix This
|
||||
}
|
||||
|
||||
// public function currentPlan()
|
||||
// {
|
||||
// return $this->hasOneThrough(
|
||||
// Plan::class,
|
||||
// MemberPlan::class,
|
||||
// 'member_id',
|
||||
// 'id',
|
||||
// 'id',
|
||||
// 'plan_id'
|
||||
// )
|
||||
// ->join('claim_requests', 'claim_requests.service_code', '=', 'plans.service_code')
|
||||
// ->latest('claim_requests.created_at') // Atau sesuaikan dengan kolom timestamp yang sesuai
|
||||
// ->select('plans.*');
|
||||
// }
|
||||
|
||||
|
||||
public function currentEmployeds()
|
||||
{
|
||||
return $this->hasOneThrough(CorporateEmployee::class, Person::class, 'nik', 'id', 'id', 'nik')
|
||||
->latest(); // TODO Fix This
|
||||
->latest();
|
||||
}
|
||||
|
||||
public function policies()
|
||||
@@ -196,7 +177,6 @@ class Member extends Model
|
||||
return $this->hasOneThrough(CorporatePolicy::class, MemberPolicy::class, 'member_id', 'code', 'member_id', 'policy_id')
|
||||
->where('status', 'active')
|
||||
->orderBy('end', 'DESC');
|
||||
// return $this->hasOne(MemberPolicy::class, 'member_id', 'member_id')->where('status', 'active')->latestOfMany();
|
||||
}
|
||||
|
||||
public function currentActivePolicy()
|
||||
@@ -228,18 +208,20 @@ class Member extends Model
|
||||
{
|
||||
$arr = [];
|
||||
|
||||
if (!empty($this->person->name_prefix)) {
|
||||
$arr[] = $this->person->name_prefix;
|
||||
}
|
||||
if ($this->relationLoaded('person')) {
|
||||
if (!empty($this->person->name_prefix)) {
|
||||
$arr[] = $this->person->name_prefix;
|
||||
}
|
||||
|
||||
$arr[] = $this->person->name ?? '-';
|
||||
$arr[] = $this->person->name ?? '-';
|
||||
|
||||
if (!empty($this->person->name_suffix)) {
|
||||
$arr[] = $this->person->name_suffix;
|
||||
if (!empty($this->person->name_suffix)) {
|
||||
$arr[] = $this->person->name_suffix;
|
||||
}
|
||||
}
|
||||
|
||||
return Attribute::make(
|
||||
get: fn () => !$this->person ? null : implode(' ', $arr)
|
||||
get: fn () => !empty($arr) ? ucwords(strtolower(implode(' ', $arr))) : null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -252,46 +234,90 @@ class Member extends Model
|
||||
|
||||
protected function name(): Attribute
|
||||
{
|
||||
if ($this->relationLoaded('person')) {
|
||||
return Attribute::make(
|
||||
get: fn () => $this->person->name ?? ($this->name ?? null)
|
||||
);
|
||||
} else {
|
||||
return Attribute::make(
|
||||
get: fn () => $this->name ?? null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function maritalStatus(): Attribute
|
||||
{
|
||||
if ($this->relationLoaded('person')) {
|
||||
$marital_status = $this->person->marital_status ?? ($this->marital_status ?? null);
|
||||
|
||||
if ($marital_status === 'M') {
|
||||
$marital_status = 'Menikah';
|
||||
}
|
||||
|
||||
return Attribute::make(
|
||||
get: fn () => $marital_status
|
||||
);
|
||||
} else {
|
||||
$marital_status = $this->marital_status ?? null;
|
||||
|
||||
if ($marital_status === 'M') {
|
||||
$marital_status = 'Menikah';
|
||||
}
|
||||
|
||||
return Attribute::make(
|
||||
get: fn () => $marital_status
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function relationship(): Attribute
|
||||
{
|
||||
$relation = null;
|
||||
|
||||
if ($this->relation_with_principal === 'S') {
|
||||
$relation = 'Son';
|
||||
} elseif ($this->relation_with_principal === 'H') {
|
||||
$relation = 'Husband';
|
||||
} elseif ($this->relation_with_principal === 'D') {
|
||||
$relation = 'Daughter';
|
||||
} elseif ($this->relation_with_principal === 'Wife') {
|
||||
$relation = 'Wife';
|
||||
}
|
||||
|
||||
return Attribute::make(
|
||||
get: fn () => $this->person->name ?? ($this->name ?? null)
|
||||
get: fn () => $relation
|
||||
);
|
||||
}
|
||||
|
||||
// protected function birthDate(): Attribute
|
||||
// {
|
||||
// // $date = $this->person->birth_date ?? ($this->birth_date ?? null);
|
||||
// $date = $this->birth_date;
|
||||
// if ($date){
|
||||
// $date = ($this->birth_date ?? $this->person->birth_date);
|
||||
// return Attribute::make(
|
||||
// get: fn () => !empty($date) ? Carbon::parse($date)->format('d / M / Y') : '-'
|
||||
// );
|
||||
// } else {
|
||||
// return Attribute::make(
|
||||
// get: fn () => '-'
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
protected function birthDateeCard(): Attribute
|
||||
protected function status(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->active ? ($this->active == 1 ? 'Active' : 'Inactive') : null
|
||||
);
|
||||
}
|
||||
|
||||
protected function birthDateCard(): Attribute
|
||||
{
|
||||
// $date = $this->person->birth_date ?? ($this->birth_date ?? null);
|
||||
$date = $this->birth_date;
|
||||
|
||||
if ($date) {
|
||||
$date = ($this->birth_date ?? $this->person->birth_date);
|
||||
return Attribute::make(
|
||||
get: fn () => !empty($date) ? Carbon::parse($date)->format('d / M / Y') : '-'
|
||||
);
|
||||
} else if ($this->relationLoaded('person')) {
|
||||
$date = $this->person->birth_date;
|
||||
return Attribute::make(
|
||||
get: fn () => !empty($date) ? Carbon::parse($date)->format('d / M / Y') : '-'
|
||||
);
|
||||
} else {
|
||||
return Attribute::make(
|
||||
get: fn () => '-'
|
||||
get: fn () => '-'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function startDate(): Attribute
|
||||
{
|
||||
// $date = $this->person->birth_date ?? ($this->birth_date ?? null);
|
||||
$date = $this->members_effective_date;
|
||||
return Attribute::make(
|
||||
get: fn () => !empty($date) ? Carbon::parse($date)->format('d / M / Y') : null
|
||||
@@ -300,34 +326,28 @@ class Member extends Model
|
||||
|
||||
protected function endDate(): Attribute
|
||||
{
|
||||
// $date = $this->person->birth_date ?? ($this->birth_date ?? null);
|
||||
$date = $this->members_expire_date;
|
||||
return Attribute::make(
|
||||
get: fn () => !empty($date) ? Carbon::parse($date)->format('d / M / Y') : null
|
||||
);
|
||||
}
|
||||
|
||||
// protected function gender(): Attribute
|
||||
// {
|
||||
// return Attribute::make(
|
||||
// get: fn () => $this->person->gender ? ucfirst($this->person->gender) : '-'
|
||||
// // get: fn () => '-'
|
||||
// );
|
||||
// }
|
||||
|
||||
protected function corporateLogo(): Attribute
|
||||
{
|
||||
$avatar = File::where(['type' => 'avatar', 'fileable_id' => $this->currentPolicy->corporate->id])->orderBy('id', 'desc')->get()->first();
|
||||
if ($avatar) {
|
||||
$path = $_ENV['LMS_APP_STORAGE'] . $avatar->path ? $avatar->path : '';
|
||||
return Attribute::make(
|
||||
get: fn () => $avatar ? $path : null
|
||||
);
|
||||
} else {
|
||||
return Attribute::make(
|
||||
get: fn () => null
|
||||
);
|
||||
$avatar = null;
|
||||
|
||||
if ($this->relationLoaded('currentPolicy')) {
|
||||
$corporateId = $this->currentPolicy->corporate->id;
|
||||
$avatar = File::where(['type' => 'avatar', 'fileable_id' => $corporateId])
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
$path = $avatar ? $_ENV['LMS_APP_STORAGE'] . $avatar->path : '';
|
||||
|
||||
return Attribute::make(
|
||||
get: fn () => $path
|
||||
);
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user