Ejemplo n.º 1
0
 function create(Etablissement $etablissement, Contrat $contrat)
 {
     $passage = new Passage();
     $passage->setEtablissement($etablissement);
     foreach ($contrat->getPrestations() as $prestationContrat) {
         $prestation = clone $prestationContrat;
         $prestation->setNbPassages(0);
         $passage->addPrestation($prestation);
     }
     $previousPassage = null;
     foreach ($contrat->getPassagesEtablissementNode($etablissement)->getPassagesSorted(true) as $p) {
         if ($p->getId() != $passage->getId() && count($p->getTechniciens())) {
             $previousPassage = $p;
             break;
         }
     }
     if ($previousPassage) {
         foreach ($previousPassage->getTechniciens() as $tech) {
             $passage->addTechnicien($tech);
         }
     } elseif ($contrat->getTechnicien()) {
         $passage->addTechnicien($contrat->getTechnicien());
     }
     foreach ($contrat->getProduits() as $produitContrat) {
         $produit = clone $produitContrat;
         $produit->setNbUtilisePassage(0);
         $passage->addProduit($produit);
     }
     $passage->setContrat($contrat);
     return $passage;
 }
Ejemplo n.º 2
0
 /**
  * @Route("/contrat/{id}/acceptation", name="contrat_acceptation")
  * @ParamConverter("contrat", class="AppBundle:Contrat")
  */
 public function acceptationAction(Request $request, Contrat $contrat)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $contratManager = new ContratManager($dm);
     $oldTechnicien = $contrat->getTechnicien();
     $oldNbFactures = $contrat->getNbFactures();
     $form = $this->createForm(new ContratAcceptationType($dm, $contrat), $contrat, array('action' => $this->generateUrl('contrat_acceptation', array('id' => $contrat->getId())), 'method' => 'POST'));
     $isBrouillon = $request->get('brouillon');
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $contrat = $form->getData();
         if ($contrat->isModifiable() && !$isBrouillon && $contrat->getDateDebut()) {
             $contratManager->generateAllPassagesForContrat($contrat);
             $contrat->setDateFin($contrat->getDateDebut()->modify("+" . $contrat->getDuree() . " month"));
             $contrat->setStatut(ContratManager::STATUT_EN_COURS);
             $dm->persist($contrat);
             $dm->flush();
             return $this->redirectToRoute('contrat_visualisation', array('id' => $contrat->getId()));
         } else {
             if (!$oldTechnicien || $oldTechnicien->getId() != $contrat->getTechnicien()->getId()) {
                 $contrat->changeTechnicien($contrat->getTechnicien());
             }
             if ($oldNbFactures != $contrat->getNbFactures()) {
                 $contratManager->updateNbFactureForContrat($contrat);
             }
             if ($contrat->getDateDebut()) {
                 $dateFinCalcule = \DateTime::createFromFormat('Y-m-d H:i:s', $contrat->getDateDebut()->format('Y-m-d') . " 00:00:00");
                 $contrat->setDateFin($dateFinCalcule->modify("+" . $contrat->getDuree() . " month"));
             }
             $dm->persist($contrat);
             $dm->flush();
             return $this->redirectToRoute('passage_etablissement', array('id' => $contrat->getEtablissements()->first()->getId()));
         }
     }
     $factures = $contratManager->getAllFactureForContrat($contrat);
     return $this->render('contrat/acceptation.html.twig', array('contrat' => $contrat, 'factures' => $factures, 'form' => $form->createView(), 'societe' => $contrat->getSociete()));
 }