src/Noahtech/Sistemas/InterjamaBundle/Controller/Atencion/TurnoController.php line 213

Open in your IDE?
  1. <?php
  2. namespace Noahtech\Sistemas\InterjamaBundle\Controller\Atencion;
  3. use Noahtech\Sistemas\InterjamaBundle\Utils\Codes;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Noahtech\Sistemas\InterjamaBundle\Controller\BaseController;
  8. use Noahtech\Sistemas\InterjamaBundle\Handler\McTurnoHandler;
  9. use Noahtech\Sistemas\InterjamaBundle\Handler\McChoferHandler;
  10. use Noahtech\Sistemas\InterjamaBundle\Handler\McClienteHandler;
  11. use Noahtech\Sistemas\InterjamaBundle\Handler\McVehiculoHandler;
  12. use Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaHandler;
  13. use Noahtech\Sistemas\InterjamaBundle\Handler\McTiposTramiteHandler;
  14. use Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler;
  15. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  16. use Noahtech\Sistemas\InterjamaBundle\Utils\Constants;
  17. use Noahtech\Sistemas\InterjamaBundle\Handler\McTurnoProximoHandler;
  18. class TurnoController extends BaseController {
  19.     private function validarAtencion () {
  20.         $usuario $this->getUser();
  21.         if ($usuario) {
  22.             $atencion false;
  23.             foreach ($usuario->getRoles() as $rol) {
  24.                 if ($rol == 'ROLE_ATENCION'){
  25.                     $atencion true;
  26.                 }
  27.             }
  28.             if (!$atencion){
  29.                 throw new AccessDeniedException("No tiene permiso para acceder a esta pagina.");
  30.             }
  31.         } else {
  32.             throw new AccessDeniedException("No tiene permiso para acceder a esta pagina.");
  33.         }
  34.     }
  35.     
  36.     /**
  37.      * @Route("/atencion/turnos", name="atencion_turnos_listado")
  38.      * @return type
  39.      */
  40.     public function turnoListadoAction() {
  41.         $this->validarAtencion();
  42.         $usuario $this->getUser();               
  43.         $this->setTitle("Listado de turnos | InterJama");
  44.         $this->addBreadCrumb("Inicio - Atención"false"atencion_home");
  45.         $this->addBreadCrumb("Listado de turnos"true);        
  46.         $this->data['data'] = null;
  47.         return $this->render(
  48.                         '@NoahtechSistemasInterjama/atencion/turnos/listado.html.twig'$this->data
  49.         );
  50.     }
  51.     /**
  52.      * consulta de turnos
  53.      *
  54.      * @Route("/atencion/ajax/turnos/search", name="atencion_ajax_turnos_listado", methods={"POST"}, condition="request.isXmlHttpRequest()")
  55.      */
  56.     public function searchAction(Request $request) {
  57.         $this->validarAtencion();
  58.         $searchParam $request->request->all();        
  59.         $usuario $this->getUser();               
  60.         $currentPage $request->query->get('page');
  61.         $sortField $request->query->get('sort');
  62.         $sortDirection $request->query->get('direction');
  63.         $currentPage null == $currentPage $currentPage;
  64.         $offset = ($currentPage 1) * 100;
  65.         $limit 100;
  66.         try {
  67.             /** @var McTurnoHandler $handler */
  68.             $handler $this->get(McTurnoHandler::class);
  69.             $lp $handler->search($offset$limit$sortField$sortDirection$searchParam);
  70.             $lp->setCurrentPage($currentPage);
  71.             $lp->setPageSize(100);
  72.             $this->response->setData($lp);
  73.             $this->response->setCode(Codes::OK);
  74.         } catch (Exception $e) {
  75.             $this->response->setCode(Codes::ERROR);
  76.             $this->response->setMessage($e->getMessage());
  77.         }
  78.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  79.         return new Response($serializedEntity);
  80.     }
  81.     /**
  82.      * @Route("/atencion/turno/nuevo", name="atencion_turno_nuevo")
  83.      * @return type
  84.      */
  85.     public function turnoNuevoAction() {
  86.         $this->validarAtencion();
  87.         $this->setTitle("Nuevo Turno");
  88.         $this->addBreadCrumb("Inicio - Atención"false"atencion_home");        
  89.         $this->addBreadCrumb("Nuevo Turno"true);        
  90.         $this->data['data'] = null;
  91.         return $this->render(
  92.                         '@NoahtechSistemasInterjama/atencion/turnos/nuevo.html.twig'$this->data
  93.         );
  94.     }
  95.     /**
  96.      * Guarda un turno
  97.      *
  98.      * @Route("/atencion/ajax/turnos/nuevo", name="atencion_turnos_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  99.      */
  100.     public function postTurnoSaveAction(Request $request) {
  101.         $this->validarAtencion();
  102.         $handler $this->get(McTurnoHandler::class);
  103.         $turno $handler->getTurnoFromRequest($request);
  104.         $result $handler->save($turno);
  105.         $this->response->setData($result);
  106.         $this->response->setCode(Codes::OK);
  107.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  108.         return new Response($serializedEntity);
  109.     }
  110.     /**
  111.      * @Route("/atencion/turnero", name="atencion_turnero")
  112.      * @return type
  113.      */
  114.     public function turneroAction(Request $request) {
  115.         $this->validarAtencion();
  116.         $this->setTitle("");
  117.         $this->data['data'] = null;
  118.         return $this->render(
  119.                         '@NoahtechSistemasInterjama/atencion/turnos/turnero.html.twig'$this->data
  120.         );
  121.     }
  122.     /**
  123.      * Guardar el turno actual
  124.      *
  125.      * @Route("/atencion/ajax/turno/proximo", name="atencion_turno_proximo_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  126.      */
  127.     public function postTurnoProximoSaveAction(Request $request) {        
  128.         $this->validarAtencion();        
  129.         $handler $this->get(McTurnoProximoHandler::class);
  130.         $id 1;
  131.         $turnoProximo $handler->getTurnoProximoFromRequest($request$id);      
  132.         $result $handler->save($turnoProximo);
  133.         $this->response->setData($result);
  134.         $this->response->setCode(Codes::OK);
  135.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  136.         return new Response($serializedEntity);
  137.     }
  138.     /**
  139.      * Devuelve el turno actual
  140.      *
  141.      * @Route("/atencion/ajax/turno/actual/{id}", name="atencion_ajax_turno_actual_get_by_id", methods={"GET"}, condition="request.isXmlHttpRequest()")
  142.      */
  143.     public function getTurnoActualByIdAction($id) {
  144.         $this->validarAtencion();
  145.         try {
  146.             $handler $this->get(McTurnoProximoHandler::class);
  147.             $turnoActual $handler->getById($id);
  148.             $this->response->setData($turnoActual);
  149.             $this->response->setCode(Codes::OK);
  150.         } catch (Exception $e) {
  151.             $this->response->setCode(Codes::ERROR);
  152.             $this->response->setMessage($e->getMessage());
  153.         }
  154.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  155.         return new Response($serializedEntity);
  156.     }
  157.      /**
  158.      * Devuelve los choferes
  159.      *
  160.      * @Route("/atencion/ajax/search/choferes/Bytermino", name="atencion_ajax_search_choferes_by_termino", methods={"GET"}, condition="request.isXmlHttpRequest()")
  161.      */
  162.     public function searchChoferesByTerminoAction(Request $request) {
  163.         $this->validarAtencion();
  164.         $searchParam $request->query->get('q');
  165.         try {
  166.             $handler $this->get(McChoferHandler::class);
  167.             $choferes $handler->searchChoferesByTermino($searchParam);
  168.             $this->response->setData($choferes);
  169.             $this->response->setCode(Codes::OK);
  170.         } catch (Exception $e) {
  171.             $this->response->setCode(Codes::ERROR);
  172.             $this->response->setMessage($e->getMessage());
  173.         }
  174.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  175.         return new Response($serializedEntity);
  176.     }
  177.     /**
  178.      * Devuelve todos los clientes
  179.      *
  180.      * @Route("/atencion/ajax/clientes/all", name="atencion_ajax_clientes_all", methods={"GET"}, condition="request.isXmlHttpRequest()")
  181.      */
  182.     public function searchClientesAction() {
  183.         $this->validarAtencion();
  184.         $userCurrent $this->getUser();
  185.         try {
  186.             $handler $this->get(McClienteHandler::class);
  187.             $choferes $handler->getClientes();
  188.             $this->response->setData($choferes);
  189.             $this->response->setCode(Codes::OK);
  190.         } catch (Exception $e) {
  191.             $this->response->setCode(Codes::ERROR);
  192.             $this->response->setMessage($e->getMessage());
  193.         }
  194.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  195.         return new Response($serializedEntity);
  196.     }
  197.     /**
  198.      * @Route("/atencion/turno/{turnoId}/precarga/nueva", name="atencion_turno_precarga_nueva")
  199.      * @return type
  200.      */
  201.     public function precargaNuevoAction($turnoId) {
  202.         $this->validarAtencion();
  203.         $this->setTitle("Nuevo ingreso");
  204.         $this->addBreadCrumb("Inicio - Atención"false"atencion_home");
  205.         $this->addBreadCrumb("Turnos"false"atencion_turnos_listado");        
  206.         $this->addBreadCrumb("Nuevo trámite"true);
  207.         $turno $this->get(McTurnoHandler::class)->getById($turnoId);
  208.         $clientes $this->get(McClienteHandler::class)->getClientes();
  209.         $tiposTramite $this->get(McTiposTramiteHandler::class)->getTiposTramite();
  210.         $caja $this->get(McCajaHandler::class)->getCajaAbierta('operador');
  211.         $this->data['turno'] = $turno;
  212.         $this->data['clientes'] = $clientes;
  213.         $this->data['tiposTramite'] = $tiposTramite;
  214.         $this->data['caja'] = $caja;
  215.         return $this->render(
  216.                         '@NoahtechSistemasInterjama/atencion/precargas/nueva.html.twig'$this->data
  217.         );
  218.     }
  219.     /**
  220.      * Devuelve los vehiculos de un cliente
  221.      *
  222.      * @Route("/atencion/ajax/cliente/{clienteId}/search/vehiculos/Bytermino", name="atencion_ajax_search_vehiculos_by_termino", methods={"GET"}, condition="request.isXmlHttpRequest()")
  223.      */
  224.     public function searchVehiculoByTerminoAction(Request $request$clienteId) {
  225.         $this->validarAtencion();
  226.         $searchParam $request->query->get('q');
  227.         try {
  228.             $handler $this->get(McVehiculoHandler::class);
  229.             $vehiculos $handler->searchVehiculosByTermino($searchParam, (int)$clienteId);
  230.             $this->response->setData($vehiculos);
  231.             $this->response->setCode(Codes::OK);
  232.         } catch (Exception $e) {
  233.             $this->response->setCode(Codes::ERROR);
  234.             $this->response->setMessage($e->getMessage());
  235.         }
  236.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  237.         return new Response($serializedEntity);
  238.     }
  239.     /**
  240.      * Guarda una precarga
  241.      *
  242.      * @Route("/atencion/ajax/precargas", name="atencion_ajax_precargas_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  243.      */
  244.     public function postPrecargaSaveAction(Request $request) {
  245.         $this->validarAtencion();
  246.         $archivos = (isset($_FILES)) ? $_FILES null;
  247.         try {
  248.             $handler $this->get(McPrecargaHandler::class);
  249.             $usuario $this->getUser();
  250.             $precarga $handler->getPrecargaFromRequest($request$usuario);
  251.             $result $handler->save($precarga$archivos$request);
  252.             $this->response->setData($result);
  253.             $this->response->setCode(Codes::OK);
  254.         } catch (Exception $e) {
  255.             $this->response->setCode(Codes::ERROR);
  256.             $this->response->setMessage($e->getMessage());
  257.         }
  258.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  259.         return new Response($serializedEntity);
  260.     }
  261.     /**
  262.      * Guarda un vehículo
  263.      *
  264.      * @Route("/atencion/ajax/vehiculos", name="atencion_ajax_vehiculo_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  265.      */
  266.     public function vehiculoSaveAction(Request $request) {
  267.         $this->validarAtencion();
  268.         try {
  269.             $handler $this->get(McVehiculoHandler::class);            
  270.             $vehiculo $handler->getVehiculoFromRequest($request);
  271.             $result $handler->save($vehiculo);
  272.             $this->response->setData($result);
  273.             $this->response->setCode(Codes::OK);            
  274.         } catch (Exception $e) {
  275.             $this->response->setCode(Codes::ERROR);
  276.             $this->response->setMessage($e->getMessage());
  277.         }
  278.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  279.         return new Response($serializedEntity);       
  280.     }
  281. }