add work date to work log

main
msquare 7 years ago
parent d95e488893
commit ee9fbda098

@ -56,3 +56,4 @@ ALTER TABLE `UserWorkLog` ADD FOREIGN KEY (`created_user_id`) REFERENCES `User`(
ALTER TABLE `UserWorkLog` ADD INDEX(`created_timestamp`); ALTER TABLE `UserWorkLog` ADD INDEX(`created_timestamp`);
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL, 'admin_user_worklog', 'Manage user work log entries.'); INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL, 'admin_user_worklog', 'Manage user work log entries.');
ALTER TABLE `UserWorkLog` CHANGE `work_hours` `work_hours` DECIMAL(10,2) NOT NULL; ALTER TABLE `UserWorkLog` CHANGE `work_hours` `work_hours` DECIMAL(10,2) NOT NULL;
ALTER TABLE `UserWorkLog` ADD `work_timestamp` INT NOT NULL AFTER `user_id`;

@ -69,6 +69,12 @@ function user_worklog_from_request($userWorkLog)
$valid = true; $valid = true;
$userWorkLog['work_timestamp'] = parse_date('Y-m-d H:i', $request->input('work_timestamp') . ' 00:00');
if ($userWorkLog['work_timestamp'] == null) {
$valid = false;
error(_('Please enter work date.'));
}
$userWorkLog['work_hours'] = $request->input('work_hours'); $userWorkLog['work_hours'] = $request->input('work_hours');
if (! preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) { if (! preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) {
$valid = false; $valid = false;

@ -3,22 +3,31 @@ use Engelsystem\Database\Db;
/** /**
* Load a single work log entry. * Load a single work log entry.
*
* @param int $user_worklog_id * @param int $user_worklog_id
*/ */
function UserWorkLog($user_worklog_id) { function UserWorkLog($user_worklog_id)
return Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [$user_worklog_id]); {
return Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [
$user_worklog_id
]);
} }
/** /**
* Returns all work log entries for a user. * Returns all work log entries for a user.
*
* @param User $user * @param User $user
*/ */
function UserWorkLogsForUser($user) { function UserWorkLogsForUser($user)
return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [$user['UID']]); {
return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [
$user['UID']
]);
} }
/** /**
* Delete a work log entry. * Delete a work log entry.
*
* @param UserWorkLog $userWorkLog * @param UserWorkLog $userWorkLog
*/ */
function UserWorkLog_delete($userWorkLog) function UserWorkLog_delete($userWorkLog)
@ -28,16 +37,14 @@ function UserWorkLog_delete($userWorkLog)
$userWorkLog['id'] $userWorkLog['id']
]); ]);
engelsystem_log(sprintf('Delete work log for %s, %s hours, %s', engelsystem_log(sprintf('Delete work log for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment']));
User_Nick_render($user_source),
$userWorkLog['work_hours'],
$userWorkLog['comment']));
return $result; return $result;
} }
/** /**
* Update work log entry (only work hours and comment) * Update work log entry (only work hours and comment)
*
* @param UserWorkLog $userWorkLog * @param UserWorkLog $userWorkLog
*/ */
function UserWorkLog_update($userWorkLog) function UserWorkLog_update($userWorkLog)
@ -45,24 +52,24 @@ function UserWorkLog_update($userWorkLog)
$user_source = User($userWorkLog['user_id']); $user_source = User($userWorkLog['user_id']);
$result = Db::update("UPDATE `UserWorkLog` SET $result = Db::update("UPDATE `UserWorkLog` SET
`work_timestamp`=?,
`work_hours`=?, `work_hours`=?,
`comment`=? `comment`=?
WHERE `id`=?", [ WHERE `id`=?", [
$userWorkLog['work_hours'], $userWorkLog['work_timestamp'],
$userWorkLog['comment'],
$userWorkLog['id']
]);
engelsystem_log(sprintf('Updated work log for %s, %s hours, %s',
User_Nick_render($user_source),
$userWorkLog['work_hours'], $userWorkLog['work_hours'],
$userWorkLog['comment'])); $userWorkLog['comment'],
$userWorkLog['id']
]);
engelsystem_log(sprintf('Updated work log for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment']));
return $result; return $result;
} }
/** /**
* Create a new work log entry * Create a new work log entry
*
* @param UserWorkLog $userWorkLog * @param UserWorkLog $userWorkLog
*/ */
function UserWorkLog_create($userWorkLog) function UserWorkLog_create($userWorkLog)
@ -73,23 +80,22 @@ function UserWorkLog_create($userWorkLog)
$result = Db::insert("INSERT INTO `UserWorkLog` ( $result = Db::insert("INSERT INTO `UserWorkLog` (
`user_id`, `user_id`,
`work_timestamp`,
`work_hours`, `work_hours`,
`comment`, `comment`,
`created_user_id`, `created_user_id`,
`created_timestamp` `created_timestamp`
) )
VALUES (?, ?, ?, ?, ?)", [ VALUES (?, ?, ?, ?, ?, ?)", [
$userWorkLog['user_id'], $userWorkLog['user_id'],
$userWorkLog['work_hours'], $userWorkLog['work_timestamp'],
$userWorkLog['comment'],
$user['UID'],
time()
]);
engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s',
User_Nick_render($user_source),
$userWorkLog['work_hours'], $userWorkLog['work_hours'],
$userWorkLog['comment'])); $userWorkLog['comment'],
$user['UID'],
time()
]);
engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment']));
return $result; return $result;
} }
@ -101,8 +107,14 @@ function UserWorkLog_create($userWorkLog)
*/ */
function UserWorkLog_new($user) function UserWorkLog_new($user)
{ {
$work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time()));
$event_config = EventConfig();
if (! empty($event_config['buildup_start_date'])) {
$work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', $event_config['buildup_start_date']));
}
return [ return [
'user_id' => $user['UID'], 'user_id' => $user['UID'],
'work_timestamp' => $work_date,
'work_hours' => 0, 'work_hours' => 0,
'comment' => '' 'comment' => ''
]; ];

