private function loadEntityAnnualPlans()
 {
     $entities = $this->manager->getRepository('sisconeeAppBundle:Entidad')->findAll();
     foreach ($entities as $e) {
         var_dump('Loading annual plan for entity ' . $e->getNombre() . ' ..........');
         $subordinatedServices = $this->manager->getRepository('sisconeeAppBundle:Servicio')->servicesSubordinated($e);
         $entityPlan = 0;
         foreach ($subordinatedServices as $s) {
             $serviceAnnualPlan = $this->manager->getRepository('sisconeeAppBundle:PlanAnualServicio')->getServiceAnnualPlanObjectInAYear($s, $this->year);
             if ($serviceAnnualPlan != null) {
                 $entityPlan += $serviceAnnualPlan->getPlan();
             }
         }
         $entityAnnualPlan = $this->manager->getRepository('sisconeeAppBundle:PlanAnualEntidad')->getAnnualPlanOfEntityInAYear($e, $this->year);
         if ($entityAnnualPlan != null) {
             $entityAnnualPlan->setPlan($entityPlan);
         } else {
             $entityAnnualPlan = new PlanAnualEntidad();
             $entityAnnualPlan->setEntidad($e);
             $entityAnnualPlan->setAnno($this->year);
             $entityAnnualPlan->setPlan($entityPlan);
         }
         $this->manager->persist($entityAnnualPlan);
     }
     $this->manager->flush();
 }
 /**
  * Creates a new Configuracion entity.
  *
  */
 public function createAction(Request $request)
 {
     $entity = new Configuracion();
     $entity->setOrganismo($this->getOrganismOfCurrentUser());
     $entity->setCerrado(false);
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         /*$baseEntity = $em->getRepository('sisconeeAppBundle:Entidad')->getBaseEntity(
           $this->getOrganismOfCurrentUser()->getId());*/
         try {
             $baseEntity = $em->getRepository('sisconeeAppBundle:Entidad')->getBaseEntity($this->getOrganismOfCurrentUser()->getId());
         } catch (\Doctrine\ORM\NonUniqueResultException $e) {
             $this->get('session')->getFlashBag()->add('error', 'Existe más de una entidad base para el organismo ' . $this->getOrganismOfCurrentUser()->getSiglas() . '.');
         }
         $annualPlanEntity = new PlanAnualEntidad();
         $annualPlanEntity->setEntidad($baseEntity);
         $annualPlanEntity->setAnno($entity->getPeriodoTrabajo());
         $annualPlanEntity->setPlan($entity->getPlan());
         $em->persist($annualPlanEntity);
         try {
             $em->flush();
             $this->get('session')->getFlashBag()->add('notice', 'La configuración ha sido creada satisfactoriamente.');
         } catch (Exception $e) {
             $this->get('session')->getFlashBag()->add('error', 'La configuración general no pudo ser creada.');
         }
         return $this->redirect($this->generateUrl('configuracion_edit', array('id' => $entity->getId())));
     }
     return $this->render('sisconeeAdministracionBundle:Configuracion:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }