[WIP] Claims
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -56,6 +57,8 @@ class Member extends Model
|
||||
"end_no_claim",
|
||||
];
|
||||
|
||||
protected $appends = ['full_name'];
|
||||
|
||||
public function claims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'member_id', 'id');
|
||||
@@ -66,6 +69,35 @@ class Member extends Model
|
||||
return $this->hasMany(CorporateEmployee::class, 'member_id');
|
||||
}
|
||||
|
||||
public function corporates()
|
||||
{
|
||||
return $this
|
||||
->belongsToMany(Corporate::class, 'corporate_employees', 'corporate_id', 'member_id')
|
||||
->withPivot([
|
||||
'branch_code',
|
||||
'divison_id',
|
||||
'nik',
|
||||
'status',
|
||||
'start',
|
||||
'end'
|
||||
]);
|
||||
}
|
||||
|
||||
public function currentCorporate()
|
||||
{
|
||||
return $this->belongsToMany(Corporate::class, 'corporate_employees', 'corporate_id', 'member_id')
|
||||
// ->withPivot([
|
||||
// 'branch_code',
|
||||
// 'divison_id',
|
||||
// 'nik',
|
||||
// 'status',
|
||||
// 'start',
|
||||
// 'end'
|
||||
// ])
|
||||
->where('start', '<', now())
|
||||
->where('end', '>', now());
|
||||
}
|
||||
|
||||
public function memberPlans()
|
||||
{
|
||||
return $this->hasMany(MemberPlan::class, 'member_id');
|
||||
@@ -91,6 +123,20 @@ class Member extends Model
|
||||
return $this->hasOne(MemberPolicy::class, 'member_id', 'member_id')->where('status', 'active')->latestOfMany();
|
||||
}
|
||||
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
$arr = [];
|
||||
if (!empty($this->name_prefix)) {
|
||||
$arr[] = $this->name_prefix;
|
||||
}
|
||||
$arr[] = $this->name;
|
||||
if (!empty($this->name_suffix)) {
|
||||
$arr[] = $this->name_suffix;
|
||||
}
|
||||
|
||||
return implode(' ', $arr);
|
||||
}
|
||||
|
||||
public function scopeFilter($query, array $filters)
|
||||
{
|
||||
$query->when($filters['search'] ?? false, function ($query, $search) {
|
||||
|
||||
Reference in New Issue
Block a user