src/MDS/EventsBundle/Controller/ProposalControlController.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 11/08/2017
  6.  * Time: 11:19
  7.  */
  8. namespace App\MDS\EventsBundle\Controller;
  9. use App\Entity\Cities;
  10. use App\Entity\Country;
  11. use App\Entity\Destination;
  12. use App\Entity\DestinationGallery;
  13. use App\Entity\Provinces;
  14. use App\Entity\Regions;
  15. use App\Entity\Supplier;
  16. use App\MDS\EventsBundle\Entity\Proposal;
  17. use App\MDS\EventsBundle\Entity\ProposalBriefingList;
  18. use App\MDS\EventsBundle\Entity\ProposalControl;
  19. use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
  20. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  21. use App\MDS\EventsBundle\Form\ProposalControlType;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Contracts\Translation\TranslatorInterface;
  26. class ProposalControlController extends AbstractController
  27. {
  28.     private $translator;
  29.     public function __construct(TranslatorInterface $translator) {
  30.         $this->translator $translator;
  31.     }
  32.     
  33.     /*
  34.      * ATENCION LAS RAIZ DE @Route POR DEFECTO DEL BUNDLE: EventsBundle ES  /events/, NO PONERLO EN LA @Route("")
  35.      *
  36.      * */
  37.     /**
  38.      * @Route("/proposal/destination/add/{id}",  name="proposal_destination_view")
  39.      */
  40.     public function viewAction($idRequest $request)
  41.     {
  42.         /* Formulario */
  43.         $control= new ProposalControl();
  44.         $control->setProposalId($id);
  45.         $form $this->createDestinationProposalCreateForm($control);
  46.         /* Si hay un destino cargado */
  47.         $em $this->getDoctrine()->getManager();
  48.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  49.         $briefing $em->getRepository(ProposalBriefingList::class)->findByProposalId($id);
  50.         $control_destination $em->getRepository(ProposalControl::class)->findByProposalId($id);
  51.         $mostrar_destino = array();
  52.         if (!empty($control_destination)){
  53.             foreach($control_destination as $destinationCrtl){
  54.                 $destination $em->getRepository(Destination::class)->findOneById($destinationCrtl->getDestinationId());
  55.                 $destinationGallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($destinationCrtl->getDestinationId());
  56.                 $country $em->getRepository(Country::class)->findOneById($destination->getCountry());
  57.                 $destination->setCountry($country->getCountry());
  58.                 $regions $em->getRepository(Regions::class)->findOneById($destination->getRegion());
  59.                 $destination->setRegion($regions->getRegion());
  60.                 $regions $em->getRepository(Provinces::class)->findOneById($destination->getProvince());
  61.                 $destination->setProvince($regions->getName());
  62.                 $cities $em->getRepository(Cities::class)->findOneById($destination->getPopulation());
  63.                 $destination->setPopulation($cities->getCity());
  64.                 $mostrar_destino[] = array(
  65.                     'idcontrol' => $destinationCrtl->getId(),
  66.                     'title' => $destination->getTitle(),
  67.                     'image' => empty($destinationGallery)? null $destinationGallery->getImageSmall(),
  68.                     'country' => $destination->getCountry(),
  69.                     'region' => $destination->getRegion(),
  70.                     'province' => $destination->getProvince(),
  71.                     'population' =>$destination->getPopulation(),
  72.                     'disabled' =>$destinationCrtl->getDisabled(),
  73.                     'disabledPresentation' =>$destinationCrtl->getDisabledPresentation(),
  74.                 );
  75.             }
  76.         }
  77.         $parameters = array(
  78.         );
  79.         $dql 'SELECT p
  80.                         FROM App:Destination p
  81.                         ORDER BY p.title ASC ';
  82.         $query $em->createQuery($dql)->setParameters($parameters);
  83.         $destinationList $query->getResult();
  84.         return $this->render('MDS/EventsBundle/destination/add-destination-proposal.html.twig',
  85.             array(
  86.                 'proposal' => $proposal,
  87.                 'briefing' => $briefing,
  88.                 'destinations' => $mostrar_destino,
  89.                 'destinationList' => $destinationList,
  90.                 'id' => $id,
  91.                 'token' => $proposal->getAccessKey(),
  92.                 'mcp' => $proposal->getMcp(),
  93.                 'form' => $form->createView()
  94.             )
  95.         );
  96.     }
  97.     private function createDestinationProposalCreateForm(ProposalControl $entity)
  98.     {
  99.         $form $this->createForm(ProposalControlType::class, $entity, array(
  100.             'action' => $this->generateUrl('proposal_destination_create'),
  101.             'method' => 'POST'
  102.         ));
  103.         return $form;
  104.     }
  105.     /**
  106.      * @Route("/proposal/destination/create", name="proposal_destination_create")
  107.      */
  108.     public function createProposalDestinationAction(Request $request)
  109.     {
  110.         $control = new ProposalControl();
  111.         $form $this->createDestinationProposalCreateForm($control);
  112.         $form->handleRequest($request);
  113.         $destination_proposalId $form->get('proposalId')->getData();
  114.         $destination_proposal $form->get('destinationId')->getData();
  115.         if(!is_null($destination_proposal)){
  116.             $control->setDestinationId($destination_proposal->getId());
  117.         }
  118.         $em $this->getDoctrine()->getManager();
  119.         $check_exists $em->getRepository(ProposalControl::class)->findBy(
  120.             array(
  121.                 'proposalId' => $destination_proposalId,
  122.                 'destinationId' => $destination_proposal->getId(),
  123.             )
  124.         );
  125.         if(empty($check_exists)){
  126.             if($form->isValid())
  127.             {
  128.                 $em->persist($control);
  129.                 $em->flush();
  130.                 $event 'The Destination Proposal has been created.';
  131.                 $successMessage $this->translator->trans($event);
  132.                 $this->addFlash('mensajeproposaldestination'$successMessage);
  133.                 $proposalsuppliercontrol = new ProposalSupplierControl();
  134.                 $proposalsuppliercontrol->setControlDestinationId($control->getId());
  135.                 $proposalsuppliercontrol->setProposalId($destination_proposalId);
  136.                 $proposalsuppliercontrol->setDestinoId($destination_proposal->getId());
  137.                 $proposalsuppliercontrol->setSupplierId('0');
  138.                 $proposalsuppliercontrol->setRank('0');
  139.                 $proposalsuppliercontrol->setStatus('Pending');
  140.                 $em->persist($proposalsuppliercontrol);
  141.                 $em->flush();
  142.     //            try{
  143.     //                $em->persist($proposal);
  144.     //                $em->flush();
  145.     //                $event = 'The Client has been created. Now, add some contacts';
  146.     //
  147.     //                $successMessage = $this->translator->trans($event);
  148.     //                $this->addFlash('mensajeclient', $successMessage);
  149.     //
  150.     //                $logger->info($event_complete.' | '.$event);
  151.     //
  152.     //            } catch (\Exception $e){
  153.     //
  154.     //                $event = 'An error occurred: '.$e->getMessage();
  155.     //
  156.     //                /* Para el log */
  157.     //                $logger->error($event_complete.' | '.$event);
  158.     //                /* Para el usuario */
  159.     //                $errorMessage = $this->translator->trans($event);
  160.     //                $this->addFlash('mensajeclienterror', $errorMessage);
  161.     //            }
  162.     //            /* Fin Gestión de eventos en Log */
  163.                 return $this->redirectToRoute('proposal_destination_view', array(
  164.                     'id' => $control->getProposalId()
  165.                 ));
  166.             }else{
  167.                 $errorMessage $this->translator->trans('Error, some fields are empty');
  168.                 $this->addFlash('mensajeproposaldestinationerror'$errorMessage);
  169.             }
  170.         }else{
  171.             $errorMessage $this->translator->trans('Error, The destination already exists in the proposal');
  172.             $this->addFlash('mensajeproposaldestinationerror'$errorMessage);
  173.         }
  174.         return $this->redirectToRoute('proposal_destination_view',
  175.             array(
  176.                 'id' => $destination_proposalId
  177.             )
  178.         );
  179.     }
  180.     /**
  181.      * @Route("proposal/destination/deleted/{id}", name="proposal_destination_deleted")
  182.      *
  183.      */
  184. //    public function deleteAction($id, Request $request, LoggerInterface $logger)
  185.     public function deleteAction($idRequest $request)
  186.     {
  187.         $em $this->getDoctrine()->getManager();
  188.         $delete $em->getRepository(ProposalControl::class)->findOneById($id);
  189.         $delete_suppliers $em->getRepository(ProposalSupplierControl::class)->findByControlDestinationId($id);
  190.         foreach ($delete_suppliers as $delete_supplier) {
  191.             $em->remove($delete_supplier);
  192.             $delete_services $em->getRepository(ProposalSupplierServices::class)->findByControlId($delete_supplier->getId());
  193.             foreach ($delete_services as $delete_service) {
  194.                 $em->remove($delete_service);
  195.             }
  196.         }
  197.         $em->remove($delete);
  198.         $em->flush();
  199.         $event 'The Destination the has been Deleted.';
  200.         $successMessage $this->translator->trans($event);
  201.         $this->addFlash('mensajeproposaldestinationservices'$successMessage);
  202. //        /* Gestión de eventos en Log */
  203. //        /* Obtengo usuario logueado */
  204. //        $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  205. //        $user_lastname = $user_logueado->getLastname();
  206. //        $user_name = $user_logueado->getName();
  207. //        $user_email = $user_logueado->getEmail();
  208. //        $user_rol = $user_logueado->getRoles();
  209. //        $event_url = $request->getPathInfo();
  210. //        $event_complete = $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  211. //
  212. //        try{
  213. //            $em->remove($delete);
  214. //            $em->flush();
  215. //
  216. //            $event = 'The supplier services Accommodation has been Deleted.';
  217. //            $successMessage = $this->translator->trans($event);
  218. //            $this->addFlash('mensajeservices', $successMessage);
  219. //
  220. //            $logger->info($event_complete.' | '.$event);
  221. //
  222. //        } catch (\Exception $e){
  223. //
  224. //            $event = 'An error occurred: '.$e->getMessage().' | transport';
  225. //
  226. //            /* Para el log */
  227. //            $logger->error($event_complete.' | '.$event);
  228. //            /* Para el usuario */
  229. //            $errorMessage = $this->translator->trans($event);
  230. //            $this->addFlash('mensajeserviceserror', $errorMessage);
  231. //        }
  232. //        /* Fin Gestión de eventos en Log */
  233.         return $this->redirectToRoute('proposal_destination_view',
  234.             array(
  235.                 'id' => $delete->getProposalId()
  236.             )
  237.         );
  238.     }
  239.     /**
  240.      * @Route("proposal/destination/disabled/{id}", name="proposal_destination_disabled")
  241.      *
  242.      */
  243.     public function disabledDestinationAction($idRequest $request)
  244.     {
  245.         $em $this->getDoctrine()->getManager();
  246.         $disabled $em->getRepository(ProposalControl::class)->findOneById($id);
  247.         $proposal$em->getRepository(Proposal::class)->findOneById($disabled->getProposalId());
  248.         $actual $disabled->getDisabled();
  249.         $var_mensaje="";
  250.         if($actual == "0"){
  251.             $disabled->setDisabled('1');
  252.             $var_mensaje "Disabled";
  253.         }
  254.         if($actual == "1"){
  255.             $disabled->setDisabled('0');
  256.             $var_mensaje "Activated";
  257.         }
  258.         $em->persist($disabled);
  259.         $em->flush();
  260.         $event 'The Destination has been. '.$var_mensaje;
  261.         $successMessage $this->translator->trans($event);
  262.         $this->addFlash('mensajeproposaldestination'$successMessage);
  263.         return $this->redirectToRoute('proposal_destination_view',
  264.             array(
  265.                 'id' => $proposal->getId(),
  266.             )
  267.         );
  268.     }
  269.     /**
  270.      * @Route("proposal/destination/disabledpresentation/{id}", name="proposal_destination_disabled_presentation")
  271.      *
  272.      */
  273.     public function disabledDestinationPresentationAction($idRequest $request)
  274.     {
  275.         $em $this->getDoctrine()->getManager();
  276.         $disabled $em->getRepository(ProposalControl::class)->findOneById($id);
  277.         $proposal$em->getRepository(Proposal::class)->findOneById($disabled->getProposalId());
  278.         $actual $disabled->getDisabledPresentation();
  279.         $var_mensaje="";
  280.         if($actual == "0"){
  281.             $disabled->setDisabledPresentation('1');
  282.             $var_mensaje "Disabled";
  283.         }
  284.         if($actual == "1"){
  285.             $disabled->setDisabledPresentation('0');
  286.             $var_mensaje "Activated";
  287.         }
  288.         $em->persist($disabled);
  289.         $em->flush();
  290.         $event 'The Destination in presentation has been. '.$var_mensaje;
  291.         $successMessage $this->translator->trans($event);
  292.         $this->addFlash('mensajeproposaldestination'$successMessage);
  293.         return $this->redirectToRoute('proposal_destination_view',
  294.             array(
  295.                 'id' => $proposal->getId(),
  296.             )
  297.         );
  298.     }
  299.     /**
  300.      * @Route("proposal/destination/editdstsuppliers/{id}", name="proposal_destination_edit_destination_suppliers")
  301.      *
  302.      */
  303.     public function editDestinationSuppliersAction($idRequest $request)
  304.     {
  305.         $em $this->getDoctrine()->getManager();
  306.         $proposalControl $em->getRepository(ProposalControl::class)->findOneById($id);
  307.         $proposal $em->getRepository(Proposal::class)->findOneById($proposalControl->getProposalId());
  308.         $arrayProposalSupplierControl $em->getRepository(ProposalSupplierControl::class)->findByControlDestinationId($id);
  309.         //INICIO: Buscamos los proveedores
  310.         $arraySuppliersId = array();
  311.         $arrayWhiteServicesId = array();
  312.         foreach ($arrayProposalSupplierControl as $item){
  313.             if ($item->getSupplierId()==0){
  314.                 //Aqui esta el ID de los servicios blancos
  315.                 $arrayWhiteServicesId[] = $item->getId();
  316.             }
  317.             if (!empty($item->getSupplierId())){
  318.                 //Ademas de ser distinto de null el ID del supplier debe existir en la tabla de Suppliers. Para actividades hay ID de suppliers que no estan en la tabla
  319.                 $elem $em->getRepository(Supplier::class)->findOneById($item->getSupplierId());
  320.                 if (!empty($elem)){
  321.                     $arraySuppliersId[] = array(
  322.                                                 'idSupplier' => $item->getSupplierId(),
  323.                                                 'company' => $elem->getCompany(),
  324.                                                 'supplier' => $elem,
  325.                     ) ;
  326.                 }
  327.             }
  328.         }
  329.         //A estos proveedores debemos agregar los proveedores que sean de servicios en blanco, por si se desean pasar a servicios de un proveedor en especifico
  330.         $arrayWhiteServices = array();
  331.         foreach ($arrayWhiteServicesId as $item){
  332.             $elem $em->getRepository(ProposalSupplierServices::class)->findOneByControlId($item);
  333.             if (!empty($elem)){
  334.                 $arrayWhiteServices[] = $elem->getSupplierId();
  335.             }
  336.         }
  337.         $arraySuppliersIdWhiteServices = array();
  338.         if (!empty($arrayWhiteServices)){
  339.             foreach ($arrayWhiteServices as $item){
  340.                 if (!empty($item)){
  341.                     //Ademas de ser distinto de null el ID del supplier debe existir en la tabla de Suppliers. Para actividades hay ID de suppliers que no estan en la tabla
  342.                     $elem $em->getRepository(Supplier::class)->findOneById($item);
  343.                     if (!empty($elem)){
  344.                         $arraySuppliersIdWhiteServices[] = array(
  345.                                                                 'idSupplier' => $item,
  346.                                                                 'company' => $elem->getCompany(),
  347.                                                                 'supplier' => $elem,
  348.                         );
  349.                     }
  350.                 }
  351.             }
  352.         }
  353.         //FIN: Buscamos los proveedores
  354.         $arrayProposalSupplierServices = array();
  355.         foreach ($arrayProposalSupplierControl as $item){
  356.             $arrayTemp $em->getRepository(ProposalSupplierServices::class)->findByControlId($item->getId());
  357.             $arrayProposalSupplierServices[] = $arrayTemp;
  358.         }
  359.         $briefing $em->getRepository(ProposalBriefingList::class)->findByProposalId($proposal->getId());
  360.         $control_destination $id;
  361. //        $mostrar_destino = array();
  362. //        if (!empty($control_destination)){
  363. //
  364. //            foreach($control_destination as $destinationCrtl){
  365.                 $destination $em->getRepository(Destination::class)->findOneById($proposalControl->getDestinationId());
  366.                 $destinationGallery $em->getRepository(DestinationGallery::class)->findOneByDestinationId($proposalControl->getDestinationId());
  367.                 $country $em->getRepository(Country::class)->findOneById($destination->getCountry());
  368.                 $destination->setCountry($country->getCountry());
  369.                 $regions $em->getRepository(Regions::class)->findOneById($destination->getRegion());
  370.                 $destination->setRegion($regions->getRegion());
  371.                 $regions $em->getRepository(Provinces::class)->findOneById($destination->getProvince());
  372.                 $destination->setProvince($regions->getName());
  373.                 $cities $em->getRepository(Cities::class)->findOneById($destination->getPopulation());
  374.                 $destination->setPopulation($cities->getCity());
  375.                 $mostrar_destino = array(
  376.                     'idcontrol' => $proposalControl->getId(),
  377.                     'title' => $destination->getTitle(),
  378.                     'image' => empty($destinationGallery)? null $destinationGallery->getImageSmall(),
  379.                     'country' => $destination->getCountry(),
  380.                     'region' => $destination->getRegion(),
  381.                     'province' => $destination->getProvince(),
  382.                     'population' =>$destination->getPopulation(),
  383. //                    'disabled' =>$proposalControl->getDisabled(),
  384. //                    'disabledPresentation' =>$proposalControl->getDisabledPresentation(),
  385.                 );
  386. //            }
  387. //        }
  388.         $listAllSuppliers $em->getRepository("App:Supplier")->findAll();
  389.         //Los IDs estan cruzados
  390.         $proposalControlId $id;
  391.         $id $proposal->getId();
  392.         return $this->render('MDS/EventsBundle/destination/edit-destination-proposal-suppliers.html.twig',
  393.             array(
  394.                 'proposal' => $proposal,
  395.                 'briefing' => $briefing,
  396.                 'listAllSuppliers' => $listAllSuppliers,
  397.                 'arraySuppliersId' => $arraySuppliersId,
  398.                 'arraySuppliersIdWhiteServices' => $arraySuppliersIdWhiteServices,
  399.                 'destination' => $mostrar_destino,
  400. //                'destinationList' => $destinationList,
  401.                 'id' => $id,
  402.                 'token' => $proposal->getAccessKey(),
  403.                 'mcp' => $proposal->getMcp(),
  404.                 'proposalControlId' => $proposalControlId,
  405.             )
  406.         );
  407.     }
  408.     /**
  409.      * @Route("proposal/destination/updatesuppliersdestination/{id}", name="update_suppliers_destination")
  410.      *
  411.      */
  412.     public function updateSuppliersDestinationAction($idRequest $request)
  413.     {
  414.         // Buscamos el Id de Proveedores de servicios blancos
  415.         $arraySuppliersIdWhiteServices $request->request->get('supplier_white');
  416.         // Buscamos el Id de Proveedores de servicios blancos
  417.         $arraySuppliersId $request->request->get('supplier');
  418.         $em $this->getDoctrine()->getManager();
  419.         $proposalControl $em->getRepository(ProposalControl::class)->findOneById($id);
  420.         $proposalSupplierControl $em->getRepository(ProposalSupplierControl::class)->findByControlDestinationId($id);
  421.         //Inicio: Caso de Suppliers desde white services
  422.             //Crearemos una entrada para los servicios en blanco y luego mofi
  423.         if (!empty($arraySuppliersIdWhiteServices)){
  424.             $arrayKeys array_keys($arraySuppliersIdWhiteServices);
  425.         } else {
  426.             $arrayKeys = array();
  427.         }
  428.         foreach ($arrayKeys as $key) {
  429.             $oldSupplierId $key;
  430.             $newSupplierId $arraySuppliersIdWhiteServices[$key];
  431.             // Si $newSupplierId es empty no se ha seleccionado un proveedor del selector, en este caso no se modifica el supplier
  432.             if (!empty($newSupplierId)) {
  433.                 if (!empty($proposalSupplierControl)) {
  434.                     //Verificamos que no haya previamente un control de donde deseamos poner el servicio
  435.                     $existeProposalSupplierControl $em->getRepository(ProposalSupplierControl::class)->findOneBy(array('controlDestinationId'=>$id,'supplierId'=>$newSupplierId));
  436.                     if(empty($existeProposalSupplierControl)){
  437.                         $newProposalSupplierControl = new ProposalSupplierControl();
  438.                         $newProposalSupplierControl->setControlDestinationId($proposalSupplierControl[0]->getControlDestinationId());
  439.                         $newProposalSupplierControl->setProposalId($proposalSupplierControl[0]->getProposalId());
  440.                         $newProposalSupplierControl->setDestinoId($proposalSupplierControl[0]->getDestinoId());
  441.                         $newProposalSupplierControl->setSupplierId($newSupplierId);
  442.                         $newProposalSupplierControl->setIdeaId($proposalSupplierControl[0]->getIdeaId());
  443.                         $newProposalSupplierControl->setStatus($proposalSupplierControl[0]->getStatus());
  444.                         $newProposalSupplierControl->setDisabled($proposalSupplierControl[0]->getDisabled());
  445.                         $newProposalSupplierControl->setRank($proposalSupplierControl[0]->getRank());
  446.                         $newProposalSupplierControl->setDateBlockLimit($proposalSupplierControl[0]->getDateBlockLimit());
  447.                         $newProposalSupplierControl->setActivityId($proposalSupplierControl[0]->getActivityId());
  448.                         $em->persist($newProposalSupplierControl);
  449.                         $em->flush();
  450.                     } else {
  451.                         //El supplier ya existia, solo necesitamos agregar el servicio
  452.                         $newProposalSupplierControl $existeProposalSupplierControl;
  453.                     }
  454.                     //INICIO: Se modifica la tabla ProposalSuplierServices segun lo que se modificara en la tabla ProposalSupplierControl
  455. //                    $proposalSupplierServices = $em->getRepository(ProposalSupplierServices::class)->findByControlId($newProposalSupplierControl->getId());
  456.                     $proposalSupplierServices $em->getRepository(ProposalSupplierServices::class)->findBy(
  457.                                                                                                                     array('proposalId'=>$newProposalSupplierControl->getProposalId(),
  458.                                                                                                                         'destinationId'=>$newProposalSupplierControl->getDestinoId()));
  459.                     foreach ($proposalSupplierServices as $elem) {
  460.                         if($elem->getSupplierId()==$oldSupplierId){
  461.                             $elem->setSupplierId($newSupplierId);
  462.                             $elem->setControlId($newProposalSupplierControl->getId());
  463.                             $em->persist($elem);
  464.                             $em->flush();
  465.                         }
  466.                     }
  467.                     //FIN: Se modifica la tabla ProposalSuplierServices segun lo que se modificara en la tabla ProposalSupplierControl
  468.                 }
  469.             }
  470.         }
  471.         //Fin: Caso de Suppliers desde white services
  472.         //Inicio: Caso de Suppliers comunes
  473.         if (!empty($arraySuppliersId)){
  474.             $arrayKeys array_keys($arraySuppliersId);
  475.         } else {
  476.             $arrayKeys = array();
  477.         }
  478.         foreach ($arrayKeys as $key){
  479.             $oldSupplierId $key;
  480.             $newSupplierId $arraySuppliersId[$key];
  481.             // Si $newSupplierId es empty no se ha seleccionado un proveedor del selector, en este caso no se modifica el supplier
  482.             if (!empty($newSupplierId)){
  483.                 foreach ($proposalSupplierControl as $item){
  484.                     if($item->getSupplierId() == $oldSupplierId){
  485.                         //INICIO: Se modifica la tabla ProposalSuplierServices segun lo que se modificara en la tabla ProposalSupplierControl
  486.                         $proposalSupplierServices $em->getRepository(ProposalSupplierServices::class)->findByControlId($item->getId());
  487.                         $existeProposalSupplierControl $em->getRepository(ProposalSupplierControl::class)->findOneBy(array('controlDestinationId'=>$id,'supplierId'=>$newSupplierId));
  488.                         foreach ($proposalSupplierServices as $elem){
  489.                             $elem->setSupplierId($newSupplierId);
  490.                             if (!empty($existeProposalSupplierControl)){
  491.                                 $elem->setControlId($existeProposalSupplierControl->getId());
  492.                             }
  493.                             $em->persist($elem);
  494.                             $em->flush();
  495.                         }
  496.                         //FIN: Se modifica la tabla ProposalSuplierServices segun lo que se modificara en la tabla ProposalSupplierControl
  497.                         $item->setSupplierId($newSupplierId);
  498.                         $em->persist($item);
  499.                         $em->flush();
  500.                     }
  501.                 }
  502.             }
  503.         }
  504.         //Fin: Caso de Suppliers comunes
  505.         return $this->redirectToRoute('proposal_destination_view', array('id'=>$proposalControl->getProposalId()));
  506.     }
  507. }