partial update create kpi and progress bar
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user