[WIP] Store Limit
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Claim extends Model
|
||||
{
|
||||
@@ -19,6 +20,28 @@ class Claim extends Model
|
||||
'benefit_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
try {
|
||||
$model->code = (string) Str::orderedUuid(); // generate uuid
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function member()
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id');
|
||||
@@ -38,4 +61,5 @@ class Claim extends Model
|
||||
{
|
||||
return $this->belongsTo(Benefit::class, 'benefit_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,4 +106,9 @@ class Corporate extends Model
|
||||
{
|
||||
return $this->hasMany(Corporate::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function getLimitBalanceAttribute()
|
||||
{
|
||||
return $this->currentPolicy->limit_balance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ class CorporatePolicy extends Model
|
||||
return $this->belongsTo(Corporate::class);
|
||||
}
|
||||
|
||||
public function limitJournals()
|
||||
{
|
||||
return $this->morphMany(LimitJournal::class, 'journalable');
|
||||
}
|
||||
|
||||
public function setCodeAttribute($value)
|
||||
{
|
||||
$this->attributes['code'] = !empty($value) ? $value : Str::upper(Str::random('6'));
|
||||
@@ -53,4 +58,11 @@ class CorporatePolicy extends Model
|
||||
{
|
||||
$this->attributes['end'] = !empty($value) ? Carbon::parse($value)->format('Y-m-d') : null;
|
||||
}
|
||||
|
||||
public function getLimitBalanceAttribute()
|
||||
{
|
||||
$journal = $this->limitJournals()->latest()->first();
|
||||
|
||||
return $journal ? $journal->balance : (!empty($this->total_premi) ? $this->total_premi : "0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,15 @@ class Icd extends Model
|
||||
'active'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function getTypeAttribute()
|
||||
{
|
||||
return 'ICD-'.$this->rev;
|
||||
|
||||
@@ -11,7 +11,9 @@ class LimitJournal extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'journalable',
|
||||
'mutation',
|
||||
'previous_balance',
|
||||
'total_credit',
|
||||
'total_debit',
|
||||
'type',
|
||||
'balance',
|
||||
'description',
|
||||
@@ -21,4 +23,15 @@ class LimitJournal extends Model
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function setTotalCreditAttribute($value)
|
||||
{
|
||||
$this->attributes['total_credit'] = empty($value) ? 0 : $value;
|
||||
}
|
||||
|
||||
public function setTotalDebitAttribute($value)
|
||||
{
|
||||
$this->attributes['total_debit'] = empty($value) ? 0 : $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,20 @@ class Member extends Model
|
||||
"end_no_claim",
|
||||
];
|
||||
|
||||
protected $appends = ['full_name'];
|
||||
protected $appends = [
|
||||
'full_name',
|
||||
'age',
|
||||
'gender_code'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function claims()
|
||||
{
|
||||
@@ -105,12 +118,12 @@ class Member extends Model
|
||||
|
||||
public function plans()
|
||||
{
|
||||
return $this->hasManyThrough(Plan::class, MemberPlan::class, 'member_id', 'code', 'id', 'plan_id');
|
||||
return $this->hasManyThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id');
|
||||
}
|
||||
|
||||
public function currentPlan()
|
||||
{
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'code', 'id', 'plan_id')->latest();
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')->latest();
|
||||
}
|
||||
|
||||
public function policies()
|
||||
@@ -120,7 +133,21 @@ class Member extends Model
|
||||
|
||||
public function currentPolicy()
|
||||
{
|
||||
return $this->hasOne(MemberPolicy::class, 'member_id', 'member_id')->where('status', 'active')->latestOfMany();
|
||||
return $this->hasOneThrough(CorporatePolicy::class, MemberPolicy::class, 'member_id', 'code', 'member_id', 'policy_id')
|
||||
->where('corporate_policies.start', '<', now())
|
||||
->where('corporate_policies.end', '>', now())
|
||||
->where('member_policies.start', '<', now())
|
||||
->where('member_policies.end', '>', now());
|
||||
// return $this->hasOne(MemberPolicy::class, 'member_id', 'member_id')->where('status', 'active')->latestOfMany();
|
||||
}
|
||||
|
||||
public function getAgeAttribute()
|
||||
{
|
||||
if ($this->birth_date) {
|
||||
return Carbon::parse($this->birth_date)->diffInYears(now());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFullNameAttribute()
|
||||
@@ -137,6 +164,11 @@ class Member extends Model
|
||||
return implode(' ', $arr);
|
||||
}
|
||||
|
||||
public function getGenderCodeAttribute()
|
||||
{
|
||||
return $this->gender ? ($this->gender == 'female' ? 'F' : 'M') : $this->gender;
|
||||
}
|
||||
|
||||
public function scopeFilter($query, array $filters)
|
||||
{
|
||||
$query->when($filters['search'] ?? false, function ($query, $search) {
|
||||
|
||||
Reference in New Issue
Block a user