Merge branch 'spidev' into 'master'

Zeiterfassung Update/Bugfix/Migration

See merge request fronk/thetool!269
This commit is contained in:
Frank Schubert
2024-02-27 13:36:04 +00:00
14 changed files with 583 additions and 32 deletions

View File

@@ -294,7 +294,7 @@ $years[time() - 31536000] = date('Y', time() - 31536000);
</div>
<div class="col text-center">
<div class="input-group ">
<label class="col-form-label form-control fixed-state"><span
<label id="plushours-label" class="col-form-label form-control fixed-state"><span
class="text-bold">Gutzeit: </span><span
id="plushours"
class="ml-1 text-normal"></span></label>

View File

@@ -169,6 +169,7 @@ $daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
let requestUrl = "<?= self::getUrl("TimerecordingReport", "api", ['do' => 'getTimerecordings', 'datatype' => '3', 'datayear' => time()]) ?>";
var cindex = 1;
var holiDays = [];
var birthdays = [];
<?php
$counter = 1;
foreach ($timerecordingholidays as $timerecordingholiday) :?>
@@ -176,12 +177,34 @@ $daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
id: <?= $counter ?>,
start: '<?= date("Y-m-d", $timerecordingholiday->timestamp) ?>',
end: '<?= date("Y-m-d", $timerecordingholiday->timestamp) ?>',
title: '<?= $timerecordingholiday->description ?>'
title: '<?= $timerecordingholiday->description ?>',
description: '<?= $timerecordingholiday->description ?>'
});
<?php
$counter++;
endforeach;
foreach ($timerecordingemployees as $timerecordingemployee) :
if ($timerecordingemployee->birthday) :
$year = date("Y", time());
$year = $year - 1;
$Byear = date("Y", $timerecordingemployee->birthday);
for ($i = 0; $i < 5; $i++) :
$age = $year - $Byear;
?>
birthdays.push({
id: <?= $counter ?>,
start: '<?= date("$year-m-d", $timerecordingemployee->birthday) ?>',
end: '<?= date("$year-m-d", $timerecordingemployee->birthday) ?>',
title: '<?= $timerecordingemployee->user->name ?> (<?= $age ?>)',
description: 'Geburtstag <?= $timerecordingemployee->user->name ?> (<?= $age ?>)'
});
<?php
$year++;
endfor;
$counter++;
endif;
endforeach; ?>
cindex = <?= $counter ?>;
$.getJSON(requestUrl, function (data) {
@@ -223,7 +246,7 @@ $daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
// Calendar Event Source
// Birthday Events Source
var birthdayEvents = {
var holiDayEvents = {
id: 1,
backgroundColor: 'rgba(255, 0, 0 , 1)',
borderColor: 'rgba(255, 0, 0 , 1)',
@@ -232,12 +255,19 @@ $daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
};
var holidayEvents = {
id: 5,
id: 7,
backgroundColor: 'rgba(0,204,204,.25)',
borderColor: 'rgb(192 0 255)',
borderColor: 'rgb(8 241 8)',
textColor: '#000',
events: holidays
};
var birthdayEvents = {
id: 5,
backgroundColor: 'rgb(68 15 241 / 76%)',
borderColor: 'rgb(68 15 241 / 76%)',
textColor: '#fff',
events: birthdays
};
var initialLocaleCode = 'en';
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
@@ -265,7 +295,7 @@ $daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
navLinks: 'true',
events: [],
height: 800,
eventSources: [holidayEvents, birthdayEvents]
eventSources: [birthdayEvents, holiDayEvents, holidayEvents]
});
calendar.render();
});

View File

@@ -89,6 +89,15 @@ $daysSelect .= "</select>";
value="<?= ($timerecordingemployees->startdate) ? date('Y-m-d', $timerecordingemployees->startdate): "" ?>"/>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="birthday">Geburtstag</label>
<div class="col-lg-2">
<input type="date" id="birthday" name="birthday"
class="form-control"
value="<?= ($timerecordingemployees->birthday) ? date('Y-m-d', $timerecordingemployees->birthday): "" ?>"/>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="holidays">Initiale Urlaubstage</label>
<div class="col-lg-1">
@@ -106,6 +115,14 @@ $daysSelect .= "</select>";
value="<?= str_replace(".", ",", $timerecordingemployees->plushours / 3600) ?>"/>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="overtime">Initiale Überstunden</label>
<div class="col-lg-1">
<input type="text" id="overtime" name="overtime"
class="form-control"
value="<?= str_replace(".", ",", $timerecordingemployees->overtime / 3600) ?>"/>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label"
for="auto_workinghours">Schnellbuchung</label>

