64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Dashboard;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\Doctor;
|
|
use App\Models\Patient;
|
|
use App\Models\Payment;
|
|
use Livewire\Component;
|
|
use App\Models\Registration;
|
|
|
|
class Statistics extends Component
|
|
{
|
|
public $totalPatients;
|
|
public $totalDoctors;
|
|
public $todayRegistrations;
|
|
public $todayIncome;
|
|
public $weeklyIncome = [];
|
|
public $incomeChangePercentage;
|
|
public $incomeTrendStatus;
|
|
|
|
public function mount()
|
|
{
|
|
$this->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');
|
|
}
|
|
}
|