- Implemented routes for managing payroll periods, including current, close, and reopen functionalities. - Added payroll payment and cancellation routes. - Introduced payroll adjustments with store and delete functionalities. - Created comprehensive feature tests for payroll management, covering authentication, CRUD operations, and business logic. - Ensured proper handling of payroll adjustments and their impact on payroll totals. - Developed tests for generating payrolls and managing payroll periods, ensuring accurate status transitions and data integrity.
63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PayrollPeriodStatus;
|
|
use App\Enums\PayrollStatus;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
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'])]
|
|
class PayrollPeriod extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => PayrollPeriodStatus::class,
|
|
'closed_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
#[Scope]
|
|
protected function closed(Builder $query): void
|
|
{
|
|
$query->where('status', PayrollPeriodStatus::CLOSED);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function open(Builder $query): void
|
|
{
|
|
$query->where('status', PayrollPeriodStatus::OPEN);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function paid(Builder $query): void
|
|
{
|
|
$query->where('status', PayrollStatus::PAID);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function cancelled(Builder $query): void
|
|
{
|
|
$query->where('status', PayrollStatus::CANCELLED);
|
|
}
|
|
|
|
public function closedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'closed_by_id');
|
|
}
|
|
|
|
public function payrolls(): HasMany
|
|
{
|
|
return $this->hasMany(Payroll::class);
|
|
}
|
|
}
|