Voucher: Add worklog entries to calculation

main
Igor Scheller 5 years ago
parent ec47d124bb
commit 7fb10ec569

@ -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
]
);
} }
/** /**

@ -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;

Loading…
Cancel
Save