Explorar o código

feat(student-summary): enhance summary response to include student counts by status

alvesantos hai 3 días
pai
achega
20ba5703b8

+ 8 - 0
app/Http/Controllers/FranchiseeDashboardController.php

@@ -20,8 +20,16 @@ public function summary(): JsonResponse
         $contracts = StudentContract::latestVersion()->where('unit_id', $unitId)->get(['id', 'status']);
         $contracts = StudentContract::latestVersion()->where('unit_id', $unitId)->get(['id', 'status']);
         $unit = \App\Models\Unit::find($unitId);
         $unit = \App\Models\Unit::find($unitId);
 
 
+        $studentsByStatus = Student::where('unit_id', $unitId)->get(['status']);
+
         return $this->successResponse(payload: [
         return $this->successResponse(payload: [
             'students_count' => $students->count(),
             'students_count' => $students->count(),
+            'students_by_status' => [
+                'lead' => $studentsByStatus->where('status', Student::STATUS_LEAD)->count(),
+                'active' => $studentsByStatus->where('status', Student::STATUS_ACTIVE)->count(),
+                'ex_student' => $studentsByStatus->where('status', Student::STATUS_EX_STUDENT)->count(),
+                'locked' => $studentsByStatus->where('status', Student::STATUS_LOCKED)->count(),
+            ],
             'unit_config' => [
             'unit_config' => [
                 'active_students_min' => $unit->active_students_min ?? 30,
                 'active_students_min' => $unit->active_students_min ?? 30,
                 'active_students_medium' => $unit->active_students_medium ?? 50,
                 'active_students_medium' => $unit->active_students_medium ?? 50,

+ 8 - 1
app/Services/StudentService.php

@@ -175,7 +175,14 @@ public function getFranchisorSummary(array $unitIds = []): array
 
 
         $active = (clone $query)->where('status', 'active')->count();
         $active = (clone $query)->where('status', 'active')->count();
 
 
-        return ['total' => $total, 'active' => $active];
+        $byStatus = [
+            'lead' => (clone $query)->where('status', Student::STATUS_LEAD)->count(),
+            'active' => $active,
+            'ex_student' => (clone $query)->where('status', Student::STATUS_EX_STUDENT)->count(),
+            'locked' => (clone $query)->where('status', Student::STATUS_LOCKED)->count(),
+        ];
+
+        return ['total' => $total, 'active' => $active, 'by_status' => $byStatus];
     }
     }
 
 
     //
     //