public function addAction($ligne_id, $type_id)
 {
     $request = $this->get('request');
     $em = $this->get('doctrine.orm.entity_manager');
     $ligne = $em->getRepository('TrezLogicielTrezBundle:Ligne')->find($ligne_id);
     $object = new Facture();
     $object->setLigne($ligne);
     // take care of type facture and numerotation
     $type_facture = $em->getRepository('TrezLogicielTrezBundle:TypeFacture')->find($type_id);
     $object->setTypeFacture($type_facture);
     $exercice = $ligne->getSousCategorie()->getCategorie()->getBudget()->getExercice();
     $last_numero = $em->getRepository('TrezLogicielTrezBundle:Exercice')->getLastFactureNumero($exercice->getId(), $type_id);
     $object->setNumero($last_numero[0]['numero'] + 1);
     if ('POST' === $this->get('request')->getMethod()) {
         // if user asked to adjust the ligne total, we disable some validation
         if ($request->request->get('adjust', false)) {
             $form = $this->get('form.factory')->create(new FactureType(), $object, array('validation_groups' => array('Default')));
         } else {
             $form = $this->get('form.factory')->create(new FactureType(), $object);
         }
         $form->handleRequest($this->get('request'));
         if ($form->isValid()) {
             $em->persist($object);
             $em->flush();
             // if user asked to adjust the ligne total just do it
             if ($request->request->get('adjust', false)) {
                 $object->getLigne()->adjustTotal($object->getTypeFacture()->getSens());
                 $em->flush();
                 // we have to flush before AND after, a second time
             }
             $this->get('session')->getFlashBag()->set('success', "La facture a bien été émise");
             return new RedirectResponse($this->generateUrl('facture_index', array('ligne_id' => $ligne_id)));
         }
     } else {
         $form = $this->get('form.factory')->create(new FactureType(), $object);
     }
     $this->get('trez.logiciel_trez.breadcrumbs')->setBreadcrumbs($ligne, 'Ajouter une facture');
     return $this->render('TrezLogicielTrezBundle:Facture:add.html.twig', array('form' => $form->createView(), 'ligne_id' => $ligne_id, 'type_facture_id' => $type_id));
 }
 protected function setFacture(Facture $entity)
 {
     $this->tempBreadcrumbs[] = new BreadcrumbsItem('Facture ' . $entity->getObjet(), $this->router->generate('facture_detail', array('id' => $entity->getId(), 'ligne_id' => $entity->getLigne()->getId())));
     $this->setLigne($entity->getLigne());
 }