40 lines
1019 B
PHP
40 lines
1019 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\SalaryAdjustmentType;
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
#[Guarded(['id'])]
|
|
#[Appends(['amount_formatted'])]
|
|
class PayrollAdjustment extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'type' => SalaryAdjustmentType::class,
|
|
'amount' => 'integer',
|
|
];
|
|
}
|
|
|
|
protected function amountFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->amount ? 'Rp '.number_format($this->amount, 0, ',', '.') : null,
|
|
);
|
|
}
|
|
|
|
public function payroll(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Payroll::class);
|
|
}
|
|
}
|