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);
     }
     foreach ($csv as $data) {
         $produit = new Produit();
         $produit->setIdentifiant(strtoupper(Transliterator::urlize(trim(preg_replace("/[ ]+/", " ", $data[self::CSV_NOM])))));
         $produit->setNom(ucfirst(strtolower($data[self::CSV_NOM])));
         $produit->setConditionnement($data[self::CSV_CONDITIONNEMENT]);
         $produit->setPrixHt($data[self::CSV_PRIX_HT]);
         $produit->setPrixPrestation($data[self::CSV_PRIX_PRESTATION]);
         $produit->setPrixVente($data[self::CSV_PRIX_VENTE]);
         if ($data[self::CSV_STATUT]) {
             $produit->setStatut(Produit::PRODUIT_ACTIF);
         } else {
             $produit->setStatut(Produit::PRODUIT_INACTIF);
         }
         $configuration->addProduit($produit);
         $this->dm->persist($configuration);
     }
     $this->dm->flush();
 }
 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();
         }
     }
 }
Esempio n. 3
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $progress = new ProgressBar($output, 100);
     $progress->start();
     $cpt = 0;
     $cptTotal = 0;
     foreach ($csv as $data) {
         $etablissement = $this->createFromImport($data, $output);
         if (!$etablissement) {
             continue;
         }
         $this->dm->persist($etablissement);
         $cptTotal++;
         if ($cptTotal % (count($csv) / 100) == 0) {
             $progress->advance();
         }
         if ($cpt > 1000) {
             $this->dm->flush();
             $this->dm->clear();
             gc_collect_cycles();
             $cpt = 0;
         }
         $cpt++;
     }
     $this->dm->flush();
     $progress->finish();
 }
Esempio n. 4
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     foreach ($csv as $data) {
         $compte = $this->createFromImport($data, $output);
         if ($compte) {
             $this->dm->persist($compte);
         }
         $this->dm->flush();
     }
     $this->dm->flush();
 }
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $progress = new ProgressBar($output, 100);
     $progress->start();
     $csv = $csvFile->getCsv();
     $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
     $prestationsArray = $configuration->getPrestationsArray();
     $i = 0;
     $cptTotal = 0;
     foreach ($csv as $data) {
         $contrat = $this->cm->getRepository()->findOneByIdentifiantReprise($data[self::CSV_OLD_ID_CONTRAT]);
         if (!$contrat) {
             $i++;
             $cptTotal++;
             continue;
         }
         $prestationNom = strtoupper(Transliterator::urlize(str_replace('#', '', $data[self::CSV_PRESTATION])));
         if (!array_key_exists($prestationNom, $prestationsArray)) {
             $i++;
             $cptTotal++;
             $output->writeln(sprintf("<comment>La prestation '%s' du contrat %s n'existe pas en base!</comment>", $prestationNom, $contrat->getId()));
             continue;
         }
         $prestationConf = $prestationsArray[$prestationNom];
         $prestation = clone $prestationConf;
         $prestation->setNbPassages(0);
         $contrat->addPrestation($prestation);
         $i++;
         $cptTotal++;
         if ($cptTotal % (count($csv) / 100) == 0) {
             $progress->advance();
         }
         if ($i >= 1000) {
             $this->dm->flush();
             $this->dm->clear();
             gc_collect_cycles();
             $i = 0;
         }
     }
     $this->dm->flush();
     $progress->finish();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->dm = $this->getContainer()->get('doctrine_mongodb.odm.default_document_manager');
     $documentName = $input->getArgument('document');
     $fieldName = $input->getArgument('field');
     $pathFile = $input->getArgument('path');
     $repo = 'AppBundle:' . $documentName;
     $allDocs = $this->dm->getRepository($repo)->findAll();
     $allDocsArray = array();
     foreach ($allDocs as $doc) {
         $allDocsArray[$doc->getIdentifiantReprise()] = $doc;
     }
     $cptTotal = 0;
     $i = 0;
     $csvFile = new CsvFile($pathFile);
     $csv = $csvFile->getCsv();
     $progress = new ProgressBar($output, 100);
     $progress->start();
     foreach ($csv as $ligne) {
         $setFonctionName = "set" . ucfirst($fieldName);
         $idReprise = "" . $ligne[self::CSV_ID_REPRISE];
         if (!array_key_exists($idReprise, $allDocsArray)) {
             continue;
         }
         $docToChange = $allDocsArray[$idReprise];
         if ($ligne[self::CSV_FIELD_TO_CHANGE]) {
             $docToChange->{$setFonctionName}($ligne[self::CSV_FIELD_TO_CHANGE]);
             $output->writeln(sprintf("\n<comment>Mis à jour du contrat %s : '%s' va être assigné à %s</comment>", $docToChange->getId(), $fieldName, $ligne[self::CSV_FIELD_TO_CHANGE]));
         }
         $cptTotal++;
         if ($cptTotal % (count($allDocsArray) / 100) == 0) {
             $progress->advance();
         }
         if ($i >= 100) {
             $this->dm->flush();
             $i = 0;
         }
         $i++;
     }
     $this->dm->flush();
     $progress->finish();
 }
