Skip to content

Commit 4772fa7

Browse files
committed
expert dashboard
1 parent 07fe642 commit 4772fa7

File tree

5 files changed

+216
-39
lines changed

5 files changed

+216
-39
lines changed

app/Http/Controllers/Backend/DashboardController.php

+36-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,48 @@ public function __construct()
2727
public function index()
2828
{
2929
$statReports = $this->getStatReports();
30+
$expertStats = [];
31+
$recentConsultations = null;
32+
33+
if (auth()->user()->role_name == 'expert') {
34+
$expertProfile = auth()->user()->expertProfile;
35+
$recentConsultations = UserAppointment::where('expert_profile_id', $expertProfile->id)
36+
->latest()
37+
->limit(10)
38+
->paginate();
39+
$expertStats['Today'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
40+
->whereDate('created_at', now())
41+
->count();
42+
$expertStats['This week'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
43+
->whereBetween('created_at', [
44+
now()->subWeek()->startOf('week'),
45+
now()->startOf('week')
46+
])
47+
->count();
48+
$expertStats['This month'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
49+
->whereBetween('created_at', [
50+
now()->subMonth()->startOf('month'),
51+
now()->startOf('month')
52+
])
53+
->count();
54+
$expertStats['This year'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
55+
->whereBetween('created_at', [
56+
now()->subYear()->startOf('year'),
57+
now()->startOf('year')
58+
])
59+
->count();
60+
$expertStats['All time'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
61+
->count();
62+
}
3063
$fiscalYear = FiscalYear::where('year', currentFiscalYear())->first();
3164
$chartData = $this->getChartData();
3265
$events = Calendar::with('client')->latest()->latest()->get();
3366
$today = today('Asia/Dhaka')->format('Y-m-d');
3467
$clients = Client::get();
3568
$services = Calendar::select('service')->distinct()->latest()->get();
3669
$currentEvents = Calendar::where('start', 'like', "$today%")
37-
->whereNotNull('rejected_at')
38-
->whereNotNull('completed_at')
70+
->whereNotNull('rejected_at')
71+
->whereNotNull('completed_at')
3972
->latest()->get()->groupBy('type');
4073
$projects = Project::get();
4174
$totalExpense = Expense::where('type', 'debit')->sum('amount');
@@ -47,7 +80,7 @@ public function index()
4780
'total' => $totalExpense,
4881
'today' => $todaysExpense?->amount ?? 0
4982
];
50-
return view('backend.dashboard.dashboard', compact('statReports', 'clients', 'expenses', 'events', 'today', 'services', 'currentEvents', 'fiscalYear', 'chartData', 'projects'));
83+
return view('backend.dashboard.dashboard', compact('statReports', 'expertStats', 'recentConsultations', 'clients', 'expenses', 'events', 'today', 'services', 'currentEvents', 'fiscalYear', 'chartData', 'projects'));
5184
}
5285

5386
protected function getStatReports(): array

resources/views/backend/dashboard/dashboard.blade.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@
4343

4444
<x-backend.ui.section-card>
4545
@hasrole('expert')
46-
46+
@if ($expertStats)
47+
@include('backend.includes.expert-stats', ['expertStats' => $expertStats])
48+
@endif
49+
@if ($recentConsultations)
50+
@include('backend.includes.recent-consultations', ['recentConsultations' => $recentConsultations])
51+
@endif
4752
@endhasrole
4853

4954
@can('read invoice')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class="mb-5">
2+
<h4 class="text-center mb-3">
3+
Consultation Overview
4+
</h4>
5+
<table class="table table-bordered border-black border-2">
6+
<thead>
7+
<tr class="bg-light">
8+
<th class="p-1 text-center fs-5">Time Period</th>
9+
<th class="p-1 text-center fs-5">Consultations</th>
10+
</tr>
11+
</thead>
12+
<tbody>
13+
@foreach ($expertStats as $key => $value)
14+
<tr>
15+
<td class="p-2 text-center fs-5">{{ $key }}</td>
16+
<td class="p-2 text-center fs-5">{{ $value }}</td>
17+
</tr>
18+
@endforeach
19+
</tbody>
20+
</table>
21+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<div>
2+
<h4 class="text-center">
3+
Recent Consultations
4+
</h4>
5+
<x-backend.table.basic :items="$recentConsultations">
6+
<thead>
7+
<tr>
8+
<th>#</th>
9+
<th>User Info</th>
10+
@if (request('type') == 'consultation' && auth()->user()->hasRole('admin'))
11+
<th>Appointment With</th>
12+
@endif
13+
<th>Date & Time</th>
14+
<th>Status</th>
15+
<th>Location</th>
16+
<th>Created at</th>
17+
@canany(['update appointment', 'approve appointment'])
18+
<th>Action</th>
19+
@endcanany
20+
</tr>
21+
</thead>
22+
23+
<tbody>
24+
@forelse ($recentConsultations as $key => $appointment)
25+
<tr>
26+
<td>{{++$key}}</td>
27+
<td>
28+
<p class="mb-1">
29+
<strong>Name:</strong> <span>{{ $appointment->name }}</span>
30+
</p>
31+
<p class="mb-1">
32+
<strong>Email:</strong> <span>{{ $appointment->email }}</span>
33+
</p>
34+
<p class="mb-1">
35+
<strong>Phone:</strong> <span>{{ $appointment->phone }}</span>
36+
</p>
37+
<div class="d-flex gap-3">
38+
<p class="mb-1">
39+
<strong>District:</strong> <span>{{ $appointment->district }}</span>
40+
</p>
41+
<p class="mb-1">
42+
<strong>Thana:</strong> <span>{{ $appointment->thana }}</span>
43+
</p>
44+
</div>
45+
</td>
46+
@if (request('type') == 'consultation' && auth()->user()->hasRole('admin'))
47+
<td>
48+
<p class="mb-1">
49+
<strong>Expert Name:</strong> <span>{{ $appointment->expertProfile?->name }}</span>
50+
</p>
51+
<p class="mb-1">
52+
<strong>Post:</strong> <span
53+
class="badge bg-success p-2">{{ $appointment->expertProfile?->post }}</span>
54+
</p>
55+
</td>
56+
@endif
57+
<td>
58+
<strong class="d-block">Date:
59+
{{ Carbon\Carbon::parse($appointment->date)->format('d M, Y') }}</strong>
60+
<strong class="d-block">Time: {{ $appointment->time }}</strong>
61+
62+
</td>
63+
<td>
64+
@if ($appointment->is_completed)
65+
<span class="badge bg-soft-success text-success p-1 fs-6">Completed</span>
66+
@else
67+
<span class="badge bg-warning p-1 fs-6">Yet to complete</span>
68+
@endif
69+
</td>
70+
@isset($appointment->map_id)
71+
<td>
72+
<strong>Location: {{ $appointment->map->location }}</strong>
73+
<strong class="d-block">Address:</strong>
74+
<p class="text-muted">
75+
{{ $appointment->map->address }}
76+
</p>
77+
</td>
78+
@else
79+
<td>
80+
<span class="badge bg-info p-1 fs-6">
81+
Virtual
82+
</span>
83+
</td>
84+
@endisset
85+
<td>
86+
<span class="fw-bold">
87+
{{ $appointment->created_at->format('d F, Y') }}
88+
</span>
89+
</td>
90+
@canany(['update appointment', 'approve appointment'])
91+
<td>
92+
<form action="{{ route('user-appointments.approve', $appointment->id) }}" method="post">
93+
@csrf
94+
@method('PATCH')
95+
<button type="submit" class="btn btn-primary btn-sm">
96+
Approve
97+
</button>
98+
</form>
99+
</td>
100+
@endcanany
101+
</tr>
102+
@empty
103+
<tr>
104+
<td colspan="7" class="bg-light">
105+
<div class="text-center text-muted">
106+
No Appointments Found
107+
</div>
108+
</td>
109+
</tr>
110+
@endforelse
111+
</tbody>
112+
113+
114+
115+
</x-backend.table.basic>
116+
</div>

resources/views/backend/layouts/sidebar.blade.php

+37-35
Original file line numberDiff line numberDiff line change
@@ -730,43 +730,45 @@
730730
</a>
731731
<div class="collapse" id="appointments-tab">
732732
<ul class="nav-second-level">
733-
@canany(['update appointment', 'read appointment'])
734-
<li>
735-
<a href="#my-appointmentSection" data-bs-toggle="collapse">
736-
<i class="mdi mdi-face-agent"></i>
737-
<span>My Appointments</span>
738-
<span class="menu-arrow"></span>
739-
</a>
740-
<div class="collapse" id="my-appointmentSection">
741-
<ul class="nav-second-level">
742-
@canany(['update appointment', 'approve appointment', 'read appointment'])
743-
<li>
744-
<a href="{{ route('user-appointments.index') }}">
745-
Pending For Approval
746-
</a>
747-
</li>
748-
<li>
749-
<a href="{{ route('user-appointments.approved') }}">
750-
Approved
751-
</a>
752-
</li>
753-
<li>
754-
<a href="{{ route('user-appointments.completed') }}">
755-
Completed
756-
</a>
757-
</li>
758-
<li>
759-
<a href="{{ route('user-appointments.times') }}">
760-
Appointment Times
761-
</a>
762-
</li>
763-
@endcanany
733+
@hasanyrole(['admin', 'super admin'])
734+
@canany(['update appointment', 'read appointment'])
735+
<li>
736+
<a href="#my-appointmentSection" data-bs-toggle="collapse">
737+
<i class="mdi mdi-face-agent"></i>
738+
<span>My Appointments</span>
739+
<span class="menu-arrow"></span>
740+
</a>
741+
<div class="collapse" id="my-appointmentSection">
742+
<ul class="nav-second-level">
743+
@canany(['update appointment', 'approve appointment', 'read appointment'])
744+
<li>
745+
<a href="{{ route('user-appointments.index') }}">
746+
Pending For Approval
747+
</a>
748+
</li>
749+
<li>
750+
<a href="{{ route('user-appointments.approved') }}">
751+
Approved
752+
</a>
753+
</li>
754+
<li>
755+
<a href="{{ route('user-appointments.completed') }}">
756+
Completed
757+
</a>
758+
</li>
759+
<li>
760+
<a href="{{ route('user-appointments.times') }}">
761+
Appointment Times
762+
</a>
763+
</li>
764+
@endcanany
764765

765766

766-
</ul>
767-
</div>
768-
</li>
769-
@endcanany
767+
</ul>
768+
</div>
769+
</li>
770+
@endcanany
771+
@endhasanyrole
770772
@canany(['update consultation', 'read consultation'])
771773
<li>
772774
<a href="#my-consultation" data-bs-toggle="collapse">

0 commit comments

Comments
 (0)