View File

@@ -42,6 +42,9 @@ $type[3] = "Lehrling";
<th class="text-center">Start Zeitaufzeichnung</th>
<th class="text-center">Sollzeiten</th>
<th class="text-center">Sollstunden</th>
<th class="text-center">Mehrstunden</th>
<th class="text-center">Überstunden</th>
<th class="text-center">Offene Urlaube</th>
<th class="text-center edit-width">Schnellbuchung</th>
<th class="edit-width"></th>
</tr>
@@ -53,6 +56,9 @@ $type[3] = "Lehrling";
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@@ -73,6 +79,9 @@ $type[3] = "Lehrling";
<td class="text-center"><?= ($timerecordingemployees[$timerecordinguser->id]['startdate']) ? date("d.m.Y", $timerecordingemployees[$timerecordinguser->id]['startdate']) : "-" ?></td>
<td class="text-center"><?= ($timerecordingworkinghours) ? $timerecordingworkinghours[$timerecordinguser->id]['datetimetext'] : "" ?></td>
<td class="text-center"><?= $sum ?></td>
<td class="text-center"><?= sprintf('%02d:%02d', ($timerecordingemployees[$timerecordinguser->id]['plushours_now']/ 3600),($timerecordingemployees[$timerecordinguser->id]['plushours_now']/ 60 % 60)) ?></td>
<td class="text-center"><?= sprintf('%02d:%02d', ($timerecordingemployees[$timerecordinguser->id]['overtime_now']/ 3600),($timerecordingemployees[$timerecordinguser->id]['overtime_now']/ 60 % 60)) ?></td>
<td class="text-center"><?= ($timerecordingemployees[$timerecordinguser->id]['holidays_now']) ? $timerecordingemployees[$timerecordinguser->id]['holidays_now'].' Tage' : '' ?> </td>
<td class="text-center"><?= ($timerecordingemployees[$timerecordinguser->id]['auto_workinghours'] == '1') ? 'Ja' : 'Nein' ?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
<a href="<?= self::getUrl("TimerecordingEmployee", "edit", ['id' => $timerecordingemployees[$timerecordinguser->id]['id'], "userid" => $timerecordinguser->id]) ?>"><i
@@ -91,7 +100,7 @@ $type[3] = "Lehrling";
<script type="text/javascript">
var hidesearch = [6];
var hidesearch = [3,4,5,6,7,9];
$(document).ready(function () {

View File

@@ -352,6 +352,7 @@ $years[time() - 31536000] = date('Y', time() - 31536000);
let insertUrl = "<?= self::getUrl("Timerecording", "save") ?>";
let deleteUrl = "<?= self::getUrl("Timerecording", "delete") ?>";
let requestUrl = "<?= self::getUrl("TimerecordingReport", "api", ['do' => 'getTimerecordings']) ?>";
let requestTimesUrl = "<?= self::getUrl("TimerecordingReport", "api", ['do' => 'getTimerecordingsTimes']) ?>";
</script>

View File

@@ -18,6 +18,9 @@ class TimerecordingController extends mfBaseController
protected function indexAction()
{
$this->updatePlushours($this->me->id);
$this->updateHolidays($this->me->id);
$timerecordingCategoriess = TimerecordingCategoryModel::getAll();
$this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess);
$this->layout()->setTemplate("Timerecording/Index");
@@ -197,6 +200,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);
@@ -262,7 +266,7 @@ class TimerecordingController extends mfBaseController
}
if ($id) {
$timerecordingCategoriess = TimerecordingCategoryModel::search(['id' => $data['timerecordingCategory_id']]);
if ($timerecordingCategoriess[0]->approval == "1") {
if ($timerecordingCategoriess[0]->approval == "1" && !$r->user_id) {
$body = 'Beantrag von: ' . $this->me->name . '
';
$body .= 'Buchungsart: ' . $timerecordingCategoriess[0]->name . '
@@ -286,6 +290,10 @@ class TimerecordingController extends mfBaseController
$email->setTo(TT_TIMERECORDING_EMAIL);
$email->send();
}
if ($data['timerecordingCategory_id'] == "3") {
$this->updateHolidays($data['user_id']);
}
$this->updatePlushours($data['user_id']);
}
if ($mode == "edit") {
@@ -303,8 +311,96 @@ class TimerecordingController extends mfBaseController
$this->redirect("Timerecording");
}
protected function updateHolidays($userid)
{
$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_now = $holidays;
}
$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 = $daycounter * 86400;
if (is_int($daycounter)) {
for ($i = 86400; $i <= $daycounter; $i = $i + 86400) {
$holidayDays[date("Y-m-d", $timerecording->start + $i - 86400)] = 1;
}
}
}
protected function getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear)
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;
}
}
//check if holiday is already in the list
foreach ($holidayDays as $key => $holidayDay) {
if ($realholiDay[$key]) {
} else if ($workingHours[date('w', strtotime($key))]) {
$holidays_now--;
}
}
if ($holidays_now != $employee->holidays_now) {
$employeeupdate = new TimerecordingEmployee($employee->id);
$data = [];
$data['holidays_now'] = $holidays_now;
$employeeupdate->update($data);
$employeeupdate->save();
}
}
}
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, $startime = null, $endtime = null)
{
$mustSeconds = 0;
$isSeconds = 0;
@@ -314,8 +410,8 @@ class TimerecordingController extends mfBaseController
$rows = [];
$employee = TimerecordingEmployeeModel::search(['user_id' => $this->me->id]);
if ($employee) {
$holiDays = $employee[0]->holidays;
$plusHours = $employee[0]->plushours;
$holiDays = $employee[0]->holidays_now;
$plusHours = $employee[0]->plushours_now;
$auto_workinghours = $employee[0]->auto_workinghours;
}
@@ -394,6 +490,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;
}
}
@@ -535,23 +651,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;
@@ -585,7 +713,7 @@ class TimerecordingController extends mfBaseController
$daycounter = '0';
$update = false;
$timestamp = $timestamp_montag;
for ($i = 1; $i <= 7; $i++) {
$dDate = date('Y-m-d', $timestamp);
@@ -597,6 +725,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;
@@ -615,18 +744,25 @@ class TimerecordingController extends mfBaseController
$timestamp = $timestamp + 86400;;
}
if ($update) {
$this->updatePlushours($this->me->id);
$this->updateHolidays($this->me->id);
}
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordings = new Timerecording($id);
$userid = $timerecordings->user_id;
if (!$timerecordings->id || $timerecordings->id != $id) {
$this->layout()->setFlash("Buchung nicht gefunden.", "error");
$this->redirect("Timerecording");
}
$timerecordings->delete();
$this->updateHolidays($userid);
$this->updatePlushours($userid);
if ($this->request->ajax == 1) {
die();
}

