Shifts: Save time as worklog if past shift gets deleted

This commit is contained in:
Igor Scheller 2019-09-07 00:41:48 +02:00
parent 64c4743f57
commit d71b27b78b
3 changed files with 37 additions and 1 deletions

View File

@ -220,6 +220,7 @@ function shift_delete_controller()
// Schicht löschen bestätigt // Schicht löschen bestätigt
if ($request->hasPostData('delete')) { if ($request->hasPostData('delete')) {
UserWorkLog_from_shift($shift_id);
Shift_delete($shift_id); Shift_delete($shift_id);
engelsystem_log( engelsystem_log(

View File

@ -508,8 +508,8 @@ function Shift_delete_by_psid($shift_psid)
*/ */
function Shift_delete($shift_id) function Shift_delete($shift_id)
{ {
DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
mail_shift_delete(Shift($shift_id)); mail_shift_delete(Shift($shift_id));
DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]);
} }
/** /**

View File

@ -121,6 +121,41 @@ function UserWorkLog_create($userWorkLog)
return $result; return $result;
} }
/**
* @param array|int $shift
*/
function UserWorkLog_from_shift($shift)
{
$shift = is_array($shift) ? $shift : Shift($shift);
if ($shift['start'] > time()) {
return;
}
$room = Room($shift['RID']);
foreach ($shift['ShiftEntry'] as $entry) {
if ($entry['freeloaded']) {
continue;
}
$type = AngelType($entry['TID']);
UserWorkLog_create([
'user_id' => $entry['UID'],
'work_timestamp' => $shift['start'],
'work_hours' => ($shift['end'] - $shift['start']) / 60 / 60,
'comment' => sprintf(
'%s (%s as %s) in %s, %s-%s',
$shift['name'],
$shift['title'],
$type['name'],
$room['Name'],
Carbon::createFromTimestamp($shift['start'])->format(__('m/d/Y h:i a')),
Carbon::createFromTimestamp($shift['end'])->format(__('m/d/Y h:i a'))
),
]);
}
}
/** /**
* New user work log entry * New user work log entry
* *