From 5ddca458201d56d73fcc5ed4a58ff48d8cbb47f7 Mon Sep 17 00:00:00 2001 From: Daniel Spitzer Date: Mon, 3 Mar 2025 14:52:25 +0100 Subject: [PATCH] Zeiterfassung neues Feature: * Auswertungen nicht bebuchter Arbeitstage --- .../default/TimerecordingBilling/Detail.php | 6 + .../Timerecording/TimerecordingController.php | 83 ++++++------ .../TimerecordingBillingController.php | 128 +++++++++++++++++- public/assets/js/datatables-std2.js | 1 + 4 files changed, 178 insertions(+), 40 deletions(-) diff --git a/Layout/default/TimerecordingBilling/Detail.php b/Layout/default/TimerecordingBilling/Detail.php index 0ba37dd81..2aca0e0d8 100644 --- a/Layout/default/TimerecordingBilling/Detail.php +++ b/Layout/default/TimerecordingBilling/Detail.php @@ -142,6 +142,12 @@ $('body').on('click', '#bmd-export-nlz', function () { window.open(' 'generatebmdexportnlz']) ?>&month=' + $('#month').data('month'), '_blank'); }); + $('body').on('click', '#open-workdays', function () { + window.open(' 'generateopenworkdays']) ?>&month=' + $('#month').data('month'), '_blank'); + }); + + + $('body').on('click', '#month-complete', function () { if (confirm('Monat ' + $('#month').data('month') + ' wirklich abschließen?')) { $('#datatable_wrapper').hide(); diff --git a/application/Timerecording/TimerecordingController.php b/application/Timerecording/TimerecordingController.php index e1446ab49..c93dc6e9c 100644 --- a/application/Timerecording/TimerecordingController.php +++ b/application/Timerecording/TimerecordingController.php @@ -263,7 +263,7 @@ class TimerecordingController extends mfBaseController { $r = $this->request; $id = $r->id; - $oldbpseconds=0; + $oldbpseconds = 0; $enddate = $r->enddate; $hourday = $r->hourday; @@ -530,7 +530,7 @@ class TimerecordingController extends mfBaseController } $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $userid]); if ($workinghourshistory) { - $workingHoursHistory[2147483500]=$workingHours; + $workingHoursHistory[2147483500] = $workingHours; foreach ($workinghourshistory as $workinghourhistory) { $whenddate = $workinghourhistory->enddate; $workinghourhistoryhours = json_decode($workinghourhistory->workinghours, true); @@ -547,13 +547,11 @@ class TimerecordingController extends mfBaseController } //check if holiday is already in the list foreach ($holidayDays as $key => $holidayDay) { - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); $timestamp = strtotime($key); - if ($whtimestamp >= $timestamp) - { + if ($whtimestamp >= $timestamp) { $workingHours = $whdata; } } @@ -672,7 +670,7 @@ class TimerecordingController extends mfBaseController } } - protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear, $startime = null, $endtime = null, $userid = null) + public function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear, $startime = null, $endtime = null, $userid = null, $ajax = 1) { $holidayrows = []; $mustSeconds = 0; @@ -680,7 +678,7 @@ class TimerecordingController extends mfBaseController $holiDays = 0; $plusHours = 0; $startdate = time(); - $allhours=0; + $allhours = 0; if (!$userid) { $userid = $this->me->id; } @@ -699,8 +697,8 @@ class TimerecordingController extends mfBaseController $overtime = $employee[0]->overtime_now; if ($employee[0]->only_admin) { - $getAllHours=TimerecordingModel::getAllHours($userid); - $getAllHours=$getAllHours[0]->gesamt_summe; + $getAllHours = TimerecordingModel::getAllHours($userid); + $getAllHours = $getAllHours[0]->gesamt_summe; } } $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]); @@ -718,7 +716,7 @@ class TimerecordingController extends mfBaseController $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $userid]); if ($workinghourshistory) { - $workingHoursHistory[2147483500]=$workingHours; + $workingHoursHistory[2147483500] = $workingHours; foreach ($workinghourshistory as $workinghourhistory) { $whenddate = $workinghourhistory->enddate; $workinghourhistoryhours = json_decode($workinghourhistory->workinghours, true); @@ -757,12 +755,10 @@ class TimerecordingController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); - if ($whtimestamp >= $timestamp) - { + if ($whtimestamp >= $timestamp) { unset($workingHours); $workingHours = $whdata; } @@ -792,12 +788,10 @@ class TimerecordingController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); - if ($whtimestamp >= $timestamp) - { + if ($whtimestamp >= $timestamp) { unset($workingHours); $workingHours = $whdata; } @@ -826,12 +820,10 @@ class TimerecordingController extends mfBaseController } $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); $dDay = date('w', $timestamp + $WintertimeCompensation); - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); - if ($whtimestamp >= $timestamp) - { + if ($whtimestamp >= $timestamp) { unset($workingHours); $workingHours = $whdata; } @@ -859,12 +851,10 @@ class TimerecordingController extends mfBaseController if (date('I', $timestamp) == 0) { $WintertimeCompensation = 3600; } - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); - if ($whtimestamp >= $timestamp) - { + if ($whtimestamp >= $timestamp) { unset($workingHours); $workingHours = $whdata; // echo date('Y-m-d 23:59:59', $whkey).PHP_EOL; @@ -908,6 +898,9 @@ class TimerecordingController extends mfBaseController $sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes); $day = $daysgerm[date("w", $timerecording->start)]; $isSeconds = $isSeconds + $seconds; + if ($ajax == 0) { + $workdaycheck[] = $datadate; + } } else if ($timerecording->timerecordingCategory->hourday == 2 || ($timerecording->timerecordingCategory->hourday == 3 && $timerecording->end)) { $date = date("d.m.", $timerecording->start) . " - " . $daysgerm[date("w", $timerecording->end)] . " " . date("d.m.Y", $timerecording->end); @@ -931,12 +924,10 @@ class TimerecordingController extends mfBaseController $savecounter = 0; $sumdays = 0; for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); - if ($whtimestamp >= $i) - { + if ($whtimestamp >= $i) { unset($workingHours); $workingHours = $whdata; } @@ -944,6 +935,10 @@ class TimerecordingController extends mfBaseController } $holidaycounter = $workingHours[date("w", $i)]; $daycheck = date("Y-m-d", $i); + if ($ajax == 0) { + $workdaycheck[] = $daycheck; + } + if (!$holiDay[$daycheck]) { if ($holidaycounter) { $isSeconds = $isSeconds + $holidaycounter; @@ -991,17 +986,19 @@ class TimerecordingController extends mfBaseController $savecounter = 0; // echo $starttimecalc."
"; for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) { - if ($workingHoursHistory) - { + if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); - if ($whtimestamp >= $i) - { + if ($whtimestamp >= $i) { unset($workingHours); $workingHours = $whdata; } } } + if ($ajax == 0) { + $daycheck = date("Y-m-d", $i); + $workdaycheck[] = $daycheck; + } $holidaycounter = $workingHours[$timerecording->user_id][date("w", $i)]; $daycheck = date("Y-m-d", $i); if (!$holiDay[$daycheck]) { @@ -1049,6 +1046,10 @@ class TimerecordingController extends mfBaseController $sum = "-" . sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes); $day = $daysgerm[date("w", $timerecording->start)]; $isSeconds = $isSeconds + $seconds; + if ($ajax == 0) { + $workdaycheck[] = $datadate; + } + } else if ($timerecording->timerecordingCategory->hourday == 7) { $date = date("d.m.Y", $timerecording->start); $datadate = date("Y-m-d", $timerecording->start); @@ -1164,9 +1165,15 @@ class TimerecordingController extends mfBaseController $json['data'] = $rows; $json['recordsFiltered'] = $responsecount; $json['recordsTotal'] = $responsecount; - $json = json_encode($json); - echo trim($json); - die(); + + if ($ajax == 1) { + $json = json_encode($json); + echo trim($json); + die(); + } else { + $json['workcheck'] = $workdaycheck; + return $json; + } } } diff --git a/application/TimerecordingBilling/TimerecordingBillingController.php b/application/TimerecordingBilling/TimerecordingBillingController.php index ce4b9ae42..118e0995a 100644 --- a/application/TimerecordingBilling/TimerecordingBillingController.php +++ b/application/TimerecordingBilling/TimerecordingBillingController.php @@ -107,6 +107,9 @@ class TimerecordingBillingController extends mfBaseController case "generatebmdexportnlz": $return = $this->generateBmdExport($month, 1); break; + case "generateopenworkdays": + $return = $this->generateopenworkdays($month); + break; case "generatebmdexportclosed": $return = $this->generateBmdExportClosed($month); break; @@ -383,6 +386,37 @@ class TimerecordingBillingController extends mfBaseController exit; } + protected function generateopenworkdays($month) + { + $filename = "open_workdays_" . $month . ".csv"; + $file = fopen("php://output", 'w'); + header('Content-Type: text/csv; charset=utf-8'); + header('Content-Disposition: attachment; filename=' . $filename); + $headerarray = ["Monat", "Mitarbeiter", "Tag"]; + fputcsv($file, $headerarray, ";"); + $month = strtotime("01." . $month); + //last of month + $monthend = date("Y-m-d", strtotime("last day of this month", $month)); + $monthend = strtotime($monthend . " 23:59:59"); + $monthbmd = date("n", $month); + $timerecordingsEmolyees = TimerecordingEmployeeModel::getAll(); + foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) { + unset($bodyarray); + if ($timerecordingsEmolyee->bmd_active == 0 || $timerecordingsEmolyee->startdate > $monthend || ($timerecordingsEmolyee->enddate && $timerecordingsEmolyee->enddate < $month)) continue; + $user = new User($timerecordingsEmolyee->user_id); + $employee_number = (string)$user->getFlag('employee_number'); + + $WorkingDays = $this->checkWorkingDays($user->id, $month, $timerecordingsEmolyee); + foreach ($WorkingDays as $WorkingDay) { + $bodyarray = [date("m-Y", $month), mb_convert_encoding($user->name, 'ISO-8859-1', 'UTF-8'), date("d.m.Y", strtotime($WorkingDay))]; + fputcsv($file, $bodyarray, ";"); + } + } + + fclose($file); + exit; + } + protected function generateBmdExport($month, $nlz = 0, $export = 1) { //create and download csv file @@ -606,8 +640,8 @@ class TimerecordingBillingController extends mfBaseController } if ($timerecording['daysum']) { $data['nlz'] = $timerecording['daysum']; - if (strpos($data['nlz'],"Urlaub aufbuchen") !== false) { - $holidays=$this->getholidays($timerecording['user_id'], $enddate); + if (strpos($data['nlz'], "Urlaub aufbuchen") !== false) { + $holidays = $this->getholidays($timerecording['user_id'], $enddate); $data['holidays'] = $holidays; } } @@ -879,4 +913,94 @@ class TimerecordingBillingController extends mfBaseController return $holidays_now; } + + protected function checkWorkingDays($user_id, $month, $employee) + { + $holidays = TimerecordingHolidayModel::getAll(); + $datamonth = $month; + $firstdate = strtotime(date("Y-m-01", $datamonth)); + $lastdate = strtotime(date("Y-m-t", $datamonth)); + $daycount = date("t", $datamonth); + $lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59'); + + $startdate = $employee->startdate; + if ($employee->enddate) { + $enddate = strtotime(date('Y-m-d', $employee->enddate) . " 23:59:59"); + } else { + $enddate = 2208985200; + } + $bpahours = $employee->bpahours; + + $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $user_id]); + foreach ($workinghours as $workinghour) { + + $whstart = strtotime(date('Y-m-d', time()) . " " . $workinghour->start . ":00"); + $whend = strtotime(date('Y-m-d', time()) . " " . $workinghour->end . ":00"); + if (!$workingHours[$workinghour->day]) { + $workingHours[$workinghour->day] = $whend - $whstart; + } else { + $workingHours[$workinghour->day] = $workingHours[$workinghour->day] + $whend - $whstart; + } + } + $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $user_id]); + if ($workinghourshistory) { + $workingHoursHistory[9732489200] = $workingHours; + foreach ($workinghourshistory as $workinghourhistory) { + $whenddate = $workinghourhistory->enddate; + $workinghourhistoryhours = json_decode($workinghourhistory->workinghours, true); + foreach ($workinghourhistoryhours as $workinghourhistoryhour) { + $whstart = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['start'] . ":00"); + $whend = strtotime(date('Y-m-d', time()) . " " . $workinghourhistoryhour['end'] . ":00"); + if (!$workingHoursHistory[$whenddate][$workinghourhistoryhour['day']]) { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $whend - $whstart; + } else { + $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] = $workingHoursHistory[$whenddate][$workinghourhistoryhour['day']] + $whend - $whstart; + } + } + } + } + foreach ($holidays as $holiday) { + $holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp; + } + + //Lastdate staticmust deleted +// $lastdate = strtotime("2024-03-22 23:59:59"); +// $daycount=22; + + $searchArray = ['user_id' => $user_id, 'start' => $firstdate, 'end' => $lastdate]; + $timestamp = $firstdate; + for ($i = 1; $i <= $daycount; $i++) { + $WintertimeCompensation = 0; + if (date('I', $timestamp) == 0) { + $WintertimeCompensation = 3600; + } + $dDate = date('Y-m-d', $timestamp + $WintertimeCompensation); + $dDay = date('w', $timestamp + $WintertimeCompensation); + if ($workingHoursHistory) { + foreach ($workingHoursHistory as $whkey => $whdata) { + $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); + if ($whtimestamp >= $timestamp) { + $workingHours = $whdata; + } + } + } + + if (!$holiDay[$dDate] && $dDate >= date('Y-m-d', $startdate) && $dDate <= date('Y-m-d', $enddate)) { + $mustSeconds = $mustSeconds + $workingHours[$dDay]; + if ($workingHours[$dDay]) { + $workDays[$dDate] = $dDate; + } + } + + $timestamp = $timestamp + 86400; + } + $timerecordingC = new TimerecordingController(); + $timerecordingC = $timerecordingC->getTimerecordingsApi('2', $month, $month, $month, 0, 0, $user_id, 0); + foreach ($timerecordingC['workcheck'] as $key => $value) { + unset($workDays[$value]); + } + + return $workDays; + } + } diff --git a/public/assets/js/datatables-std2.js b/public/assets/js/datatables-std2.js index 7d4fc120a..0d15ab5dd 100644 --- a/public/assets/js/datatables-std2.js +++ b/public/assets/js/datatables-std2.js @@ -89,6 +89,7 @@ table = $('#datatable').DataTable({ }); if (initc === 2) { $('.buttons-excel').closest('div').append('
'); + $('.buttons-excel').closest('div').append('
'); $('.buttons-excel').closest('div').append('
'); $('.buttons-excel').closest('div').append('
'); }