[WIP] Store Limit
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user