@php $configData = Helper::appClasses(); @endphp @extends('layouts/layoutMaster') @section('title', __('My Leave Balance')) @section('vendor-style') @vite([ 'resources/assets/vendor/libs/apex-charts/apex-charts.scss' ]) @endsection @section('vendor-script') @vite([ 'resources/assets/vendor/libs/apex-charts/apexcharts.js' ]) @endsection @section('page-script') @vite(['resources/assets/js/app/hrcore-leave-balance-display.js']) @endsection @section('content')
{{-- Breadcrumb --}} {{-- Leave Balance Summary Cards --}}
@php $totalEntitlement = 0; $totalUsed = 0; $totalAvailable = 0; $totalPending = 0; @endphp @foreach($leaveTypes as $type) @php $entitlement = $type->entitled_leaves ?? $type->days_allowed ?? 0; $used = $type->used_leaves ?? 0; $available = $type->available_leaves ?? 0; // Calculate pending leaves for this type $pending = App\Models\LeaveRequest::where('user_id', $user->id) ->where('leave_type_id', $type->id) ->where('status', 'pending') ->whereYear('from_date', date('Y')) ->sum('total_days') ?? 0; $totalEntitlement += $entitlement; $totalUsed += $used; $totalPending += $pending; $totalAvailable += $available; @endphp @endforeach

{{ __('Total Entitlement') }}

{{ $totalEntitlement }}

{{ __('days') }}

{{ __('Used Leaves') }}

{{ $totalUsed }}

{{ __('days') }}

{{ __('Pending Approval') }}

{{ $totalPending }}

{{ __('days') }}

{{ __('Available Balance') }}

{{ $totalAvailable }}

{{ __('days') }}
{{-- Leave Balance Details --}}
{{ __('Leave Balance by Type') }}
{{ __('Apply Leave') }}
@foreach($leaveTypes as $type) @php $entitlement = $type->entitled_leaves ?? $type->days_allowed ?? 0; $used = $type->used_leaves ?? 0; $available = $type->available_leaves ?? 0; // Calculate pending leaves for this type $pending = App\Models\LeaveRequest::where('user_id', $user->id) ->where('leave_type_id', $type->id) ->where('status', 'pending') ->whereYear('from_date', date('Y')) ->sum('total_days') ?? 0; $usagePercentage = $entitlement > 0 ? ($used / $entitlement) * 100 : 0; @endphp @endforeach
{{ __('Leave Type') }} {{ __('Entitlement') }} {{ __('Used') }} {{ __('Pending') }} {{ __('Available') }} {{ __('Usage') }}
  {{ $type->name }}
{{ $entitlement }} {{ $used }} @if($pending > 0) {{ $pending }} @else {{ $pending }} @endif {{ $available }}
{{ round($usagePercentage) }}% {{ __('used') }}
{{-- Leave Balance Chart --}}
{{ __('Balance Overview') }}
{{-- Upcoming Leaves --}}
{{ __('Upcoming Leaves') }}
@php $upcomingLeaves = App\Models\LeaveRequest::where('user_id', $user->id) ->where('status', 'approved') ->where('from_date', '>', now()) ->orderBy('from_date') ->limit(5) ->get(); @endphp @if($upcomingLeaves->count() > 0)
@foreach($upcomingLeaves as $leave)
{{ $leave->leaveType->name }}
{{ $leave->from_date->format('M d') }} - {{ $leave->to_date->format('M d, Y') }}
{{ $leave->total_days }} {{ __('days') }}
@endforeach
@else

{{ __('No upcoming leaves scheduled') }}

@endif
{{-- Leave History --}}
{{ __('Recent Leave History') }}
@php $leaveHistory = App\Models\LeaveRequest::where('user_id', $user->id) ->orderBy('created_at', 'desc') ->limit(10) ->get(); @endphp
@foreach($leaveHistory as $leave) @endforeach
{{ __('Leave Type') }} {{ __('From Date') }} {{ __('To Date') }} {{ __('Days') }} {{ __('Status') }} {{ __('Applied On') }}
{{ $leave->leaveType->name }} {{ $leave->from_date->format('M d, Y') }} {{ $leave->to_date->format('M d, Y') }} {{ $leave->total_days }} @php $statusColors = [ 'pending' => 'warning', 'approved' => 'success', 'rejected' => 'danger', 'cancelled' => 'secondary' ]; $statusValue = is_string($leave->status) ? $leave->status : $leave->status->value; @endphp {{ __(ucfirst($statusValue)) }} {{ $leave->created_at->format('M d, Y') }}
{{-- Chart Data for JavaScript --}} @endsection