@if (Auth::user()?->member()->exists()) @php $member = Auth::user()->member; // Check if user is a leader (anything other than basic Member role) $isLeader = $member->role_id !== null && $member->role?->name !== 'Member'; if ($isLeader) { // Get attendance stats for their department or role audience $audienceIds = []; $roleName = $member->role?->name; if ($member->sunday_school_class_id) { // Priority for Sunday School Teachers assigned to a specific class $audienceIds = \App\Models\Member::where('sunday_school_class_id', $member->sunday_school_class_id)->pluck('id')->toArray(); } elseif ($member->department_id) { // For HODs, Deacons, etc. assigned to a department $audienceIds = \App\Models\Member::where('department_id', $member->department_id)->pluck('id')->toArray(); } // If they are a top-level leader (Pastor/Admin), they might see everything or a specific group. // For now, we'll stick to department/class assignment. $totalMembers = count($audienceIds); $attendanceToday = \App\Models\Attendance::whereIn('member_id', $audienceIds) ->where('date', now()->toDateString()) ->where('status', 'Present') ->count(); $absentToday = \App\Models\Attendance::whereIn('member_id', $audienceIds) ->where('date', now()->toDateString()) ->where('status', 'Absent') ->count(); // Last 4 Sundays trend data (Simplified) $trendData = []; $labels = []; for ($i = 3; $i >= 0; $i--) { $date = now()->subWeeks($i)->previous(\Carbon\Carbon::SUNDAY)->toDateString(); $labels[] = \Carbon\Carbon::parse($date)->format('M d'); $trendData[] = \App\Models\Attendance::whereIn('member_id', $audienceIds) ->where('date', $date) ->where('status', 'Present') ->count(); } } else { // Normal member attendance stats $startOfMonth = now()->startOfMonth()->toDateString(); $endOfMonth = now()->endOfMonth()->toDateString(); $presentDaysMonth = \App\Models\Attendance::where('member_id', $member->id) ->whereBetween('date', [$startOfMonth, $endOfMonth]) ->where('status', 'Present') ->count(); $absentDaysMonth = \App\Models\Attendance::where('member_id', $member->id) ->whereBetween('date', [$startOfMonth, $endOfMonth]) ->where('status', 'Absent') ->count(); $totalMarked = $presentDaysMonth + $absentDaysMonth; $attendancePercentage = $totalMarked > 0 ? round(($presentDaysMonth / $totalMarked) * 100) : 0; } @endphp @if($isLeader)
Total Members {{ $totalMembers }} Present Today {{ $attendanceToday }} Absent Today {{ $absentToday }}
{{-- Main Column --}}
{{-- Cell Group Leader Register Link --}} @if($member->isCellGroupLeader() || $member->is_cell_group_assistant)
Cell Group Register Manage attendance for {{ $member->ledCellGroup->name ?? $member->cellGroup->name }}
Open Register
@endif Attendance Trend (Last 4 Weeks)
{{-- Sidebar Column --}}
{{-- HOD: Show pending department applications --}} @if($member->role?->name === 'HOD') @endif {{-- Pastors: Show appointment management widget --}} @if(in_array($member->role?->name, ['Pastor', 'Senior Pastor'])) @endif {{-- Leader: Manage Cell Group Applications --}} @if($member->isCellGroupLeader() || auth()->user()->isEventManager()) @endif {{-- If leader is not in a cell group themselves, let them apply --}} @if(!$member->cell_group_id) @endif
@else
Welcome Back, {{ $member->first_name }}! Here is an overview of your attendance progress for {{ now()->format('F Y') }}.
Present this Month {{ $presentDaysMonth }} Days Absent this Month {{ $absentDaysMonth }} Days Attendance Progress
{{ $attendancePercentage }}%
{{-- Main Column --}}
@if($member->cell_group_id) @php $cg = $member->cellGroup; $cgPresent = \App\Models\CellGroupAttendance::where('member_id', $member->id) ->where('status', 'Present') ->count(); $cgTotal = \App\Models\CellGroupAttendance::where('member_id', $member->id) ->count(); $cgPercentage = $cgTotal > 0 ? round(($cgPresent / $cgTotal) * 100) : 0; @endphp
Cell Group: {{ $cg->name }} Your attendance progress in your weekly Bible Study.
Meeting Attendance
{{ $cgPercentage }}%
@if($cgTotal > 0) @php $lastCg = \App\Models\CellGroupAttendance::where('member_id', $member->id)->latest('date')->first(); @endphp
Last meeting ({{ $lastCg->date->format('M d') }}): {{ $lastCg->status }}
@endif
@endif Recent Attendance Records @php $recentAttendances = $member->attendances()->latest()->take(5)->get(); @endphp @if($recentAttendances->count() > 0)
@foreach($recentAttendances as $attendance) @endforeach
Date Status Marked By
{{ $attendance->date->format('M d, Y') }} {{ $attendance->status }} {{ $attendance->markedBy->name ?? 'System' }}
@else
No attendance records found for this period.
@endif
{{-- Sidebar Column --}}
@if(!$member->cell_group_id) @endif
@endif {{-- Shared Calendar Section for all members (including leaders) --}}
Church Calendar @livewire('user.calendar-view')
@livewire('user.upcoming-events-sidebar')
@else
Complete Your Member Profile Please provide your details below to activate your member account and access the dashboard.
@endif