View File

@@ -150,6 +150,15 @@ class TimerecordingModel
$where .= " AND ((`start` >= $start AND `start` <= $end) OR (`end` >= $start AND `end` <= $end) OR `end` is NULL) ORDER by user_id ASC";
}
}
if (array_key_exists("start", $filter) && array_key_exists("timerecordingCategory_id", $filter)) {
$start = $filter['start'];
$timerecordingCategory_id = $filter['timerecordingCategory_id'];
if (is_numeric($start) && is_numeric($timerecordingCategory_id)) {
$where .= " AND `start` >= $start AND `timerecordingCategory_id` = $timerecordingCategory_id ORDER by start ASC";
}
}
if (array_key_exists("starttime", $filter) && array_key_exists("endtime", $filter)) {
$starttime = $filter['starttime'];
$endtime = $filter['endtime'];

View File

@@ -20,6 +20,8 @@ class TimerecordingCalendarController extends mfBaseController
{
$timerecordingholidays = TimerecordingHolidayModel::getAll();
$this->layout()->set("timerecordingholidays", $timerecordingholidays);
$timerecordingemployees = TimerecordingEmployeeModel::getAll();
$this->layout()->set("timerecordingemployees", $timerecordingemployees);
$this->layout()->setTemplate("TimerecordingCalendar/Index");
}

View File

@@ -101,6 +101,12 @@ class TimerecordingEmployeeController extends mfBaseController
if (is_numeric($plushours)) {
$plushours = $plushours * 3600;
}
$overtime = $r->overtime;
$overtime = str_replace(',', '.', $overtime);
if (is_numeric($overtime)) {
$overtime = $overtime * 3600;
}
$data = [];
$data['user_id'] = trim($r->user_id);
@@ -109,8 +115,18 @@ class TimerecordingEmployeeController extends mfBaseController
$data['plushours'] = $plushours;
$data['startdate'] = strtotime($r->startdate);
$data['type'] = trim($r->type);
$data['overtime'] = $overtime;
#
if (!$data['overtime']) {
$data['overtime'] = 0;
}
if ($r->birthday) {
$data['birthday'] = strtotime($r->birthday);
} else {
$data['birthday'] = null;
}
if (!$data['user_id']) {
$this->layout()->setFlash("Mitarbeiter darf nicht leer sein", "error");
$this->redirect("TimerecordingEmployee");

View File

@@ -6,8 +6,17 @@ class TimerecordingEmployeeModel
private $type;
private $auto_workinghours;
private $holidays;
private $holidays_now;
private $holidays_timestamp;
private $plushours;
private $plushours_now;
private $plushours_timestamp;
private $overtime;
private $overtime_now;
private $overtime_timestamp;
private $bpahours;
private $startdate;
private $birthday;
public static function find($data)
@@ -138,6 +147,9 @@ class TimerecordingEmployeeModel
$where .= " AND user_id=$userid";
}
}
if (array_key_exists("startdate", $filter)) {
$where .= " AND startdate is not null";
}
//var_dump($filter, $where);exit;
return $where;

