needlogin = true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me", $me); if (!$me->can(["Fibu"])) { $this->redirect("Dashboard"); } } protected function indexAction() { $startdate = 1709254800; $today = time(); $months = []; $month = $startdate; while ($month < $today) { $months[] = date("m.Y", $month); $month = strtotime("+1 month", $month); } $timerecordingBillings = TimerecordingBillingModel::getAll(); foreach ($timerecordingBillings as $timerecordingBilling) { $timerecordingbillings[$timerecordingBilling->month] = $timerecordingBilling; echo $timerecordingBilling->month; } $this->layout()->set("months", $months); $this->layout()->set("timerecordingbillings", $timerecordingbillings); $this->layout()->setTemplate("TimerecordingBilling/Index"); } protected function overviewAction() { $timerecordingBillings = TimerecordingBillingModel::getAll(); $timerecordingBillingsEmployees = TimerecordingBillingEmployeeModel::getAllOrderbyNameDate(); $timerecordingemployees = TimerecordingEmployeeModel::getAll(); $enddate = strtotime("01." . '12.2024'); $enddate = strtotime("last day of this month", $enddate); $enddate = strtotime("23:59:59", $enddate); foreach ($timerecordingemployees as $timerecordingemployee) { $holidays[$timerecordingemployee->user_id] = $this->getholidays($timerecordingemployee->user_id, $enddate); } $this->layout()->setTemplate("TimerecordingBilling/Overview"); $this->layout()->set("timerecordingbillings", $timerecordingBillings); $this->layout()->set("timerecordingbillingsemployees", $timerecordingBillingsEmployees); $this->layout()->set("holidays", $holidays); } protected function detailClosedAction($timerecordingBilling) { $r = $this->request; $month = $r->get("month"); $month = strtotime("01." . $month); $timerecordings = TimerecordingBillingEmployeeModel::search(["timerecordingBilling_id" => $timerecordingBilling[0]->id]); $this->layout()->setTemplate("TimerecordingBilling/DetailClosed"); $this->layout()->set("month", date("m.Y", $month)); $this->layout()->set("timerecordings", $timerecordings); } protected function detailAction() { $r = $this->request; $month = $r->get("month"); $monthstart = strtotime("01." . $month); $monthend = strtotime("last day of this month", $monthstart); if (!$month) { $this->redirect("TimerecordingBilling"); } $timerecordingBilling = TimerecordingBillingModel::search(["month" => $month]); if ($timerecordingBilling) { $this->detailclosedAction($timerecordingBilling); } else { $month = strtotime("01." . $month); $timerecordingsEmolyees = TimerecordingEmployeeModel::getAll(); $timerecordingReport = new TimerecordingReportController(); foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) { if ($timerecordingsEmolyee->bmd_active == 0 || $timerecordingsEmolyee->startdate > $monthend || ($timerecordingsEmolyee->enddate && $timerecordingsEmolyee->enddate < $monthstart)) continue; $user = new User($timerecordingsEmolyee->user_id); $employee_number = (string)$user->getFlag('employee_number'); $timerecordings[$timerecordingsEmolyee->user_id]['user_id'] = $timerecordingsEmolyee->user_id; $timerecordings[$timerecordingsEmolyee->user_id]['user_name'] = $timerecordingsEmolyee->user->name; $timerecordings[$timerecordingsEmolyee->user_id]['employee_number'] = $employee_number; $timerecordings[$timerecordingsEmolyee->user_id]['data'] = $timerecordingReport->getTimerecordingsTimes('2', $month, $month, $month, $timerecordingsEmolyee->user_id, 0); } $this->layout()->set("timerecordings", $timerecordings); $this->layout()->setTemplate("TimerecordingBilling/Detail"); $this->layout()->set("month", date("m.Y", $month)); } } protected function apiAction() { $do = $this->request->do; $month = $this->request->month; $data = []; switch ($do) { case "generatebmdexport": $return = $this->generateBmdExport($month); break; case "generatebmdexportnlz": $return = $this->generateBmdExport($month, 1); break; case "generateopenworkdays": $return = $this->generateopenworkdays($month); break; case "generateworkdaysdetail": $return = $this->generateworkdaysdetail($month); break; case "generatebmdexportclosed": $return = $this->generateBmdExportClosed($month); break; case "generatebmdexportnlzclosed": $return = $this->generateBmdExportClosed($month, 1); break; case "completemonth": $return = $this->completemonth($month); break; case "abortmonth": $return = $this->abortmonth($month); break; case "saveovertime": $return = $this->saveovertime(); break; default: $return = false; } if (!is_array($return) || !count($return)) { $data = ["status" => "error"]; $this->returnJson($data); } $data['status'] = "OK"; $data['result'] = $return; $this->returnJson($data); } protected function addAction() { } protected function editAction() { } protected function saveAction() { $r = $this->request; $id = $r->id; //var_dump($r->get());exit; if (is_numeric($id) && $id > 0) { $mode = "edit"; $timerecordingbillings = new TimerecordingBilling($id); if (!$timerecordingbillings->id) { $this->layout()->setFlash("Timerecording nicht gefunden", "error"); $this->redirect("TimerecordingBilling"); } } else { $mode = "add"; } $data = []; $data['month'] = trim($r->month); $data['closetime'] = time(); if (!$data['month']) { $data['month'] = NULL; } if (!$data['closetime']) { $data['closetime'] = NULL; } // var_dump($_FILES); // var_dump($upload); // exit; if ($mode == "edit") { $timerecordingbillings->update($data); } else { $timerecordingbillings = TimerecordingBillingModel::create($data); } // var_dump($filestore); // exit; $id = $timerecordingbillings->save(); if (!$id) { $this->layout()->setFlash("Timerecording konnte nicht angelegt werden", "error"); $this->redirect("TimerecordingBilling"); } if ($mode == "edit") { // $this->layout()->setFlash("Timerecording erfolgreich geändert", "success"); } else if ($mode = "add") { // $this->layout()->setFlash("Timerecording erfolgreich angelegt", "success"); } return $id; } protected function deleteAction() { $id = $this->request->id; $timerecordingbillings = new TimerecordingBilling($id); if (!$timerecordingbillings->id || $timerecordingbillings->id != $id) { $this->layout()->setFlash("Timerecording nicht gefunden.", "error"); $this->redirect("TimerecordingBilling"); } $timerecordingbillings->delete(); $this->redirect("TimerecordingBilling"); } protected function generateBmdLine() { } protected function generateBmdExportClosed($month, $nlz = 0) { $filename = "import_bmd_" . $month . ".csv"; $file = fopen("php://output", 'w'); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $filename); $monthunix = (strtotime("01." . $month)); $monthbmd = date("n", $monthunix); $monthend = date("d.m.Y", strtotime("last day of this month", $monthunix)); $companybmd = "1"; if ($nlz == 0) { $headerarray = ["Monat", "Firma", "Mitarbeiter", "Lohnart", "Menge", "Satz", "Betrag", "Kostenstelle", "NLZ-Kennzeichen", "NLZ Von-Datum", "NLZ Bis-Datum"]; fputcsv($file, $headerarray, ";"); } else { $headerarray = ["Firma", "Mitarbeiter", "DV-Nr", "Art", "Sonderzeit", "Verarbeitungs-KZ", "Von", "Bis", "Verwaltung", "Bezahlt"]; fputcsv($file, $headerarray, ";"); } $billing = TimerecordingBillingModel::search(["month" => $month]); $timerecordingBillingEmployees = TimerecordingBillingEmployeeModel::search(["timerecordingBilling_id" => $billing[0]->id]); foreach ($timerecordingBillingEmployees as $timerecordingBillingEmployee) { if ($timerecordingBillingEmployee->timerecordingEmployee->bmd_active == 0) continue; $user = new User($timerecordingBillingEmployee->timerecordingEmployee->user_id); $employee_number = (string)$user->getFlag('employee_number'); $employeetypesbmd = TimerecordingEmployeeModel::$employeetypesbmd; $employee_type = $employeetypesbmd[$timerecordingBillingEmployee->timerecordingEmployee->type]; $overtimebase = 0; $plushoursbase = 0; if ($nlz == 0) { $hours = $timerecordingBillingEmployee->ishours / 3600; $hours = round($hours, 2); $hours = str_replace(".", ",", $hours); if ($hours > 0) { $bodyarray = [$monthbmd, "1", $employee_number, $employee_type, $hours, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($timerecordingBillingEmployee->night_allowance > 0) { $nightAllowance = $timerecordingBillingEmployee->night_allowance / 3600; $nightAllowance = round($nightAllowance, 2); $nightAllowance = str_replace(".", ",", $nightAllowance); $bodyarray = [$monthbmd, $companybmd, $employee_number, "4080", $nightAllowance, "", '', "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($timerecordingBillingEmployee->plushours25 > 0) { $plushours25 = $timerecordingBillingEmployee->plushours25 / 3600; $plushours25 = round($plushours25, 2); $plushoursbase = $plushoursbase + $plushours25; $plushours25 = str_replace(".", ",", $plushours25); $bodyarray = [$monthbmd, "1", $employee_number, "3050", $plushours25, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($timerecordingBillingEmployee->overtime50free > 0) { $overtime50free = $timerecordingBillingEmployee->overtime50free / 3600; $overtime50free = round($overtime50free, 2); $overtimebase = $overtimebase + $overtime50free; if ($timerecordingBillingEmployee->overtime50free > 64800) { $bodyarray = [$monthbmd, "1", $employee_number, "3110", "18", "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); if ($timerecordingBillingEmployee->jobbike == 1) { $bodyarray = [$monthbmd, "1", $employee_number, "3115", "18", "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); $bodyarray = [$monthbmd, "1", $employee_number, "3116", "18", "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } $diffsum = $timerecordingBillingEmployee->overtime50free - 64800; $diffsum = $diffsum / 3600; $diffsum = round($diffsum, 2); $diffsum = str_replace(".", ",", $diffsum); $bodyarray = [$monthbmd, "1", $employee_number, "3120", $diffsum, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } else { $overtime50free = str_replace(".", ",", $overtime50free); $bodyarray = [$monthbmd, "1", $employee_number, "3110", $overtime50free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); if ($timerecordingBillingEmployee->jobbike == 1) { $bodyarray = [$monthbmd, "1", $employee_number, "3115", $overtime50free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); $bodyarray = [$monthbmd, "1", $employee_number, "3116", $overtime50free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } } } if ($timerecordingBillingEmployee->overtime100free > 0) { $overtime100free = $timerecordingBillingEmployee->overtime100free / 3600; $overtime100free = round($overtime100free, 2); $overtimebase = $overtimebase + $overtime100free; $overtime100free = str_replace(".", ",", $overtime100free); if ($timerecordingBillingEmployee->overtime100free > 64800) { $bodyarray = [$monthbmd, "1", $employee_number, "3160", "18", "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); if ($timerecordingBillingEmployee->jobbike == 1) { $bodyarray = [$monthbmd, "1", $employee_number, "3165", "18", "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); $bodyarray = [$monthbmd, "1", $employee_number, "3166", "18", "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } $diffsum = $timerecordingBillingEmployee->overtime100free - 64800; $diffsum = $diffsum / 3600; $diffsum = round($diffsum, 2); $diffsum = str_replace(".", ",", $diffsum); $bodyarray = [$monthbmd, "1", $employee_number, "3150", $diffsum, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } else { $bodyarray = [$monthbmd, "1", $employee_number, "3160", $overtime100free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); if ($timerecordingBillingEmployee->jobbike == 1) { $bodyarray = [$monthbmd, "1", $employee_number, "3165", $overtime100free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); $bodyarray = [$monthbmd, "1", $employee_number, "3166", $overtime100free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } } } if ($timerecordingBillingEmployee->overtime100 > 0) { $overtime100 = $timerecordingBillingEmployee->overtime100 / 3600; $overtime100 = round($overtime100, 2); $overtimebase = $overtimebase + $overtime100; $overtime100free = str_replace(".", ",", $overtime100); $bodyarray = [$monthbmd, "1", $employee_number, "3150", $overtime100, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($overtimebase > 0) { $overtimebase = str_replace(".", ",", $overtimebase); $bodyarray = [$monthbmd, "1", $employee_number, "3100", $overtimebase, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($plushoursbase > 0) { $plushoursbase = str_replace(".", ",", $plushoursbase); $bodyarray = [$monthbmd, "1", $employee_number, "3000", $plushoursbase, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($timerecordingBillingEmployee->homeoffice > 0) { $homeoffice = $timerecordingBillingEmployee->homeoffice; $homeoffice = round($homeoffice, 2); $homeoffice = str_replace(".", ",", $homeoffice); $bodyarray = [$monthbmd, "1", $employee_number, "7590", $homeoffice, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } } else { if ($timerecordingBillingEmployee->nlz_detail) { foreach (json_decode($timerecordingBillingEmployee->nlz_detail, true) as $nlztime) { if ($nlztime['categoryshort'] != "99") { $bodyarray = [$companybmd, $employee_number, 1, $nlztime['categoryshort'], $nlztime['catExtended'], "3", $nlztime['start'], $nlztime['end'], $nlztime['time'], $nlztime['pay']]; fputcsv($file, $bodyarray, ";"); } } } if ($timerecordingBillingEmployee->holidays > 0) { //last day of month $bodyarray = [$companybmd, $employee_number, 1, "1", "", "4", $monthend, $monthend, $timerecordingBillingEmployee->holidays, '0']; fputcsv($file, $bodyarray, ";"); } } if ($timerecordingBillingEmployee->diet > 0 && $nlz == 0) { $dietsum = round($timerecordingBillingEmployee->diet, 2); $dietsum = str_replace(".", ",", $dietsum); $bodyarray = [$monthbmd, $companybmd, $employee_number, "2500", "", "", $dietsum, "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } } fclose($file); 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 generateworkdaysdetail($month) { // Aktiviert das 1904-Datumssystem global für dieses Script, um negative Zeiten zu unterstützen \PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar(\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904); $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $headerarray = ["Monat", "Mitarbeiter", "Datum", "Soll", "Ist", "Differenz"]; $column = 'A'; foreach ($headerarray as $header) { $sheet->setCellValue($column . '1', $header); $column++; } $month_start = strtotime("01." . $month); $month_end = strtotime("last day of this month", $month_start); $month_end = strtotime("23:59:59", $month_end); $daycount = date("t", $month_start); $holidays = TimerecordingHolidayModel::getAll(); $holiDay = []; foreach ($holidays as $holiday) { $holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp; } $rowIdx = 2; $timerecordingsEmployees = TimerecordingEmployeeModel::getAll(); foreach ($timerecordingsEmployees as $timerecordingsEmployee) { if ($timerecordingsEmployee->bmd_active == 0 || $timerecordingsEmployee->startdate > $month_end || ($timerecordingsEmployee->enddate && $timerecordingsEmployee->enddate < $month_start)) continue; $user = new User($timerecordingsEmployee->user_id); $user_id = $user->id; // Schedule $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $user_id]); $userWorkingHours = []; foreach ($workinghours as $wh) { if (!isset($userWorkingHours[$wh->day])) $userWorkingHours[$wh->day] = 0; $userWorkingHours[$wh->day] += (strtotime("2000-01-01 " . $wh->end . ":00") - strtotime("2000-01-01 " . $wh->start . ":00")); } $workinghourshistory = TimerecordingEmployeeWorkingHourHistoryModel::search(['user_id' => $user_id]); $userWorkingHoursHistory = []; if ($workinghourshistory) { $userWorkingHoursHistory[9732489200] = $userWorkingHours; foreach ($workinghourshistory as $whh) { $histWH = []; $whh_hours = json_decode($whh->workinghours, true); foreach ($whh_hours as $h) { if (!isset($histWH[$h['day']])) $histWH[$h['day']] = 0; $histWH[$h['day']] += (strtotime("2000-01-01 " . $h['end'] . ":00") - strtotime("2000-01-01 " . $h['start'] . ":00")); } $userWorkingHoursHistory[$whh->enddate] = $histWH; } ksort($userWorkingHoursHistory); } // Ist $timerecordings = TimerecordingModel::search(['user_id' => $user_id, 'start' => $month_start, 'end' => $month_end]); $istPerDay = []; foreach ($timerecordings as $tr) { $cat = $tr->timerecordingCategory; if ($cat->hourday == 1 || $cat->hourday == 7) { $day = date('Y-m-d', $tr->start); if (!isset($istPerDay[$day])) $istPerDay[$day] = 0; $seconds = $tr->end - $tr->start; $istPerDay[$day] += $seconds; } else if ($cat->hourday == 6 || $cat->hourday == 10) { $day = date('Y-m-d', $tr->start); if (!isset($istPerDay[$day])) $istPerDay[$day] = 0; // Zeitausgleich/Abzug wird hier POSITIV angerechnet um das Soll zu füllen $seconds = $tr->end - $tr->start; $istPerDay[$day] += $seconds; } else if ($cat->hourday == 2 || $cat->hourday == 3) { $calcstart = max($tr->start, $month_start); $calcend = $tr->end ? min($tr->end, $month_end) : min(time(), $month_end); for ($t = $calcstart; $t <= $calcend; $t += 86400) { $dDate = date('Y-m-d', $t); if (isset($holiDay[$dDate])) continue; $dDay = date('w', $t); $activeWH = $userWorkingHours; if ($userWorkingHoursHistory) { foreach ($userWorkingHoursHistory as $whkey => $whdata) { if (strtotime(date('Y-m-d 23:59:59', $whkey)) >= $t) { $activeWH = $whdata; break; } } } if (isset($activeWH[$dDay])) { if (!isset($istPerDay[$dDate])) $istPerDay[$dDate] = 0; $istPerDay[$dDate] += $activeWH[$dDay]; } } } } // Loop Days for ($i = 0; $i < $daycount; $i++) { $t = strtotime("+$i days", $month_start); $dDate = date('Y-m-d', $t); $dDay = date('w', $t); $activeWH = $userWorkingHours; if ($userWorkingHoursHistory) { foreach ($userWorkingHoursHistory as $whkey => $whdata) { if (strtotime(date('Y-m-d 23:59:59', $whkey)) >= $t) { $activeWH = $whdata; break; } } } $soll = 0; if (!isset($holiDay[$dDate]) && $t >= $timerecordingsEmployee->startdate && (!$timerecordingsEmployee->enddate || $t <= $timerecordingsEmployee->enddate)) { $soll = $activeWH[$dDay] ?? 0; } $ist = $istPerDay[$dDate] ?? 0; if ($soll > 0 || $ist > 0) { $diff = $ist - $soll; $sheet->setCellValue('A' . $rowIdx, date("m-Y", $month_start)); $sheet->setCellValue('B' . $rowIdx, $user->name); $sheet->setCellValue('C' . $rowIdx, date("d.m.Y", $t)); // Zeitwerte als Excel-Zeit (Sekunden / 86400) $sheet->setCellValue('D' . $rowIdx, $soll / 86400); $sheet->setCellValue('E' . $rowIdx, $ist / 86400); $sheet->setCellValue('F' . $rowIdx, $diff / 86400); $rowIdx++; } } } // Styling & Formate $sheet->getStyle('A1:F1')->getFont()->setBold(true); // Zeitformat [hh]:mm für die Spalten D, E und F $sheet->getStyle('D2:F' . ($rowIdx - 1))->getNumberFormat()->setFormatCode('[hh]:mm'); foreach (range('A', 'F') as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } $filename = "workdays_detail_" . $month . ".xlsx"; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $filename . '"'); header('Cache-Control: max-age=0'); $writer = new Xlsx($spreadsheet); $writer->save('php://output'); exit; } protected function generateBmdExport($month, $nlz = 0, $export = 1) { //create and download csv file if ($export == 1) { $filename = "import_bmd_" . $month . ".csv"; $file = fopen("php://output", 'w'); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $filename); } if ($export == 1) { if ($nlz == 0) { $headerarray = ["Monat", "Firma", "Mitarbeiter", "Lohnart", "Menge", "Satz", "Betrag", "Kostenstelle", "NLZ-Kennzeichen", "NLZ Von-Datum", "NLZ Bis-Datum"]; fputcsv($file, $headerarray, ";"); } else { $headerarray = ["Firma", "Mitarbeiter", "DV-Nr", "Art", "Sonderzeit", "Verarbeitungs-KZ", "Von", "Bis", "Verwaltung", "Bezahlt"]; 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); $companybmd = "1"; $timerecordingsEmolyees = TimerecordingEmployeeModel::getAll(); foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) { 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'); $employeetypesbmd = TimerecordingEmployeeModel::$employeetypesbmd; $employee_type = $employeetypesbmd[$timerecordingsEmolyee->type]; $timerecordingReport = new TimerecordingReportController(); $timerecording = $timerecordingReport->getTimerecordingsTimes('2', $month, $month, $month, $timerecordingsEmolyee->user_id, 0); if ($export == 0) { $reponse[$employee_number]['employee_id'] = $timerecordingsEmolyee->id; $reponse[$employee_number]['user_id'] = $timerecordingsEmolyee->user_id; $reponse[$employee_number]['jobbike'] = $timerecordingsEmolyee->jobbike; $reponse[$employee_number]['homeoffice'] = $timerecording['time']['homeoffice']; $reponse[$employee_number]['istimeall'] = $timerecording['time']['isorder']; $reponse[$employee_number]['musttime'] = $timerecording['time']['mustorder']; $reponse[$employee_number]['overtimes'] = $timerecording['time']['overtimes']; } foreach ($timerecording['time']['isclean'] as $key => $value) { $hours = $value; //calc ishours in hours $hours = $hours / 3600; $hours = round($hours, 2); $hours = str_replace(".", ",", $hours); if (strpos($key, ',') !== false && $nlz == 0) { if ($export == 1) { $bodyarray = [$monthbmd, $companybmd, $employee_number, $employee_type, $hours, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } else { $reponse[$employee_number]['istime'] = $value; } } else if (strpos($key, ',') === false && $nlz == 1) { } } if ($timerecording['time']['diet'] > 0 && $nlz == 0) { $dietsum = round($timerecording['time']['diet'], 2); if ($export == 1) { $dietsum = str_replace(".", ",", $dietsum); $bodyarray = [$monthbmd, $companybmd, $employee_number, "2500", "", "", $dietsum, "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } else { $reponse[$employee_number]['diet'] = $dietsum; } } if (!empty($timerecording['time']['nlztimes']) && ($nlz == 1 || $export == 0)) { foreach ($timerecording['time']['nlztimes'] as $nlztime) { if (strtotime($nlztime['start']) < $month) { $nlztime['start'] = date("d.m.Y", $month); } if ((strtotime($nlztime['end']) + 84599) > $monthend) { $nlztime['end'] = date("d.m.Y", $monthend); } if (strpos($nlztime['categoryshort'], '6-') !== false) { $catExtended = explode("-", $nlztime['categoryshort']); $catExtended = $catExtended[1]; $nlztime['categoryshort'] = "6"; } else { $catExtended = ""; } if ($nlztime['minutes']) { $timesecounds = $nlztime['minutes']; $time = $nlztime['minutes'] / 60; $time = round($time, 2); $time = str_replace(".", ",", $time); if ($nlztime['unpaid'] == "0") { $pay = $time; } else { $pay = 0; } } else { if (empty($catExtended)) { $time = ""; $timesecounds = ""; $pay = ""; } else { //calc days from $nlztime['start'] to $nlztime['end'] $start = strtotime($nlztime['start']); $end = strtotime($nlztime['end']); $time = ($end - $start); $timesecounds = $time; $time = $time / 86400 + 1; $time = round($time, 0); if ($nlztime['unpaid'] == "0") { $pay = $time; } else { $pay = 0; } } } if ($export == 1) { $bodyarray = [$companybmd, $employee_number, 1, $nlztime['categoryshort'], $catExtended, "3", $nlztime['start'], $nlztime['end'], $time, $pay]; fputcsv($file, $bodyarray, ";"); } else { $reponse[$employee_number]['nlz'][] = array("categoryshort" => $nlztime['categoryshort'], "catExtended" => $catExtended, "start" => $nlztime['start'], "end" => $nlztime['end'], "time" => $time, "pay" => $pay); } } if ($export == 0) { $reponse[$employee_number]['daysum'] = json_encode($timerecording['time']['daysum']); } } } if ($export == 1) { fclose($file); exit; } else { return $reponse; } } protected function completemonth($month) { $id = $this->saveAction(); $enddate = strtotime("01." . $month); $enddate = strtotime("last day of this month", $enddate); $enddate = strtotime("23:59:59", $enddate); $timerecordings = $this->generateBmdExport($month, 0, 0); $timerecordingworkinghours = TimerecordingEmployeeWorkingHourModel::getAllArray(); foreach ($timerecordings as $employeenumber => $timerecording) { $timerecordingworkinghour = $timerecordingworkinghours[$timerecording['user_id']]['secondcounter']; if ($timerecordingworkinghour == 138600) { $maxplushours = 23400; } else { $maxplushours = (138600 - $timerecordingworkinghour) * 4.33; $maxplushours = round($maxplushours, 0); $maxplushours = $maxplushours + 23400; } $data = []; $data['timerecordingBilling_id'] = $id; $data['timerecordingEmployee_id'] = $timerecording['employee_id']; $data['jobbike'] = $timerecording['jobbike']; $data['musthours'] = $timerecording['musttime']; $data['overtime50'] = $timerecording['overtimes']['O50pfl']; $data['overtime50free'] = $timerecording['overtimes']['O50free']; $data['overtime100'] = $timerecording['overtimes']['O100pfl']; $data['overtime100free'] = $timerecording['overtimes']['O100free']; $data['night_allowance'] = $timerecording['overtimes']['nightAllowance']; $data['transfer_plushours'] = $timerecording['overtimes']['Osum']; $diff = $timerecording['istimeall'] - $timerecording['musttime']; if ($diff > $maxplushours) { $data['overtime50free'] = $data['overtime50free'] + ($diff - $maxplushours); $data['transfer_plushours'] = $data['transfer_plushours'] + ($diff - $maxplushours); } $data['transfer_plushours'] = $data['transfer_plushours'] - $data['overtime50free']; $data['overtime_plushours'] = $data['overtime50free']; $data['overtime50free'] = 0; if ($data['transfer_plushours'] > 0) { $timerecordingEmployee = new TimerecordingEmployee($timerecording['employee_id']); $dataemployee = []; $dataemployee['plushours_now'] = $timerecordingEmployee->plushours_now - $data['transfer_plushours']; $dataemployee['plushours'] = $timerecordingEmployee->plushours - $data['transfer_plushours']; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } $timerecordingController = new TimerecordingController(); $plushours = $timerecordingController->updatePlushours($timerecording['user_id'], $enddate); $data['plushours_all'] = $plushours['plushours']; if ($timerecording['istime']) { $data['ishours'] = $timerecording['istime']; } else { $data['ishours'] = 0; } $data['ishourssum'] = $timerecording['istimeall']; $data['diet'] = $timerecording['diet']; if ($timerecording['nlz']) { $data['nlz_detail'] = json_encode($timerecording['nlz']); } if ($timerecording['daysum']) { $data['nlz'] = $timerecording['daysum']; if (strpos($data['nlz'], "Urlaub aufbuchen") !== false) { $holidays = $this->getholidays($timerecording['user_id'], $enddate); $data['holidays'] = $holidays; } } if ($timerecording['homeoffice']) { $data['homeoffice'] = $timerecording['homeoffice']; } if (!$data['diet']) { $data['diet'] = 0; } $timerecordingbillingemployee = TimerecordingBillingEmployeeModel::create($data); $timerecordingbillingemployee->save(); } $result['state'] = "success"; echo json_encode($result); die(); } protected function abortmonth($month) { $timerecordingBilling = TimerecordingBillingModel::search(["month" => $month]); $timerecordingBillingEmployees = TimerecordingBillingEmployeeModel::search(["timerecordingBilling_id" => $timerecordingBilling[0]->id]); foreach ($timerecordingBillingEmployees as $timerecordingBillingEmployee) { $timerecordingEmployee = new TimerecordingEmployee($timerecordingBillingEmployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['plushours_now'] = $timerecordingEmployee->plushours_now + $timerecordingBillingEmployee->transfer_plushours; $dataemployee['plushours'] = $timerecordingEmployee->plushours + $timerecordingBillingEmployee->transfer_plushours; $dataemployee['overtime_now'] = $timerecordingEmployee->overtime_now + $timerecordingBillingEmployee->transfer_overtime; $dataemployee['overtime'] = $timerecordingEmployee->overtime + $timerecordingBillingEmployee->transfer_overtime; $dataemployee['bpahours'] = $timerecordingEmployee->bpahours + $timerecordingBillingEmployee->transfer_bpahours; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } $timerecordingBilling[0]->delete(); $result['state'] = "success"; echo json_encode($result); die(); } protected function saveovertime() { $id = $this->request->id; $type = $this->request->type; $timerecordingbillingsemployee = new TimerecordingBillingEmployee($id); if ($type == "overtime") { $sum = 0; $data = []; if ($this->request->overtime50) { $data['overtime50free'] = $timerecordingbillingsemployee->overtime50free + $this->request->overtime50 * 3600; $sum += $this->request->overtime50 * 3600; } if ($this->request->overtime100) { $data['overtime100free'] = $timerecordingbillingsemployee->overtime100free + $this->request->overtime100 * 3600; $sum += $this->request->overtime100 * 3600; } if ($this->request->overtimebpa) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['bpahours'] = $timerecordingEmployee->bpahours + $this->request->overtimebpa * 3600; $data['transfer_bpahours'] = $timerecordingbillingsemployee->transfer_bpahours - $this->request->overtimebpa * 3600; $sum += $this->request->overtimebpa * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($data) { $data['transfer_overtime'] = $timerecordingbillingsemployee->transfer_overtime + $sum; $timerecordingbillingsemployee->update($data); $timerecordingbillingsemployee->save(); $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['overtime_now'] = $timerecordingEmployee->overtime_now - $sum; $dataemployee['overtime'] = $timerecordingEmployee->overtime - $sum; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } } else if ($type == "difference") { $sum = 0; $data = []; if ($this->request->plushours25) { $data['plushours25'] = $timerecordingbillingsemployee->plushours25 + $this->request->plushours25 * 3600; $sum += $this->request->plushours25 * 3600; } if ($this->request->overtime50) { $data['overtime50free'] = $timerecordingbillingsemployee->overtime50free + $this->request->overtime50 * 3600; $sum += $this->request->overtime50 * 3600; } if ($this->request->overtime100) { $data['overtime100free'] = $timerecordingbillingsemployee->overtime100free + $this->request->overtime100 * 3600; $sum += $this->request->overtime100 * 3600; } if ($this->request->overtimebpa) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['bpahours'] = $timerecordingEmployee->bpahours + $this->request->overtimebpa * 3600; $data['transfer_bpahours'] = $timerecordingbillingsemployee->transfer_bpahours - $this->request->overtimebpa * 3600; $sum += $this->request->overtimebpa * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($this->request->overtimehours) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['overtime_now'] = $timerecordingEmployee->overtime_now + $this->request->overtimehours * 3600; $dataemployee['overtime'] = $timerecordingEmployee->overtime + $this->request->overtimehours * 3600; $data['transfer_overtime'] = $timerecordingbillingsemployee->transfer_overtime - $this->request->overtimehours * 3600; $sum += $this->request->overtimehours * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($sum > 0) { $data['transfer_plushours'] = $timerecordingbillingsemployee->transfer_plushours + $sum; $data['plushours_all'] = $timerecordingbillingsemployee->plushours_all - $sum; $timerecordingbillingsemployee->update($data); $timerecordingbillingsemployee->save(); $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['plushours_now'] = $timerecordingEmployee->plushours_now - $sum; $dataemployee['plushours'] = $timerecordingEmployee->plushours - $sum; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } } else if ($type == "bpa") { $sum = 0; $data = []; if ($this->request->plushours) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['plushours_now'] = $timerecordingEmployee->plushours_now + $this->request->plushours * 3600; $dataemployee['plushours'] = $timerecordingEmployee->plushours + $this->request->plushours * 3600; $data['transfer_plushours'] = $timerecordingbillingsemployee->transfer_plushours - $this->request->plushours * 3600; $data['plushours_all'] = $timerecordingbillingsemployee->plushours_all + $this->request->plushours * 3600; $sum += $this->request->plushours * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($this->request->overtimehours) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['overtime_now'] = $timerecordingEmployee->overtime_now + $this->request->overtimehours * 3600; $dataemployee['overtime'] = $timerecordingEmployee->overtime + $this->request->overtimehours * 3600; $data['transfer_overtime'] = $timerecordingbillingsemployee->transfer_overtime - $this->request->overtimehours * 3600; $sum += $this->request->overtimehours * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($data) { $data['transfer_bpahours'] = $timerecordingbillingsemployee->transfer_bpahours + $sum; $timerecordingbillingsemployee->update($data); $timerecordingbillingsemployee->save(); $dataemployee = []; $dataemployee['bpahours'] = $timerecordingEmployee->bpahours - $sum; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } } else if ($type == "plushours25" || $type == "overtime50free" || $type == "overtime100free") { $sum = 0; $data = []; if ($this->request->plushours) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['plushours_now'] = $timerecordingEmployee->plushours_now + $this->request->plushours * 3600; $dataemployee['plushours'] = $timerecordingEmployee->plushours + $this->request->plushours * 3600; $data['transfer_plushours'] = $timerecordingbillingsemployee->transfer_plushours - $this->request->plushours * 3600; $data['plushours_all'] = $timerecordingbillingsemployee->plushours_all + $this->request->plushours * 3600; $sum += $this->request->plushours * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($this->request->overtimehours) { $timerecordingbillingsemployee->timerecordingEmployee->id; $timerecordingEmployee = new TimerecordingEmployee($timerecordingbillingsemployee->timerecordingEmployee->id); $dataemployee = []; $dataemployee['overtime_now'] = $timerecordingEmployee->overtime_now + $this->request->overtimehours * 3600; $dataemployee['overtime'] = $timerecordingEmployee->overtime + $this->request->overtimehours * 3600; $data['transfer_overtime'] = $timerecordingbillingsemployee->transfer_overtime - $this->request->overtimehours * 3600; $sum += $this->request->overtimehours * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($data) { $data[$type] = $timerecordingbillingsemployee->{$type} - $sum; $timerecordingbillingsemployee->update($data); $timerecordingbillingsemployee->save(); } } $response['state'] = "success"; echo json_encode($response); die(); } protected function getholidays($userid, $enddate) { // $enddate = strtotime("01." . '12.2024'); // $enddate = strtotime("last day of this month", $enddate); // $enddate = strtotime("23:59:59", $enddate); $employee = TimerecordingEmployeeModel::search(['user_id' => $userid]); if ($employee) { $employee = $employee[0]; $holidays = $employee->holidays; $holidays_now = $employee->holidays_now; $holidays_timestamp = $employee->holidays_timestamp; $workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $userid]); $realHolidays = TimerecordingHolidayModel::getAll(); foreach ($realHolidays as $realHoliday) { $realholiDay[date('Y-m-d', $realHoliday->timestamp)] = $realHoliday->timestamp; } if (!$holidays_timestamp) { //$holidays_timestamp = $employee->startdate; $holidays_timestamp = strtotime('2024-01-01 00:00:00'); $holidays_now = $holidays; } $timerecordings = TimerecordingModel::search(['user_id' => $userid, 'start' => $holidays_timestamp, 'timerecordingCategory_id' => 3]); $timerecordingscorrections = TimerecordingModel::search(['user_id' => $userid, 'start' => $holidays_timestamp, 'endsdate' => $enddate, 'days' => 1]); foreach ($timerecordings as $timerecording) { if ($timerecording->end > $enddate) { $timerecording->end = $enddate; } $daycounter = ($timerecording->end - $timerecording->start) / 86400; $daycounter = intval(round($daycounter, 0, PHP_ROUND_HALF_DOWN)); $daycounter = $daycounter * 86400; if (is_int($daycounter)) { for ($i = 86400; $i <= $daycounter; $i = $i + 86400) { $holidayDays[date("Y-m-d", $timerecording->start + $i - 86400)] = 1; } } } 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' => $userid]); if ($workinghourshistory) { $workingHoursHistory[2147483500] = $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; } } } } //check if holiday is already in the list foreach ($holidayDays as $key => $holidayDay) { if ($workingHoursHistory) { foreach ($workingHoursHistory as $whkey => $whdata) { $whtimestamp = strtotime(date('Y-m-d 23:59:59', $whkey)); $timestamp = strtotime($key); if ($whtimestamp >= $timestamp) { $workingHours = $whdata; } } } if (($realholiDay[$key])) { } else if ($workingHours[date('w', strtotime($key))]) { $holidays_now--; } } foreach ($timerecordingscorrections as $timerecordingscorrection) { $holidays_now = $holidays_now + $timerecordingscorrection->days; } } 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; } }