83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
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\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
#[Guarded(['id'])]
|
|
#[Appends([
|
|
'base_salary_formatted',
|
|
'bonus_formatted',
|
|
'deduction_formatted',
|
|
'total_salary_formatted',
|
|
'period_month_formatted',
|
|
])]
|
|
class Payroll extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'base_salary' => 'integer',
|
|
'bonus' => 'integer',
|
|
'deduction' => 'integer',
|
|
'total_salary' => 'integer',
|
|
'is_paid' => 'boolean',
|
|
];
|
|
}
|
|
|
|
protected function baseSalaryFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->base_salary ? 'Rp '.number_format($this->base_salary, 0, ',', '.') : null,
|
|
);
|
|
}
|
|
|
|
protected function bonusFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->bonus ? 'Rp '.number_format($this->bonus, 0, ',', '.') : null,
|
|
);
|
|
}
|
|
|
|
protected function deductionFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->deduction ? 'Rp '.number_format($this->deduction, 0, ',', '.') : null,
|
|
);
|
|
}
|
|
|
|
protected function totalSalaryFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->total_salary ? 'Rp '.number_format($this->total_salary, 0, ',', '.') : null,
|
|
);
|
|
}
|
|
|
|
protected function periodMonthFormatted(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->period_month ? Carbon::parse($this->period_month)->translatedFormat('F Y') : null,
|
|
);
|
|
}
|
|
|
|
public function adjustments(): HasMany
|
|
{
|
|
return $this->hasMany(PayrollAdjustment::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|