@@ -27,15 +27,48 @@ public function __construct()
27
27
public function index ()
28
28
{
29
29
$ 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
+ }
30
63
$ fiscalYear = FiscalYear::where ('year ' , currentFiscalYear ())->first ();
31
64
$ chartData = $ this ->getChartData ();
32
65
$ events = Calendar::with ('client ' )->latest ()->latest ()->get ();
33
66
$ today = today ('Asia/Dhaka ' )->format ('Y-m-d ' );
34
67
$ clients = Client::get ();
35
68
$ services = Calendar::select ('service ' )->distinct ()->latest ()->get ();
36
69
$ currentEvents = Calendar::where ('start ' , 'like ' , "$ today% " )
37
- ->whereNotNull ('rejected_at ' )
38
- ->whereNotNull ('completed_at ' )
70
+ ->whereNotNull ('rejected_at ' )
71
+ ->whereNotNull ('completed_at ' )
39
72
->latest ()->get ()->groupBy ('type ' );
40
73
$ projects = Project::get ();
41
74
$ totalExpense = Expense::where ('type ' , 'debit ' )->sum ('amount ' );
@@ -47,7 +80,7 @@ public function index()
47
80
'total ' => $ totalExpense ,
48
81
'today ' => $ todaysExpense ?->amount ?? 0
49
82
];
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 ' ));
51
84
}
52
85
53
86
protected function getStatReports (): array
0 commit comments