diff --git a/README.md b/README.md index d457f61058ab05cce1dafca1f44302b1480947d3..dd20fdd942110e4a63d311eea56db699d7ac9a46 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,24 @@ Sistema para empréstimo de materiais (armários, CDs, Fones etc) durante a permanência dos usuários na Biblioteca. O material deve ter um código identificador único que será lido com código de barra. -## Features +## Features -Ações do grupo administrador: - - - Gerenciar usuários do sistema - - Gerenciamento dos tipos de materiais que serão emprestados: armários, fones etc - - Gerenciamento dos materiais: criar, editar, apagar ou desativar. - Ações do grupo balcão: - - Devolução + - Gerenciar visitantes - Empréstimo para visitante (externa à USP) - mediante cadastro prévio - - Empréstimo para pessoa USP (dados da replicação, tabelas PESSOA e/ou CATR_CRACHA) + - Empréstimo para pessoa USP - Listagem dos itens emprestados e ainda não devolvidos - - Listagem de empréstimos concluÃdos no dia - - Gerenciar visitantes + - Devolução - Impressão dos códigos de barras + - Não permite empréstimo de dois materiais do mesmo tipo para mesma pessoa + +Ações do grupo administrador: + + - Gerenciar usuários do sistema + - Gerenciamento dos tipos de materiais que serão emprestados: armários, fones etc + - Gerenciamento dos materiais: criar, editar, apagar ou desativar. + - Histórico dos empréstimos por material ## Integração com outros serviços: @@ -29,9 +30,9 @@ Ações do grupo administrador: - Inserir *true* na variável USAR_REPLICADO no arquivo .env - Configurar as variáveis correspondentes - baixar a estrutura das tabelas: - + git clone git@git.uspdigital.usp.br:uspdev/replicado_queries vendor/uspdev/replicado/src/replicado_queries - + ### WSfoto - Inserir *true* na variável USAR_WSFOTO em .env diff --git a/src/Controller/EmprestimoController.php b/src/Controller/EmprestimoController.php index c620663cec7a230b0e8f25f2593890c51397c3f1..c5d93f6388f441c226f62a2911eafd8bc0e6a66e 100644 --- a/src/Controller/EmprestimoController.php +++ b/src/Controller/EmprestimoController.php @@ -31,8 +31,7 @@ class EmprestimoController extends Controller { $em = $this->getDoctrine()->getManager(); - // Mostrar apenas os não devolvidos: 'dataDevolucao'=>null - $emprestimos = $em->getRepository('App:Emprestimo')->findby(['dataDevolucao'=>null],array('material' => 'ASC')); + $emprestimos = $this->emprestimos(); // Replicado $replicado = []; @@ -44,28 +43,6 @@ class EmprestimoController extends Controller } } } - - -/* - // Verificar se a pessoa já não possui armário emprestado - foreach($armarios_indisponiveis as $x){ - if($emprestimo->getPessoaUsp() == $x->getPessoaUsp()){ - $this->addFlash('danger', sprintf('Armário não emprestado! Pois o usuário(a) %s - já tem o armário %s emprestado.',$emprestimo->getPessoaUsp(),$x->getArmario())); - return $this->redirectToRoute('emprestimo_pessoausp_new'); - } - } - - $armario_em_quesao = $em->getRepository('AppBundle:Armario')->findOneById($emprestimo->getArmario()); - if(!$armario_em_quesao->getAtivo()){ - $this->addFlash('danger', sprintf('Armário não emprestado! - Pois armário %s está desativado, favor escolha outro armário!',$emprestimo->getArmario())); - return $this->redirectToRoute('emprestimo_pessoausp_new'); - } - - // Quando a pessoa não tem vÃnculo nenhum com a FFLCH, pegar nome da tabela CATR_CRACHA - $nome = $pessoa ? $pessoa[0]['PESSOA_nompes'] : $cracha[0]['CATR_CRACHA_nompescra']; -*/ return $this->render('emprestimo/index.html.twig', array( 'emprestimos' => $emprestimos, @@ -87,17 +64,31 @@ class EmprestimoController extends Controller $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + // Armário já emprestado if(!$this->estaDisponivel($emprestimo)){ $this->addFlash('danger', sprintf('Erro: Item %s já está emprestado para outra pessoa!', $emprestimo->getMaterial()->getCodigo())); return $this->redirectToRoute('emprestimo_usp'); } + + // Armário desativado if(!$emprestimo->getMaterial()->getAtivo()){ - $this->addFlash('danger', sprintf('Erro: Item %s não pode ser emprestado no momento, pois está desativado.', - $emprestimo->getMaterial()->getCodigo())); + $this->addFlash('danger', sprintf('Erro: Item %s não pode ser emprestado no momento, pois está desativado.',$emprestimo->getMaterial()->getCodigo())); return $this->redirectToRoute('emprestimo_usp'); } + // Não permite empréstimo de dois materiais do mesmo tipo + foreach($this->emprestimos() as $x){ + if( ($emprestimo->getCodpes() == $x->getCodpes()) & + ($emprestimo->getMaterial()->getTipo() == $x->getMaterial()->getTipo()) + ){ + $this->addFlash('danger', sprintf('Item não emprestado! Pois o usuário(a) %s + já tem %s emprestado.', + $emprestimo->getCodpes(),$x->getMaterial()->getTipo())); + return $this->redirectToRoute('emprestimo_usp'); + } + } + // Replicado $replicado = []; if( getenv('USAR_REPLICADO') == 'true') { @@ -148,37 +139,31 @@ class EmprestimoController extends Controller if ($form->isSubmitted() && $form->isValid()) { + // verifica se item já não está emprestado if(!$this->estaDisponivel($emprestimo)){ $this->addFlash('danger', sprintf('Erro: Item %s já está emprestado para outra pessoa!', $emprestimo->getMaterial()->getCodigo())); return $this->redirectToRoute('emprestimo_visitante'); } + + // item desativado if(!$emprestimo->getMaterial()->getAtivo()){ - $this->addFlash('danger', sprintf('Erro: Item %s não pode ser emprestado no momento, pois está desativado.', - $emprestimo->getMaterial()->getCodigo())); + $this->addFlash('danger', sprintf('Erro: Item %s não pode ser emprestado no momento, pois está desativado.',$emprestimo->getMaterial()->getCodigo())); return $this->redirectToRoute('emprestimo_visitante'); } - -/* - - // Verificar se a pessoa já não possui armário emprestado - foreach($armarios_indisponiveis as $x){ - if($emprestimo->getPessoaExterna() == $x->getPessoaExterna()){ - $this->addFlash('danger', sprintf('Armário não emprestado! Pois o usuário(a) %s - já tem o armário %s emprestado.',$emprestimo->getPessoaExterna(),$x->getArmario())); - return $this->redirectToRoute('emprestimo_pessoaexterna_new'); + // Não permite empréstimo de dois materiais do mesmo tipo + foreach($this->emprestimos() as $x){ + if( ($emprestimo->getVisitante() == $x->getVisitante()) & + ($emprestimo->getMaterial()->getTipo() == $x->getMaterial()->getTipo()) + ){ + $this->addFlash('danger', sprintf('Item não emprestado! Pois o usuário(a) %s + já tem %s emprestado.', + $emprestimo->getVisitante(),$x->getMaterial()->getTipo())); + return $this->redirectToRoute('emprestimo_visitante'); } - } - - $armario_em_quesao = $em->getRepository('AppBundle:Armario')->findOneById($emprestimo->getArmario()); - - if(!$armario_em_quesao->getAtivo()){ - $this->addFlash('danger', sprintf('Armário não emprestado! - Pois armário %s está desativado, favor escolha outro armário!',$emprestimo->getArmario())); - return $this->redirectToRoute('emprestimo_pessoaexterna_new'); - } -*/ + } + $emprestimo->setDataEmprestimo(new \DateTime()); $emprestimo->setCreatedBy($this->getUser()); $em->persist($emprestimo); @@ -186,12 +171,11 @@ class EmprestimoController extends Controller return $this->render('emprestimo/show.html.twig', array( 'emprestimo' => $emprestimo, - 'replicado' => array(), - 'wsfoto' => array(), + 'replicado' => [], + 'wsfoto' => [], )); } - - + return $this->render('emprestimo/visitante.html.twig', array( 'emprestimo' => $emprestimo, 'form' => $form->createView(), @@ -269,19 +253,20 @@ class EmprestimoController extends Controller } /********************************** Utils Functions *****************************************/ + //TODO: Move this funtions to outside this class! - public function emprestados() + public function emprestimos() { $em = $this->getDoctrine()->getManager(); - $emprestados = $em->getRepository('App:Emprestimo')->findby(['dataDevolucao'=>null],array('material' => 'ASC')); - return $emprestados; + $emprestimos = $em->getRepository('App:Emprestimo')->findby(['dataDevolucao'=>null],array('material' => 'ASC')); + return $emprestimos; } public function estaDisponivel($check) { - $emprestados = $this->emprestados(); + $emprestimos = $this->emprestimos(); - foreach($emprestados as $emprestado){ + foreach($emprestimos as $emprestado){ if($check->getMaterial() === $emprestado->getMaterial()){ return false; } diff --git a/templates/base.html.twig b/templates/base.html.twig index 51809c2426e420d92a1f8ef5f7878ceba8d75fba..de0e902ba80e65649973944976059a4aa14d11e6 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -55,12 +55,6 @@ Itens emprestados </a> </li> - <li class="nav-item"> - <a class="nav-link" href=" {{ path('emprestimo_index')}}"> - <span data-feather="file"></span> - Empréstimo concluÃdos - </a> - </li> </ul> {% else%} <center>Faça login para ver as opções</center> diff --git a/templates/material/edit.html.twig b/templates/material/edit.html.twig index de5568db447b394505a70ce03fbdd5e29d77ec11..127fccc945d9859980336ae75379072a69e0bec6 100644 --- a/templates/material/edit.html.twig +++ b/templates/material/edit.html.twig @@ -1,9 +1,9 @@ {% extends 'base.html.twig' %} -{% block title %}Edit Material{% endblock %} +{% block title %}Editar Material{% endblock %} {% block body %} - <h1>Edit Material</h1> + <h1>Editar Material</h1> {{ include('material/_form.html.twig', {'button_label': 'Salvar'}) }} diff --git a/templates/material/new.html.twig b/templates/material/new.html.twig index c40263047a0f11e24f2143d7c3d8e90fe24c3c69..7127b06777fdb6d04e6ee803e32b28541b4a9d77 100644 --- a/templates/material/new.html.twig +++ b/templates/material/new.html.twig @@ -1,11 +1,10 @@ {% extends 'base.html.twig' %} -{% block title %}New Material{% endblock %} +{% block title %}Novo Material{% endblock %} {% block body %} - <h1>Create new Material</h1> + <h1>Novo Material</h1> {{ include('material/_form.html.twig') }} - {% endblock %} diff --git a/templates/tipo_material/edit.html.twig b/templates/tipo_material/edit.html.twig index 9ff983df70d493493243755c1444476ea0e67abb..0ccd9032e5f0e95daae89ba2b3857d74a9b3eace 100644 --- a/templates/tipo_material/edit.html.twig +++ b/templates/tipo_material/edit.html.twig @@ -1,9 +1,9 @@ {% extends 'base.html.twig' %} -{% block title %}Edit TipoMaterial{% endblock %} +{% block title %}Editar categoria{% endblock %} {% block body %} - <h1>Edit TipoMaterial</h1> + <h1>Editar categoria</h1> {{ include('tipo_material/_form.html.twig', {'button_label': 'Salvar'}) }} diff --git a/templates/tipo_material/new.html.twig b/templates/tipo_material/new.html.twig index ad5f7be62ca10e49ed7977c75d7d205f434aa188..0217a0b7f3a1e43d8212cad11a261e6ffc518ebf 100644 --- a/templates/tipo_material/new.html.twig +++ b/templates/tipo_material/new.html.twig @@ -1,9 +1,9 @@ {% extends 'base.html.twig' %} -{% block title %}New TipoMaterial{% endblock %} +{% block title %}Nova categoria{% endblock %} {% block body %} - <h1>Create new TipoMaterial</h1> + <h1>Nova categoria</h1> {{ include('tipo_material/_form.html.twig') }}