Esempio n. 7
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $cpt = 0;
     foreach ($csv as $data) {
         $societe = $this->createFromImport($data);
         if (!$societe) {
             continue;
         }
         $this->dm->persist($societe);
         if ($cpt > 1000) {
             $this->dm->flush();
             $this->dm->clear();
             gc_collect_cycles();
             $cpt = 0;
         }
         $cpt++;
     }
     $this->dm->flush();
 }
Esempio n. 8
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $i = 0;
     $cptTotal = 0;
     $progress = new ProgressBar($output, 100);
     $progress->start();
     foreach ($csv as $data) {
         $this->createContactFromImport($data, $output);
         $i++;
         $cptTotal++;
         if ($cptTotal % (count($csv) / 100) == 0) {
             $progress->advance();
         }
         if ($i >= 1000) {
             $this->dm->flush();
             $this->dm->clear();
             gc_collect_cycles();
             $i = 0;
         }
     }
     $this->dm->flush();
 }
Esempio n. 9
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $progress = new ProgressBar($output, 100);
     $progress->start();
     $csv = $csvFile->getCsv();
     $i = 0;
     $cptTotal = 0;
     foreach ($csv as $data) {
         $cptTotal++;
         if ($cptTotal % (count($csv) / 100) == 0) {
             $progress->advance();
         }
         if (!$data[self::CSV_FACTURE_ID]) {
             $output->writeln(sprintf("<error>Le paiement %s ne possède aucun numéro de facture</error>", $data[self::CSV_PAIEMENT_ID]));
             continue;
         }
         $facture = $this->fm->getRepository()->findOneByIdentifiantReprise($data[self::CSV_FACTURE_ID]);
         if (!$facture) {
             if ($this->debug) {
                 $output->writeln(sprintf("<comment>La facture %s n'existe pas en base pour le paiement %s</comment>", $data[self::CSV_FACTURE_ID], $data[self::CSV_PAIEMENT_ID]));
             }
             continue;
         }
         if ($data[self::CSV_REGLEMENT_ID]) {
             if ($data[self::CSV_PAIEMENT_DATE] != $data[self::CSV_DATE_PIECE_BANQUE]) {
                 $output->writeln(sprintf("<comment> Facture %s, paiement %s : dates %s (paiement) != %s (banque) Bizar</comment>", $data[self::CSV_FACTURE_ID], $data[self::CSV_PAIEMENT_ID], $data[self::CSV_PAIEMENT_DATE], $data[self::CSV_DATE_PIECE_BANQUE]));
             }
         }
         $idDocPaiements = 'PAIEMENTS-' . (new \DateTime($data[self::CSV_PAIEMENT_DATE]))->format('Ymd');
         $paiements = $this->pm->getRepository()->findOneById($idDocPaiements);
         if (!$paiements) {
             $paiements = $this->dm->getUnitOfWork()->tryGetById($idDocPaiements, $this->pm->getRepository()->getClassMetadata());
         }
         if (!$paiements) {
             $paiements = $this->pm->createByDateCreation(new \DateTime($data[self::CSV_PAIEMENT_DATE]));
             $this->dm->persist($paiements);
         }
         $paiement = new Paiement();
         $paiement->setIdentifiantReprise($data[self::CSV_PAIEMENT_ID]);
         $index_moyen_paiement = "";
         $index_type_regl = "";
         $index_type_regl .= $data[self::CSV_TYPE_REGLEMENT];
         $paiement->setMontant($data[self::CSV_MONTANT]);
         if ($data[self::CSV_REGLEMENT_ID]) {
             $paiement->setDatePaiement(new \DateTime($data[self::CSV_DATE_PIECE_BANQUE]));
             $paiement->setLibelle($data[self::CSV_LIBELLE]);
             $index_moyen_paiement .= $data[self::CSV_MOYEN_PAIEMENT_PIECE];
         } else {
             $paiement->setDatePaiement(new \DateTime($data[self::CSV_PAIEMENT_DATE]));
             $index_moyen_paiement .= $data[self::CSV_MOYEN_PAIEMENT];
         }
         $paiement->setFacture($facture);
         if (array_key_exists(self::CSV_DATE_REMISE_CHEQUE, $data) && $data[self::CSV_REF_REMISE_CHEQUE]) {
             if ($data[self::CSV_DATE_REMISE_CHEQUE]) {
                 $output->writeln(sprintf("<comment> %s : Ajout de la date de remise de cheque : %s </comment>", $data[self::CSV_PAIEMENT_ID], $data[self::CSV_DATE_REMISE_CHEQUE]));
                 $paiement->setDatePaiement(new \DateTime($data[self::CSV_DATE_REMISE_CHEQUE]));
             }
         }
         if (!array_key_exists($index_moyen_paiement, PaiementsManager::$moyens_paiement_index)) {
             $output->writeln(sprintf("<comment> Paiement %s : Mode de Paiement inexistant? %s </comment>", $data[self::CSV_PAIEMENT_ID], $index_moyen_paiement));
         } else {
             $paiement->setMoyenPaiement(PaiementsManager::$moyens_paiement_index[$index_moyen_paiement]);
         }
         if (!array_key_exists($index_type_regl, PaiementsManager::$types_reglements_index)) {
             $output->writeln(sprintf("<comment> Paiement %s : Type de reglement inexistant? %s </comment>", $data[self::CSV_PAIEMENT_ID], $index_type_regl));
         } else {
             $paiement->setTypeReglement(PaiementsManager::$types_reglements_index[$index_type_regl]);
         }
         $paiements->addPaiement($paiement);
         $i++;
         if ($i >= 1000) {
             $this->dm->flush();
             $this->dm->clear();
             $i = 0;
         }
     }
     $this->dm->flush();
     $this->dm->clear();
     $progress->finish();
 }
