Exemplo n.º 1
0
 /**
  * @Route("/contrat/{id}/annulation", name="contrat_annulation")
  * @ParamConverter("contrat", class="AppBundle:Contrat")
  */
 public function annulationAction(Request $request, Contrat $contrat)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     if (!$contrat->isAnnulable()) {
         return $this->redirectToRoute('contrat_visualisation', array('id' => $contrat->getId()));
     }
     $form = $this->createForm(new ContratAnnulationType($dm, $contrat), $contrat, array('action' => $this->generateUrl('contrat_annulation', array('id' => $contrat->getId())), 'method' => 'POST'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $contratForm = $form->getData();
         $contrat->setTypeContrat(ContratManager::TYPE_CONTRAT_ANNULE);
         $passageList = $this->get('contrat.manager')->getPassagesByNumeroArchiveContrat($contrat);
         foreach ($passageList as $etb => $passagesByEtb) {
             foreach ($passagesByEtb as $id => $passage) {
                 if (!$passage->isRealise() && !$passage->isAnnule() && $passage->getDatePrevision()->format('Ymd') > $contrat->getDateResiliation()->format('Ymd')) {
                     $passage->setStatut(PassageManager::STATUT_ANNULE);
                     $passage->getContrat()->setTypeContrat(ContratManager::TYPE_CONTRAT_ANNULE);
                 }
             }
         }
         foreach ($contrat->getMouvements() as $mouvement) {
             if (!$mouvement->isFacture()) {
                 $contrat->removeMouvement($mouvement);
             }
         }
         $commentaire = "";
         if ($contratForm->getCommentaire()) {
             $commentaire .= $contrat->getCommentaire() . "\n";
         }
         $commentaire .= $form['commentaireResiliation']->getData();
         $contrat->setCommentaire($commentaire);
         $contrat->setReconduit(true);
         $dm->flush();
         return $this->redirectToRoute('contrats_societe', array('id' => $contrat->getSociete()->getId()));
     }
     return $this->render('contrat/annulation.html.twig', array('form' => $form->createView(), 'contrat' => $contrat, 'societe' => $contrat->getSociete()));
 }