@extends('layouts.app', ['title' => 'Monatlich Übersicht']) @section('content') @php // if (!isset($ddate)) { // # code... // $today = \Carbon\Carbon::now(); // } function secondsToTime($totalSeconds) { $sign = $totalSeconds < 0 ? '-' : ''; $totalSeconds = abs($totalSeconds); $hours = floor($totalSeconds / 3600); $minutes = floor(($totalSeconds % 3600) / 60); return $sign . sprintf('%02d:%02d', $hours, $minutes); } function hoursToSeconds($hours) { $seconds = $hours * 3600; return $seconds; } function convertDecimalToHHMM($decimalHours) { // Replace comma with dot to handle European decimal format $decimalHours = str_replace(',', '.', $decimalHours); // Determine if the value is negative $isNegative = $decimalHours < 0; // Take absolute value for calculation $decimalHours = abs($decimalHours); // Separate hours and minutes $hours = floor($decimalHours); $minutes = ($decimalHours - $hours) * 60; // Format the result as HH:MM $formattedTime = sprintf('%02d:%02d', $hours, $minutes); // Add negative sign back if the original value was negative if ($isNegative) { $formattedTime = '-' . $formattedTime; } return $formattedTime; } function convertHMToHours($time) { // Split the input string by the colon [$hours, $minutes] = explode(':', $time); // Convert hours and minutes to integers and calculate the total hours as a decimal $totalHours = $hours + $minutes / 60; // Replace the decimal point with a comma $formattedTotalHours = str_replace('.', ',', number_format($totalHours, 2)); return $formattedTotalHours; } function convertSecondsToHours($seconds) { // Convert seconds to hours as a decimal $hours = $seconds / 3600; // Format the result to have two decimal places and replace the decimal point with a comma $formattedHours = str_replace('.', ',', number_format($hours, 2)); return $formattedHours; } @endphp

HRM - monatliche Übersicht


Zeiterfassung aus:
@foreach ($months as $item) @if ($item->year > 2024) {{ Carbon\Carbon::create()->day(1)->month($item->month)->format('m.') }}{{ $item->year }} @endif @endforeach

@php $startDate = Carbon\Carbon::parse($ddate)->startOfMonth(); $endDate = Carbon\Carbon::parse($ddate)->endOfMonth(); // Prüfen ob Vormonat AZK hat $hasPrevAzK = isset($hr_workTimeAccounts) && $hr_workTimeAccounts->count() > 0; @endphp

Zeitraum: {{ $startDate->format('d.m.Y') }} - {{ $endDate->format('d.m.Y') }}

