partial update create kpi and progress bar

This commit is contained in:
2025-07-04 18:27:32 +07:00
parent 0ef03fe7cb
commit fa554446ca
19 changed files with 2150 additions and 45 deletions

View File

@@ -132,4 +132,64 @@ class User extends Authenticatable
return false;
}
}
/**
* Get all KPI targets for the User
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function kpiTargets()
{
return $this->hasMany(KpiTarget::class);
}
/**
* Get all KPI achievements for the User
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function kpiAchievements()
{
return $this->hasMany(KpiAchievement::class);
}
/**
* Check if user is mechanic
*
* @return bool
*/
public function isMechanic()
{
return $this->hasRole('mechanic');
}
/**
* Get current KPI target (no longer filtered by year/month)
*
* @return KpiTarget|null
*/
public function getCurrentKpiTarget()
{
return $this->kpiTargets()
->where('is_active', true)
->first();
}
/**
* Get KPI achievement for specific year and month
*
* @param int $year
* @param int $month
* @return KpiAchievement|null
*/
public function getKpiAchievement($year = null, $month = null)
{
$year = $year ?? now()->year;
$month = $month ?? now()->month;
return $this->kpiAchievements()
->where('year', $year)
->where('month', $month)
->first();
}
}