From 7fb10ec5695f534d1fea0c9487cd8f425c45a50f Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Fri, 27 Dec 2019 05:24:32 +0100 Subject: [PATCH] Voucher: Add worklog entries to calculation --- includes/model/UserWorkLog_model.php | 20 +++++++++++++++----- includes/model/User_model.php | 5 ++++- 2 files changed, 19 insertions(+), 6 deletions(-) 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..ea2e3008 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -236,7 +236,10 @@ 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)); + + $shifts_done = + count(ShiftEntries_finished_by_user($user->id, $start)) + + count(UserWorkLogsForUser($user->id, $start)); $earned_vouchers = $user->state->got_voucher - $voucher_settings['initial_vouchers']; $eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;