From e43ec496b90a1079b56b8094a6cc59dc271f96d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20R=C3=B4mulo?= Date: Thu, 19 Aug 2021 09:56:35 -0300 Subject: [PATCH] Adicionando substituir participante --- app/Http/Controllers/TrabalhoController.php | 175 +++++- .../views/administrador/analisar.blade.php | 5 +- .../substituirParticipante.blade.php | 280 +++++++++ .../substituirParticipanteForm.blade.php | 549 ++++++++++++++++++ resources/views/proponente/projetos.blade.php | 3 +- .../views/proponente/projetosEdital.blade.php | 3 +- routes/web.php | 1 + 7 files changed, 979 insertions(+), 37 deletions(-) create mode 100644 resources/views/administrador/substituirParticipante.blade.php create mode 100644 resources/views/administrador/substituirParticipanteForm.blade.php diff --git a/app/Http/Controllers/TrabalhoController.php b/app/Http/Controllers/TrabalhoController.php index 78b1fb5..74f57ae 100644 --- a/app/Http/Controllers/TrabalhoController.php +++ b/app/Http/Controllers/TrabalhoController.php @@ -44,35 +44,6 @@ use Illuminate\Support\Facades\Notification; class TrabalhoController extends Controller { - ###### Prototipo troca de participantes ###### - - public function telaTrocaPart(Request $request){ - $projeto = Trabalho::find($request->projeto_id); - $edital = Evento::find($projeto->evento_id); - - $participantes = $projeto->participantes; - $participantesUsersIds = Participante::where('trabalho_id', $projeto->id)->select('user_id')->get(); - - $participantesExcluidos = Participante::onlyTrashed()->where('trabalho_id', $projeto->id); - $participantesExcluidosUsersIds = Participante::onlyTrashed()->where('trabalho_id', $projeto->id)->select('user_id'); - - $users = User::whereIn('id', $participantesUsersIds)->get(); - $usersExcluidos = User::whereIn('id', $participantesExcluidosUsersIds)->get(); - - $arquivos = Arquivo::where('trabalhoId', $projeto->id)->get(); - - return view('trocarParti')->with(['projeto' => $projeto, - 'edital' => $edital, - 'users' => $users, - 'usersExcluidos' => $usersExcluidos, - 'participantes' => $participantes, - 'participantesExcluidos' => $participantesExcluidos, - 'arquivos' => $arquivos, - 'estados' => $this->estados, - 'enum_turno' => Participante::ENUM_TURNO, - ]); - } - ############################################## public $estados = array( 'AC' => 'Acre', 'AL' => 'Alagoas', @@ -460,15 +431,17 @@ class TrabalhoController extends Controller } public function excluirParticipante($id){ - $participante = Participante::where('user_id', Auth()->user()->id) - ->where('trabalho_id', $id)->first(); + $participante = Participante::where('id', $id)->first(); + //$participante = Participante::where('user_id', Auth()->user()->id) + // ->where('trabalho_id', $id)->first(); - $participante->trabalhos()->detach($id); + //$participante->trabalhos()->detach($id); $participante->delete(); return redirect()->back(); } + public function novaVersao(Request $request){ $mytime = Carbon::now('America/Recife'); $mytime = $mytime->toDateString(); @@ -1378,4 +1351,142 @@ class TrabalhoController extends Controller return redirect(route('proponente.projetos'))->with(['mensagem' => 'Projeto atualizado com sucesso!']); } + + + public function telaTrocaPart(Request $request){ + $projeto = Trabalho::find($request->projeto_id); + $edital = Evento::find($projeto->evento_id); + + $participantes = $projeto->participantes; + $participantesExcluidos = Participante::onlyTrashed()->where('trabalho_id', $projeto->id)->get(); + + + + return view('administrador.substituirParticipante')->with(['projeto' => $projeto, + 'edital' => $edital, + 'participantes' => $participantes, + 'participantesExcluidos' => $participantesExcluidos, + 'estados' => $this->estados, + 'enum_turno' => Participante::ENUM_TURNO, + ]); + } + + public function trocaParticipante(Request $request){ + try{ + DB::beginTransaction(); + $trabalho = Trabalho::find($request->projetoId); + $evento = Evento::find($request->editalId); + $participanteSubstituido = Participante::where('id', $request->participanteId)->first(); + $planoAntigo = Arquivo::where('id', $participanteSubstituido->planoTrabalho->id)->first(); + + $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['cpf'] = $request->cpf; + $data['tipo'] = 'participante'; + $data['funcao_participante_id'] = 4; + $data['rg'] = $request->rg; + $data['celular'] = $request->celular; + $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; + + if($request->instituicao != "Outra"){ + $data['instituicao'] = $request->instituicao; + }else{ + $data['instituicao'] = $request->outrainstituicao; + } + + $data['total_periodos'] = $request->total_periodos; + + if($request->curso != "Outro"){ + $data['curso'] = $request->curso; + }else{ + $data['curso'] = $request->outrocurso; + } + + $data['turno'] = $request->turno; + $data['periodo_atual'] = $request->periodo_atual; + $data['ordem_prioridade'] = $request->ordem_prioridade; + $data['media_do_curso'] = $request->media_do_curso; + $data['nomePlanoTrabalho'] = $request->nomePlanoTrabalho; + + if($request->substituirApenasPlanoCheck == 'check'){ + if ( $request->has('anexoPlanoTrabalho') ) { + $path = 'trabalhos/' . $evento->id . '/' . $trabalho->id .'/'; + $nome = $data['nomePlanoTrabalho'] .".pdf"; + $file = $request->anexoPlanoTrabalho; + Storage::putFileAs($path, $file, $nome); + $arquivo = new Arquivo(); + $arquivo->titulo = $data['nomePlanoTrabalho']; + $arquivo->nome = $path . $nome; + $arquivo->trabalhoId = $trabalho->id; + $arquivo->data = now(); + $participanteSubstituido->planoTrabalho()->delete(); + $arquivo->participanteId = $participanteSubstituido->id; + $arquivo->versaoFinal = true; + $arquivo->save(); + + } + }else{ + $participanteSubstituido->delete(); + + $user = User::where('email' , $data['email'])->first(); + if (!$user){ + $data['usuarioTemp'] = true; + $user = User::create($data); + $endereco = Endereco::create($data); + $endereco->user()->save($user); + } + $participante = $user->participantes->where('trabalho_id', $trabalho->id)->first(); + if (!$participante){ + $participante = Participante::create($data); + } + + $user->participantes()->save($participante); + $trabalho->participantes()->save($participante); + + if($request->manterPlanoCheck == 'check'){ + $planoAntigo->participanteId = $participante->id; + $planoAntigo->save(); + }else{ + + if ( $request->has('anexoPlanoTrabalho') ) { + $path = 'trabalhos/' . $evento->id . '/' . $trabalho->id .'/'; + $nome = $data['nomePlanoTrabalho'] .".pdf"; + $file = $request->anexoPlanoTrabalho; + Storage::putFileAs($path, $file, $nome); + $arquivo = new Arquivo(); + $arquivo->titulo = $data['nomePlanoTrabalho']; + $arquivo->nome = $path . $nome; + $arquivo->trabalhoId = $trabalho->id; + $arquivo->data = now(); + $arquivo->participanteId = $participante->id; + $arquivo->versaoFinal = true; + $arquivo->save(); + + } + + } + } + + $evento->trabalhos()->save($trabalho); + $trabalho->save(); + + DB::commit(); + + return redirect(route('trabalho.trocaParticipante', ['evento_id' => $evento->id, 'projeto_id' => $trabalho->id]))->with(['sucesso' => 'Troca de participantes realizada com sucesso!']); + }catch (\Throwable $th) { + DB::rollback(); + return redirect(route('trabalho.trocaParticipante', ['evento_id' => $evento->id, 'projeto_id' => $trabalho->id]))->with(['erro' => $th->getMessage()]); + } + + } + } \ No newline at end of file diff --git a/resources/views/administrador/analisar.blade.php b/resources/views/administrador/analisar.blade.php index 9002a9a..af3dda7 100644 --- a/resources/views/administrador/analisar.blade.php +++ b/resources/views/administrador/analisar.blade.php @@ -248,13 +248,12 @@ diff --git a/resources/views/administrador/substituirParticipante.blade.php b/resources/views/administrador/substituirParticipante.blade.php new file mode 100644 index 0000000..d381fa5 --- /dev/null +++ b/resources/views/administrador/substituirParticipante.blade.php @@ -0,0 +1,280 @@ +@extends('layouts.app') + +@section('content') +
+ @if (session('sucesso')) + + @endif + @if(session('erro')) + + @endif +
+
+
+
+

+ Substituir Participante +

+
{{$edital->nome}}: {{$projeto->titulo}}
+
+
+

Formação Atual

+
+
+
+ Nome/Periodo +
+
+
+ @foreach($participantes as $participante) +
+
+

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

+
{{date('d-m-Y', strtotime($participante->created_at))}} - Atualmente
+
+
+
+ + +
+
+ +
+ + + + + + + @endforeach +
+
+ +

Histórico de participantes

+
+
+
+ Nome/Periodo +
+
+
+ @foreach($participantesExcluidos as $participante) +
+
+

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

+
{{date('d-m-Y', strtotime($participante->created_at))}} - {{date('d-m-Y', strtotime($participante->deleted_at))}}
+
+
+
+ +
+
+
+ + + + @endforeach +
+
+
+
+
+
+
+@endsection + +@section('javascript') + +@endsection \ No newline at end of file diff --git a/resources/views/administrador/substituirParticipanteForm.blade.php b/resources/views/administrador/substituirParticipanteForm.blade.php new file mode 100644 index 0000000..15fa2b6 --- /dev/null +++ b/resources/views/administrador/substituirParticipanteForm.blade.php @@ -0,0 +1,549 @@ + +@if($visualizarOnly ?? '') + +
+
+
+
Dados do discente
+
+
+
+
+ @component('componentes.input', ['label' => 'Nome completo']) + + @endcomponent +
+
+ @component('componentes.input', ['label' => 'E-mail']) + + @endcomponent +
+
+
+
+ @component('componentes.input', ['label' => 'Data de nascimento']) + + @endcomponent +
+ +
+ @component('componentes.input', ['label' => 'CPF']) + + @endcomponent +
+
+
+
+ @component('componentes.input', ['label' => 'RG']) + + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Celular']) + + @endcomponent +
+
+
+
+
Endereço
+
+
+
+
+ @component('componentes.input', ['label' => 'CEP']) + + @endcomponent +
+
+ @component('componentes.select', ['label' => 'Estado']) + + @endcomponent +
+
+
+
+ @component('componentes.input', ['label' => 'Cidade']) + + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Bairro']) + + @endcomponent +
+
+
+
+ @component('componentes.input', ['label' => 'Rua']) + + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Número']) + + @endcomponent +
+
+
+
+
+ + +
+
+
+
+
+
Dados do curso
+
+
+
+
+ @component('componentes.input', ['label' => 'Instituição de Ensino']) + + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Curso']) + + @endcomponent +
+
+
+
+ @component('componentes.select', ['label' => 'Turno']) + + @endcomponent +
+
+ @component('componentes.select', ['label' => 'Total de períodos/anos do curso']) + + @endcomponent +
+
+
+
+ @component('componentes.select', ['label' => 'Período/Ano atual']) + + @endcomponent +
+ +
+ @component('componentes.select', ['label' => 'Ordem de prioridade']) + + @endcomponent +
+
+
+
+ @component('componentes.input', ['label' => 'Coeficiente de rendimento']) + + @endcomponent +
+
+
+
+
Plano de trabalho
+
+
+
+ @if($participante->planoTrabalho) +
+
{{$participante->planoTrabalho->titulo}}
+
+
+ +
+ @else +
+

+
+ @endif +
+
+ + + + + + + +@else + + + + + + + +
+ @csrf + + + + +
+
+
+
+ + +
+
+
+
Dados do discente
+
+
+ @component('componentes.input', ['label' => 'Nome completo']) + + + + @error("name") + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'E-mail']) + + + + @error('email') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Data de nascimento']) + + @error('data_de_nascimento') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+ @component('componentes.input', ['label' => 'CPF']) + + + @error('cpf') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'RG']) + + @error('rg') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Celular']) + + @error('celular') + + {{ $message }} + + @enderror + @endcomponent +
+
+
Endereço
+
+
+ @component('componentes.input', ['label' => 'CEP']) + + @error('cep') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.select', ['label' => 'Estado']) + + @error('uf') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+ @component('componentes.input', ['label' => 'Cidade']) + + + + @error('cidade') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Bairro']) + + + + @error('bairro') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Rua']) + + + + @error('rua') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Número']) + + @error('numero') + + {{ $message }} + + @enderror + @endcomponent +
+
+
+ + + + + @error('complemento') + + {{ $message }} + + @enderror +
+
+
+
Dados do curso
+
+
+ @component('componentes.input', ['label' => 'Instituição de Ensino']) + + @error('instituicao') + + {{ $message }} + + @enderror + @endcomponent +
+ + +
+ @component('componentes.input', ['label' => 'Curso']) + + @error('curso') + + {{ $message }} + + @enderror + @endcomponent +
+ + +
+ @component('componentes.select', ['label' => 'Turno']) + + @error('turno') + + {{ $message }} + + @enderror + @endcomponent +
+ @php + $options = array('3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7,'8' => 8,'9' => 9,'10' => 10,'11' => 11,'12' => 12); + @endphp +
+ @component('componentes.select', ['label' => 'Total de períodos/anos do curso']) + + @error('total_periodos') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+ @component('componentes.select', ['label' => 'Período/Ano atual']) + + @error('periodo_atual') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+ @component('componentes.select', ['label' => 'Ordem de prioridade']) + + @error('ordem_prioridade') + + {{ $message }} + + @enderror + @endcomponent +
+
+ @component('componentes.input', ['label' => 'Coeficiente de rendimento']) + + @error('media_do_curso') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+
+ + +
+
+ +
+
Plano de trabalho
+
+
+ @component('componentes.input', ['label' => 'Título']) + + + + @error('nomePlanoTrabalho') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+ @component('componentes.input', ['label' => 'Anexo (.pdf)']) + + @error('anexoPlanoTrabalho') + + {{ $message }} + + @enderror + @error('anexoPlanoTrabalho') + + {{ $message }} + + @enderror + @endcomponent +
+ +
+ + +
+ +
+
+
+@endif \ No newline at end of file diff --git a/resources/views/proponente/projetos.blade.php b/resources/views/proponente/projetos.blade.php index 62727be..fc2ad15 100644 --- a/resources/views/proponente/projetos.blade.php +++ b/resources/views/proponente/projetos.blade.php @@ -94,7 +94,8 @@ Editar - @else + @elseif($projeto->evento->fimSubmissao <= $hoje) + Substituir participante @endif Visualizar diff --git a/resources/views/proponente/projetosEdital.blade.php b/resources/views/proponente/projetosEdital.blade.php index 32ed895..9495baa 100644 --- a/resources/views/proponente/projetosEdital.blade.php +++ b/resources/views/proponente/projetosEdital.blade.php @@ -107,7 +107,8 @@ Editar - @else + @elseif($projeto->evento->fimSubmissao <= $hoje) + Substituir participante @endif Visualizar diff --git a/routes/web.php b/routes/web.php index 2abb84b..1b55be1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -129,6 +129,7 @@ Route::group(['middleware' => ['isTemp', 'auth', 'verified']], function(){ Route::get( '/projeto/{id}/excluirParticipante','TrabalhoController@excluirParticipante')->name('trabalho.excluirParticipante'); Route::get( '/projeto/exportar/{id}','TrabalhoController@exportProjeto' )->name('exportar.projeto'); Route::get( '/projeto/substituirParticipante', 'TrabalhoController@telaTrocaPart' )->name('trabalho.trocaParticipante'); + Route::post( '/projeto/substituirParticipante', 'TrabalhoController@trocaParticipante' )->name('trabalho.infoTrocaParticipante'); //######### Atribuição ####################################### Route::get( '/atribuir', 'AtribuicaoController@distribuicaoAutomatica' )->name('distribuicao'); -- GitLab