[WIP] Claims

This commit is contained in:
R
2022-11-25 05:14:40 +07:00
parent d5b43d9896
commit b3eb9b5f9d
18 changed files with 1012 additions and 376 deletions

View File

@@ -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) {