View File

@@ -41,6 +41,9 @@ class TimerecordingReportController extends mfBaseController
case "getTimerecordings":
$return = $this->getTimerecordingsApi($datatype, $dataweek, $datamonth, $datayear);
break;
case "getTimerecordingsTimes":
$return = $this->getTimerecordingsTimes($datatype, $dataweek, $datamonth, $datayear);
break;
default:
$return = false;
}
@@ -100,7 +103,7 @@ class TimerecordingReportController extends mfBaseController
$dDate = date('Y-m-d', $timestamp);
$dDay = date('w', $timestamp);
if (!$holiDay[$dDate]) {
$mustSeconds = $mustSeconds + $workingHours[$dDay];
// $mustSeconds = $mustSeconds + $workingHours[$dDay];
}
$timestamp = $timestamp + 86400;
@@ -117,7 +120,7 @@ class TimerecordingReportController extends mfBaseController
$dDate = date('Y-m-d', $timestamp);
$dDay = date('w', $timestamp);
if (!$holiDay[$dDate]) {
$mustSeconds = $mustSeconds + $workingHours[$dDay];
// $mustSeconds = $mustSeconds + $workingHours[$dDay];
}
$timestamp = $timestamp + 86400;
}
@@ -133,7 +136,7 @@ class TimerecordingReportController extends mfBaseController
$dDate = date('Y-m-d', $timestamp);
$dDay = date('w', $timestamp);
if (!$holiDay[$dDate]) {
$mustSeconds = $mustSeconds + $workingHours[$dDay];
//$mustSeconds = $mustSeconds + $workingHours[$dDay];
}
$timestamp = $timestamp + 86400;
@@ -307,6 +310,244 @@ class TimerecordingReportController extends mfBaseController
die();
}
protected function getTimerecordingsTimes($datatype, $dataweek, $datamonth, $datayear)
{
$r = $this->request;
$mustSeconds = 0;
$isSeconds = 0;
$holiDays = 0;
$plusHours = 0;
$rows = [];
$employee = TimerecordingEmployeeModel::search(['user_id' => $r->user_id]);
if ($employee) {
$holiDays = $employee[0]->holidays;
$plusHours = $employee[0]->plushours;
$auto_workinghours = $employee[0]->auto_workinghours;
}
$workinghours = TimerecordingEmployeeWorkingHourModel::search(['user_id' => $r->user_id]);
$holidays = TimerecordingHolidayModel::getAll();
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;
}
}
foreach ($holidays as $holiday) {
$holiDay[date('Y-m-d', $holiday->timestamp)] = $holiday->timestamp;
}
if ($datatype == 1) {
$kw = date('W', $dataweek);
$year = date('Y', $dataweek);
$timestamp_montag = strtotime("{$year}-W{$kw}");
$timestamp_sonntag = strtotime("{$year}-W{$kw}-7");
$firstdate = strtotime(date("Y-m-d", $timestamp_montag) . " 00:00:00");
$lastdate = strtotime(date("Y-m-d", $timestamp_sonntag) . ' 23:59:59');
$searchArray = ['user_id' => $r->user_id, 'start' => $timestamp_montag, 'end' => $lastdate];
$daycounter = '0';
$timestamp = $timestamp_montag;
for ($i = 1; $i <= 7; $i++) {
$dDate = date('Y-m-d', $timestamp);
$dDay = date('w', $timestamp);
if (!$holiDay[$dDate]) {
$mustSeconds = $mustSeconds + $workingHours[$dDay];
}
$timestamp = $timestamp + 86400;
}
} else if ($datatype == 2) {
$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');
$searchArray = ['user_id' => $r->user_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;
}
} else if ($datatype == 3) {
$firstdate = strtotime(date("Y-01-01", $datayear));
$lastdate = strtotime(date("Y-12-31 23:59:59", $datayear));
$daycount = date("t", $datamonth);
$lastdate = strtotime(date("Y-m-d", $lastdate) . ' 23:59:59');
$searchArray = ['user_id' => $r->user_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;
}
}
$daysgerm = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");
$timerecordingcategories = TimerecordingCategoryModel::getAll();
$timerecordings = TimerecordingModel::search($searchArray);
$responsecount = count($timerecordings);
foreach ($timerecordings as $timerecording):
$state = "";
$enddate = "";
$sum = "-";
$day = "";
$orderdate = $timerecording->start;
if ($timerecording->timerecordingCategory->hourday == 1) {
$date = date("d.m.Y", $timerecording->start);
$datadate = date("Y-m-d", $timerecording->start);
$start = date("H:i", $timerecording->start);
$end = date("H:i", $timerecording->end);
$seconds = $timerecording->end - $timerecording->start;
$minutes = floor(($seconds % 3600) / 60);
$hours = floor($seconds / 3600);
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
$day = $daysgerm[date("w", $timerecording->start)];
$isSeconds = $isSeconds + $seconds;
} else if ($timerecording->timerecordingCategory->hourday == 2 || ($timerecording->timerecordingCategory->hourday == 3 && $timerecording->end)) {
$date = date("d.m.", $timerecording->start) . " - " . $daysgerm[date("w", $timerecording->end)] . " " . date("d.m.Y", $timerecording->end);
$datadate = date("Y-m-d", $timerecording->start);
$enddate = date("Y-m-d", $timerecording->end);
$start = "-";
$end = "-";
$day = $daysgerm[date("w", $timerecording->start)];
if ($lastdate < $timerecording->end) {
$endtimecalc = $lastdate;
} else {
$endtimecalc = $timerecording->end;
}
if ($firstdate > $timerecording->start) {
$starttimecalc = $firstdate;
} else {
$starttimecalc = $timerecording->start;
}
$summcounter = 0;
$savecounter = 0;
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
$holidaycounter = $workingHours[date("w", $i)];
$isSeconds = $isSeconds + $holidaycounter;
$summcounter = $summcounter + $holidaycounter;
if ($savecounter == 1000) {
echo $savecounter;
die();
}
$savecounter++;
}
$seconds = $summcounter;
$minutes = floor(($seconds % 3600) / 60);
$hours = floor($seconds / 3600);
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
} else if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
$date = date("d.m.Y", $timerecording->start) . " - " . $daysgerm[date("w", time())] . " " . date("d.m.Y", time());;
$datadate = date("Y-m-d", $timerecording->start);
$start = "-";
$end = "-";
$day = $daysgerm[date("w", $timerecording->start)];
if ($lastdate < $timerecording->end) {
$endtimecalc = $lastdate;
} else {
$endtimecalc = $timerecording->end;
}
if ($firstdate > $timerecording->start) {
$starttimecalc = $firstdate;
} else {
$starttimecalc = $timerecording->start;
}
$summcounter = 0;
$savecounter = 0;
for ($i = $starttimecalc; $i <= $endtimecalc; $i = $i + 86400) {
$holidaycounter = $workingHours[date("w", $i)];
$isSeconds = $isSeconds + $holidaycounter;
$summcounter = $summcounter + $holidaycounter;
if ($savecounter == 1000) {
echo $savecounter;
die();
}
$savecounter++;
}
$seconds = $summcounter;
$minutes = floor(($seconds % 3600) / 60);
$hours = floor($seconds / 3600);
$sum = sprintf("%02d", $hours) . ":" . sprintf("%02d", $minutes);
}
if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 0) {
$state = '<i class="fa-regular fa-clock mr-1"></i>';
} else if ($timerecording->timerecordingCategory->approval == 1 && $timerecording->approved == 1) {
$state = '<i class="fa-regular fa-circle-check mr-1"></i>';
}
$edit = "";
if ($timerecording->businesstrip == 1) {
$category = "<span>" . $timerecording->timerecordingCategory->name . "</span><span class='text-bold ml-2'> (Dienstreise: " . $timerecording->businesstrip_info . ")</span>";
} else {
$category = $timerecording->timerecordingCategory->name;
}
if ($timerecording->timerecordingCategory->hourday == 3 && !$timerecording->end) {
$category = $category . "<span class='text-bold ml-2'>(offen)</span>";
}
if ($timerecording->completed == 0 && $timerecording->timerecordingCategory->only_admin == 0):
if ($timerecording->approved == 0) :
$edit = '<i class="far fa-edit edit-button" data-id="' . $timerecording->id . '"
data-date="' . $datadate . '"
data-category="' . $timerecording->timerecordingCategory->id . '"
data-start="' . $start . '"
data-end="' . $end . '"
data-enddate="' . $enddate . '"
data-comment="' . $timerecording->comment . '"
data-businesstrip="' . $timerecording->businesstrip . '"
data-businesstripinfo="' . $timerecording->businesstrip_info . '"
title="Bearbeiten"></i>';
else :
$edit .= '<div class="edit-placeholder"></div>';
endif;
$edit .= '<i data-id="' . $timerecording->id . '" class="fas fa-trash text-danger delete-item" ></i>';
endif;
if ($datatype == 3 && $timerecording->timerecordingCategory->hourday == 1) {
} else {
}
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['recordsFiltered'] = $responsecount;
$json['recordsTotal'] = $responsecount;
$json = json_encode($json);
echo trim($json);
die();
}
protected function addAction()
{

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class TimerecordingEmployeeAddFieldOvertime extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("TimerecordingEmployee", ["signed" => true]);
$table->addColumn("overtime", "integer", ["null" => false, "default" => '0', "after" => "plushours_now"]);
$table->addColumn("overtime_now", "integer", ["null" => false, "default" => '0', "after" => "plushours_now"]);
$table->addColumn("overtime_timestamp", "integer", ["null" => true, "after" => "overtime_now"]);
$table->addColumn("holidays_timestamp", "integer", ["null" => true, "after" => "holidays_now"]);
$table->addColumn("plushours_timestamp", "integer", ["null" => true, "after" => "plushours_now"]);
$table->addColumn("birthday", "integer", ["null" => true, "after" => "startdate"]);
$table->addColumn("bpahours", "integer", ["null" => false, "default" => '0', "after" => "overtime"]);
$table->changeColumn('holidays_now', 'integer', ["null" => false, "default" => '0']);
$table->changeColumn('plushours_now', 'integer', ["null" => false, "default" => '0']);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("TimerecordingEmployee")->removeColumn("overtime")->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -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();

View File

@@ -90,6 +90,7 @@ table = $('#datatable').DataTable({
$('#must-time').text(json.time.must);
$('#holidays').text(json.time.holidays);
$('#plushours').text(json.time.plushours);
$('#selectsearch').change();
return json.data;
}
@@ -182,6 +183,7 @@ if (state) {
$(document).ready(function () {
$(".select2").select2();
$("body").on("change", "#timerecordingCategory_id", function () {
if (parseInt($(this).find(':selected').data('hourday')) === 2) {
$("#endtime-div").hide();
@@ -295,6 +297,34 @@ $(document).ready(function () {
$("body").on("change", "#dataweek,#datamonth,#datayear", function () {
table.ajax.reload(null, false);
});
$("body").on("change", "#selectsearch", function () {
var datatype;
if (!$(this).val()) {
$('#must-time').text('N/A');
$('#is-time').text('N/A');
} else {
$('.display-calendar').each(function (index) {
if ($(this).hasClass('active-calendar')) {
datatype = $(this).data('datatype');
}
});
if (datatype == 1 || datatype == 2) {
$.post(requestTimesUrl, {
id: $.trim($(this).data('id')),
datatype: datatype,
user_id: $(this).find(':selected').data('userid'),
dataweek: $('#dataweek').val(),
datamonth: $('#datamonth').val(),
ajax: 1
}).done(function (data) {
var json = $.parseJSON(data);
$('#must-time').text(json.time.must);
$('#is-time').text(json.time.is);
});
}
}
});
$("body").on("click", ".display-calendar", function () {
$('.display-calendar').each(function (index) {
$(this).removeClass('active-calendar');
@@ -350,7 +380,7 @@ $(document).ready(function () {
e.preventDefault();
$('#alert-box').remove();
var userid;
userid = $('#user_id_select').val();
userid = $('#user_id_select').val();
var businesstrip = false;
if ($('#businesstrip').prop('checked') == true) {
businesstrip = 1;
@@ -403,5 +433,6 @@ $(document).ready(function () {
});
});
$('#timerecordingCategory_id').change();
})
;