Esempio n. 10
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $csv = $csvFile->getCsv();
     $i = 0;
     $cptTotal = 0;
     $progress = new ProgressBar($output, 100);
     $progress->start();
     $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
     $produitsArray = $configuration->getProduitsArray();
     $prestationsType = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration()->getPrestationsArray();
     foreach ($csv as $data) {
         if ($data[self::CSV_ETABLISSEMENT_ID] == "000000") {
             continue;
         }
         if (!preg_match('/^[0-9]+$/', $data[self::CSV_ETABLISSEMENT_ID])) {
             $output->writeln(sprintf("<error>établissement dont le numéro %s n'est pas correct</error>", $data[self::CSV_ETABLISSEMENT_ID]));
             continue;
         }
         $etablissement = $this->em->getRepository()->findOneByIdentifiantReprise($data[self::CSV_ETABLISSEMENT_ID]);
         if (!$etablissement) {
             $output->writeln(sprintf("<error>L'établissement %s n'existe pas</error>", $data[self::CSV_ETABLISSEMENT_ID]));
             continue;
         }
         $passage = new Passage();
         $passage->setEtablissement($etablissement);
         if (!$data[self::CSV_DATE_PREVISION]) {
             $output->writeln(sprintf("<error>Le passage %s ne possède aucune date de prévision!</error>", $data[self::CSV_OLD_ID]));
             continue;
         }
         $passage->setDatePrevision(new \DateTime($data[self::CSV_DATE_PREVISION]));
         $passage->setIdentifiantReprise($data[self::CSV_OLD_ID]);
         $passage->setNumeroArchive($data[self::CSV_OLD_ID]);
         $contrat = $this->cm->getRepository()->findOneByIdentifiantReprise($data[self::CSV_CONTRAT_ID]);
         if (!$contrat) {
             //$output->writeln(sprintf("<error>Le contrat %s n'existe pas</error>", $data[self::CSV_CONTRAT_ID]));
             continue;
         }
         $this->dm->persist($passage);
         $doublonPassage = $this->pm->getRepository()->findOneById($passage->getId());
         if ($doublonPassage) {
             $output->writeln(sprintf("<comment>Le passage d'id %s existe déjà en base (%s)!</comment>", $passage->getId(), $data[self::CSV_OLD_ID]));
         }
         $resultStatut = $this->generateStatut($data, $passage, $output);
         $passage->updateStatut();
         if (!$resultStatut) {
             $output->writeln(sprintf("<error>Aucun statut déterminable pour le passage d'id %s (%s)!</error>", $passage->getId(), $data[self::CSV_OLD_ID]));
             continue;
         }
         $passage->setLibelle($data[self::CSV_LIBELLE]);
         $passage->setTypePassage($data[self::CSV_TYPE_PASSAGE]);
         $passage->setDescription(str_replace('#', "\n", $data[self::CSV_DESCRIPTION]));
         if (!preg_match('/^[0-9]+$/', $data[self::CSV_CONTRAT_ID])) {
             $output->writeln(sprintf("<error>Passage dont le numéro %s n'est pas correct</error>", $data[self::CSV_CONTRAT_ID]));
             continue;
         }
         if ($data[self::CSV_PRESTATIONS]) {
             $prestations = explode('#', $data[self::CSV_PRESTATIONS]);
             foreach ($prestations as $prestationNom) {
                 if (trim($prestationNom) != "") {
                     $prestationIdentifiant = strtoupper(Transliterator::urlize($prestationNom));
                     if (!array_key_exists($prestationIdentifiant, $prestationsType)) {
                         $output->writeln(sprintf("<comment>La prestation : %s n'existe pas dans la configuration </comment>", $prestationIdentifiant));
                         continue;
                     }
                     $prestation = $prestationsType[$prestationIdentifiant];
                     $passage->addPrestation($prestation);
                     $this->dm->persist($passage);
                 }
             }
         } else {
             $output->writeln(sprintf("<comment>Le passage : %s n'a aucune presta </comment>", $data[self::CSV_OLD_ID]));
         }
         $identifiantRepriseTechnicien = $data[self::CSV_TECHNICIEN];
         if (!is_null($identifiantRepriseTechnicien)) {
             $compte = $this->um->getRepository()->findOneByIdentifiantReprise($identifiantRepriseTechnicien);
             if (!is_null($compte)) {
                 $passage->addTechnicien($compte);
             }
         }
         $passage->setContrat($contrat);
         $passage->setNumeroContratArchive($contrat->getNumeroArchive());
         $produits = explode('#', $data[self::CSV_PRODUITS]);
         foreach ($produits as $produitStr) {
             if ($produitStr) {
                 $produitdetail = explode('~', $produitStr);
                 $produitQte = 0;
                 $produitLib = $produitdetail[0];
                 if (count($produitdetail) > 1) {
                     $produitQte = $produitdetail[1];
                 }
                 if ($produitLib) {
                     $produitToAdd = clone $produitsArray[strtoupper(Transliterator::urlize($produitLib))];
                     $produitToAdd->setNbUtilisePassage(0);
                     $produitToAdd->setNbTotalContrat(null);
                     $produitToAdd->setNbUtilisePassage($produitQte);
                     $passage->addProduit($produitToAdd);
                     $this->dm->persist($passage);
                 }
             }
         }
         $contrat->addEtablissement($etablissement);
         $contrat->addPassage($etablissement, $passage);
         $i++;
         $cptTotal++;
         if ($cptTotal % (count($csv) / 100) == 0) {
             $progress->advance();
         }
         if ($i >= 2000) {
             $this->dm->flush();
             $this->dm->clear();
             gc_collect_cycles();
             $i = 0;
         }
     }
     $this->dm->flush();
     $progress->finish();
 }
