Skip to content

Commit

Permalink
expert dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
itsemon245 committed Jul 2, 2024
1 parent 07fe642 commit 4772fa7
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 39 deletions.
39 changes: 36 additions & 3 deletions app/Http/Controllers/Backend/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,48 @@ public function __construct()
public function index()
{
$statReports = $this->getStatReports();
$expertStats = [];
$recentConsultations = null;

if (auth()->user()->role_name == 'expert') {
$expertProfile = auth()->user()->expertProfile;
$recentConsultations = UserAppointment::where('expert_profile_id', $expertProfile->id)
->latest()
->limit(10)
->paginate();
$expertStats['Today'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
->whereDate('created_at', now())
->count();
$expertStats['This week'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
->whereBetween('created_at', [
now()->subWeek()->startOf('week'),
now()->startOf('week')
])
->count();
$expertStats['This month'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
->whereBetween('created_at', [
now()->subMonth()->startOf('month'),
now()->startOf('month')
])
->count();
$expertStats['This year'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
->whereBetween('created_at', [
now()->subYear()->startOf('year'),
now()->startOf('year')
])
->count();
$expertStats['All time'] = UserAppointment::where('expert_profile_id', $expertProfile->id)
->count();
}
$fiscalYear = FiscalYear::where('year', currentFiscalYear())->first();
$chartData = $this->getChartData();
$events = Calendar::with('client')->latest()->latest()->get();
$today = today('Asia/Dhaka')->format('Y-m-d');
$clients = Client::get();
$services = Calendar::select('service')->distinct()->latest()->get();
$currentEvents = Calendar::where('start', 'like', "$today%")
->whereNotNull('rejected_at')
->whereNotNull('completed_at')
->whereNotNull('rejected_at')
->whereNotNull('completed_at')
->latest()->get()->groupBy('type');
$projects = Project::get();
$totalExpense = Expense::where('type', 'debit')->sum('amount');
Expand All @@ -47,7 +80,7 @@ public function index()
'total' => $totalExpense,
'today' => $todaysExpense?->amount ?? 0
];
return view('backend.dashboard.dashboard', compact('statReports', 'clients', 'expenses', 'events', 'today', 'services', 'currentEvents', 'fiscalYear', 'chartData', 'projects'));
return view('backend.dashboard.dashboard', compact('statReports', 'expertStats', 'recentConsultations', 'clients', 'expenses', 'events', 'today', 'services', 'currentEvents', 'fiscalYear', 'chartData', 'projects'));
}

protected function getStatReports(): array
Expand Down
7 changes: 6 additions & 1 deletion resources/views/backend/dashboard/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@

<x-backend.ui.section-card>
@hasrole('expert')

@if ($expertStats)
@include('backend.includes.expert-stats', ['expertStats' => $expertStats])
@endif
@if ($recentConsultations)
@include('backend.includes.recent-consultations', ['recentConsultations' => $recentConsultations])
@endif
@endhasrole

@can('read invoice')
Expand Down
21 changes: 21 additions & 0 deletions resources/views/backend/includes/expert-stats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="mb-5">
<h4 class="text-center mb-3">
Consultation Overview
</h4>
<table class="table table-bordered border-black border-2">
<thead>
<tr class="bg-light">
<th class="p-1 text-center fs-5">Time Period</th>
<th class="p-1 text-center fs-5">Consultations</th>
</tr>
</thead>
<tbody>
@foreach ($expertStats as $key => $value)
<tr>
<td class="p-2 text-center fs-5">{{ $key }}</td>
<td class="p-2 text-center fs-5">{{ $value }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
116 changes: 116 additions & 0 deletions resources/views/backend/includes/recent-consultations.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<div>
<h4 class="text-center">
Recent Consultations
</h4>
<x-backend.table.basic :items="$recentConsultations">
<thead>
<tr>
<th>#</th>
<th>User Info</th>
@if (request('type') == 'consultation' && auth()->user()->hasRole('admin'))
<th>Appointment With</th>
@endif
<th>Date & Time</th>
<th>Status</th>
<th>Location</th>
<th>Created at</th>
@canany(['update appointment', 'approve appointment'])
<th>Action</th>
@endcanany
</tr>
</thead>

<tbody>
@forelse ($recentConsultations as $key => $appointment)
<tr>
<td>{{++$key}}</td>
<td>
<p class="mb-1">
<strong>Name:</strong> <span>{{ $appointment->name }}</span>
</p>
<p class="mb-1">
<strong>Email:</strong> <span>{{ $appointment->email }}</span>
</p>
<p class="mb-1">
<strong>Phone:</strong> <span>{{ $appointment->phone }}</span>
</p>
<div class="d-flex gap-3">
<p class="mb-1">
<strong>District:</strong> <span>{{ $appointment->district }}</span>
</p>
<p class="mb-1">
<strong>Thana:</strong> <span>{{ $appointment->thana }}</span>
</p>
</div>
</td>
@if (request('type') == 'consultation' && auth()->user()->hasRole('admin'))
<td>
<p class="mb-1">
<strong>Expert Name:</strong> <span>{{ $appointment->expertProfile?->name }}</span>
</p>
<p class="mb-1">
<strong>Post:</strong> <span
class="badge bg-success p-2">{{ $appointment->expertProfile?->post }}</span>
</p>
</td>
@endif
<td>
<strong class="d-block">Date:
{{ Carbon\Carbon::parse($appointment->date)->format('d M, Y') }}</strong>
<strong class="d-block">Time: {{ $appointment->time }}</strong>

</td>
<td>
@if ($appointment->is_completed)
<span class="badge bg-soft-success text-success p-1 fs-6">Completed</span>
@else
<span class="badge bg-warning p-1 fs-6">Yet to complete</span>
@endif
</td>
@isset($appointment->map_id)
<td>
<strong>Location: {{ $appointment->map->location }}</strong>
<strong class="d-block">Address:</strong>
<p class="text-muted">
{{ $appointment->map->address }}
</p>
</td>
@else
<td>
<span class="badge bg-info p-1 fs-6">
Virtual
</span>
</td>
@endisset
<td>
<span class="fw-bold">
{{ $appointment->created_at->format('d F, Y') }}
</span>
</td>
@canany(['update appointment', 'approve appointment'])
<td>
<form action="{{ route('user-appointments.approve', $appointment->id) }}" method="post">
@csrf
@method('PATCH')
<button type="submit" class="btn btn-primary btn-sm">
Approve
</button>
</form>
</td>
@endcanany
</tr>
@empty
<tr>
<td colspan="7" class="bg-light">
<div class="text-center text-muted">
No Appointments Found
</div>
</td>
</tr>
@endforelse
</tbody>



</x-backend.table.basic>
</div>
72 changes: 37 additions & 35 deletions resources/views/backend/layouts/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,43 +730,45 @@
</a>
<div class="collapse" id="appointments-tab">
<ul class="nav-second-level">
@canany(['update appointment', 'read appointment'])
<li>
<a href="#my-appointmentSection" data-bs-toggle="collapse">
<i class="mdi mdi-face-agent"></i>
<span>My Appointments</span>
<span class="menu-arrow"></span>
</a>
<div class="collapse" id="my-appointmentSection">
<ul class="nav-second-level">
@canany(['update appointment', 'approve appointment', 'read appointment'])
<li>
<a href="{{ route('user-appointments.index') }}">
Pending For Approval
</a>
</li>
<li>
<a href="{{ route('user-appointments.approved') }}">
Approved
</a>
</li>
<li>
<a href="{{ route('user-appointments.completed') }}">
Completed
</a>
</li>
<li>
<a href="{{ route('user-appointments.times') }}">
Appointment Times
</a>
</li>
@endcanany
@hasanyrole(['admin', 'super admin'])
@canany(['update appointment', 'read appointment'])
<li>
<a href="#my-appointmentSection" data-bs-toggle="collapse">
<i class="mdi mdi-face-agent"></i>
<span>My Appointments</span>
<span class="menu-arrow"></span>
</a>
<div class="collapse" id="my-appointmentSection">
<ul class="nav-second-level">
@canany(['update appointment', 'approve appointment', 'read appointment'])
<li>
<a href="{{ route('user-appointments.index') }}">
Pending For Approval
</a>
</li>
<li>
<a href="{{ route('user-appointments.approved') }}">
Approved
</a>
</li>
<li>
<a href="{{ route('user-appointments.completed') }}">
Completed
</a>
</li>
<li>
<a href="{{ route('user-appointments.times') }}">
Appointment Times
</a>
</li>
@endcanany


</ul>
</div>
</li>
@endcanany
</ul>
</div>
</li>
@endcanany
@endhasanyrole
@canany(['update consultation', 'read consultation'])
<li>
<a href="#my-consultation" data-bs-toggle="collapse">
Expand Down

0 comments on commit 4772fa7

Please sign in to comment.