src/Controller/DefaultController.php line 42

  1. <?php
  2. namespace App\Controller;
  3. use App\Classes\Security;
  4. use App\Classes\Utils;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use DateTime;
  13. use Symfony\Component\HttpKernel\Kernel;
  14. use App\Entity\ContactoFeria;
  15. use App\Entity\Delegado;
  16. use App\Entity\User;
  17. use App\Entity\Farmacia;
  18. use App\Entity\LandingLog;
  19. use Symfony\Component\Security\Core\Role\Role;
  20. use Doctrine\ORM\EntityManager;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Detection\MobileDetect;
  23. use App\Entity\DelegadoFerias;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. use App\Entity\TipoIncidencia;
  26. //use App\Entity\ContactoFeria;
  27. //use App\Entity\FarmaciaPersona;
  28. class DefaultController extends AbstractController
  29. {
  30.     
  31.     #[Route('/politica-de-cookies'name'politica_de_cookies')]
  32.     public function politicaCookies(Request $request) {
  33.         return $this->render('Default/politica-de-cookies.html.twig');
  34.     }
  35.     
  36.     /**
  37.      * @Route("/", name="homepage")
  38.      */
  39.     public function indexAction(EntityManagerInterface $emRequest $request): Response
  40.     {
  41.         $detect = new MobileDetect();
  42.         if($this->getUser()->hasRole("ROLE_ADMIN")) {
  43.             return $this->redirectToRoute("admin_homepage");
  44.         } else if($this->getUser()->hasRole("ROLE_GESTOR")) {
  45.             if(($detect->isMobile() || $detect->isTablet() || Utils::isIpadPro($detect))&&($this->getUser()->hasRole("ROLE_FERIAS"))) {
  46.                 return $this->redirectToRoute("ferias_homepage");
  47.             } else {
  48.                 return $this->redirectToRoute("gestor_homepage");
  49.             }
  50.         } else if($this->getUser()->hasRole("ROLE_FERIAS")) {
  51.             return $this->redirectToRoute("ferias_homepage");
  52.         } else if($this->getUser()->hasRole("ROLE_SAC")) {
  53.             return $this->redirectToRoute("gestor_incidencias");
  54.         } else {
  55.             return $this->render('Default/index.html.twig', []);
  56.         }
  57.     }
  58.     
  59.     /**
  60.      * @Route("/api/delegado", name="get_delegado_from_farmacia")
  61.      */
  62.     public function getDelegadoAction(EntityManagerInterface $emRequest $request)
  63.     {
  64.         
  65.         $farmacia $em->getRepository(Farmacia::class)->find($request->get("id"));
  66.         $arr_resultado = array();
  67.         $arr_resultado['resultado'] = -1;
  68.         if($farmacia) {
  69.             if($farmacia->getDelegado()) {
  70.                 $arr_resultado['resultado'] = $farmacia->getDelegado()->getId();
  71.                 $arr_resultado['nombre'] = $farmacia->getDelegado()->getNombre();
  72.                 $arr_resultado['zona'] = $farmacia->getZona()->getNombre();
  73.                 $arr_resultado['plataforma'] = $farmacia->getPlataforma();
  74.                 if($this->getUser()->hasRole("ROLE_FERIAS")) {
  75.                     $arr_resultado['soluciones'] = 1;
  76.                     $arr_resultado['delegados_feria'] = array();
  77.                     $arr_resultado['experience'] = $farmacia->getExperience();
  78.                     $arr_resultado['piel'] = $farmacia->getPiel();
  79.                     $arr_resultado['circulacion_venosa'] = $farmacia->getCirculacionVenosa();
  80.                     $arr_resultado['nutricion'] = $farmacia->getNutricion();
  81.                     $arr_resultado['salud_articular'] = $farmacia->isSaludArticular();
  82.                     $arr_resultado['medical_dispenser'] = $farmacia->getMedicalDispenser();
  83.                     foreach($farmacia->getDelegadosFerias() as $delegado_feria) {
  84.                         $arr_delegado_feria = array();
  85.                         $arr_delegado_feria['nombre'] = $delegado_feria->getNombre();
  86.                         $arr_delegado_feria['numero'] = $delegado_feria->getNumero();
  87.                         $arr_resultado['delegados_feria'][Utils::string2url($delegado_feria->getTipo())] = $arr_delegado_feria;
  88.                     }
  89.                     $arr_resultado['farmacia_personas'] = array();
  90.                     foreach($farmacia->getPersonas() as $persona) {
  91.                         $arr_farmacia_persona = array();
  92.                         $arr_farmacia_persona['nombre'] = $persona->getNombre();
  93.                         $arr_farmacia_persona['apellidos'] = $persona->getApellidos();
  94.                         $arr_farmacia_persona['email'] = $persona->getEmail();
  95.                         $arr_farmacia_persona['dni'] = $persona->getDni();
  96.                         $arr_resultado['farmacia_personas'][$persona->getId()] = $arr_farmacia_persona;
  97.                     }
  98.                 } else {
  99.                     $arr_resultado['soluciones'] = 0;
  100.                 }
  101.                 
  102.             }
  103.         }
  104.         
  105.         return new JsonResponse($arr_resultado);
  106.     }
  107.     
  108.     /**
  109.      * @Route("/api/feria/contactos", name="get_contactos_feria_from_farmacia")
  110.      */
  111.     public function getContactosFeriaAction(EntityManagerInterface $emRequest $request)
  112.     {
  113.         
  114.         $farmacia $em->getRepository(Farmacia::class)->find($request->get("farmacia_id"));
  115.         $arr_resultado = array();
  116.         $arr_resultado['resultado'] = 0;
  117.         if($farmacia) {
  118.             $contactos $em->getRepository(ContactoFeria::class)->getContactosFeriaFarmacia($request->get("feria_id"), $request->get("farmacia_id"));
  119.             if(count($contactos)>0) {
  120.                 $arr_resultado['resultado'] = count($contactos);
  121.                 $arr_resultado['contactos'] = array();
  122.                 foreach($contactos as $contacto) {
  123.                     $arr_contacto = array();
  124.                     $arr_contacto['farmacia_id'] = $contacto->getFarmacia()->getId();
  125.                     $arr_contacto['farmacia_nombre'] = $contacto->getFarmacia()->getNombre();
  126.                     $arr_contacto['fecha'] = $contacto->getStrFecha();
  127.                     $arr_contacto['personas'] = array();
  128.                     foreach($contacto->getPersonasContacto() as $persona) {
  129.                         $arr_contacto['personas'][] = $persona->getNombre();
  130.                     }
  131.                     $arr_contacto['intereses'] = array();
  132.                     foreach($contacto->getIntereses() as $interes) {
  133.                         $arr_contacto['intereses'][] = $interes->getNombre();
  134.                     }
  135.                     if($contacto->getDetalle()==true) {
  136.                         $arr_contacto['detalle_aurum'] = 'Sí';
  137.                     } else {
  138.                         $arr_contacto['detalle_aurum'] = 'No';
  139.                     }
  140.                     $arr_resultado['contactos'][]=$arr_contacto;
  141.                 }
  142.             }
  143.         }
  144.         
  145.         return new JsonResponse($arr_resultado);
  146.     }
  147.     
  148.     
  149.     
  150.     /**
  151.      * @Route("/api/farmacia", name="get_datos_from_farmacia")
  152.      */
  153.     public function getDatosFarmaciaAction(EntityManagerInterface $emRequest $request)
  154.     {
  155.         
  156.         $farmacia $em->getRepository(Farmacia::class)->find($request->get("id"));
  157.         $arr_resultado = array();
  158.         $arr_resultado['resultado'] = -1;
  159.         if($farmacia) {
  160.             if($farmacia->getDelegado()) {
  161.                 $arr_resultado['delegado'] = $farmacia->getDelegado()->getNombre();
  162.             } else {
  163.                 $arr_resultado['delegado'] = '';
  164.             }
  165.             $arr_resultado['zona'] = $farmacia->getZona()->getNombre();
  166.             $arr_resultado['telefono'] = $farmacia->getTelefono();
  167.             $arr_resultado['e-mail'] = $farmacia->getEmail();
  168.             $arr_resultado['cif'] = $farmacia->getNif();
  169.             $arr_resultado['localidad'] = $farmacia->getLocalidad();
  170.             $arr_resultado['provincia'] = $farmacia->getProvincia();
  171.             $arr_resultado['direccion'] = $farmacia->getDireccion();
  172.             $arr_resultado['cod_postal'] = $farmacia->getCodPostal();
  173.             $arr_resultado['plataforma'] = $farmacia->getPlataforma();
  174.             $arr_resultado['nombre'] = $farmacia->getNombre();
  175.             $arr_resultado['id'] = $farmacia->getId();
  176.             $arr_resultado['cod_cliente'] = $farmacia->getCodCliente();
  177.             $arr_resultado['cod_local'] = $farmacia->getCodLocal();
  178.             
  179.             $ahora = new \DateTime();
  180.             $arr_resultado['tope_facturacion'] = 0;
  181.             for($i=2016;$i<=$ahora->format("Y");$i++) {
  182.                 $arr_resultado['facturacion'.$i] = number_format($farmacia->getFacturacionAnio($i),2,',','.');
  183.                 $arr_resultado['tope_facturacion'] = $i;
  184.             }
  185.             $arr_resultado['facturacionDesde2016'] = number_format($farmacia->getFacturacion2016(),2,',','.');
  186.             $arr_resultado['resultado'] = 1;    
  187.             
  188.         }
  189.         return new JsonResponse($arr_resultado);
  190.     }
  191.     
  192.     
  193.     /**
  194.      * @Route("/api/farmacia/instant", name="api_farmacia_instant_search")
  195.      */
  196.     public function instantSearchAction(EntityManagerInterface $emRequest $request)
  197.     {
  198.         
  199.         
  200.         $resultados $em->getRepository(Farmacia::class)->instantSearch($request);
  201.         
  202.         return new JsonResponse($resultados);
  203.     }
  204.     
  205.     
  206.     
  207.     /**
  208.      * @Route("/api/importa/blisters", name="api_importa_blisters")
  209.      */
  210.     public function importaBlistersAction(EntityManagerInterface $emRequest $request)
  211.     {
  212.         
  213.         $phpExcelObject $this->get('phpexcel')->createPHPExcelObject('D:/work/cinfa/medical-dispenser/docs/datos_a_importar.xlsx');
  214.         $hoja $phpExcelObject->getActiveSheet();
  215.         $highestRow $hoja->getHighestRow();
  216.         $highestColumn $hoja->getHighestColumn();
  217.         $arr_fechas = array();
  218.         $importadas 0;
  219.         $i=0;
  220.         for($col 'B'$col != $highestColumn$col++){
  221.             $i++;
  222.             $arr_fechas[$i] = $hoja->getCellByColumnAndRow($i1)->getFormattedValue();
  223.         }
  224.         for ($row 2$row <= $highestRow; ++$row) {
  225.             $codigo $hoja->getCellByColumnAndRow(0$row)->getValue();
  226.             $farmacia $em->getRepository(Farmacia::class)->findOneByCodLocal($codigo);
  227.             if($farmacia) {
  228.                 $ik=0;
  229.                 for($col 'B'$col != $highestColumn$col++){
  230.                     $ik++;
  231.                     $valor $hoja->getCellByColumnAndRow($ik$row)->getValue();
  232.                     if($valor>0) {
  233.                         $RAW_QUERY "insert into venta (farmacia_id, delegado_id, plataforma, producto, fecha_compra, cajas_blister, created_at, created_by, updated_at, updated_by) ";
  234.                         $RAW_QUERY.=" values(";
  235.                         $RAW_QUERY.=$farmacia->getId().",".$farmacia->getDelegado()->getId().",'".$farmacia->getPlataforma()."','BL',";
  236.                         $fecha \DateTime::createFromFormat("m/d/Y"$arr_fechas[$ik]);
  237.                         $RAW_QUERY.="'".$fecha->format("Y-m-d")."',";
  238.                         $RAW_QUERY.=$valor.",";
  239.                         $RAW_QUERY.="NOW(),1,NOW(),1);";
  240.                         $statement $em->getConnection()->prepare($RAW_QUERY);
  241.                         $statement->execute();
  242.                         $importadas++;
  243.                   
  244.                     }
  245.                 }
  246.             }
  247.         }
  248.         die("Importadas:".$importadas);
  249.     }
  250.     
  251.     
  252.     /**
  253.      * @Route("/api/importa/facturacion", name="api_importa_facturacion")
  254.      */
  255.     public function importaFacturacionAction(EntityManagerInterface $emRequest $request)
  256.     {
  257.         set_time_limit 180 );
  258.         
  259.         $phpExcelObject $this->get('phpexcel')->createPHPExcelObject('D:/work/cinfa/medical-dispenser/docs/facturacion_16_20.xlsx');
  260.         $hoja $phpExcelObject->getActiveSheet();
  261.         $highestRow $hoja->getHighestRow();
  262.         $highestColumn $hoja->getHighestColumn();
  263.         $arr_fechas = array();
  264.         $importadas 0;
  265.         $i=0;
  266.         for($col 'C'$col != $highestColumn$col++){
  267.             $i++;
  268.             $arr_fechas[$i] = $hoja->getCellByColumnAndRow($i1)->getValue();
  269.         }
  270.         for ($row 2$row <= $highestRow; ++$row) {
  271.             $codigo $hoja->getCellByColumnAndRow(0$row)->getValue();
  272.             $farmacia $em->getRepository(Farmacia::class)->findOneByCodLocal($codigo);
  273.             if($farmacia) {
  274.                 $ik=0;
  275.                 for($col 'C'$col != $highestColumn$col++){
  276.                     $ik++;
  277.                     $valor $hoja->getCellByColumnAndRow($ik$row)->getValue();
  278.                     if($valor>0) {
  279.                         $RAW_QUERY "insert into facturacion (farmacia_id, delegado_id, plataforma, anyo, cantidad, created_at, created_by, updated_at, updated_by) ";
  280.                         $RAW_QUERY.=" values(";
  281.                         $RAW_QUERY.=$farmacia->getId().",".$farmacia->getDelegado()->getId().",'".$farmacia->getPlataforma()."',";
  282.                         $RAW_QUERY.=$arr_fechas[$ik].",";
  283.                         $RAW_QUERY.=$valor.",";
  284.                         $RAW_QUERY.="NOW(),1,NOW(),1);";
  285.                         $statement $em->getConnection()->prepare($RAW_QUERY);
  286.                         $statement->execute();
  287.                         $importadas++;
  288.                         
  289.                     }
  290.                 }
  291.             }
  292.         }
  293.         die("Importadas:".$importadas);
  294.     }
  295.     
  296.     
  297.     
  298.     /**
  299.      * @Route("/api/ext/getFarmaciasDelegado", name="ext_get_farmacias_from_delegado")
  300.      * @Method({"POST", "GET"})
  301.      */
  302.     public function getFarmaciasDelegadoAction(EntityManagerInterface $emRequest $request)
  303.     {
  304.         
  305.         $delegado $em->getRepository(Delegado::class)->findOneByEmail($request->get("email"));
  306.         $arr_resultado = array();
  307.         if($delegado) {
  308.             foreach($delegado->getFarmacias() as $farmacia)  {
  309.                 if($farmacia->getCodCliente()!='') {
  310.                     $arr_resultado[$farmacia->getId()] = $farmacia->getCodCliente()." - ".$farmacia->getNombre();
  311.                 } else {
  312.                     $arr_resultado[$farmacia->getId()] = $farmacia->getNombre();
  313.                 }
  314.             }
  315.         }
  316.         return new JsonResponse($arr_resultado);
  317.     }
  318.     
  319.     /**
  320.      * @Route("/api/ext/getDatosFarmacia", name="ext_get_datos_farmacia")
  321.      * @Method({"POST"})
  322.      */
  323.     public function getExtDatosFarmaciaAction(EntityManagerInterface $emRequest $request)
  324.     {
  325.         return $this->getDatosFarmaciaAction($em$request);
  326.     }
  327.     
  328.     /**
  329.      * @Route("/api/incidencia/tipo/hijos", name="get_tipo_incidencia_hijos")
  330.      */
  331.     public function getTipoIncidenciaHijosAction(EntityManagerInterface $emRequest $request)
  332.     {
  333.         
  334.         $tipo_incidencia $em->getRepository(TipoIncidencia::class)->find($request->get("id"));
  335.         $arr_resultado = array();
  336.         $arr_resultado['datos'] = array();
  337.         $arr_resultado['resultado'] = -1;
  338.         if($tipo_incidencia) {
  339.             foreach($tipo_incidencia->getHijos() as $hijo) {
  340.                 $arr_resultado['datos'][$hijo->getId()] = $hijo->getNombre();
  341.                 $arr_resultado['resultado'] = 1;
  342.             }
  343.             
  344.         }
  345.         return new JsonResponse($arr_resultado);
  346.     }
  347.     
  348.     /**
  349.      * @Route("/api/ext/farmacia/verify", name="verificar_farmacia")
  350.      * @Method({"GET"})
  351.      */
  352.     public function verificarFarmaciaAction(EntityManagerInterface $emRequest $request)
  353.     {
  354.         
  355.         $farmacia $em->getRepository(Farmacia::class)->findOneBy(array("codCliente"=>$request->get("cod_cliente"), "nif"=>$request->get("nif"), "activa"=>1));
  356.         $arr_resultado = array();
  357.         if($farmacia) {
  358.             $arr_resultado["resultado"]=$farmacia->getId();
  359.         } else {
  360.             $arr_resultado["resultado"]=0;
  361.         }
  362.         $response = new JsonResponse($arr_resultado);
  363.         $response->headers->set('Content-Type''application/json');
  364.         $response->headers->set('Access-Control-Allow-Origin''*');
  365.         return $response;
  366.     }
  367.     
  368.     
  369.     /**
  370.      * @Route("/api/ext/medical/log/set", name="landing_log_new")
  371.      * @Method({"GET","POST"})
  372.      */
  373.     public function newLandingLogAction(EntityManagerInterface $emRequest $request)
  374.     {
  375.         $log = new LandingLog();
  376.         $log->setCodCliente($request->get('cod_cliente'));
  377.         $log->setCif($request->get("cif"));
  378.         $log->setNombre($request->get("nombre"));
  379.         $log->setTelefono($request->get("telefono"));
  380.         $log->setAceptacionLegal($request->get("aceptacion"));
  381.         $log->setEmail($request->get("email"));
  382.         $log->setFecha(new \DateTime());
  383.         $log->setAccion($request->get("accion"));
  384.         $log->setRespuesta($request->get("respuesta"));
  385.         $log->setUserAgent($request->get("user_agent"));
  386.         $log->setRemoteIp($request->get("remote_ip"));
  387.         $log->setOrigen($request->get('org'));
  388.         $em->persist($log);
  389.         $em->flush();
  390.         
  391.         $arr_resultado = array();
  392.         $arr_resultado["resultado"]="ok";
  393.         $response = new JsonResponse($arr_resultado);
  394.         $response->headers->set('Content-Type''application/json');
  395.         $response->headers->set('Access-Control-Allow-Origin''*');
  396.         return $response;
  397.     }
  398.     
  399.     public static function getSubscribedServices(): array
  400.     {
  401.         return parent::getSubscribedServices();
  402.     }
  403.     
  404.     
  405.     
  406.     
  407.             
  408. }