src/Controller/FeInventariosController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\FeInventarios;
  4. use App\Entity\FeSucursales;
  5. use App\Form\FeInventariosType;
  6. use App\Repository\FeInventariosRepository;
  7. use App\Repository\FeSucursalesRepository;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * @Route("/fe/inventarios")
  14.  */
  15. class FeInventariosController extends AbstractController
  16. {
  17.     /** TRAE INVETARIO DE PRODUCTOS BY PRODUCTO ID
  18.      * @Route("/trae-inventario-by-producto", name="fe_inventarios_pro_producto", methods={"POST"})
  19.      */
  20.     public function traeInventarioByProducto(FeInventariosRepository $feInventariosRepository): Response
  21.     {
  22.         $response =$feInventariosRepository->getInventarioByProducto($_POST['id']);
  23.         return new Response(json_encode($response),200, array('Content-Type' => 'application/json'));
  24.     }
  25.     /** GUARDA ATRIBUTOS DE PRODUCTOS EN INVENTARIO
  26.      * @Route("/guarda-atributos", name="fe_inventarios_guarda_atributos", methods={"POST"})
  27.      */
  28.     public function guardaAtributos(FeInventariosRepository $feInventariosRepository): Response
  29.     {
  30.         $em $this->getDoctrine()->getManager();
  31.         $registro $feInventariosRepository->find($_POST['id']);
  32.         $registro->setInvAtributos($_POST['atributos']);
  33.         $em->persist($registro);
  34.         $em->flush();
  35.         return new Response(json_encode(['status'=>'OK''message'=>'Guardado Correctamente']),200, array('Content-Type' => 'application/json'));
  36.     }
  37.     /**
  38.      * @Route("/index/inventario-sucursal", name="fe_inventarios_sucursal", methods={"POST"})
  39.      */
  40.     public function indexInventarioBySucursal(FeInventariosRepository $feInventariosRepositoryFeSucursalesRepository $feSucursalesRepository): Response
  41.     {
  42.         $sucId $_POST['sucId'];
  43.         $response json_encode($feInventariosRepository->getInventarioBySucursal($sucId));
  44.         return new Response($response200, array('Content-Type' => 'application/json'));
  45.     }
  46.     /**
  47.      * @Route("/", name="fe_inventarios_index", methods={"GET"})
  48.      */
  49.     public function index(FeInventariosRepository $feInventariosRepositoryFeSucursalesRepository $feSucursalesRepository): Response
  50.     {
  51.         $user $this->getUser();
  52.         if ($user->getComercio()){
  53.             $comId $user->getComercio()->getId();
  54.         }else{
  55.             $comId 'All';
  56.         }
  57.         return $this->render('fe_inventarios/index.html.twig', [
  58.             'fe_sucursales' => $feSucursalesRepository->getByComercio($comIdnull),
  59.             'fe_inventarios' => $feInventariosRepository->findAll(),
  60.         ]);
  61.     }
  62.     /**
  63.      * @Route("/new", name="fe_inventarios_new", methods={"GET","POST"})
  64.      */
  65.     public function new(Request $request): Response
  66.     {
  67.         $feInventario = new FeInventarios();
  68.         $form $this->createForm(FeInventariosType::class, $feInventario);
  69.         $form->handleRequest($request);
  70.         if ($form->isSubmitted() && $form->isValid()) {
  71.             $entityManager $this->getDoctrine()->getManager();
  72.             $entityManager->persist($feInventario);
  73.             $entityManager->flush();
  74.             return $this->redirectToRoute('fe_inventarios_index');
  75.         }
  76.         return $this->render('fe_inventarios/new.html.twig', [
  77.             'fe_inventario' => $feInventario,
  78.             'form' => $form->createView(),
  79.         ]);
  80.     }
  81.     /**
  82.      * @Route("/{id}", name="fe_inventarios_show", methods={"GET"})
  83.      */
  84.     public function show(FeInventarios $feInventario): Response
  85.     {
  86.         return $this->render('fe_inventarios/show.html.twig', [
  87.             'fe_inventario' => $feInventario,
  88.         ]);
  89.     }
  90.     /**
  91.      * @Route("/{id}/edit", name="fe_inventarios_edit", methods={"GET","POST"})
  92.      */
  93.     public function edit(Request $requestFeInventarios $feInventario): Response
  94.     {
  95.         $form $this->createForm(FeInventariosType::class, $feInventario);
  96.         $form->handleRequest($request);
  97.         if ($form->isSubmitted() && $form->isValid()) {
  98.             $this->getDoctrine()->getManager()->flush();
  99.             return $this->redirectToRoute('fe_inventarios_index');
  100.         }
  101.         return $this->render('fe_inventarios/edit.html.twig', [
  102.             'fe_inventario' => $feInventario,
  103.             'form' => $form->createView(),
  104.         ]);
  105.     }
  106.     /**
  107.      * @Route("/{id}", name="fe_inventarios_delete", methods={"DELETE"})
  108.      */
  109.     public function delete(Request $requestFeInventarios $feInventario): Response
  110.     {
  111.         if ($this->isCsrfTokenValid('delete'.$feInventario->getId(), $request->request->get('_token'))) {
  112.             $entityManager $this->getDoctrine()->getManager();
  113.             $entityManager->remove($feInventario);
  114.             $entityManager->flush();
  115.         }
  116.         return $this->redirectToRoute('fe_inventarios_index');
  117.     }
  118. }