|
|
@@ -48,13 +48,19 @@ private function enrollments(array $unitIds): array
|
|
|
{
|
|
|
$start = Carbon::now()->startOfMonth()->subMonthsNoOverflow(5);
|
|
|
|
|
|
- $counts = DB::table('students')
|
|
|
+ // Agrupa por ano-mês de forma portável (independente do SGBD): puxa apenas
|
|
|
+ // a data de cadastro no período e conta os meses em memória.
|
|
|
+ $createdAt = DB::table('students')
|
|
|
->whereNull('deleted_at')
|
|
|
->where('created_at', '>=', $start)
|
|
|
->when(!empty($unitIds), fn ($q) => $q->whereIn('unit_id', $unitIds))
|
|
|
- ->selectRaw("DATE_FORMAT(created_at, '%Y-%m') AS ym, COUNT(*) AS total")
|
|
|
- ->groupBy('ym')
|
|
|
- ->pluck('total', 'ym');
|
|
|
+ ->pluck('created_at');
|
|
|
+
|
|
|
+ $counts = [];
|
|
|
+ foreach ($createdAt as $date) {
|
|
|
+ $ym = Carbon::parse($date)->format('Y-m');
|
|
|
+ $counts[$ym] = ($counts[$ym] ?? 0) + 1;
|
|
|
+ }
|
|
|
|
|
|
$labels = [];
|
|
|
$data = [];
|
|
|
@@ -78,12 +84,13 @@ private function birthdays(array $unitIds): array
|
|
|
->whereNull('deleted_at')
|
|
|
->whereMonth('birth_date', Carbon::now()->month)
|
|
|
->when(!empty($unitIds), fn ($q) => $q->whereIn('unit_id', $unitIds))
|
|
|
- ->orderByRaw('DAYOFMONTH(birth_date)')
|
|
|
->get(['name', 'birth_date'])
|
|
|
->map(fn ($s) => [
|
|
|
'day' => (int) Carbon::parse($s->birth_date)->day,
|
|
|
'name' => $s->name,
|
|
|
])
|
|
|
+ ->sortBy('day')
|
|
|
+ ->values()
|
|
|
->all();
|
|
|
}
|
|
|
|