[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

@@ -23,4 +23,19 @@ class Claim extends Model
{
return $this->belongsTo(Member::class, 'member_id');
}
public function diagnosis()
{
return $this->belongsTo(Icd::class, 'diagnosis_id');
}
public function plan()
{
return $this->belongsTo(Plan::class, 'plan_id');
}
public function benefit()
{
return $this->belongsTo(Benefit::class, 'benefit_id');
}
}

View File

@@ -82,6 +82,11 @@ class Corporate extends Model
return $this->morphMany(ImportLog::class, 'importable');
}
public function limitJournals()
{
return $this->morphMany(LimitJournal::class, 'journalable');
}
public function services()
{
return $this->hasManyThrough(CorporateService::class, Service::class, 'corporate_id', 'service_code', 'id', 'service_code');

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class LimitJournal extends Model
{
use HasFactory;
protected $fillable = [
'journalable',
'mutation',
'type',
'balance',
'description',
];
public function journalable()
{
return $this->morphTo();
}
}

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