From d71b27b78b29a2ed725a6e631bf8085bde257f18 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 7 Sep 2019 00:41:48 +0200 Subject: Shifts: Save time as worklog if past shift gets deleted --- includes/model/Shifts_model.php | 2 +- includes/model/UserWorkLog_model.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'includes/model') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 6bb17cf2..2408eb49 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -508,8 +508,8 @@ function Shift_delete_by_psid($shift_psid) */ function Shift_delete($shift_id) { - DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]); mail_shift_delete(Shift($shift_id)); + DB::delete('DELETE FROM `Shifts` WHERE `SID`=?', [$shift_id]); } /** diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index 7b766c5e..c450d901 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -121,6 +121,41 @@ function UserWorkLog_create($userWorkLog) 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 * -- cgit v1.3.1 From 85e440339267859f9d3f70183c32f9443ca9a27a Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 7 Sep 2019 01:44:15 +0200 Subject: Rooms: Save times as Worklog and notify on room deletion --- includes/model/Shifts_model.php | 7 +++++-- includes/pages/admin_rooms.php | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'includes/model') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 2408eb49..01295fbc 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -80,12 +80,15 @@ function Shifts_from_frab() } /** - * @param array $room + * @param array|int $room * @return array[] */ function Shifts_by_room($room) { - return DB::select('SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', [$room['RID']]); + return DB::select( + 'SELECT * FROM `Shifts` WHERE `RID`=? ORDER BY `start`', + [is_array($room) ? $room['RID'] : $room] + ); } /** diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index bc0eb651..c55eb227 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -179,9 +179,16 @@ function admin_rooms() ]); } elseif ($request->input('show') == 'delete') { if ($request->hasPostData('ack')) { + $shifts = Shifts_by_room($room_id); + foreach ($shifts as $shift) { + $shift = Shift($shift['SID']); + + UserWorkLog_from_shift($shift); + mail_shift_delete($shift); + } + Room_delete($room_id); - engelsystem_log('Room deleted: ' . $name); success(sprintf(__('Room %s deleted.'), $name)); redirect(page_link_to('admin_rooms')); } -- cgit v1.3.1 From 4154e97f3ffa6ecbbf8f6228599742cd23001f95 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 13 Oct 2019 20:28:34 +0200 Subject: Deleted shift: Multiply with night shifts multiplier for worklog entry --- includes/model/UserWorkLog_model.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'includes/model') diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index c450d901..cc7686cf 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -127,6 +127,7 @@ function UserWorkLog_create($userWorkLog) function UserWorkLog_from_shift($shift) { $shift = is_array($shift) ? $shift : Shift($shift); + $nightShifts = config('night_shifts'); if ($shift['start'] > time()) { return; @@ -137,12 +138,26 @@ function UserWorkLog_from_shift($shift) if ($entry['freeloaded']) { continue; } + $type = AngelType($entry['TID']); + $nightShiftMultiplier = 1; + $shiftStart = Carbon::createFromTimestamp($shift['start']); + $shiftEnd = Carbon::createFromTimestamp($shift['end']); + if ( + $nightShifts['enabled'] + && ( + $shiftStart->hour >= $nightShifts['start'] && $shiftStart->hour < $nightShifts['end'] + || $shiftEnd->hour >= $nightShifts['start'] && $shiftEnd->hour < $nightShifts['end'] + ) + ) { + $nightShiftMultiplier = $nightShifts['multiplier']; + } + UserWorkLog_create([ 'user_id' => $entry['UID'], 'work_timestamp' => $shift['start'], - 'work_hours' => ($shift['end'] - $shift['start']) / 60 / 60, + 'work_hours' => (($shift['end'] - $shift['start']) / 60 / 60) * $nightShiftMultiplier, 'comment' => sprintf( '%s (%s as %s) in %s, %s-%s', $shift['name'], -- cgit v1.3.1