Voucher: Added hours_per_voucher setting

This commit is contained in:
Igor Scheller 2019-12-27 06:07:48 +01:00
parent 7fb10ec569
commit 8f2da56892
2 changed files with 25 additions and 7 deletions

View File

@ -137,7 +137,8 @@ return [
// Voucher calculation // Voucher calculation
'voucher_settings' => [ 'voucher_settings' => [
'initial_vouchers' => 0, 'initial_vouchers' => 0,
'shifts_per_voucher' => 1, 'shifts_per_voucher' => 0,
'hours_per_voucher' => 2,
// 'Y-m-d' formatted // 'Y-m-d' formatted
'voucher_start' => null, 'voucher_start' => null,
], ],

View File

@ -237,17 +237,34 @@ function User_get_eligable_voucher_count($user)
? Carbon::createFromFormat('Y-m-d', $voucher_settings['voucher_start'])->setTime(0, 0) ? Carbon::createFromFormat('Y-m-d', $voucher_settings['voucher_start'])->setTime(0, 0)
: null; : null;
$shifts = ShiftEntries_finished_by_user($user->id, $start);
$worklog = UserWorkLogsForUser($user->id, $start);
$shifts_done = $shifts_done =
count(ShiftEntries_finished_by_user($user->id, $start)) count($shifts)
+ count(UserWorkLogsForUser($user->id, $start)); + count($worklog);
$earned_vouchers = $user->state->got_voucher - $voucher_settings['initial_vouchers']; $shiftsTime = 0;
$eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; foreach ($shifts as $shift){
if ($eligable_vouchers < 0) { $shiftsTime += ($shift['end'] - $shift['start']) / 60 / 60;
}
foreach ($worklog as $entry){
$shiftsTime += $entry['work_hours'];
}
$vouchers = $voucher_settings['initial_vouchers'];
if($voucher_settings['shifts_per_voucher']){
$vouchers += $shifts_done / $voucher_settings['shifts_per_voucher'];
}
if($voucher_settings['hours_per_voucher']){
$vouchers += $shiftsTime / $voucher_settings['hours_per_voucher'];
}
$vouchers -= $user->state->got_voucher;
if ($vouchers < 0) {
return 0; return 0;
} }
return $eligable_vouchers; return $vouchers;
} }
/** /**