<?php
namespace App\Controller;
use App\Entity\FeInventarios;
use App\Entity\FeSucursales;
use App\Form\FeInventariosType;
use App\Repository\FeInventariosRepository;
use App\Repository\FeSucursalesRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/fe/inventarios")
*/
class FeInventariosController extends AbstractController
{
/** TRAE INVETARIO DE PRODUCTOS BY PRODUCTO ID
* @Route("/trae-inventario-by-producto", name="fe_inventarios_pro_producto", methods={"POST"})
*/
public function traeInventarioByProducto(FeInventariosRepository $feInventariosRepository): Response
{
$response =$feInventariosRepository->getInventarioByProducto($_POST['id']);
return new Response(json_encode($response),200, array('Content-Type' => 'application/json'));
}
/** GUARDA ATRIBUTOS DE PRODUCTOS EN INVENTARIO
* @Route("/guarda-atributos", name="fe_inventarios_guarda_atributos", methods={"POST"})
*/
public function guardaAtributos(FeInventariosRepository $feInventariosRepository): Response
{
$em = $this->getDoctrine()->getManager();
$registro = $feInventariosRepository->find($_POST['id']);
$registro->setInvAtributos($_POST['atributos']);
$em->persist($registro);
$em->flush();
return new Response(json_encode(['status'=>'OK', 'message'=>'Guardado Correctamente']),200, array('Content-Type' => 'application/json'));
}
/**
* @Route("/index/inventario-sucursal", name="fe_inventarios_sucursal", methods={"POST"})
*/
public function indexInventarioBySucursal(FeInventariosRepository $feInventariosRepository, FeSucursalesRepository $feSucursalesRepository): Response
{
$sucId = $_POST['sucId'];
$response = json_encode($feInventariosRepository->getInventarioBySucursal($sucId));
return new Response($response, 200, array('Content-Type' => 'application/json'));
}
/**
* @Route("/", name="fe_inventarios_index", methods={"GET"})
*/
public function index(FeInventariosRepository $feInventariosRepository, FeSucursalesRepository $feSucursalesRepository): Response
{
$user = $this->getUser();
if ($user->getComercio()){
$comId = $user->getComercio()->getId();
}else{
$comId = 'All';
}
return $this->render('fe_inventarios/index.html.twig', [
'fe_sucursales' => $feSucursalesRepository->getByComercio($comId, null),
'fe_inventarios' => $feInventariosRepository->findAll(),
]);
}
/**
* @Route("/new", name="fe_inventarios_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$feInventario = new FeInventarios();
$form = $this->createForm(FeInventariosType::class, $feInventario);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($feInventario);
$entityManager->flush();
return $this->redirectToRoute('fe_inventarios_index');
}
return $this->render('fe_inventarios/new.html.twig', [
'fe_inventario' => $feInventario,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="fe_inventarios_show", methods={"GET"})
*/
public function show(FeInventarios $feInventario): Response
{
return $this->render('fe_inventarios/show.html.twig', [
'fe_inventario' => $feInventario,
]);
}
/**
* @Route("/{id}/edit", name="fe_inventarios_edit", methods={"GET","POST"})
*/
public function edit(Request $request, FeInventarios $feInventario): Response
{
$form = $this->createForm(FeInventariosType::class, $feInventario);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('fe_inventarios_index');
}
return $this->render('fe_inventarios/edit.html.twig', [
'fe_inventario' => $feInventario,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="fe_inventarios_delete", methods={"DELETE"})
*/
public function delete(Request $request, FeInventarios $feInventario): Response
{
if ($this->isCsrfTokenValid('delete'.$feInventario->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($feInventario);
$entityManager->flush();
}
return $this->redirectToRoute('fe_inventarios_index');
}
}