Esempio n. 11
0
 public function import($file, OutputInterface $output)
 {
     $csvFile = new CsvFile($file);
     $progress = new ProgressBar($output, 100);
     $progress->start();
     $csv = $csvFile->getCsv();
     $configuration = $this->dm->getRepository('AppBundle:Configuration')->findConfiguration();
     $produitsArray = $configuration->getProduitsArray();
     $i = 0;
     $cptTotal = 0;
     foreach ($csv as $data) {
         $societe = $this->sm->getRepository()->findOneBy(array('identifiantReprise' => $data[self::CSV_ID_SOCIETE]));
         if (!$societe) {
             $output->writeln(sprintf("<error>La societe %s n'existe pas</error>", $data[self::CSV_ID_SOCIETE]));
             continue;
         }
         $contrat = $this->cm->getRepository()->findOneBy(array('identifiantReprise', $data[self::CSV_ID_CONTRAT]));
         if (!$contrat) {
             $contrat = new Contrat();
         } else {
             $output->writeln(sprintf("<error>Le contrat : %s existe déjà en base?</error>", $data[self::CSV_ID_CONTRAT]));
         }
         $contrat->setDateCreation(new \DateTime($data[self::CSV_DATE_CREATION]));
         $contrat->setSociete($societe);
         $contrat->setTvaReduite(boolval($data[self::CSV_TVA_REDUITE]));
         $type_contrat = ContratManager::$types_contrat_import_index[$data[self::CSV_TYPE_CONTRAT]];
         $contrat->setTypeContrat($type_contrat);
         $contrat->setReconduit(false);
         if ($data[self::CSV_DATE_DEBUT]) {
             $contrat->setDateDebut(new \DateTime($data[self::CSV_DATE_DEBUT]));
         }
         if ($data[self::CSV_DATE_ACCEPTATION]) {
             $contrat->setDateAcceptation(new \DateTime($data[self::CSV_DATE_ACCEPTATION]));
             $contrat->setStatut(ContratManager::STATUT_EN_COURS);
         } else {
             $contrat->setStatut(ContratManager::STATUT_EN_ATTENTE_ACCEPTATION);
         }
         if (!preg_match("/^[0-9+]+\$/", $data[self::CSV_DUREE])) {
             $output->writeln(sprintf("<error>La durée du contrat %s n'est pas correct : %s</error>", $data[self::CSV_ID_CONTRAT], $data[self::CSV_DUREE]));
             continue;
         }
         $contrat->setDuree($data[self::CSV_DUREE]);
         $contrat->setDureeGarantie($data[self::CSV_GARANTIE]);
         $contrat->setDateDebut(new \DateTime($data[self::CSV_DATE_DEBUT]));
         $dateFin = clone $contrat->getDateDebut();
         $dateFin->modify("+ " . $contrat->getDuree() . " month");
         $contrat->setDateFin($dateFin);
         $contrat->setNomenclature(str_replace('#', "\n", $data[self::CSV_NOMENCLATURE]));
         $contrat->setPrixHt($data[self::CSV_PRIXHT]);
         $contrat->setIdentifiantReprise($data[self::CSV_ID_CONTRAT]);
         if (is_integer($data[self::CSV_ARCHIVAGE])) {
             $contrat->setNumeroArchive(0);
         }
         $contrat->setNumeroArchive($data[self::CSV_ARCHIVAGE]);
         if ($data[self::CSV_ID_COMMERCIAL]) {
             $commercial = $this->um->getRepository()->findOneByIdentifiantReprise($data[self::CSV_ID_COMMERCIAL]);
             if ($commercial) {
                 $contrat->setCommercial($commercial);
             }
         }
         if ($data[self::CSV_ID_TECHNICIEN]) {
             $technicien = $this->um->getRepository()->findOneByIdentifiantReprise($data[self::CSV_ID_TECHNICIEN]);
             if ($technicien) {
                 $contrat->setTechnicien($technicien);
             }
         }
         if ($data[self::CSV_DATE_RESILIATION]) {
             $contrat->setDateResiliation(new \DateTime($data[self::CSV_DATE_RESILIATION]));
             $contrat->setStatut(ContratManager::STATUT_RESILIE);
         }
         $produits = explode('#', $data[self::CSV_PRODUITS]);
         foreach ($produits as $produitStr) {
             if ($produitStr) {
                 $produitdetail = explode('~', $produitStr);
                 $produitQte = 0;
                 $produitLib = $produitdetail[0];
                 if (count($produitdetail) > 1) {
                     $produitQte = $produitdetail[1];
                 }
                 if ($produitLib) {
                     $produitToAdd = clone $produitsArray[strtoupper(Transliterator::urlize($produitLib))];
                     $produitToAdd->setNbTotalContrat(0);
                     $produitToAdd->setNbTotalContrat($produitQte);
                     $contrat->addProduit($produitToAdd);
                 }
             }
         }
         $this->dm->persist($contrat);
         $i++;
         $cptTotal++;
         if ($cptTotal % (count($csv) / 100) == 0) {
             $progress->advance();
         }
         if ($i >= 1000) {
             $this->dm->flush();
             $this->dm->clear();
             gc_collect_cycles();
             $i = 0;
         }
     }
     $this->dm->flush();
     $progress->finish();
 }