From 47a167467b384a0ccd7761e2842f08b846dd913b Mon Sep 17 00:00:00 2001 From: Marcelo-k-USP Date: Fri, 16 Jan 2026 08:30:08 -0300 Subject: [PATCH] adicionada funcionalidade de se informar justificativa em caso de recusa de reserva --- app/Http/Controllers/ReservaController.php | 5 +- app/Http/Controllers/SalaController.php | 1 + app/Http/Requests/SalaRequest.php | 1 + app/Mail/DeleteReservaMail.php | 9 ++-- ...tiva_recusa_column_to_restricoes_table.php | 32 +++++++++++++ ...cativa_recusa_column_to_reservas_table.php | 32 +++++++++++++ .../views/emails/delete_reserva.blade.php | 10 +++- .../views/reserva/partials/fields.blade.php | 47 +++++++++++++++---- resources/views/sala/partials/form.blade.php | 18 ++++++- 9 files changed, 139 insertions(+), 16 deletions(-) create mode 100644 database/migrations/2026_01_14_113400_add_exige_justificativa_recusa_column_to_restricoes_table.php create mode 100644 database/migrations/2026_01_15_142100_add_justificativa_recusa_column_to_reservas_table.php diff --git a/app/Http/Controllers/ReservaController.php b/app/Http/Controllers/ReservaController.php index ce3e87c..13d66b5 100644 --- a/app/Http/Controllers/ReservaController.php +++ b/app/Http/Controllers/ReservaController.php @@ -368,9 +368,12 @@ public function destroy(Request $request, Reserva $reserva) $parent_id = $reserva->parent_id; $purge = !is_null($request->input('purge')); + $justificativa = $request->input('justificativa_recusa'); + $reserva->removerTarefa_AprovacaoAutomatica(); - if(config('salas.emailConfigurado')) Mail::queue(new DeleteReservaMail($reserva, $purge)); + if(config('salas.emailConfigurado')) + Mail::queue(new DeleteReservaMail($reserva, $purge, $justificativa)); if($purge){ Reserva::where('parent_id', $reserva->parent_id)->delete(); diff --git a/app/Http/Controllers/SalaController.php b/app/Http/Controllers/SalaController.php index 8e042ce..fa3fc5b 100644 --- a/app/Http/Controllers/SalaController.php +++ b/app/Http/Controllers/SalaController.php @@ -204,6 +204,7 @@ public function update(SalaRequest $request, Sala $sala) 'periodo_letivo_id' => $validated['periodo_letivo'], 'aprovacao' => $validated['aprovacao'], 'prazo_aprovacao' => $validated['prazo_aprovacao'], + 'exige_justificativa_recusa' => $validated['exige_justificativa_recusa'], ] ); diff --git a/app/Http/Requests/SalaRequest.php b/app/Http/Requests/SalaRequest.php index d791071..28b2051 100644 --- a/app/Http/Requests/SalaRequest.php +++ b/app/Http/Requests/SalaRequest.php @@ -44,6 +44,7 @@ public function rules() 'instrucoes_reserva' => 'nullable', 'aceite_reserva' => 'nullable', 'prazo_aprovacao' => 'nullable|integer', + 'exige_justificativa_recusa' => 'required|integer', ]; } diff --git a/app/Mail/DeleteReservaMail.php b/app/Mail/DeleteReservaMail.php index 0d24251..240391d 100644 --- a/app/Mail/DeleteReservaMail.php +++ b/app/Mail/DeleteReservaMail.php @@ -12,19 +12,21 @@ class DeleteReservaMail extends Mailable { - use Queueable, SerializesModels; + use Queueable; // SerializesModels provocava erro de reserva já deletada e tendo acessá-la private $reserva; private $purge; + private $justificativa; /** * Create a new message instance. * * @return void */ - public function __construct(Reserva $reserva, bool $purge = false) + public function __construct(Reserva $reserva, bool $purge = false, string $justificativa = null) { $this->reserva = $reserva; $this->purge = $purge; + $this->justificativa = $justificativa; } /** @@ -40,7 +42,8 @@ public function build() ->to($user->email) ->with([ 'reserva' => $this->reserva, - 'purge' => $this->purge + 'purge' => $this->purge, + 'justificativa' => $this->justificativa ]); } } diff --git a/database/migrations/2026_01_14_113400_add_exige_justificativa_recusa_column_to_restricoes_table.php b/database/migrations/2026_01_14_113400_add_exige_justificativa_recusa_column_to_restricoes_table.php new file mode 100644 index 0000000..7808a22 --- /dev/null +++ b/database/migrations/2026_01_14_113400_add_exige_justificativa_recusa_column_to_restricoes_table.php @@ -0,0 +1,32 @@ +boolean('exige_justificativa_recusa')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('restricoes', function (Blueprint $table) { + $table->dropColumn('exige_justificativa_recusa'); + }); + } +} diff --git a/database/migrations/2026_01_15_142100_add_justificativa_recusa_column_to_reservas_table.php b/database/migrations/2026_01_15_142100_add_justificativa_recusa_column_to_reservas_table.php new file mode 100644 index 0000000..fd58861 --- /dev/null +++ b/database/migrations/2026_01_15_142100_add_justificativa_recusa_column_to_reservas_table.php @@ -0,0 +1,32 @@ +text('justificativa_recusa')->nullable()->after('status'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('reservas', function (Blueprint $table) { + $table->dropColumn('justificativa_recusa'); + }); + } +} diff --git a/resources/views/emails/delete_reserva.blade.php b/resources/views/emails/delete_reserva.blade.php index d9f8939..3796377 100644 --- a/resources/views/emails/delete_reserva.blade.php +++ b/resources/views/emails/delete_reserva.blade.php @@ -15,6 +15,14 @@

Data: {{$reserva->data}}

@endif +@if (!empty($justificativa)) +
+
+ Motivo da Recusa:
+ {{ $justificativa }} +
+@endif +
-

Mensagem automática do sistema de reserva de salas: {{route('home')}}

\ No newline at end of file +

Mensagem automática do sistema de reserva de salas: {{route('home')}}

diff --git a/resources/views/reserva/partials/fields.blade.php b/resources/views/reserva/partials/fields.blade.php index c9fcb39..70de0b9 100644 --- a/resources/views/reserva/partials/fields.blade.php +++ b/resources/views/reserva/partials/fields.blade.php @@ -21,7 +21,7 @@ @if ($reserva->status == 'pendente')
- Pendente + Pendente
@endif @@ -121,10 +121,10 @@ @if($reserva->irmaos())
Recorrências: - @php + @php $reservas_array = $reserva->irmaos()->toArray(); @endphp - + @foreach($reservas_array as $key => $reservaIterator) {{ $reservaIterator['data'] }}@if( $key !== count($reservas_array) -1 ),@endif @endforeach @@ -138,13 +138,42 @@ @if ($reserva->status == 'pendente') @can('responsavel', $reserva->sala) -
- @csrf - @method('DELETE') -
+ @if ($reserva->sala->restricao->exige_justificativa_recusa) + + @else +
+ @csrf + @method('DELETE') +
+ @endif +
Aprovar - +
@endcan -@endif \ No newline at end of file +@endif diff --git a/resources/views/sala/partials/form.blade.php b/resources/views/sala/partials/form.blade.php index aac28ee..9d7fae2 100644 --- a/resources/views/sala/partials/form.blade.php +++ b/resources/views/sala/partials/form.blade.php @@ -62,6 +62,17 @@
+
+ Exigir justificativa no ato da recusa? +
+ restricao->exige_justificativa_recusa ?? 0) > 0) ? 'checked' : '' }}> + +
+
+ restricao->exige_justificativa_recusa ?? 0) == 0) ? 'checked' : '' }}> + +
+
Aprovar automaticamente após certo prazo sem aprovação nem rejeição?
@@ -276,9 +287,12 @@ }); function aprovacaoChanged() { - if ($("#aprovacao-sim").is(":checked")) + if ($("#aprovacao-sim").is(":checked")) { + $('#exige_justificativa_recusa_sim_nao').show(); $('#prazo_aprovacao_sim_nao').show(); - else { + } else { + $('#exige_justificativa_recusa_sim_nao').hide(); + $("#exige-justificativa-recusa-nao").prop("checked", true); $('#prazo_aprovacao_sim_nao').hide(); $("#aprovacao-prazo-nao").prop("checked", true); }