Jelajahi Sumber

feat: adiciona metodos para buscar contratos congelados, ativos e cancelados

ebagabee 1 bulan lalu
induk
melakukan
9656bd2ba6

+ 17 - 0
app/Http/Controllers/StudentContractController.php

@@ -15,6 +15,23 @@ public function __construct(
         protected StudentContractService $service,
     ) {}
 
+    public function franchisorSummary(): JsonResponse
+    {
+        return $this->successResponse(payload: $this->service->getFranchisorSummary());
+    }
+
+    public function franchisorFrozen(): JsonResponse
+    {
+        $items = $this->service->getFranchisorByStatus('frozen');
+        return $this->successResponse(payload: StudentContractResource::collection($items));
+    }
+
+    public function franchisorCancelled(): JsonResponse
+    {
+        $items = $this->service->getFranchisorByStatus('cancelled');
+        return $this->successResponse(payload: StudentContractResource::collection($items));
+    }
+
     public function index(): JsonResponse
     {
         $unitId    = Auth::user()->load('units')->units->first()?->id;

+ 1 - 0
app/Http/Resources/StudentContractResource.php

@@ -40,6 +40,7 @@ public function toArray(Request $request): array
             'fine_cancelled'          => $this->fine_cancelled,
             'status'                  => $this->status,
             'package_name'            => $this->whenLoaded('classPackageUnit', fn () => $this->classPackageUnit?->name),
+            'unit_name'               => $this->whenLoaded('unit', fn () => $this->unit?->fantasy_name),
             'student_name'            => $this->whenLoaded('student', fn () => $this->student->name),
             'student_document'        => $this->whenLoaded('student', fn () => $this->student->document_number),
             'student_birth_date'      => $this->whenLoaded('student', fn () => $this->student->birth_date?->format('d/m/Y')),

+ 16 - 0
app/Services/StudentContractService.php

@@ -9,6 +9,22 @@
 
 class StudentContractService
 {
+    public function getFranchisorSummary(): array
+    {
+        return [
+            'frozen'    => StudentContract::where('status', 'frozen')->count(),
+            'cancelled' => StudentContract::where('status', 'cancelled')->count(),
+        ];
+    }
+
+    public function getFranchisorByStatus(string $status): Collection
+    {
+        return StudentContract::with(['student', 'unit'])
+            ->where('status', $status)
+            ->orderBy('created_at', 'desc')
+            ->get();
+    }
+
     public function getAll(int $unitId, ?int $studentId = null): Collection
     {
         return StudentContract::with(['student.city', 'student.state', 'classPackageUnit'])

+ 4 - 0
routes/authRoutes/student_contract.php

@@ -4,6 +4,10 @@
 use App\Http\Controllers\StudentContractController;
 
 Route::controller(StudentContractController::class)->prefix('student-contract')->group(function () {
+    Route::get('/franchisor/summary', 'franchisorSummary');
+    Route::get('/franchisor/frozen', 'franchisorFrozen');
+    Route::get('/franchisor/cancelled', 'franchisorCancelled');
+
     Route::get('/', 'index');
 
     Route::post('/', 'store');