|
|
@@ -821,4 +821,54 @@ public function editarRegistroAdmin(Request $request, $id)
|
|
|
return response()->json($usuario, 200);
|
|
|
}
|
|
|
|
|
|
+ public function RecalcularCompletado()
|
|
|
+{
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ // Traer todos los registros
|
|
|
+ $registros = DB::table('registroacademico')->get();
|
|
|
+
|
|
|
+ foreach ($registros as $registro) {
|
|
|
+ $data = (array) $registro;
|
|
|
+
|
|
|
+ // Revisar campos (excluyendo los que no deben contar)
|
|
|
+ $incompleto = false;
|
|
|
+ foreach ($data as $key => $val) {
|
|
|
+ if (in_array($key, ['id', 'idEscuela', 'idAlumno', 'personasAutorizadas', 'completado', 'usuarioRegistro'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (is_null($val)) {
|
|
|
+ $incompleto = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (is_string($val) && trim($val) === '') {
|
|
|
+ $incompleto = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $nuevoCompletado = $incompleto ? 0 : 1;
|
|
|
+
|
|
|
+ // Solo actualizar si cambia
|
|
|
+ if ($registro->completado != $nuevoCompletado) {
|
|
|
+ DB::table('registroacademico')
|
|
|
+ ->where('id', $registro->id)
|
|
|
+ ->update(['completado' => $nuevoCompletado]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+
|
|
|
+ return response()->json([
|
|
|
+ 'mensaje' => 'Proceso finalizado con éxito',
|
|
|
+ 'total' => count($registros)
|
|
|
+ ], 200);
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ return response()->json(['mensaje' => $e->getMessage()], 500);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
}
|