public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $cpt = 0;
     $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
     if (!$configuration) {
         $configuration = new Configuration();
         $configuration->setId(Configuration::PREFIX);
         $this->dm->persist($configuration);
         $this->dm->flush();
     }
     foreach ($csv as $data) {
         $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
         $founded = false;
         foreach ($configuration->getPrestationsArray() as $prestaConf) {
             if ($prestaConf->getNom() == $data[self::CSV_NOM]) {
                 $founded = true;
             }
         }
         if ($founded) {
             continue;
         }
         if ($data[self::CSV_ID]) {
             $prestation = new Prestation();
             $prestation->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_ID])))));
             $prestation->setNom($data[self::CSV_NOM]);
             $prestation->setNomCourt($data[self::CSV_NOM_COURT]);
             $configuration->addPrestation($prestation);
             $this->dm->flush();
         }
     }
 }
Exemple #2
0
 /**
  * Add prestation
  *
  * @param AppBundle\Document\Prestation $prestation
  */
 public function addPrestation(\AppBundle\Document\Prestation $prestation)
 {
     foreach ($this->getPrestations() as $prest) {
         if ($prest->getIdentifiant() == $prestation->getIdentifiant()) {
             return;
         }
     }
     $this->prestations[] = $prestation;
 }
Exemple #3
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();
 }
Exemple #4
0
 public function setUniquePrestations($prestationsIdentifiant)
 {
     $this->prestations = new ArrayCollection();
     foreach ($prestationsIdentifiant as $identifiant) {
         $prestation = new Prestation();
         $prestation->setIdentifiant($identifiant);
         $prestation->setNbPassages(1);
         $this->addPrestation($prestation);
     }
     return $this;
 }