barbershop()->whereDate('created_at', now()->today())->sum('total'); $yesterdayIncome = Transaction::query()->barbershop()->whereDate('created_at', now()->yesterday())->sum('total'); $todayShaving = Transaction::query()->barbershop()->today()->count(); $yesterdayShaving = Transaction::query()->barbershop()->yesterday()->count(); $todayExpense = Expense::query()->barbershop()->today()->sum('amount'); $yesterdayExpense = Expense::query()->barbershop()->yesterday()->sum('amount'); $todayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) { $query->where('id', '<>', DB::raw('transactions.id')); }) ->barbershop() ->today() ->distinct('customer_id') ->count('customer_id'); $yesterdayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) { $query->where('id', '<>', DB::raw('transactions.id')); }) ->barbershop() ->yesterday() ->distinct('customer_id') ->count('customer_id'); $topCustomersByTotal = Transaction::groupBy('customer_id') ->select( 'customer_id', DB::raw('SUM(total) as total_transaction'), DB::raw('COUNT(*) as transaction_count') ) ->orderBy('total_transaction', 'desc') ->limit(5) ->get(); return view('pages.admin.dashboard.overview', [ 'pageTitle' => 'Ringkasan', 'todayIncome' => $todayIncome, 'yesterdayIncome' => $yesterdayIncome, 'todayShaving' => $todayShaving, 'yesterdayShaving' => $yesterdayShaving, 'todayExpense' => $todayExpense, 'yesterdayExpense' => $yesterdayExpense, 'todayNewCustomer' => $todayNewCustomer, 'yesterdayNewCustomer' => $yesterdayNewCustomer, 'cash' => Barbershop::findOrFail(Auth::user()->barbershop_id)->cash, 'topCustomersByTotal' => $topCustomersByTotal, ]); } }