@ -42,8 +42,10 @@ function User_tshirt_score($user) {
FROM `User` FROM `User`
LEFT JOIN `UserWorkLog` ON `User`.`UID` = `UserWorkLog`.`user_id` LEFT JOIN `UserWorkLog` ON `User`.`UID` = `UserWorkLog`.`user_id`
WHERE `User`.`UID` = ? WHERE `User`.`UID` = ?
AND `UserWorkLog`.`work_timestamp` < ?
',[ ',[
$user['UID'] $user['UID'],
time()
]); ]);
return $result_shifts['tshirt_score'] + $result_worklog['tshirt_score']; return $result_shifts['tshirt_score'] + $result_worklog['tshirt_score'];

@ -59,7 +59,8 @@ function admin_active()
`User`.*, `User`.*,
COUNT(`ShiftEntry`.`id`) AS `shift_count`, COUNT(`ShiftEntry`.`id`) AS `shift_count`,
(%s + ( (%s + (
SELECT SUM(`work_hours`) * 3600 FROM `UserWorkLog` WHERE `user_id`=`User`.`UID` SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`User`.`UID`
AND `work_timestamp` < %s
)) AS `shift_length` )) AS `shift_length`
FROM `User` FROM `User`
LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
@ -71,6 +72,7 @@ function admin_active()
%s %s
', ',
$shift_sum_formula, $shift_sum_formula,
time(),
$limit $limit
)); ));
$user_nicks = []; $user_nicks = [];
@ -143,7 +145,8 @@ function admin_active()
`User`.*, `User`.*,
COUNT(`ShiftEntry`.`id`) AS `shift_count`, COUNT(`ShiftEntry`.`id`) AS `shift_count`,
(%s + ( (%s + (
SELECT SUM(`work_hours`) * 3600 FROM `UserWorkLog` WHERE `user_id`=`User`.`UID` SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`User`.`UID`
AND `work_timestamp` < %s
)) AS `shift_length` )) AS `shift_length`
FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` ' LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` '
@ -154,6 +157,7 @@ function admin_active()
%s %s
', ',
$shift_sum_formula, $shift_sum_formula,
time(),
$limit $limit
)); ));
$matched_users = []; $matched_users = [];

