From 78915fa2ce10ec2303f598909c7a737b6492a69b Mon Sep 17 00:00:00 2001 From: Alessandro Costa de Oliveira Date: Thu, 30 Nov 2023 11:37:12 -0300 Subject: [PATCH 1/3] Supervisor e Autorizador gerenciando seus grupos --- app/Http/Controllers/GrupoController.php | 8 ++++---- config/laravel-usp-theme.php | 2 +- resources/views/grupos/index.blade.php | 12 +++++++++++- resources/views/grupos/partials/form.blade.php | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/GrupoController.php b/app/Http/Controllers/GrupoController.php index 5a8bb84..a1b9eac 100644 --- a/app/Http/Controllers/GrupoController.php +++ b/app/Http/Controllers/GrupoController.php @@ -14,7 +14,7 @@ class GrupoController extends Controller */ public function index() { - $this->authorize('admin'); + $this->authorize('boss'); $grupos = Grupo::all(); @@ -60,7 +60,7 @@ public function store(GrupoRequest $request) */ public function show(Grupo $grupo) { - $this->authorize('admin'); + $this->authorize('boss'); // } @@ -72,7 +72,7 @@ public function show(Grupo $grupo) */ public function edit(Grupo $grupo) { - $this->authorize('admin'); + $this->authorize('boss'); return view('grupos.edit', [ 'grupo' => $grupo, ]); @@ -87,7 +87,7 @@ public function edit(Grupo $grupo) */ public function update(GrupoRequest $request, Grupo $grupo) { - $this->authorize('admin'); + $this->authorize('boss'); $validated = $request->validated(); $grupo->update($validated); request()->session()->flash('alert-info','Grupo atualizado com sucesso'); diff --git a/config/laravel-usp-theme.php b/config/laravel-usp-theme.php index fa3c87a..27579c6 100644 --- a/config/laravel-usp-theme.php +++ b/config/laravel-usp-theme.php @@ -31,7 +31,7 @@ [ 'text' => 'Grupos', 'url' => '/grupos', - 'can' => 'admin', + 'can' => 'boss', ], ], ], diff --git a/resources/views/grupos/index.blade.php b/resources/views/grupos/index.blade.php index ec43997..9747b6e 100644 --- a/resources/views/grupos/index.blade.php +++ b/resources/views/grupos/index.blade.php @@ -19,21 +19,31 @@ - @foreach($grupos as $grupo) + @foreach($grupos as $grupo) + + {{-- Se o usuário logado é supervisor, autorizador ou admin, lista o grupo --}} + @if (App\Models\Grupo::find($grupo->id)->codpes_supervisor == Auth::user()->codpes || App\Models\Grupo::find($grupo->id)->codpes_autorizador == Auth::user()->codpes || Gate::allows('admin')) + {{ $grupo->name }} {{ $grupo->codpes_supervisor }} {{ $grupo->codpes_autorizador }} + @can ('admin')
@csrf @method('delete')
+ @endcan + + @endif + @endforeach + diff --git a/resources/views/grupos/partials/form.blade.php b/resources/views/grupos/partials/form.blade.php index 41038fb..5f63b1c 100644 --- a/resources/views/grupos/partials/form.blade.php +++ b/resources/views/grupos/partials/form.blade.php @@ -13,7 +13,7 @@

- +
From b1f3822255346ac56ac381f5d83b74d2e5cdfb1b Mon Sep 17 00:00:00 2001 From: Alessandro Costa de Oliveira Date: Fri, 1 Dec 2023 11:47:29 -0300 Subject: [PATCH 2/3] =?UTF-8?q?Acerto=20do=20filtro=20por=20per=C3=ADodo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/PessoaController.php | 29 +++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PessoaController.php b/app/Http/Controllers/PessoaController.php index b037ae5..7911dc1 100644 --- a/app/Http/Controllers/PessoaController.php +++ b/app/Http/Controllers/PessoaController.php @@ -13,7 +13,7 @@ use App\Models\Grupo; use App\Utils\Util; - +use Illuminate\Support\Facades\Auth; class PessoaController extends Controller { @@ -47,11 +47,32 @@ public function show(Request $request, $codpes = 'my') 'out' => 'required|date_format:d/m/Y' ]); } else { + // Verificar o início e fim da folha no Grupo que a pessoa pertence + $inicio_folha = (Grupo::getGroup($pessoa['codpes'])) ? Grupo::getGroup($pessoa['codpes'])->inicio_folha : 21; + $fim_folha = (Grupo::getGroup($pessoa['codpes'])) ? Grupo::getGroup($pessoa['codpes'])->fim_folha : 20; + // Formato dia com dois dígitos + $inicio_folha = (strlen($inicio_folha) < 2) ? '0' . $inicio_folha : $inicio_folha; + $fim_folha = (strlen($fim_folha) < 2) ? '0' . $fim_folha : $fim_folha; // Se o dia corrente é dia 31, não estava subtraindo 1 mês em $request->in // https://stackoverflow.com/questions/9058523/php-date-and-strtotime-return-wrong-months-on-31st Answer #31 - $base = strtotime(date('Y-m',time()) . '-01 00:00:01'); - $request->in = '21/' . date('m/Y', strtotime('-1 month', $base)); - $request->out = "20/" . date("m/Y"); + $base = strtotime(date('Y-m', time()) . '-01 00:00:01'); + if ($inicio_folha == 1) { + // Bolsistas Pró-Aluno, inicia dia 1º e vai até o último dia do mês + $request->in = $inicio_folha . '/' . date('m/Y'); + $request->out = Carbon::createFromFormat('d/m/Y', $request->in)->modify('last day of this month')->format('d/m/Y'); + } else { + // Estagiários setores, inicia dia 21 e vai até o dia 20 do outro mês + // Se o dia corrente é menor ou igual ao dia de fim da folha, ex.: data corrente 01/12/2023, trazer início 21/11/2023 à 20/12/2023 + if (now()->format('d') <= $fim_folha) { + // Diminui 1 mês na data de início da folha + $request->in = $inicio_folha . '/' . date('m/Y', strtotime('-1 month', $base)); + $request->out = $fim_folha . '/' . date("m/Y"); + } else { + // Aumenta 1 mês na data de fim da folha + $request->in = $inicio_folha . '/' . date('m/Y'); + $request->out = $fim_folha . '/' . date("m/Y", strtotime('+1 month', $base)); + } + } } $in = Carbon::createFromFormat('d/m/Y H:i:s', $request->in . ' 00:00:00'); From 6b57c7c2a601beb7b43b1258493c490b6e015e0d Mon Sep 17 00:00:00 2001 From: Alessandro Costa de Oliveira Date: Fri, 1 Dec 2023 14:35:40 -0300 Subject: [PATCH 3/3] =?UTF-8?q?Ajuste=20para=20considerar=20=C3=BAltimo=20?= =?UTF-8?q?dia=20do=20m=C3=AAs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quando bolsista e o início for dia 1 considerar o último dia do mês --- app/Http/Controllers/PessoaController.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/PessoaController.php b/app/Http/Controllers/PessoaController.php index 7911dc1..d7c263f 100644 --- a/app/Http/Controllers/PessoaController.php +++ b/app/Http/Controllers/PessoaController.php @@ -41,18 +41,24 @@ public function show(Request $request, $codpes = 'my') $emails = Pessoa::emails($pessoa['codpes']); $telefones = Pessoa::telefones($pessoa['codpes']); + // Verificar o início e fim da folha no Grupo que a pessoa pertence + $inicio_folha = (Grupo::getGroup($pessoa['codpes'])) ? Grupo::getGroup($pessoa['codpes'])->inicio_folha : 21; + $fim_folha = (Grupo::getGroup($pessoa['codpes'])) ? Grupo::getGroup($pessoa['codpes'])->fim_folha : 20; + // Formato dia com dois dígitos + $inicio_folha = (strlen($inicio_folha) < 2) ? '0' . $inicio_folha : $inicio_folha; + $fim_folha = (strlen($fim_folha) < 2) ? '0' . $fim_folha : $fim_folha; + if(!empty($request->in) and !empty($request->out)){ $request->validate([ 'in' => 'required|date_format:d/m/Y', 'out' => 'required|date_format:d/m/Y' ]); - } else { - // Verificar o início e fim da folha no Grupo que a pessoa pertence - $inicio_folha = (Grupo::getGroup($pessoa['codpes'])) ? Grupo::getGroup($pessoa['codpes'])->inicio_folha : 21; - $fim_folha = (Grupo::getGroup($pessoa['codpes'])) ? Grupo::getGroup($pessoa['codpes'])->fim_folha : 20; - // Formato dia com dois dígitos - $inicio_folha = (strlen($inicio_folha) < 2) ? '0' . $inicio_folha : $inicio_folha; - $fim_folha = (strlen($fim_folha) < 2) ? '0' . $fim_folha : $fim_folha; + // Ajustando a data de fim de folha quando for Bolsista + if ($inicio_folha == 1) { + // Bolsistas Pró-Aluno, inicia dia 1º e vai até o último dia do mês + $request->out = Carbon::createFromFormat('d/m/Y', $request->in)->modify('last day of this month')->format('d/m/Y'); + } + } else { // Se o dia corrente é dia 31, não estava subtraindo 1 mês em $request->in // https://stackoverflow.com/questions/9058523/php-date-and-strtotime-return-wrong-months-on-31st Answer #31 $base = strtotime(date('Y-m', time()) . '-01 00:00:01');