|
|
|
@ -5,17 +5,81 @@ namespace App\Http\Controllers; |
|
|
|
use App\Models\UaderMapuchePersona; |
|
|
|
use App\Models\UaderMapuchePersona; |
|
|
|
use App\Models\UaderDjPersona; |
|
|
|
use App\Models\UaderDjPersona; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
|
|
use App\Constants\HttpStatus; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
|
|
|
|
|
|
|
class ApiPersonaController extends Controller |
|
|
|
class ApiPersonaController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
/** |
|
|
|
|
|
|
|
* Display a listing of the resource. |
|
|
|
public function getDatos(Request $request) |
|
|
|
*/ |
|
|
|
|
|
|
|
public function index() |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
return json_encode(['reply' => 'hola']); |
|
|
|
if ($request->has('dni')) { |
|
|
|
|
|
|
|
return ApiPersonaController::rutaGetDatosPorDni($request->get('dni')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($request->has('telefono')) { |
|
|
|
|
|
|
|
return ApiPersonaController::rutaGetDatosPorTelefono($request->get('telefono')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.DEBE_INGRESAR_DNI_O_TELEFONO')], HttpStatus::BAD_REQUEST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function rutaGetDatosPorDni($dni){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$persona = UaderMapuchePersona::buscarPersonaPorDni($dni); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($persona) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ApiPersonaController::extraerDatos($persona); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.NO_ENCONTRADA_POR_DNI')], HttpStatus::NOT_FOUND); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
Log::error(trans('persona.LOG_POR_DNI') . $e->getMessage()); |
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.ERROR_POR_DNI')], HttpStatus::INTERNAL_SERVER_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function rutaGetDatosPorTelefono($telefono){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
$persona = UaderMapuchePersona::BuscarPersonaPorTelefono($telefono); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($persona) { |
|
|
|
|
|
|
|
return ApiPersonaController::extraerDatos($persona); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.NO_ENCONTRADA_POR_TELEFONO')], HttpStatus::NOT_FOUND); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
Log::error(trans('persona.LOG_POR_TELEFONO') . $e->getMessage()); |
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.ERROR_POR_TELEFONO')], HttpStatus::INTERNAL_SERVER_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function extraerDatos($persona){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$declaracion_jurada = $persona->declaracion_jurada; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$declaracion_jurada){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['error' => trans('persona.DECLARACION_JURADA_NO_ENCONTRADA')], HttpStatus::NOT_FOUND); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$datos = array( |
|
|
|
|
|
|
|
'id' => $declaracion_jurada->id_persona ?? null, # id persona de la tabla 'uader_persona' |
|
|
|
|
|
|
|
'dni' => $persona->nro_docum ?? null, |
|
|
|
|
|
|
|
'apellido' => ucwords(strtolower(trim($persona->desc_appat))) ?? null, |
|
|
|
|
|
|
|
'nombres' => ucwords(strtolower(trim($persona->desc_nombr))) ?? null, |
|
|
|
|
|
|
|
'telefono' => '549' . preg_replace('([^0-9])', '', trim($persona->telefono_celular)) ?? null, |
|
|
|
|
|
|
|
'email' => strtolower(trim($persona->correo_electronico)) ?? null, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json($datos, HttpStatus::OK); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function store(Request $request) |
|
|
|
public function store(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -109,35 +173,4 @@ class ApiPersonaController extends Controller |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Display the specified resource. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function show(UaderDjPersona $uaderDjPersona) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Show the form for editing the specified resource. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function edit(UaderDjPersona $uaderDjPersona) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Update the specified resource in storage. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function update(Request $request, UaderDjPersona $uaderDjPersona) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Remove the specified resource from storage. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function destroy(UaderDjPersona $uaderDjPersona) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|