@ -36,9 +36,10 @@ function UserWorkLog_edit_form($user_source, $userWorkLog)
{ {
return form([ return form([
form_info(_('User'), User_Nick_render($user_source)), form_info(_('User'), User_Nick_render($user_source)),
form_date('work_timestamp', _('Work date'), $userWorkLog['work_timestamp'], null, time()),
form_text('work_hours', _('Work hours'), $userWorkLog['work_hours']), form_text('work_hours', _('Work hours'), $userWorkLog['work_hours']),
form_text('comment', _('Comment'), $userWorkLog['comment']), form_text('comment', _('Comment'), $userWorkLog['comment']),
form_submit('submit', _('Add')) form_submit('submit', _('Save'))
]); ]);
} }

@ -356,7 +356,7 @@ function User_view_myshift($shift, $user_source, $its_me)
. glyph('time') . date('H:i', $shift['start']) . glyph('time') . date('H:i', $shift['start'])
. ' - ' . ' - '
. date('H:i', $shift['end']), . date('H:i', $shift['end']),
'duration' => round(($shift['end'] - $shift['start']) / 3600, 2) . ' h', 'duration' => sprintf('%.2f', round(($shift['end'] - $shift['start']) / 3600, 2)) . ' h',
'room' => Room_name_render($shift), 'room' => Room_name_render($shift),
'shift_info' => $shift_info, 'shift_info' => $shift_info,
'comment' => '' 'comment' => ''
@ -413,7 +413,7 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi
$myshifts_table = []; $myshifts_table = [];
$timesum = 0; $timesum = 0;
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$myshifts_table[] = User_view_myshift($shift, $user_source, $its_me); $myshifts_table[$shift['start']] = User_view_myshift($shift, $user_source, $its_me);
if (!$shift['freeloaded']) { if (!$shift['freeloaded']) {
$timesum += ($shift['end'] - $shift['start']); $timesum += ($shift['end'] - $shift['start']);
@ -422,15 +422,16 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi
if($its_me || $admin_user_worklog_privilege) { if($its_me || $admin_user_worklog_privilege) {
foreach($user_worklogs as $worklog) { foreach($user_worklogs as $worklog) {
$myshifts_table[] = User_view_worklog($worklog, $admin_user_worklog_privilege); $myshifts_table[$worklog['work_timestamp']] = User_view_worklog($worklog, $admin_user_worklog_privilege);
$timesum += $worklog['work_hours'] * 3600; $timesum += $worklog['work_hours'] * 3600;
} }
} }
if (count($myshifts_table) > 0) { if (count($myshifts_table) > 0) {
ksort($myshifts_table);
$myshifts_table[] = [ $myshifts_table[] = [
'date' => '<b>' . _('Sum:') . '</b>', 'date' => '<b>' . _('Sum:') . '</b>',
'duration' => '<b>' . round($timesum / 3600, 2) . ' h</b>', 'duration' => '<b>' . sprintf('%.2f', round($timesum / 3600, 2)) . ' h</b>',
'room' => '', 'room' => '',
'shift_info' => '', 'shift_info' => '',
'comment' => '', 'comment' => '',
@ -439,7 +440,7 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi
if (config('enable_tshirt_size', false) && ($its_me || $tshirt_admin)) { if (config('enable_tshirt_size', false) && ($its_me || $tshirt_admin)) {
$myshifts_table[] = [ $myshifts_table[] = [
'date' => '<b>' . _('Your t-shirt score') . '&trade;:</b>', 'date' => '<b>' . _('Your t-shirt score') . '&trade;:</b>',
'duration' => '<b>' . $tshirt_score . '</b>', 'duration' => '<b>' . sprintf('%.2f', $tshirt_score) . ' h</b>',
'room' => '', 'room' => '',
'shift_info' => '', 'shift_info' => '',
'comment' => '', 'comment' => '',
@ -473,8 +474,8 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege) {
} }
return [ return [
'date' => '', 'date' => glyph('calendar') . date('Y-m-d', $worklog['work_timestamp']),
'duration' => '<b>' . $worklog['work_hours'] . ' h</b>', 'duration' => '<b>' . sprintf('%.2f', $worklog['work_hours']) . ' h</b>',
'room' => '', 'room' => '',
'shift_info' => _('Work log entry'), 'shift_info' => _('Work log entry'),
'comment' => $worklog['comment'] . '<br>' 'comment' => $worklog['comment'] . '<br>'

Loading…
Cancel
Save