Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 21/04/2018
|
||||
* Time: 19:55
|
||||
*/
|
||||
|
||||
class Employeetarget extends BaseModel {
|
||||
|
||||
protected $table = 'employeetargets';
|
||||
|
||||
public function user()
|
||||
{
|
||||
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;
|
||||
|
||||
$monthtarget = $monthTarget->first();
|
||||
|
||||
return $monthtarget->target;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user