count(); $upcomingPayments = PaymentScheduleItem::whereNull('schedule_id') ->orWhereHas('schedule', fn ($q) => $q->whereHas('contract')) ->whereDate('due_date', '<=', now()->addDays(30)) ->whereDate('due_date', '>=', now()) ->count(); return [ Stat::make('Tổng doanh thu', number_format($totalRevenue) . ' VNĐ') ->description('Tổng giá trị tất cả HĐ') ->color('primary'), Stat::make('Đã thu', number_format($totalPaid) . ' VNĐ') ->description('Tổng tiền đã thanh toán') ->color('success'), Stat::make('Công nợ phải thu', number_format($totalRemaining) . ' VNĐ') ->description('Tổng tiền chưa thu') ->color('danger'), Stat::make('HĐ hiệu lực', $activeContracts) ->description('Số hợp đồng đang hiệu lực') ->color('warning'), Stat::make('Đợt TT sắp đến hạn', $upcomingPayments) ->description('Trong 30 ngày tới') ->color('info'), ]; } }