|
|
|
|
@ -163,6 +163,53 @@ class ApiPersonaController extends Controller
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getFunciones(Request $request){ |
|
|
|
|
/** |
|
|
|
|
* Obtiene las funciones de una persona según el DNI o el número de teléfono. |
|
|
|
|
* |
|
|
|
|
* @param \Illuminate\Http\Request $request La solicitud HTTP que contiene los parámetros de búsqueda. |
|
|
|
|
* @return \Illuminate\Http\JsonResponse La respuesta JSON con los datos de la persona encontrada, o un mensaje de error si no se encuentra. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
if(!$request->has('unidad_academica')){ |
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.DEBE_INGRESAR_UNIDAD_ACADEMICA')], HttpStatus::BAD_REQUEST); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!$request->has('dni') && !$request->has('telefono')){ |
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.DEBE_INGRESAR_DNI_O_TELEFONO')], HttpStatus::BAD_REQUEST); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
|
|
if ($request->has('dni')) { |
|
|
|
|
|
|
|
|
|
$persona = UaderMapuchePersona::buscarPersonaPorDni($request->get('dni')); |
|
|
|
|
|
|
|
|
|
if ($persona) { |
|
|
|
|
return ApiPersonaController::extraerFunciones($persona, $request->get('unidad_academica')); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($request->has('telefono')) { |
|
|
|
|
|
|
|
|
|
$persona = UaderMapuchePersona::BuscarPersonaPorTelefono($request->get('telefono')); |
|
|
|
|
|
|
|
|
|
if ($persona) { |
|
|
|
|
return ApiPersonaController::extraerFunciones($persona, $request->get('unidad_academica')); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.NO_ENCONTRADA')], HttpStatus::NOT_FOUND); |
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
|
|
Log::error(trans('persona.LOG_DATOS') . $e->getMessage()); |
|
|
|
|
return response()->json(['error' => trans('persona.ERROR')], HttpStatus::INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# SUB RUTAS ADICIONALES |
|
|
|
|
|
|
|
|
|
public function extraerHorarios($persona, $unidad_academica, $funcion, $dia, $tipo_horario){ |
|
|
|
|
@ -292,6 +339,44 @@ class ApiPersonaController extends Controller
|
|
|
|
|
return response()->json($datos, HttpStatus::OK); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function extraerFunciones($persona, $unidad_academica){ |
|
|
|
|
|
|
|
|
|
$declaracion_jurada = $persona->declaracion_jurada; |
|
|
|
|
|
|
|
|
|
if(!$declaracion_jurada){ |
|
|
|
|
return response()->json(['error' => trans('persona.DECLARACION_JURADA_NO_ENCONTRADA')], HttpStatus::NOT_FOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$designaciones = $declaracion_jurada->CargosGrupo()->where('estado', 'A')->get(); |
|
|
|
|
|
|
|
|
|
if(empty($designaciones)){ |
|
|
|
|
return response()->json(['error' => trans('persona.NO_TIENE_DESIGNACIONES')], HttpStatus::NOT_FOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$funciones = array(); |
|
|
|
|
$funcion = null; |
|
|
|
|
|
|
|
|
|
foreach ($designaciones as $designacion) { |
|
|
|
|
|
|
|
|
|
if($designacion->Sede->ua_guarani == $unidad_academica){ |
|
|
|
|
|
|
|
|
|
$funcion = ['tipo' => $designacion->id_funcion, 'unidad_academica' => $unidad_academica]; |
|
|
|
|
|
|
|
|
|
if(!in_array($funcion, $funciones)){ # para que no se repitan las funciones por tarea o designacion |
|
|
|
|
$funciones[] = $funcion; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$datos = array( |
|
|
|
|
'id' => $declaracion_jurada->id_persona, |
|
|
|
|
'nombre' => ucwords(strtolower(trim($persona->desc_nombr))) . ' ' . ucwords(strtolower(trim($persona->desc_appat))), |
|
|
|
|
'funciones' => $funciones, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return response()->json($datos, HttpStatus::OK); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# FUNCION STANDALONE: |
|
|
|
|
public static function compararHorarios($a, $b) { |
|
|
|
|
return strcmp($a['hora_entra'], $b['hora_entra']); |
|
|
|
|
|