/**
  * @name update($pOperation)
  * @param OperationVO
  * @return integer
  * @desc Met à jour une opération
  */
 private function update($pOperation)
 {
     $pOperation->setDateMaj(StringUtils::dateTimeAujourdhuiDb());
     $pOperation->setIdLogin($_SESSION[DROIT_ID]);
     $this->insertHistorique($pOperation);
     // Ajout historique
     $lTypeModificationSolde = array(1, 2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14);
     if (in_array($pOperation->getTypePaiement(), $lTypeModificationSolde)) {
         $lOperationActuelle = $this->get($pOperation->getId());
         // Dans le cas la réservation devient achat. La date de création doit être mise à jour.
         if ($lOperationActuelle->getTypePaiement() == 0 && $pOperation->getTypePaiement() == 7) {
             $pOperation->setDate($pOperation->getDateMaj());
         }
         // Mise à jour du solde
         $lCompteService = new CompteService();
         $lCompte = $lCompteService->get($pOperation->getIdCompte());
         // Si l'operation actuelle impacte le solde
         if (in_array($lOperationActuelle->getTypePaiement(), $lTypeModificationSolde)) {
             $lCompte->setSolde($lCompte->getSolde() - $lOperationActuelle->getMontant() + $pOperation->getMontant());
         } else {
             $lCompte->setSolde($lCompte->getSolde() + $pOperation->getMontant());
         }
         $lCompteService->set($lCompte);
     }
     // Maj des champs complémentaires
     // Suppression des champs complementaires
     OperationChampComplementaireManager::deleteByIdOpe($pOperation->getId());
     // Ajout des champs complementaires
     $lChampComplementaire = $pOperation->getChampComplementaire();
     if (!empty($lChampComplementaire)) {
         // Vérifie si le champ est autorisé en modification
         $lChampAutorise = TypePaiementChampcomplementaireManager::champAutoriseMaj($pOperation->getTypePaiement());
         $lChampAjout = array();
         foreach ($pOperation->getChampComplementaire() as $lChamp) {
             if (in_array($lChamp->getChcpId(), $lChampAutorise)) {
                 $lChamp->setOpeId($pOperation->getId());
                 array_push($lChampAjout, $lChamp);
             }
         }
         if (!empty($lChampAjout)) {
             OperationChampComplementaireManager::insert($lChampAjout);
         }
     }
     // 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, $pOperation->getId()), array(), array());
     if (!is_null($lOperationChampComplementaireFacture[0]->getOpeId())) {
         $lMontant = $pOperation->getMontant();
         // Maj de l'operation de facture
         $lOperationFacture = $this->getDetail($lOperationChampComplementaireFacture[0]->getOpeId());
         $lOperationFacture->setMontant($lMontant);
         $this->set($lOperationFacture);
         // Maj de l'operation zeybu
         $lOpeFacChampComp = $lOperationFacture->getChampComplementaire();
         if (isset($lOpeFacChampComp[10])) {
             $lOperationZeybu = $this->getDetail($lOpeFacChampComp[10]->getValeur());
             $lOperationZeybu->setMontant(-1 * $lMontant);
             $lOperationZeybu->setTypePaiement($pOperation->getTypePaiement());
             $lOperationZeybu->setChampComplementaire($pOperation->getChampComplementaire());
             $this->set($lOperationZeybu);
         }
     }
     return OperationManager::update($pOperation);
     // update de l'opération
 }
Exemplo n.º 2
0
     }
 } else {
     if ($action == "update") {
         if (!empty($_POST['montant']) and !empty($_POST['numeroOperation'])) {
             $idOperation = htmlentities($_POST['idOperation']);
             $dateOperation = htmlentities($_POST['dateOperation']);
             $dateReglement = htmlentities($_POST['dateReglement']);
             $compteBancaire = htmlentities($_POST['compteBancaire']);
             $observation = htmlentities($_POST['observation']);
             $montant = htmlentities($_POST['montant']);
             $modePaiement = htmlentities($_POST['modePaiement']);
             $numeroOperation = htmlentities($_POST['numeroOperation']);
             $updatedBy = $_SESSION['userMerlaTrav']->login();
             $updated = date('Y-m-d h:i:s');
             $operation = new Operation(array('id' => $idOperation, 'date' => $dateOperation, 'dateReglement' => $dateReglement, 'compteBancaire' => $compteBancaire, 'observation' => $observation, 'montant' => $montant, 'numeroCheque' => $numeroOperation, 'modePaiement' => $modePaiement, 'updatedBy' => $updatedBy, 'updated' => $updated));
             $operationManager->update($operation);
             $idClient = htmlentities($_POST['idClient']);
             $idContrat = htmlentities($_POST['idContrat']);
             $client = $clientManager->getClientById($idClient);
             $contrat = $contratManager->getContratById($idContrat);
             $projet = $projetManager->getProjetById($contrat->idProjet());
             $nomProjet = $projet->nom();
             //add History data
             $createdBy = $_SESSION['userMerlaTrav']->login();
             $created = date('Y-m-d h:i:s');
             $history = new History(array('action' => "Modification", 'target' => "Table des paiements clients", 'description' => "Modification d'une opération paiement client, pour " . ucfirst($client->nom()) . " d'un montant de {$montant} - N° Contrat : {$idContrat} - Projet : {$nomProjet} - N° Opération : {$numeroOperation} - Mode Paiement : {$modePaiement} - Compte Bancaire : {$compteBancaire} - Obersvation : {$observation}", 'created' => $created, 'createdBy' => $createdBy));
             //add it to db
             $historyManager->add($history);
             $actionMessage = "<strong>Opération Valide</strong> : Paiement Client Modifié avec succès.";
             $typeMessage = "success";
         } else {