Voucher: Add worklog entries to calculation

This commit is contained in:
Igor Scheller 2019-12-27 05:24:32 +01:00
parent ec47d124bb
commit 7fb10ec569
2 changed files with 19 additions and 6 deletions

View File

@ -22,14 +22,24 @@ function UserWorkLog($user_worklog_id)
/** /**
* Returns all work log entries for a user. * Returns all work log entries for a user.
* *
* @param int $userId * @param int $userId
* @param Carbon|null $sinceTime
* @return array[] * @return array[]
*/ */
function UserWorkLogsForUser($userId) function UserWorkLogsForUser($userId, Carbon $sinceTime = null)
{ {
return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [ return Db::select(
$userId '
]); SELECT *
FROM `UserWorkLog`
WHERE `user_id`=?
' . ($sinceTime ? 'AND work_timestamp >= ' . $sinceTime->getTimestamp() : '') . '
ORDER BY `created_timestamp`
',
[
$userId
]
);
} }
/** /**

View File

@ -236,7 +236,10 @@ function User_get_eligable_voucher_count($user)
$start = $voucher_settings['voucher_start'] $start = $voucher_settings['voucher_start']
? 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_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']; $earned_vouchers = $user->state->got_voucher - $voucher_settings['initial_vouchers'];
$eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; $eligable_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;