totalPatients = Patient::count(); $this->totalDoctors = Doctor::count(); $this->todayRegistrations = Registration::whereDate('registration_date', Carbon::today())->count(); $this->todayIncome = Payment::whereDate('payment_date', Carbon::today())->sum('total_amount'); $dates = collect(); $today = Carbon::today(); for ($i = 6; $i >= 0; $i--) { $date = $today->copy()->subDays($i); $income = Payment::whereDate('payment_date', $date)->sum('total_amount'); $dates->push([ 'date' => $date->format('Y-m-d'), 'income' => $income, ]); } $this->weeklyIncome = $dates; $yesterdayIncome = Payment::whereDate('payment_date', Carbon::yesterday())->sum('total_amount'); if ($yesterdayIncome > 0) { $this->incomeChangePercentage = (($this->todayIncome - $yesterdayIncome) / $yesterdayIncome) * 100; if ($this->incomeChangePercentage > 0) { $this->incomeTrendStatus = 'Naik'; } elseif ($this->incomeChangePercentage < 0) { $this->incomeTrendStatus = 'Turun'; } else { $this->incomeTrendStatus = 'Stabil'; } } else { $this->incomeChangePercentage = null; $this->incomeTrendStatus = 'Tidak Ada Data'; } } public function render() { return view('livewire.dashboard.statistics'); } }