diff --git a/app/Http/Controllers/Admin/Dashboard/OverviewController.php b/app/Http/Controllers/Admin/Dashboard/OverviewController.php index 43f9d9e..9b7e975 100644 --- a/app/Http/Controllers/Admin/Dashboard/OverviewController.php +++ b/app/Http/Controllers/Admin/Dashboard/OverviewController.php @@ -15,11 +15,35 @@ class OverviewController extends Controller { public function index() { - $todayIncome = Transaction::query()->barbershop()->whereDate('created_at', now()->today())->sum('total'); - $yesterdayIncome = Transaction::query()->barbershop()->whereDate('created_at', now()->yesterday())->sum('total'); + $todayIncome = Transaction::query() + ->barbershop() + ->whereDate('created_at', now()->today()) + ->when(auth()->user()->role_id === 5, function ($query) { + return $query->where('user_id', auth()->id()); + }) + ->sum('total'); + $yesterdayIncome = Transaction::query() + ->barbershop() + ->whereDate('created_at', now()->yesterday()) + ->when(auth()->user()->role_id === 5, function ($query) { + return $query->where('user_id', auth()->id()); + }) + ->sum('total'); - $todayShaving = Transaction::query()->barbershop()->today()->count(); - $yesterdayShaving = Transaction::query()->barbershop()->yesterday()->count(); + $todayShaving = Transaction::query() + ->barbershop() + ->today() + ->when(auth()->user()->role_id === 5, function ($query) { + return $query->where('user_id', auth()->id()); + }) + ->count(); + $yesterdayShaving = Transaction::query() + ->barbershop() + ->yesterday() + ->when(auth()->user()->role_id === 5, function ($query) { + return $query->where('user_id', auth()->id()); + }) + ->count(); $todayExpense = Expense::query()->barbershop()->today()->sum('amount'); $yesterdayExpense = Expense::query()->barbershop()->yesterday()->sum('amount'); @@ -50,6 +74,13 @@ public function index() ->limit(5) ->get(); + $incomeByBarber = User::with('biography') + ->barbershop() + ->barber() + ->withSum('transactions', 'total') + ->withCount('transactions') + ->get(); + return view('pages.admin.dashboard.overview', [ 'pageTitle' => 'Ringkasan', 'todayIncome' => $todayIncome, @@ -62,6 +93,7 @@ public function index() 'yesterdayNewCustomer' => $yesterdayNewCustomer, 'cash' => Barbershop::findOrFail(Auth::user()->barbershop_id)->cash, 'topCustomersByTotal' => $topCustomersByTotal, + 'incomeByBarber' => $incomeByBarber, ]); } diff --git a/resources/views/pages/admin/dashboard/overview.blade.php b/resources/views/pages/admin/dashboard/overview.blade.php index e90ccc4..b0eff63 100644 --- a/resources/views/pages/admin/dashboard/overview.blade.php +++ b/resources/views/pages/admin/dashboard/overview.blade.php @@ -132,6 +132,35 @@ +