summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.default.php7
-rw-r--r--includes/model/ShiftsFilter.php5
-rw-r--r--includes/model/UserWorkLog_model.php20
-rw-r--r--includes/model/User_model.php30
4 files changed, 51 insertions, 11 deletions
diff --git a/config/config.default.php b/config/config.default.php
index a0dcd1bb..9b93eb25 100644
--- a/config/config.default.php
+++ b/config/config.default.php
@@ -140,7 +140,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,
],
@@ -169,6 +170,10 @@ return [
'4XL' => '4XLarge Straight-Cut',
],
+ // Shifts overview
+ // Set max number of hours that can be shown at once
+ 'filter_max_duration' => 0,
+
// Session config
'session' => [
// Supported: pdo or native
diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php
index fe3bfa56..c3811977 100644
--- a/includes/model/ShiftsFilter.php
+++ b/includes/model/ShiftsFilter.php
@@ -119,6 +119,11 @@ class ShiftsFilter
*/
public function setEndTime($endTime)
{
+ $filterMaxDuration = config('filter_max_duration') * 60 * 60;
+ if ($filterMaxDuration && ($endTime - $this->startTime > $filterMaxDuration)) {
+ $endTime = $this->startTime + $filterMaxDuration;
+ }
+
$this->endTime = $endTime;
}
diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php
index cc7686cf..e785067d 100644
--- a/includes/model/UserWorkLog_model.php
+++ b/includes/model/UserWorkLog_model.php
@@ -22,14 +22,24 @@ function UserWorkLog($user_worklog_id)
/**
* Returns all work log entries for a user.
*
- * @param int $userId
+ * @param int $userId
+ * @param Carbon|null $sinceTime
* @return array[]
*/
-function UserWorkLogsForUser($userId)
+function UserWorkLogsForUser($userId, Carbon $sinceTime = null)
{
- return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [
- $userId
- ]);
+ return Db::select(
+ '
+ SELECT *
+ FROM `UserWorkLog`
+ WHERE `user_id`=?
+ ' . ($sinceTime ? 'AND work_timestamp >= ' . $sinceTime->getTimestamp() : '') . '
+ ORDER BY `created_timestamp`
+ ',
+ [
+ $userId
+ ]
+ );
}
/**
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 1b1434bb..0858c0e2 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -236,15 +236,35 @@ function User_get_eligable_voucher_count($user)
$start = $voucher_settings['voucher_start']
? Carbon::createFromFormat('Y-m-d', $voucher_settings['voucher_start'])->setTime(0, 0)
: null;
- $shifts_done = count(ShiftEntries_finished_by_user($user->id, $start));
- $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) {
+ $shifts = ShiftEntries_finished_by_user($user->id, $start);
+ $worklog = UserWorkLogsForUser($user->id, $start);
+ $shifts_done =
+ count($shifts)
+ + count($worklog);
+
+ $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;
}
/**