summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-12-27 06:07:48 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2019-12-27 06:07:48 +0100
commit8f2da568929232fd6cf206909c05ebefc1b24737 (patch)
tree8aeb29aa764451543c584415cd5b907c688eca83
parent7fb10ec5695f534d1fea0c9487cd8f425c45a50f (diff)
Voucher: Added hours_per_voucher setting
-rw-r--r--config/config.default.php3
-rw-r--r--includes/model/User_model.php29
2 files changed, 25 insertions, 7 deletions
diff --git a/config/config.default.php b/config/config.default.php
index 06f8201f..1454017b 100644
--- a/config/config.default.php
+++ b/config/config.default.php
@@ -137,7 +137,8 @@ return [
// Voucher calculation
'voucher_settings' => [
'initial_vouchers' => 0,
- 'shifts_per_voucher' => 1,
+ 'shifts_per_voucher' => 0,
+ 'hours_per_voucher' => 2,
// 'Y-m-d' formatted
'voucher_start' => null,
],
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index ea2e3008..0858c0e2 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -237,17 +237,34 @@ function User_get_eligable_voucher_count($user)
? Carbon::createFromFormat('Y-m-d', $voucher_settings['voucher_start'])->setTime(0, 0)
: null;
+ $shifts = ShiftEntries_finished_by_user($user->id, $start);
+ $worklog = UserWorkLogsForUser($user->id, $start);
$shifts_done =
- count(ShiftEntries_finished_by_user($user->id, $start))
- + count(UserWorkLogsForUser($user->id, $start));
+ count($shifts)
+ + count($worklog);
- $earned_vouchers = $user->state->got_voucher - $voucher_settings['initial_vouchers'];
- $eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
- if ($eligable_vouchers < 0) {
+ $shiftsTime = 0;
+ foreach ($shifts as $shift){
+ $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 $eligable_vouchers;
+ return $vouchers;
}
/**