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 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"); if (!$month) { $this->redirect("TimerecordingBilling"); } $timerecordingBilling = TimerecordingBillingModel::search(["month" => $month]); if ($timerecordingBilling) { $this->detailclosedAction($timerecordingBilling); } else { $month = strtotime("01." . $month); $timerecordingsEmolyees = TimerecordingEmployeeModel::getAll(); foreach ($timerecordingsEmolyees as $timerecordingsEmolyee) { if ($timerecordingsEmolyee->bmd_active == 0) continue; $user = new User($timerecordingsEmolyee->user_id); $employee_number = (string)$user->getFlag('employee_number'); $timerecordingReport = new TimerecordingReportController(); $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 "generatebmdexportclosed": $return = $this->generateBmdExportClosed($month); break; case "generatebmdexportnlzclosed": $return = $this->generateBmdExportClosed($month, 1); break; case "completemonth": $return = $this->completemonth($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); $monthbmd = date("n", strtotime("01." . $month)); $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]; 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->overtime50free > 0) { $overtime50free = $timerecordingBillingEmployee->overtime50free / 3600; $overtime50free = round($overtime50free, 2); $overtime50free = str_replace(".", ",", $overtime50free); $bodyarray = [$monthbmd, "1", $employee_number, "3110", $overtime50free, "", "", "", "", "", ""]; fputcsv($file, $bodyarray, ";"); } if ($timerecordingBillingEmployee->overtime100free > 0) { $overtime100free = $timerecordingBillingEmployee->overtime100free / 3600; $overtime100free = round($overtime100free, 2); $overtime100free = str_replace(".", ",", $overtime100free); $bodyarray = [$monthbmd, "1", $employee_number, "3150", $overtime100free, "", "", "", "", "", ""]; 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) { $bodyarray = [$companybmd, $employee_number, 1, $nlztime['categoryshort'], $nlztime['catExtended'], "3", $nlztime['start'], $nlztime['end'], $nlztime['time'], $nlztime['pay']]; 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 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) 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]['homeoffice'] = $timerecording['time']['homeoffice']; $reponse[$employee_number]['istimeall'] = $timerecording['time']['isorder']; $reponse[$employee_number]['musttime'] = $timerecording['time']['mustorder']; } 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(); $user = new User($timerecordingsEmolyee->user_id); $employee_number = (string)$user->getFlag('employee_number'); $timerecordings = $this->generateBmdExport($month, 0, 0); foreach ($timerecordings as $employeenumber => $timerecording) { $data = []; $data['timerecordingBilling_id'] = $id; $data['timerecordingEmployee_id'] = $timerecording['employee_id']; $data['musthours'] = $timerecording['musttime']; 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 ($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 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; $sum += $this->request->overtimebpa * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($data) { $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->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; $sum += $this->request->overtimebpa * 3600; $timerecordingEmployee->update($dataemployee); $timerecordingEmployee->save(); } if ($sum > 0) { $data['ishourssum'] = $timerecordingbillingsemployee->ishourssum - $sum; $timerecordingbillingsemployee->update($data); $timerecordingbillingsemployee->save(); } } $response['state'] = "success"; echo json_encode($response); die(); } }