Diversen nav opmerkingen

This commit is contained in:
2018-05-03 19:54:32 +02:00
parent 6bc0b37f06
commit 860c5db95a
18 changed files with 405 additions and 143 deletions
@@ -15,4 +15,48 @@ class Employeetarget extends BaseModel {
return $this->belongsTo( 'User' );
}
public static function saveTarget( $targetID, $target )
{
$target = (array) $target;
if ( $targetID == 0 )
{
$target = self::create( $target );
$targetID = $target['id'];
}
else
{
self::whereId( $targetID )->update( $target );
}
return $targetID;
}
public static function getTargetHoursPerEmployee( $employeeID, $year, $monthID )
{
$months = $monthID == 0 ? [1,2,3,4,5,6,7,8,9,10,11,12] : [$monthID];
$targetHours = 0;
foreach($months as $month)
{
$targetHours += self::getCurrentMonthTarget( $employeeID, $year, $month);
}
return $targetHours;
}
public static function getCurrentMonthTarget( $employeeID, $year, $month )
{
$monthTarget = Self::whereUserId($employeeID)
->where('startyear', '<=', $year)
->where('startmonth', '<=', $month)
->orderBy('startyear', 'DESC')
->orderBy('startmonth', 'DESC');
if( $monthTarget->count() == 0 ) return 0;
return $monthTarget->first()->target;
}
}