/**
  * @name supprimerAdherent($pParam)
  * @desc Passe l'adhérent en état supprimé
  */
 public function supprimerAdherent($pParam)
 {
     $lVr = AdherentValid::validDelete($pParam);
     if ($lVr->getValid()) {
         $lIdAdherent = $pParam['id'];
         $lAdherentService = new AdherentService();
         $lAdherentService->delete($lIdAdherent);
         // Gestion du compte
         $lCompteService = new CompteService();
         $lData = $lVr->getData();
         $lIdAncienCompte = $lData['adherent']->getAdhIdCompte();
         $lAdherentAncienCompte = $lCompteService->getAdherentCompte($lIdAncienCompte);
         // RAZ de l'adhérent principal
         $lIdAdherentPrincipalAncienCompte = 0;
         // Ou positionnement du nouvel
         if (!is_null($lAdherentAncienCompte[0]->getId()) && $pParam['idAdherentPrincipal'] != -1) {
             $lIdAdherentPrincipalAncienCompte = $pParam['idAdherentPrincipal'];
         }
         // Maj de l'ancien compte
         $lAncienCompte = $lCompteService->get($lIdAncienCompte);
         $lAncienCompte->setIdAdherentPrincipal($lIdAdherentPrincipalAncienCompte);
         $lCompteService->set($lAncienCompte);
         $lResponse = new AjoutAdherentResponse();
         $lResponse->setId($lIdAdherent);
         return $lResponse;
     }
     return $lVr;
 }
 /**
  * @name ajouterFerme($pParam)
  * @return AjoutFermeResponse
  * @desc Ajoute une ferme
  */
 public function ajouterFerme($pParam)
 {
     $lVr = FermeValid::validAjout($pParam);
     if ($lVr->getValid()) {
         // Création d'un nouveau compte
         $lCompte = new CompteVO();
         $lCompteService = new CompteService();
         $lCompte = $lCompteService->set($lCompte);
         // Création de la ferme
         $lFerme = new FermeVO();
         $lFerme->setNom($pParam["nom"]);
         $lFerme->setIdCompte($lCompte->getId());
         $lFerme->setSiren($pParam["siren"]);
         $lFerme->setAdresse($pParam["adresse"]);
         $lFerme->setCodePostal($pParam["codePostal"]);
         $lFerme->setVille($pParam["ville"]);
         $lFerme->setDateAdhesion($pParam["dateAdhesion"]);
         $lFerme->setDescription($pParam["description"]);
         $lFerme->setEtat(0);
         $lId = FermeManager::insert($lFerme);
         $lResponse = new AjoutFermeResponse();
         $lResponse->setId($lId);
         return $lResponse;
     }
     return $lVr;
 }
 /**
  * @name modifierInformation($pParam)
  * @return VR
  * @desc Modification des informations de l'adhérent.
  */
 public function modifierInformation($pParam)
 {
     $lVr = InfoAdherentValid::validUpdateInformation($pParam);
     if ($lVr->getValid()) {
         // Chargement de l'adherent
         $lAdherentActuel = AdherentManager::select($pParam['id_adherent']);
         //Mise à jour des inscriptions de mailing liste
         $lMailingListeService = new MailingListeService();
         if ($lAdherentActuel->getCourrielPrincipal() != "") {
             $lMailingListeService->delete($lAdherentActuel->getCourrielPrincipal());
         }
         if ($lAdherentActuel->getCourrielSecondaire() != "") {
             $lMailingListeService->delete($lAdherentActuel->getCourrielSecondaire());
         }
         if ($pParam['courrielPrincipal'] != "") {
             $lMailingListeService->insert($pParam['courrielPrincipal']);
         }
         if ($pParam['courrielSecondaire'] != "") {
             $lMailingListeService->insert($pParam['courrielSecondaire']);
         }
         $lAdherentActuel->setNom($pParam['nom']);
         $lAdherentActuel->setPrenom($pParam['prenom']);
         $lAdherentActuel->setCourrielPrincipal($pParam['courrielPrincipal']);
         $lAdherentActuel->setCourrielSecondaire($pParam['courrielSecondaire']);
         $lAdherentActuel->setTelephonePrincipal($pParam['telephonePrincipal']);
         $lAdherentActuel->setTelephoneSecondaire($pParam['telephoneSecondaire']);
         $lAdherentActuel->setAdresse($pParam['adresse']);
         $lAdherentActuel->setCodePostal($pParam['codePostal']);
         $lAdherentActuel->setVille($pParam['ville']);
         $lAdherentActuel->setDateNaissance($pParam['dateNaissance']);
         $lAdherentActuel->setCommentaire($pParam['commentaire']);
         // Insertion de la première mise à jour
         $lAdherentActuel->setDateMaj(StringUtils::dateTimeAujourdhuiDb());
         // Maj de l'adherent dans la BDD
         AdherentManager::update($lAdherentActuel);
         $lCompteService = new CompteService();
         $lCompte = $lCompteService->get($lAdherentActuel->getIdCompte());
         $lCompte->setIdAdherentPrincipal($pParam['idAdherentPrincipal']);
         $lCompteService->set($lCompte);
     }
     return $lVr;
 }
 /**
  * @name delete($pId)
  * @param integer
  * @desc Met à jour une opération
  */
 public function delete($pId)
 {
     $lOperationValid = new OperationValid();
     if ($lOperationValid->delete($pId)) {
         $lOperation = $this->getDetail($pId);
         // Maj du solde du compte
         $lTypeModificationSolde = array(1, 2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14);
         if (in_array($lOperation->getTypePaiement(), $lTypeModificationSolde)) {
             $lCompteService = new CompteService();
             // Mise à jour du solde
             $lCompte = $lCompteService->get($lOperation->getIdCompte());
             $lCompte->setSolde($lCompte->getSolde() - $lOperation->getMontant());
             $lCompteService->set($lCompte);
         }
         // Si c'est un paiement de facture de producteur il faut mettre à jour les paiements associés
         $lOperationChampComplementaireFacture = OperationChampComplementaireManager::recherche(array(OperationChampComplementaireManager::CHAMP_OPERATIONCHAMPCOMPLEMENTAIRE_CHCP_ID, OperationChampComplementaireManager::CHAMP_OPERATIONCHAMPCOMPLEMENTAIRE_VALEUR), array('=', '='), array(9, $pId), array(), array());
         if (!is_null($lOperationChampComplementaireFacture[0]->getOpeId())) {
             // Suppression de l'operation de facture
             $lOperationFacture = $this->getDetail($lOperationChampComplementaireFacture[0]->getOpeId());
             $this->delete($lOperationFacture->getId());
             // Suppression de l'operation zeybu
             $lOpeFacChampComp = $lOperationFacture->getChampComplementaire();
             $this->delete($lOpeFacChampComp[10]->getValeur());
         }
         switch ($lOperation->getTypePaiement()) {
             case 0:
                 // Annulation de la reservation
             // Annulation de la reservation
             case 16:
             case 22:
                 $lOperation->setTypePaiement(16);
                 return $this->update($lOperation);
                 break;
             case 15:
                 // Réservation non récupérée
                 $lOperation->setTypePaiement(15);
                 return $this->update($lOperation);
                 break;
             case 1:
                 // Annulation achat/dépot
             // Annulation achat/dépot
             case 2:
             case 6:
                 $lOperation->setTypePaiement(18);
                 return $this->update($lOperation);
                 break;
             case 7:
                 $lOperation->setTypePaiement(18);
                 return $this->update($lOperation);
                 break;
             case 8:
                 $lOperation->setTypePaiement(20);
                 return $this->update($lOperation);
                 break;
             default:
                 $lOperation->setDate(StringUtils::dateTimeAujourdhuiDb());
                 $lOperation->setlibelle("Supression");
                 $this->insertHistorique($lOperation);
                 // Ajout historique
                 //$this->insertHistorique($lDetailOperation); // Ajout historique
                 return OperationManager::delete($pId);
                 // delete de l'opération
                 break;
         }
     } else {
         return false;
     }
 }
 /**
  * @name modifierAdherent($pParam)
  * @desc Met à jour les informations de l'adherent ainsi que ses autorisations
  */
 public function modifierAdherent($pParam)
 {
     $lVr = AdherentValid::validUpdate($pParam);
     if ($lVr->getValid()) {
         // Conversion en objet
         $lAdherent = AdherentToVO::convertFromArray($pParam);
         // Maj de l'adhérent
         $lAdherentService = new AdherentService();
         $lAdherentService->set($lAdherent);
         $lIdNouveauCompte = $lAdherent->getIdcompte();
         $lData = $lVr->getData();
         $lIdAncienCompte = $lData['adherent']->getAdhIdCompte();
         // Gestion du compte
         $lCompteService = new CompteService();
         if ($lIdAncienCompte != $lIdNouveauCompte) {
             // Liaison avec un autre compte gestion du précédent compte
             $lAdherentAncienCompte = $lCompteService->getAdherentCompte($lIdAncienCompte);
             // RAZ de l'adhérent principal
             $lIdAdherentPrincipalAncienCompte = 0;
             // Ou positionnement du nouvel
             if (!is_null($lAdherentAncienCompte[0]->getId()) && $pParam['idAncienAdherentPrincipal'] != -1) {
                 $lIdAdherentPrincipalAncienCompte = $pParam['idAncienAdherentPrincipal'];
             }
             // Maj de l'ancien compte
             $lAncienCompte = $lCompteService->get($lIdAncienCompte);
             $lAncienCompte->setIdAdherentPrincipal($lIdAdherentPrincipalAncienCompte);
             $lCompteService->set($lAncienCompte);
         }
         // Mise à jour du compte
         $lNouveauCompte = $lCompteService->get($lIdNouveauCompte);
         if ($pParam['idAdherentPrincipal'] > 0) {
             // Uniquement si il y a un adhérent pincipal
             $lNouveauCompte->setIdAdherentPrincipal($pParam['idAdherentPrincipal']);
         }
         $lCompteService->set($lNouveauCompte);
         $lResponse = new AjoutAdherentResponse();
         $lResponse->setId($lAdherent->getId());
         return $lResponse;
     }
     return $lVr;
 }
 /**
  * @name update($pAdherent)
  * @param AdherentVO
  * @return AdherentVO
  * @desc Modifie un adherent
  */
 private function update($pAdherent)
 {
     $lAdherentActuel = AdherentManager::select($pAdherent->getId());
     // Si pas de liaison création d'un nouveau compte
     if ($pAdherent->getIdCompte() == 0) {
         // Création d'un nouveau compte
         $lCompte = new CompteVO();
         $lCompteService = new CompteService();
         $lCompte = $lCompteService->set($lCompte);
         $pAdherent->setIdCompte($lCompte->getId());
         // Laision avec l'adhérent
         $lCompte->setIdAdherentPrincipal($pAdherent->getId());
         // Positionnement de l'adhérent en adhérent principal du compte
         $lCompteService->set($lCompte);
     } else {
         if ($pAdherent->getIdCompte() != $lAdherentActuel->getIdCompte()) {
             // Liaison avec un autre compte
             $lAdhesionService = new AdhesionService();
             // Suppression des adhésions actuelles
             $lAdhesionService->deleteAdhesionAdherentByIdAdherent($pAdherent->getId());
             // Les adhérents du compte
             $lListeAdherent = $this->selectActifByIdCompte($pAdherent->getIdCompte());
             // Le premier adhérent
             $lAdherent = $lListeAdherent[0];
             // Les adhésions sur le premier adhérent
             $lAdhesions = $lAdhesionService->getAdhesionSurAdherent($lAdherent->getId());
             // Positionne les mêmes adhésions si elles existent
             foreach ($lAdhesions as $lAdhesion) {
                 $lAdhesionAdherentDetail = $lAdhesionService->getAdhesionAdherent($lAdhesion->getAdadId());
                 if ($lAdhesionAdherentDetail) {
                     $lAdhesionAdherent = $lAdhesionAdherentDetail->getAdhesionAdherent();
                     $lTypeAdhesion = $lAdhesionService->getTypeAdhesion($lAdhesionAdherent->getIdTypeAdhesion());
                     if ($lTypeAdhesion->getIdPerimetre() == 2) {
                         // Si type d'adhésion sur périmètre compte
                         $lAdhesionAdherent->setId('');
                         $lAdhesionAdherent->setIdAdherent($pAdherent->getId());
                         $lAdhesionService->setAdhesionAdherent($lAdhesionAdherent);
                     }
                 }
             }
         }
     }
     // Insertion de la date de mise à jour
     $pAdherent->setDateMaj(StringUtils::dateTimeAujourdhuiDb());
     // On reporte le numero dans la maj
     $pAdherent->setNumero($lAdherentActuel->getNumero());
     // L'adherent n'est pas supprimé
     $pAdherent->setEtat(1);
     // Mise en forme des données
     $pAdherent->setNom(StringUtils::formaterNom(trim($pAdherent->getNom())));
     $pAdherent->setPrenom(StringUtils::formaterPrenom(trim($pAdherent->getPrenom())));
     $pAdherent->setCourrielPrincipal(trim($pAdherent->getCourrielPrincipal()));
     $pAdherent->setCourrielSecondaire(trim($pAdherent->getCourrielSecondaire()));
     $pAdherent->setTelephonePrincipal(trim($pAdherent->getTelephonePrincipal()));
     $pAdherent->setTelephoneSecondaire(trim($pAdherent->getTelephoneSecondaire()));
     $pAdherent->setAdresse(trim($pAdherent->getAdresse()));
     $pAdherent->setCodePostal(trim($pAdherent->getCodePostal()));
     $pAdherent->setVille(StringUtils::formaterVille(trim($pAdherent->getVille())));
     $pAdherent->setCommentaire(trim($pAdherent->getCommentaire()));
     // Protection des dates vides
     if ($pAdherent->getDateNaissance() == '') {
         $pAdherent->setDateNaissance(StringUtils::FORMAT_DATE_NULLE);
     }
     if ($pAdherent->getDateAdhesion() == '') {
         $pAdherent->setDateAdhesion(StringUtils::FORMAT_DATE_NULLE);
     }
     if ($pAdherent->getDateMaj() == '') {
         $pAdherent->setDateMaj(StringUtils::FORMAT_DATE_NULLE);
     }
     // Maj de l'adherent dans la BDD
     $lRetour = AdherentManager::update($pAdherent);
     // Récupération des autorisations acutelles
     $lAutorisationsActuelles = AutorisationManager::selectByIdAdherent($pAdherent->getId());
     $lModuleService = new ModuleService();
     $lModulesDefaut = $lModuleService->selectAllDefautVisible();
     $lIdModuleDefaut = array();
     foreach ($lModulesDefaut as $lModule) {
         array_push($lIdModuleDefaut, $lModule->getId());
     }
     // Suppression des autorisations
     $lIdSuppAutorisation = array();
     foreach ($lAutorisationsActuelles as $lAutorisationActu) {
         // Suppression si ce n'est pas un module par defaut
         if (!in_array($lAutorisationActu->getIdModule(), $lIdModuleDefaut)) {
             $lSupp = true;
             foreach ($pAdherent->getListeModule() as $lIdModule) {
                 if ($lAutorisationActu->getIdModule() == $lIdModule) {
                     $lSupp = false;
                 }
             }
             if ($lSupp) {
                 array_push($lIdSuppAutorisation, $lAutorisationActu->getId());
             }
         }
     }
     if (!empty($lIdSuppAutorisation)) {
         AutorisationManager::deleteByArray($lIdSuppAutorisation);
     }
     // Ajout des nouvelles autorisations du compte
     $lAutorisations = array();
     foreach ($pAdherent->getListeModule() as $lIdModule) {
         $lAjout = true;
         foreach ($lAutorisationsActuelles as $lAutorisationActu) {
             if ($lAutorisationActu->getIdModule() == $lIdModule) {
                 $lAjout = false;
             }
         }
         if ($lAjout) {
             $lAutorisation = new AutorisationVO();
             $lAutorisation->setIdAdherent($pAdherent->getId());
             $lAutorisation->setIdModule($lIdModule);
             array_push($lAutorisations, $lAutorisation);
         }
     }
     if (!empty($lAutorisations)) {
         AutorisationManager::insertByArray($lAutorisations);
     }
     //Mise à jour des inscriptions de mailing liste
     $lMailingListeService = new MailingListeService();
     // Suppression des anciens mails
     if ($lAdherentActuel->getCourrielPrincipal() != "") {
         $lMailingListeService->delete($lAdherentActuel->getCourrielPrincipal());
     }
     if ($lAdherentActuel->getCourrielSecondaire() != "") {
         $lMailingListeService->delete($lAdherentActuel->getCourrielSecondaire());
     }
     // Ajout des nouveaux mails
     if ($pAdherent->getCourrielPrincipal() != "") {
         $lMailingListeService->insert($pAdherent->getCourrielPrincipal());
     }
     if ($pAdherent->getCourrielSecondaire() != "") {
         $lMailingListeService->insert($pAdherent->getCourrielSecondaire());
     }
     return $lRetour;
 }