Skip to content

Commit

Permalink
fix: Fixing agendamento feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriolino committed Oct 30, 2024
1 parent 4b4053b commit 33d826a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Novosga\Service\TicketServiceInterface;
use Novosga\TriageBundle\Dto\NovaSenhaDto;
use Novosga\TriageBundle\NovosgaTriageBundle;
use Psr\Clock\ClockInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -220,7 +221,9 @@ public function distribuiSenha(
public function distribuiSenhaAgendamento(
AtendimentoServiceInterface $atendimentoService,
AgendamentoServiceInterface $agendamentoService,
PrioridadeRepositoryInterface $prioridadeRepository,
TranslatorInterface $translator,
ClockInterface $clock,

Check failure on line 226 in src/Controller/DefaultController.php

View workflow job for this annotation

GitHub Actions / build

Parameter $clock of method Novosga\TriageBundle\Controller\DefaultController::distribuiSenhaAgendamento() has invalid type Psr\Clock\ClockInterface.
int $id,
): Response {
$agendamento = $agendamentoService->getById($id);
Expand All @@ -234,13 +237,17 @@ public function distribuiSenhaAgendamento(
$data = $agendamento->getData()->format('Y-m-d');
$hora = $agendamento->getHora()->format('H:i');
$dt = DateTime::createFromFormat('Y-m-d H:i', "{$data} {$hora}");
$now = new DateTime();
$now = $clock->now();

Check failure on line 240 in src/Controller/DefaultController.php

View workflow job for this annotation

GitHub Actions / build

Call to method now() on an unknown class Psr\Clock\ClockInterface.

if ($dt < $now) {
$diff = $now->diff($dt);
$mins = $diff->i + ($diff->h * 60);
if ($mins > self::MAX_SCHEDULING_MINUTES_DELAY) {
throw new Exception($translator->trans('error.schedule.expired', [], NovosgaTriageBundle::getDomain()));
throw new Exception($translator->trans(
'error.schedule.expired',
[ '%min%' => self::MAX_SCHEDULING_MINUTES_DELAY ],
NovosgaTriageBundle::getDomain()
));
}
}

Expand All @@ -249,8 +256,8 @@ public function distribuiSenhaAgendamento(
$usuario = $this->getUser();
$unidade = $agendamento->getUnidade();
$servico = $agendamento->getServico();
$prioridade = 1;
$cliente = $agendamento->getCliente();
$prioridade = $prioridadeRepository->findAtivas()[0];

$data = $atendimentoService->distribuiSenha($unidade, $usuario, $servico, $prioridade, $cliente, $agendamento);
$envelope->setData($data);
Expand Down Expand Up @@ -285,9 +292,9 @@ public function clientes(
Request $request,
ClienteRepositoryInterface $clienteRepository,
): Response {
$envelope = new Envelope();
$envelope = new Envelope();
$documento = $request->get('q');
$clientes = $clienteRepository->findByDocumento("{$documento}%");
$clientes = $clienteRepository->findByDocumento("{$documento}%");

$envelope->setData($clientes);

Expand All @@ -297,12 +304,13 @@ public function clientes(
#[Route("/agendamentos/{servicoId}", name: "atendamentos", methods: ["GET"])]
public function agendamentos(
AgendamentoRepositoryInterface $agendamentoRepository,
ClockInterface $clock,

Check failure on line 307 in src/Controller/DefaultController.php

View workflow job for this annotation

GitHub Actions / build

Parameter $clock of method Novosga\TriageBundle\Controller\DefaultController::agendamentos() has invalid type Psr\Clock\ClockInterface.
int $servicoId,
): Response {
/** @var UsuarioInterface */
$usuario = $this->getUser();
$unidade = $usuario->getLotacao()->getUnidade();
$data = new DateTime();
$data = $clock->now();

Check failure on line 313 in src/Controller/DefaultController.php

View workflow job for this annotation

GitHub Actions / build

Call to method now() on an unknown class Psr\Clock\ClockInterface.

$agendamentos = $agendamentoRepository->findByUnidadeAndServicoAndData(
$unidade,
Expand Down
9 changes: 7 additions & 2 deletions src/Resources/public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@
}
},
loadAgendamentos() {
this.agendamentos = [];
if (!this.servicoAgendamento) {
return;
}
this.agendamentos = [];
App.ajax({
url: App.url(`/novosga.triage/agendamentos/${this.servicoAgendamento}`),
success: (response) => {
Expand All @@ -153,6 +153,7 @@
this.servicoAgendamento = null;
this.loadAgendamentos();
this.agendamentosModal.hide();
this.update();
}
});
},
Expand Down Expand Up @@ -210,7 +211,7 @@
error() {
reject();
},
complete() {
complete: () => {
this.pausado = false;
}
});
Expand Down Expand Up @@ -294,6 +295,10 @@
this.agendamentosModal = new bootstrap.Modal(this.$refs.agendamentosModal);
this.prioridadeModal = new bootstrap.Modal(this.$refs.prioridadeModal);

this.$refs.agendamentosModal.addEventListener('show.bs.modal', () => {
this.loadAgendamentos();
})

App.SSE.connect([
`/unidades/${this.unidade.id}/fila`
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/default/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
<div class="col-6">
<div class="mb-3">
<label>{{ 'label.service'|trans }}</label>
<select class="form-control" v-on:change="loadAgendamentos" v-model="servicoAgendamento">
<select class="form-select" v-on:change="loadAgendamentos" v-model="servicoAgendamento">
<option value=""></option>
<option v-bind:value="s.servico.id" v-for="s in servicos">
{%- verbatim -%}
Expand Down

0 comments on commit 33d826a

Please sign in to comment.