Quellcode durchsuchen

feat: adiciona dashboard correto

ebagabee vor 2 Wochen
Ursprung
Commit
e527749efd

+ 6 - 0
app/Models/Student.php

@@ -5,6 +5,7 @@
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Database\Eloquent\SoftDeletes;
 
 /**
@@ -78,6 +79,11 @@ class Student extends Model
         'deleted_at' => 'datetime',
     ];
 
+    public function contracts(): HasMany
+    {
+        return $this->hasMany(StudentContract::class);
+    }
+
     public function unit(): BelongsTo
     {
         return $this->belongsTo(Unit::class, 'unit_id');

+ 1 - 0
app/Services/StudentContractService.php

@@ -17,6 +17,7 @@ public function getFranchisorSummary(array $unitIds = []): array
             ->when(!empty($unitIds), fn ($q) => $q->whereIn('unit_id', $unitIds));
 
         return [
+            'active'    => (clone $base)->where('status', 'active')->count(),
             'frozen'    => (clone $base)->where('status', 'frozen')->count(),
             'cancelled' => (clone $base)->where('status', 'cancelled')->count(),
         ];

+ 1 - 1
app/Services/StudentService.php

@@ -23,7 +23,7 @@ public function getAll(User $user): Collection
     public function getFranchisorActive(array $unitIds = []): Collection
     {
         return Student::with('unit')
-            ->where('status', 'active')
+            ->whereHas('contracts', fn ($q) => $q->where('status', 'active'))
             ->when(!empty($unitIds), fn ($q) => $q->whereIn('unit_id', $unitIds))
             ->orderBy('name')
             ->get();