Files
CKB/app/Models/KpiTarget.php

61 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Carbon\Carbon;
class KpiTarget extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'target_value',
'is_active',
'description'
];
protected $casts = [
'is_active' => 'boolean'
];
protected $attributes = [
'is_active' => true
];
/**
* Get the user that owns the KPI target
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Get the achievements for this target
*/
public function achievements(): HasMany
{
return $this->hasMany(KpiAchievement::class);
}
/**
* Scope to get active targets
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* Check if target is currently active
*/
public function isCurrentlyActive(): bool
{
return $this->is_active;
}
}