Beispiel #1
0
 public function generateAllPassagesForContrat($contrat)
 {
     $this->removeAllPassagesForContrat($contrat);
     $date_debut = $contrat->getDateDebut();
     $date_acceptation = $contrat->getDateAcceptation();
     if (!$date_debut || !$date_acceptation) {
         return false;
     }
     $date_debut = clone $contrat->getDateDebut();
     $passagesArray = $contrat->getPrevisionnel($date_debut);
     ksort($passagesArray);
     $firstEtb = true;
     foreach ($contrat->getEtablissements() as $etablissement) {
         $cpt = 0;
         foreach ($passagesArray as $datePassage => $passageInfos) {
             $datePrevision = new \DateTime($datePassage);
             $passage = new Passage();
             $passage->setEtablissement($etablissement);
             $passage->setEtablissementIdentifiant($etablissement->getIdentifiant());
             if ($contrat->getTechnicien()) {
                 $passage->addTechnicien($contrat->getTechnicien());
             }
             $passage->setDatePrevision($datePrevision);
             if (!$cpt) {
                 $passage->setDateDebut($datePrevision);
             }
             if ($firstEtb) {
                 $passage->setMouvementDeclenchable($passageInfos->mouvement_declenchable);
             }
             $passage->setContrat($contrat);
             $passage->setTypePassage(PassageManager::TYPE_PASSAGE_CONTRAT);
             foreach ($passageInfos->prestations as $prestationPrevu) {
                 $prestationObj = new Prestation();
                 $prestationObj->setNom($prestationPrevu->getNom());
                 $prestationObj->setNomCourt($prestationPrevu->getNomCourt());
                 $prestationObj->setIdentifiant($prestationPrevu->getIdentifiant());
                 $prestationObj->setNbPassages(0);
                 $passage->addPrestation($prestationObj);
             }
             foreach ($contrat->getProduits() as $produit) {
                 $produitNode = clone $produit;
                 $passage->addProduit($produitNode);
             }
             if ($passage) {
                 $contrat->addPassage($etablissement, $passage);
                 $this->dm->persist($passage);
             }
             $cpt++;
         }
         $firstEtb = false;
     }
     $contrat->updateNumeroOrdrePassage();
     //    $this->dm->flush();
 }