diff --git a/Layout/default/Timerecording/Index.php b/Layout/default/Timerecording/Index.php
index dc073fd1f..af5b2dcee 100644
--- a/Layout/default/Timerecording/Index.php
+++ b/Layout/default/Timerecording/Index.php
@@ -294,7 +294,7 @@ $years[time() - 31536000] = date('Y', time() - 31536000);
-
diff --git a/application/Timerecording/TimerecordingController.php b/application/Timerecording/TimerecordingController.php
index 48bf920a7..455c7579b 100644
--- a/application/Timerecording/TimerecordingController.php
+++ b/application/Timerecording/TimerecordingController.php
@@ -197,6 +197,7 @@ class TimerecordingController extends mfBaseController
} else {
$data['user_id'] = $this->me->id;
}
+
$data['start'] = $starttime;
$data['end'] = $endtime;
$data['timerecordingCategory_id'] = trim($r->timerecordingCategory_id);
@@ -289,6 +290,7 @@ class TimerecordingController extends mfBaseController
if ($data['timerecordingCategory_id'] == "3") {
$this->updateHolidays($data['user_id']);
}
+ $this->updatePlushours($data['user_id']);
}
if ($mode == "edit") {
@@ -326,7 +328,7 @@ class TimerecordingController extends mfBaseController
$timerecordings = TimerecordingModel::search(['user_id' => $userid, 'start' => $holidays_timestamp, 'timerecordingCategory_id' => 3]);
foreach ($timerecordings as $timerecording) {
$daycounter = ($timerecording->end - $timerecording->start) / 86400;
- $daycounter=intval(round($daycounter,0,PHP_ROUND_HALF_DOWN));
+ $daycounter = intval(round($daycounter, 0, PHP_ROUND_HALF_DOWN));
$daycounter = $daycounter * 86400;
if (is_int($daycounter)) {
for ($i = 86400; $i <= $daycounter; $i = $i + 86400) {
@@ -367,10 +369,35 @@ class TimerecordingController extends mfBaseController
protected function updatePlushours($userid)
{
+ $employee = TimerecordingEmployeeModel::search(['user_id' => $userid]);
+ if ($employee) {
+ $employee = $employee[0];
+ $plushours = $employee->plushours;
+ $plushours_now = $employee->plushours_now;
+ $plushours_timestamp = $employee->plushours_timestamp;
+ if (!$plushours_timestamp) {
+ $plushours_timestamp = $employee->startdate;
+ $plushours_now = $plushours;
+ }
+ $endtime = time() - 86400;
+ $endtime = date("Y-m-d", $endtime);
+ $endtime = strtotime($endtime . " 23:59:00");
+
+ $return = $this->getTimerecordingsApi(5, null, null, null, $plushours_timestamp, $endtime);
+ $diffTime = $return['is'] - $return['must'];
+ $plushours_now = $plushours_now + $diffTime;
+ if ($employee->plushours_now != $diffTime) {
+ $employeeupdate = new TimerecordingEmployee($employee->id);
+ $data = [];
+ $data['plushours_now'] = $plushours_now;
+ $employeeupdate->update($data);
+ $employeeupdate->save();
+ }
+ }
}
- protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear)
+ protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear, $startime = null, $endtime = null)
{
$mustSeconds = 0;
$isSeconds = 0;
@@ -460,6 +487,26 @@ class TimerecordingController extends mfBaseController
}
+ } else if ($datatype == 5) {
+ $firstdate = $startime;
+ $lastdate = $endtime;
+ $timediff = $lastdate - $firstdate;
+ $daycount = $timediff / 86400;
+ $daycount = round($daycount, 0, PHP_ROUND_HALF_DOWN);
+ $searchArray = ['user_id' => $this->me->id, 'start' => $firstdate, 'end' => $lastdate];
+ $timestamp = $firstdate;
+
+ for ($i = 1; $i <= $daycount; $i++) {
+ $dDate = date('Y-m-d', $timestamp);
+ $dDay = date('w', $timestamp);
+ if (!$holiDay[$dDate]) {
+ $mustSeconds = $mustSeconds + $workingHours[$dDay];
+ }
+
+ $timestamp = $timestamp + 86400;
+ }
+
+
}
@@ -601,23 +648,35 @@ class TimerecordingController extends mfBaseController
);
}
endforeach;
- $json['success'] = true;
- $json['time']['auto_workinghours'] = $auto_workinghours;
- $json['time']['is'] = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
- $json['time']['must'] = sprintf('%02dh:%02dm', floor($mustSeconds / 3600), floor($mustSeconds / 60 % 60));
- $json['time']['holidays'] = $holiDays;
- $json['time']['plushours'] = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHours / 60 % 60));
- $json['data'] = $rows;
- $json['recordsFiltered'] = $responsecount;
- $json['recordsTotal'] = $responsecount;
- $json = json_encode($json);
- echo trim($json);
- die();
+ if ($datatype == 5) {
+ $response['is'] = $isSeconds;
+ $response['must'] = $mustSeconds;
+ return $response;
+ } else {
+ if ($plusHours < 0) {
+ $plusHoursMinutes = $plusHours * -1;
+ } else {
+ $plusHoursMinutes = $plusHours;
+ }
+
+ $json['success'] = true;
+ $json['time']['auto_workinghours'] = $auto_workinghours;
+ $json['time']['is'] = sprintf('%02dh:%02dm', floor($isSeconds / 3600), floor($isSeconds / 60 % 60));
+ $json['time']['must'] = sprintf('%02dh:%02dm', floor($mustSeconds / 3600), floor($mustSeconds / 60 % 60));
+ $json['time']['holidays'] = $holiDays;
+ $json['time']['plushours'] = sprintf('%02dh:%02dm', floor($plusHours / 3600), floor($plusHoursMinutes / 60 % 60));
+ $json['data'] = $rows;
+ $json['recordsFiltered'] = $responsecount;
+ $json['recordsTotal'] = $responsecount;
+ $json = json_encode($json);
+ echo trim($json);
+ die();
+ }
}
protected function fillWorkinghours($dataweek)
{
- $dataweek = strtotime($dataweek);
+
$employee = TimerecordingEmployeeModel::search(['user_id' => $this->me->id]);
if ($employee) {
$auto_workinghours = $employee[0]->auto_workinghours;
@@ -651,7 +710,7 @@ class TimerecordingController extends mfBaseController
$daycounter = '0';
-
+ $update = false;
$timestamp = $timestamp_montag;
for ($i = 1; $i <= 7; $i++) {
$dDate = date('Y-m-d', $timestamp);
@@ -663,6 +722,7 @@ class TimerecordingController extends mfBaseController
$endtime = strtotime($dDate . " " . $workingHour['end'] . ":00");
$check = $this->checkTimerecording($starttime, $endtime);
if ($check['state'] == "success") {
+ $update = 1;
$data = [];
$data['user_id'] = $this->me->id;
$data['start'] = $starttime;
@@ -681,6 +741,10 @@ class TimerecordingController extends mfBaseController
$timestamp = $timestamp + 86400;;
}
+ if ($update) {
+ $this->updatePlushours($this->me->id);
+ $this->updateHolidays($this->me->id);
+ }
}
protected function deleteAction()
@@ -694,6 +758,7 @@ class TimerecordingController extends mfBaseController
}
$timerecordings->delete();
$this->updateHolidays($userid);
+ $this->updatePlushours($userid);
if ($this->request->ajax == 1) {
die();
diff --git a/public/js/pages/timerecording/index.js b/public/js/pages/timerecording/index.js
index dca9798cf..6bfceedec 100644
--- a/public/js/pages/timerecording/index.js
+++ b/public/js/pages/timerecording/index.js
@@ -86,6 +86,11 @@ table = $('#datatable').DataTable({
$('#must-time').text(json.time.must);
$('#holidays').text(json.time.holidays);
$('#plushours').text(json.time.plushours);
+ if ($("#plushours").text().includes("-")) {
+ $('#plushours-label').css('background-color', '#fda7a7');
+ } else {
+ $('#plushours-label').css('background-color', '#d0fbd9');
+ }
if (json.time.auto_workinghours == "1") {
$('#auto-workinghours-button').show();
}
@@ -317,7 +322,8 @@ $(document).ready(function () {
});
$("body").on("click", "#auto-workinghours-button", function () {
- const date = new Date($('#date').val());
+ var timestamp = $('#dataweek').val() * 1000
+ const date = new Date(timestamp);
var day = date.getDay(),
diff = date.getDate() - day + (day == 0 ? -6 : 1);
diff = date.getDate() - day + (day == 0 ? -6 : 1);
@@ -333,7 +339,7 @@ $(document).ready(function () {
if (confirm('Sollen die Arbeitszeiten von ' + monday + ' bis ' + sunday + ' automatisch eingetragen werden?')) {
$.post(autoWorkinghoursUrl, {
- dataweek: $.trim($('#date').val()),
+ dataweek: $.trim($('#dataweek').val()),
ajax: 1
}).done(function (data) {
table.ajax.reload();