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"); $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 "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); $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]; $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->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, ";"); $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->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, ";"); $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->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) { $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 || $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]['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['musthours'] = $timerecording['musttime']; $data['overtime50'] = $timerecording['overtimes']['O50pfl']; $data['overtime50free'] = $timerecording['overtimes']['O50free']; $data['overtime100'] = $timerecording['overtimes']['O100pfl']; $data['overtime100free'] = $timerecording['overtimes']['O100free']; $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 ($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(); } } $response['state'] = "success"; echo json_encode($response); die(); } }