diff --git a/app/Http/Controllers/TrabalhoController.php b/app/Http/Controllers/TrabalhoController.php index f4117d5f67e90f4cd266879ff94ac3ca0e92f963..faaf2afaaec2ad08cefd3370ac688c37c2d98b29 100755 --- a/app/Http/Controllers/TrabalhoController.php +++ b/app/Http/Controllers/TrabalhoController.php @@ -1902,6 +1902,7 @@ class TrabalhoController extends Controller public function telaTrocaPart(Request $request) { + $funcaoParticipantes = FuncaoParticipantes::orderBy('nome')->get(); $projeto = Trabalho::find($request->projeto_id); $edital = Evento::find($projeto->evento_id); @@ -1920,37 +1921,44 @@ class TrabalhoController extends Controller 'estados' => $this->estados, 'enum_turno' => Participante::ENUM_TURNO, 'desligamentosProjeto' => $desligamentosProjeto, + 'funcaoParticipantes'=> $funcaoParticipantes ]); } public function trocaParticipante(Request $request) { + //dd($request->all()); try { DB::beginTransaction(); $trabalho = Trabalho::find($request->projetoId); $evento = Evento::find($request->editalId); $participanteSubstituido = Participante::where('id', $request->participanteId)->first(); + $usuarioNovo = User::where('id', $request->novoParticianteId)->first(); + $enderecoUsuarioNovo = $usuarioNovo->endereco; + $participanteNovo = $usuarioNovo->participantes->first(); $planoAntigo = Arquivo::where('id', $participanteSubstituido->planoTrabalho->id)->first(); - + //dd($enderecoUsuarioNovo); + //dd($usuarioNovo); $passwordTemporario = Str::random(8); - $data['name'] = $request->name; - $data['email'] = $request->email; - $data['password'] = bcrypt($passwordTemporario); - $data['data_de_nascimento'] = $request->data_de_nascimento; + $data['name'] = $usuarioNovo->name; //$request->name; + $data['email'] = $usuarioNovo->email; //$request->email; + $data['password'] = $usuarioNovo->password; //bcrypt($passwordTemporario); + $data['data_de_nascimento'] = $participanteNovo->data_de_nascimento; //$request->data_de_nascimento; $data['data_entrada'] = $request->data_entrada; - $data['cpf'] = $request->cpf; + $data['cpf'] = $usuarioNovo->cpf; //$request->cpf; $data['tipo'] = 'participante'; $data['funcao_participante_id'] = 4; - $data['rg'] = $request->rg; - $data['celular'] = $request->celular; - $data['linkLattes'] = $request->linkLattes; - $data['cep'] = $request->cep; - $data['uf'] = $request->uf; - $data['cidade'] = $request->cidade; - $data['rua'] = $request->rua; - $data['numero'] = $request->numero; - $data['bairro'] = $request->bairro; - $data['complemento'] = $request->complemento; + $data['rg'] = $participanteNovo->rg; //$request->rg; + $data['celular'] = $usuarioNovo->celular; //$request->celular; + $data['linkLattes'] = $participanteNovo->linkLattes; //$request->linkLattes; + $data['cep'] = $enderecoUsuarioNovo->cep; //$request->cep; + $data['uf'] = $enderecoUsuarioNovo->uf; //$request->uf; + $data['cidade'] = $enderecoUsuarioNovo->cidade; //$request->cidade; + $data['rua'] = $enderecoUsuarioNovo->rua; //$request->rua; + $data['numero'] = $enderecoUsuarioNovo->numero; //$request->numero; + $data['bairro'] = $enderecoUsuarioNovo->bairro; //$request->bairro; + $data['complemento'] = $enderecoUsuarioNovo->complemento; //$request->complemento; + if ($request->instituicao != "Outra") { $data['instituicao'] = $request->instituicao; @@ -2009,8 +2017,8 @@ class TrabalhoController extends Controller } $participanteSubstituido->data_saida = $request->data_entrada; - - \App\Validator\CpfValidator::validate($request->all()); + //\App\Validator\CpfValidator::validate($request->all()); + //dd($data); $user = User::where('email', 'ilike', $data['email'])->first(); if (!$user) { $data['usuarioTemp'] = true; @@ -2024,16 +2032,16 @@ class TrabalhoController extends Controller $participanteSubstituido->save(); } - $pasta = 'participantes/' . $participante->id; - $participante->anexoTermoCompromisso = Storage::putFileAs($pasta, $request->anexoTermoCompromisso, "Termo_de_Compromisso.pdf"); - $participante->anexoComprovanteMatricula = Storage::putFileAs($pasta, $request->anexoComprovanteMatricula, "Comprovante_de_Matricula.pdf"); - $participante->anexoLattes = Storage::putFileAs($pasta, $request->anexoCurriculoLattes, "Curriculo_Lattes.pdf"); - if ($request->anexoAutorizacaoPais != null) { - $participante->anexoAutorizacaoPais = Storage::putFileAs($pasta, $request->anexoAutorizacaoPais, "Autorização_dos_Pais.pdf"); - } - if ($request->anexoComprovanteBancario != null) { - $participante->anexoComprovanteBancario = Storage::putFileAs($pasta, $request->anexoComprovanteBancario, "Comprovante_Bancario." . $request->file('anexoComprovanteBancario')->getClientOriginalExtension()); - } + // $pasta = 'participantes/' . $participante->id; + // $participante->anexoTermoCompromisso = Storage::putFileAs($pasta, $request->anexoTermoCompromisso, "Termo_de_Compromisso.pdf"); + // $participante->anexoComprovanteMatricula = Storage::putFileAs($pasta, $request->anexoComprovanteMatricula, "Comprovante_de_Matricula.pdf"); + // $participante->anexoLattes = Storage::putFileAs($pasta, $request->anexoCurriculoLattes, "Curriculo_Lattes.pdf"); + // if ($request->anexoAutorizacaoPais != null) { + // $participante->anexoAutorizacaoPais = Storage::putFileAs($pasta, $request->anexoAutorizacaoPais, "Autorização_dos_Pais.pdf"); + // } + // if ($request->anexoComprovanteBancario != null) { + // $participante->anexoComprovanteBancario = Storage::putFileAs($pasta, $request->anexoComprovanteBancario, "Comprovante_Bancario." . $request->file('anexoComprovanteBancario')->getClientOriginalExtension()); + // } $user->participantes()->save($participante); //$trabalho->participantes()->save($participante); diff --git a/resources/views/administrador/substituirParticipante.blade.php b/resources/views/administrador/substituirParticipante.blade.php index bdde868473694c6babfc830b41454de7272a9f7f..698e4ef7b59b864468d92b65105d5c3992daafae 100644 --- a/resources/views/administrador/substituirParticipante.blade.php +++ b/resources/views/administrador/substituirParticipante.blade.php @@ -30,7 +30,7 @@
- @foreach($participantes as $participante) + @foreach($participantes as $i => $participante)

{{$participante->user->name}}

@@ -73,6 +73,19 @@
+ + + + + + +
+ + + + @endsection @section('javascript') @@ -610,5 +1056,129 @@ $("#modalTestSubParticipante"+discenteId).modal('hide'); setTimeout(() => { $("#modalSubParticipantePlano"+discenteId).modal(); }, 500); } + + + function preencherUsuarioExistente(integranteAntigoId) { + if (!document.getElementById(`exampleModal${integranteAntigoId}`)) { + exibirModalNumeroMaximoDeIntegrantes(); + return; + } + + + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); + + $.ajax({ + url: '{{ route('trabalho.buscarUsuario') }}', + type: 'POST', + dataType: 'json', + data: { + 'cpf_consulta': $(`#cpf_consulta${integranteAntigoId}`).val(), + 'funcao': $(`#funcao_participante${integranteAntigoId}`).val() + }, + + success: function (data) { + if (data == 'inexistente' || $(`#cpf_consulta${integranteAntigoId}`).val() == "") { + exibirModalUsuarioInexistente(); + } else { + if ($(`#funcao_participante${integranteAntigoId}`).val() != 4 || data[0].tipo == 'participante') { + exibirUsuarioAdicionado(data, integranteAntigoId); + } + } + } + }); + + } + + function exibirModalUsuarioInexistente() { + $('#aviso-modal-usuario-nao-existe').modal('show'); + } + + $(document).ready(function () { + $("#cpf_consulta").mask("999.999.999-99"); + }); + + function exibirUsuarioAdicionado(data, integranteAntigoId) { + console.log(data) + $('#modalIntegrante').modal('hide'); + document.getElementById(`nome${integranteAntigoId}`).value = data[0]['name']; + document.getElementById(`nome${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`email${integranteAntigoId}`).value = data[0]['email']; + document.getElementById(`email${integranteAntigoId}`).setAttribute("readonly", ""); + + if (data[0]['tipo'] == "participante") { + let [y, m, d] = data[2]['data_de_nascimento'].split('-'); + document.getElementById(`data_de_nascimento${integranteAntigoId}`).value = (new Date(y, m - 1, d)).toLocaleDateString(); + document.getElementById(`data_de_nascimento${integranteAntigoId}`).setAttribute("readonly", ""); + } else { + + document.getElementById(`data_de_nascimento${integranteAntigoId}`).value = null; + document.getElementById(`data_de_nascimento${integranteAntigoId}`).setAttribute("readonly", ""); + } + + document.getElementById(`cpf${integranteAntigoId}`).value = data[0]['cpf']; + document.getElementById(`cpf${integranteAntigoId}`).setAttribute("readonly", ""); + + if (data?.[2]?.rg) { + document.getElementById(`rg${integranteAntigoId}`).value = data[2]['rg']; + document.getElementById(`rg${integranteAntigoId}`).setAttribute("readonly", ""); + } + + if (data?.[0]?.celular) { + document.getElementById(`celular${integranteAntigoId}`).value = data[0]['celular']; + document.getElementById(`celular${integranteAntigoId}`).setAttribute("readonly", ""); + } + + if (data[3] != null) { + document.getElementById(`cep${integranteAntigoId}`).value = data[3].cep; + document.getElementById(`cep${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`uf${integranteAntigoId}`).value = data[3].uf; + document.getElementById(`uf${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`cidade${integranteAntigoId}`).value = data[3].cidade; + document.getElementById(`cidade${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`bairro${integranteAntigoId}`).value = data[3].bairro; + document.getElementById(`bairro${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`rua${integranteAntigoId}`).value = data[3].rua; + document.getElementById(`rua${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`numero${integranteAntigoId}`).value = data[3].numero; + document.getElementById(`numero${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`complemento${integranteAntigoId}`).value = data[3].complemento; + document.getElementById(`complemento${integranteAntigoId}`).setAttribute("readonly", ""); + } + + document.getElementById(`instituicao${integranteAntigoId}`).value = data[0].instituicao; + document.getElementById(`instituicao${integranteAntigoId}`).setAttribute("readonly", ""); + + document.getElementById(`curso${integranteAntigoId}`).value = data[2].curso; + document.getElementById(`curso${integranteAntigoId}`).setAttribute("readonly", ""); + + + //document.getElementById(`funcaoParticipante${modal_id}`).value = data[1]['nome']; + + if (data[1].nome != "Bolsista" && data[1].nome != "Voluntário") { + document.getElementById(`plano-titulo${integranteAntigoId}`).setAttribute('hidden', ""); + document.getElementById(`plano-nome${integranteAntigoId}`).setAttribute('hidden', ""); + document.getElementById(`plano-anexo${integranteAntigoId}`).setAttribute('hidden', ""); + } else { + document.getElementById(`plano-titulo${integranteAntigoId}`).removeAttribute('hidden'); + document.getElementById(`plano-nome${integranteAntigoId}`).removeAttribute('hidden'); + document.getElementById(`plano-anexo${integranteAntigoId}`).removeAttribute('hidden'); + } + + document.getElementById(`novoParticianteId${integranteAntigoId}`).value = data[0].id; + + $(`#exampleModal${integranteAntigoId}`).modal('show'); + } + @endsection \ No newline at end of file