{{-- ⚠️ Hinweis, wenn der Vormonat kein AZK hat --}} @if (!$hasPrevAzK)
Für den Vormonat ({{ $ddate->copy()->subMonth()->format('m.Y') }}) existiert kein AZK-Konto.
Es wird automatisch mit einem Startsaldo von 0 Stunden gerechnet.
@endif {{-- 🟢 Monat wurde bereits festgeschrieben --}} @if ($isFixed)
Für diesen Monat wurde die AZK bereits festgeschrieben.
{{-- 🔵 Monat wurde NOCH NICHT festgeschrieben --}} @else
Für diesen Monat wurde die AZK noch nicht festgeschrieben.
@endif
@php $work_days = 0; for ( $start = Carbon\Carbon::parse($ddate)->startOfMonth(); $start <= Carbon\Carbon::parse($ddate)->endOfMonth(); $start->addDay() ) { if (!in_array($start->isoFormat('dd'), ['Sa', 'So'])) { if ($holidays->where('date', $start->toDateString())->count() <= 0) { # code... $work_days += 1; } } } @endphp Arbeitstage: {{ $work_days }} | Feirtage: {{ $holidays->whereBetween('date', [$ddate->startOfMonth()->format('Y-m-d'), $ddate->endOfMonth()->format('Y-m-d')])->count() }}

{{-- --}} @php // Group employees by 'fk_emp_id' and get unique items $groupedEmployees = $employees->pluck('fk_employee_id')->unique(); @endphp @foreach ($department as $item) @php $startDate = Carbon\Carbon::parse($ddate)->startOfMonth(); $endDate = Carbon\Carbon::parse($ddate)->endOfMonth(); @endphp {{-- @foreach ($item->get_employee->where('has_time_recording', '1') as $iteme) --}} @foreach ($item->get_employee as $iteme) @if ($hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('work', '1')->count()) {{-- @if (1) --}} @php $total_work_days = 0; $total_sicks = 0; $contractStart = $iteme->contract->start_day ? Carbon\Carbon::parse($iteme->contract->start_day) : null; $total_vacations = 0; $total_soll = 0; $startDate = Carbon\Carbon::parse($ddate)->startOfMonth(); $endDate = Carbon\Carbon::parse($ddate)->endOfMonth(); for ($start = $startDate; $start <= $endDate; $start->addDay()) { $isSick = 0; $isVacation = 0; $isHoliday = 0; if ( $hrtimerecords ->where('fk_employee_id', $iteme->employee_id) ->where('start_date', $start->toDateString()) ->where('work', '1') ->where('status_open', '0') ->count() ) { $total_work_days += 1; } if ( $HrSickRequest ->where('fk_employee_id', $iteme->employee_id) ->where('date_from', '<=', $start->toDateString()) ->where('date_to', '>=', $start->toDateString()) ->count() & ($iteme->contract->get_days[strtolower($start->format('l'))] > 0) ) { $total_sicks += 1; $isSick = 1; } $isHoliday = $holidays->contains(function ($holiday) use ($start) { return $holiday->date == $start->toDateString(); }); if ( !$isHoliday && $Vacations ->where('is_accepted', '1') ->where('fk_employee_id', $iteme->employee_id) ->where('date_from', '<=', $start->toDateString()) ->where('date_to', '>=', $start->toDateString()) ->count() & ($iteme->contract->get_days[strtolower($start->format('l'))] > 0) ) { $total_vacations += 1; $isVacation = 1; } // $isSick = $HrSickRequest->contains(function ($HrSickRequest) use ($start) { // return $HrSickRequest->date_from <= $start->toDateString() && // $HrSickRequest->date_to >= $start->toDateString(); // }); // $isVacation = $Vacations // ->where('is_accepted', '1') // ->where('date_from', '<=', $start->toDateString()) // ->where('date_to', '>=', $start->toDateString()) // ->count(); if ( !$isHoliday && !$isSick && !$isVacation && (!$contractStart || $start->greaterThanOrEqualTo($contractStart)) ) { $dayOfWeek = strtolower($start->format('l')); $total_soll += $iteme->contract->get_days[$dayOfWeek] ?? 0; } } // for ( // $start = Carbon\Carbon::parse($ddate)->startOfMonth(); // $start <= Carbon\Carbon::parse($ddate)->endOfMonth(); // $start->addDay() // ) { // if ( // $hrtimerecords // ->where('fk_employee_id', $iteme->employee_id) // ->where('start_date', $start->toDateString()) // ->where('work', '1') // ->where('status_open', '0') // ->count() // ) { // $total_work_days += 1; // } // if ( // $HrSickRequest // ->where('fk_employee_id', $iteme->employee_id) // ->where('date_from', '<=', $start->toDateString()) // ->where('date_to', '>=', $start->toDateString()) // ->count() & // ($iteme->contract->get_days[strtolower($start->format('l'))] > 0) // ) { // $total_sicks += 1; // } // if ( // $Vacations // ->where('is_accepted', '1') // ->where('fk_employee_id', $iteme->employee_id) // ->where('date_from', '<=', $start->toDateString()) // ->where('date_to', '>=', $start->toDateString()) // ->count() & // ($iteme->contract->get_days[strtolower($start->format('l'))] > 0) // ) { // $total_vacations += 1; // } // if ( // !$Vacations // ->where('is_accepted', '1') // ->where('fk_employee_id', $iteme->employee_id) // ->where('date_from', '<=', $start->toDateString()) // ->where('date_to', '>=', $start->toDateString()) // ->count() // ) { // $total_soll += $iteme->contract->get_days[strtolower($start->format('l'))]; // } // } @endphp @endif @endforeach @endforeach
Mitarbeiter
Arbeitstage
soll / ist
Krank
Urlaub
VJ Url. üb.
Url. Anspr.
Url.Tg.gen.
Rest
Urlaubstage diesen Monat
soll ist AZK Vormonat AZK aktuellBeginn Ende Arbeitsschichten Pausen Pause Soll Ist Notiz
{{ $item->name }} {{-- {{ $groupedEmployees->whereIn('fk_employee_id', $item->get_employee->pluck('employee_id'))->count() }} --}} {{-- {{ $HrTimeRecordingToday->pluck('fk_employee_id')->unique()->whereIn('fk_employee_id', $item->get_employee->pluck('employee_id'))->count() }} --}} {{-- / {{ $item->get_employee->count() }} --}}
{{ $iteme->first_name }} {{ $iteme->last_name }} {{-- {{ $iteme->first_name }} {{ $iteme->last_name }} --}}
{{ $work_days - $total_sicks - $total_vacations }} / {{ $total_work_days }} {{ $total_sicks }} @php $got_vacations = 0; $Vacations_manual_days_sum = 0; $Vacations_manual_days_sum_all = $Vacations_manual_days ->where('is_accepted', '1') ->where('fk_employee_id', $iteme->employee_id) ->where('date_from', '>=', Carbon\Carbon::parse('2025-01')->startOfMonth()) ->where('date_to', '<=', Carbon\Carbon::parse($ddate)->endOfMonth()) ->sum('manual_days'); $Vacations_manual_days_sum = $Vacations_manual_days ->where('is_accepted', '1') ->where('fk_employee_id', $iteme->employee_id) ->where('date_from', '>=', Carbon\Carbon::parse($ddate)->startOfMonth()) ->where('date_to', '<=', Carbon\Carbon::parse($ddate)->endOfMonth()) ->sum('manual_days'); for ( $start = Carbon\Carbon::parse('2025-01')->startOfMonth(); $start <= Carbon\Carbon::parse($ddate)->endOfMonth(); $start->addDay() ) { $isVacationDay = $Vacations ->where('is_accepted', '1') ->where('fk_employee_id', $iteme->employee_id) ->where('date_from', '<=', $start->toDateString()) ->where('date_to', '>=', $start->toDateString()) ->count(); $isWorkDay = $iteme->contract->get_days[strtolower($start->format('l'))] > 0; $isHoliday = in_array( $start->toDateString(), $holidays->pluck('date')->toArray(), ); if ($isVacationDay && $isWorkDay && !$isHoliday) { $got_vacations += 1; } // if ($isVacationDay && $isWorkDay && !$isHoliday) { // $got_vacations += 1; // } } @endphp
{{ $iteme->contract->get_days->last_year_vacation_rest }}
{{ $iteme->contract->get_days->vacation_entitlement }}
{{ $got_vacations + $Vacations_manual_days_sum_all }}
{{ $iteme->contract->get_days->last_year_vacation_rest + $iteme->contract->get_days->vacation_entitlement - $got_vacations - $Vacations_manual_days_sum_all }}
{{ $total_vacations + $Vacations_manual_days_sum }}
{{ convertDecimalToHHMM($total_soll) }} ({{ $total_soll }} Std.) @if ($hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('work', '1')->where('status_open', '0')->count()) {{ secondsToTime( $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('work', '1')->where('status_open', '0')->sum('total_second') - $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('break', '1')->where('status_open', '0')->sum('total_second'), ) }} ({{ convertHMToHours( secondsToTime( $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('work', '1')->where('status_open', '0')->sum('total_second') - $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('break', '1')->where('status_open', '0')->sum('total_second'), ), ) }} Std.) @else 0 @endif @php // Hole den WorkTimeAccount für den letzten Monat $workTimeAccount = $hr_workTimeAccounts ->where('fk_employee_id', $iteme->employee_id) ->last(); // Falls kein Eintrag für den letzten Monat vorhanden ist, setze new_balance auf 0 $oldBalance = $workTimeAccount ? $workTimeAccount->previous_balance : 0; @endphp @if ($oldBalance < 0) {{ convertDecimalToHHMM($oldBalance) }} ({{ number_format($oldBalance, 2, ',', '.') }} Stunde) @else @endif {{-- @if ($iteme->contract->get_days->old_work_time_account < 0)
{{ convertDecimalToHHMM($iteme->contract->get_days->old_work_time_account) }} ({{ number_format($iteme->contract->get_days->old_work_time_account, 2, ',', '.') }} Std.)
@else {{ convertDecimalToHHMM($iteme->contract->get_days->old_work_time_account) }} ({{ number_format($iteme->contract->get_days->old_work_time_account, 2, ',', '.') }} Std.) @endif --}}
{{-- {{ secondsToTime( $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('work', '1')->where('status_open', '0')->sum('total_second') - $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('break', '1')->where('status_open', '0')->sum('total_second') + hoursToSeconds($iteme->contract->get_days->old_work_time_account) - hoursToSeconds($total_soll), ) }} ({{ convertSecondsToHours( $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('work', '1')->where('status_open', '0')->sum('total_second') - $hrtimerecords->where('fk_employee_id', $iteme->employee_id)->where('break', '1')->where('status_open', '0')->sum('total_second') + hoursToSeconds($iteme->contract->get_days->old_work_time_account) - hoursToSeconds($total_soll), ) }} Std.) --}} @php // Hole den WorkTimeAccount für den letzten Monat $workTimeAccount = $hr_workTimeAccounts ->where('fk_employee_id', $iteme->employee_id) ->last(); // Falls kein Eintrag für den letzten Monat vorhanden ist, setze new_balance auf 0 $newBalance = $workTimeAccount ? $workTimeAccount->new_balance : 0; @endphp @if ($newBalance < 0) {{ convertDecimalToHHMM($newBalance) }} ({{ number_format($newBalance, 2, ',', '.') }} Stunde) @else @endif
{{-- für container --}} @endsection