Bläddra i källkod

feat(contracts): set new contracts to pending until signed file is uploaded

alvesantos 1 vecka sedan
förälder
incheckning
fb3c795440
2 ändrade filer med 13 tillägg och 0 borttagningar
  1. 8 0
      app/Models/Student.php
  2. 5 0
      app/Services/StudentContractService.php

+ 8 - 0
app/Models/Student.php

@@ -162,6 +162,14 @@ public function calculateStatus(): string
             return self::STATUS_LOCKED;
         }
 
+        $hasPending = $contracts->contains(function ($contract) {
+            return $contract->status === 'pending';
+        });
+
+        if ($hasPending) {
+            return self::STATUS_LEAD; // Or whatever is appropriate. Lead makes sense for pending signatures.
+        }
+
         return self::STATUS_EX_STUDENT;
     }
 

+ 5 - 0
app/Services/StudentContractService.php

@@ -126,6 +126,7 @@ public function create(array $data): StudentContract
             $data['protocol'] = $this->generateNextProtocol();
         }
 
+        $data['status'] = 'pending';
         $contract = StudentContract::create($data);
 
         $this->generateInstallments($contract);
@@ -279,6 +280,10 @@ public function attachFile(int $id, UploadedFile $file, bool $signed = false): ?
             $typeAttribute => $file->getMimeType(),
         ]);
 
+        if ($signed && $model->status === 'pending') {
+            $model->update(['status' => 'active']);
+        }
+
         return $model->fresh();
     }