/**
  * @name insert($pReservation)
  * @param ReservationVO
  * @return integer
  * @desc Ajoute une réservation
  */
 private function insert($pReservation)
 {
     // Calcul du total
     $lTotal = 0;
     foreach ($pReservation->getDetailReservation() as $lProduit) {
         $lTotal += $lProduit->getMontant();
     }
     // L'operation
     $lOperation = new OperationDetailVO();
     $lOperation->setIdCompte($pReservation->getId()->getIdCompte());
     $lOperation->setMontant($lTotal);
     $lOperation->setLibelle("Marché N°" . $pReservation->getId()->getIdCommande());
     $lOperation->setTypePaiement(0);
     $lOperation->setType(0);
     $lChampComplementaire = array();
     // Id Marché
     $lOperationChampComplementaire = new OperationChampComplementaireVO();
     $lOperationChampComplementaire->setChcpId(1);
     $lOperationChampComplementaire->setValeur($pReservation->getId()->getIdCommande());
     array_push($lChampComplementaire, $lOperationChampComplementaire);
     $lOperation->setChampComplementaire($lChampComplementaire);
     //
     //		$lOperation->setIdCommande($pReservation->getId()->getIdCommande());
     $lListeIdDetailCommande = array();
     foreach ($pReservation->getDetailReservation() as $lProduit) {
         array_push($lListeIdDetailCommande, $lProduit->getIdDetailCommande());
     }
     $lDetailMarche = DetailMarcheViewManager::selectByIdDetailCommande($lListeIdDetailCommande);
     $lOperationService = new OperationService();
     $lIdOperation = $lOperationService->set($lOperation);
     // Ajout detail operation
     $lStockService = new StockService();
     $lDetailOperationService = new DetailOperationService();
     foreach ($pReservation->getDetailReservation() as $lProduit) {
         // Ajout du stock
         $lStock = new StockVO();
         $lStock->setQuantite($lProduit->getQuantite());
         $lStock->setType(0);
         $lStock->setIdCompte($pReservation->getId()->getIdCompte());
         $lStock->setIdDetailCommande($lProduit->getIdDetailCommande());
         $lStock->setIdOperation($lIdOperation);
         $lStock->setIdNomProduit($lDetailMarche[$lProduit->getIdDetailCommande()]->getProIdNomProduit());
         $lStock->setUnite($lDetailMarche[$lProduit->getIdDetailCommande()]->getProUniteMesure());
         $lStockService->set($lStock);
         // Ajout du détail de l'operation
         $lDetailOperation = new DetailOperationVO();
         $lDetailOperation->setIdOperation($lIdOperation);
         $lDetailOperation->setIdCompte($pReservation->getId()->getIdCompte());
         $lDetailOperation->setMontant($lProduit->getMontant());
         $lDetailOperation->setLibelle("Marché N°" . $pReservation->getId()->getIdCommande());
         $lDetailOperation->setTypePaiement(0);
         $lDetailOperation->setIdDetailCommande($lProduit->getIdDetailCommande());
         $lDetailOperation->setIdNomProduit($lDetailMarche[$lProduit->getIdDetailCommande()]->getProIdNomProduit());
         $lDetailOperationService->set($lDetailOperation);
     }
     return $lIdOperation;
 }
Ejemplo n.º 2
0
 /**
  * @name insert($pCompte)
  * @param CompteVO
  * @return CompteVO
  * @desc Ajoute un compte
  */
 private function insert($pCompte)
 {
     $lId = CompteManager::insert($pCompte);
     // Le label est l'id du compte par défaut
     $pCompte->setId($lId);
     $pCompte->setLabel('C' . $lId);
     $this->update($pCompte);
     // Initialisation du compte
     $lOperation = new OperationDetailVO();
     $lOperation->setIdCompte($lId);
     $lOperation->setMontant(0);
     $lOperation->setLibelle("Création du compte");
     $lOperation->setDate(StringUtils::dateAujourdhuiDb());
     $lOperation->setTypePaiement(-1);
     $lOperationService = new OperationService();
     $lOperationService->set($lOperation);
     return $pCompte;
 }
Ejemplo n.º 3
0
 /**
  * @name update($pAchat)
  * @param AchatVO
  * @return integer
  * @desc Met à jour un achat
  */
 private function update($pAchat)
 {
     $lOperationService = new OperationService();
     // Rechargement
     $lIdRechargement = $pAchat->getRechargement()->getId();
     $lCompteRechargement = $pAchat->getRechargement()->getIdCompte();
     $lMajRechargement = false;
     if (!empty($lIdRechargement) && !is_null($lIdRechargement)) {
         $lMontantRechargement = $pAchat->getRechargement()->getMontant();
         if (!empty($lMontantRechargement) && !is_null($lMontantRechargement)) {
             // Maj du rechargement
             $lMajRechargement = true;
             $lIdRechargement = $lOperationService->set($pAchat->getRechargement());
         } else {
             if ($lMontantRechargement == 0) {
                 // Suppression du rechargement
                 $lOperationService->delete($lIdRechargement);
                 $lIdRechargement = NULL;
             }
         }
     } else {
         if (!empty($lCompteRechargement) && !is_null($lCompteRechargement)) {
             // Ajout du rechargement
             $pAchat->getRechargement()->setLibelle('Rechargement');
             $lIdRechargement = $lOperationService->set($pAchat->getRechargement());
         }
     }
     //$lIdOperationAchat = 0;
     //$lIdOperationAchatSolidaire = 0;
     $lIdCompte = 0;
     $lIdMarche = 0;
     $lLibelleOperation = '';
     $lLibelleOperationSolidaire = '';
     $lAchatActuel = NULL;
     $lIdOperationAchatActuel = 0;
     $lIdOperationAchatSolidaireActuel = 0;
     // Achat
     $lIdOperationAchat = $pAchat->getOperationAchat()->getId();
     $lTestCompteAchat = $pAchat->getOperationAchat()->getIdCompte();
     $lMajAchat = false;
     if (!empty($lIdOperationAchat) && !is_null($lIdOperationAchat)) {
         $lAchatActuel = $this->select($lIdOperationAchat);
         $lIdOperationAchatActuel = $lIdOperationAchat;
         $lMontantAchat = $pAchat->getOperationAchat()->getMontant();
         $ltestChampComplementaire = $pAchat->getOperationAchat()->getChampComplementaire();
         $lIdOperationZeybu = $ltestChampComplementaire[8]->getValeur();
         $lLibelleOperation = $pAchat->getOperationAchat()->getLibelle();
         $lIdCompte = $pAchat->getOperationAchat()->getIdCompte();
         if (isset($ltestChampComplementaire[1])) {
             $lIdMarche = $ltestChampComplementaire[1]->getValeur();
         }
         if (!empty($lMontantAchat) && !is_null($lMontantAchat)) {
             // Maj de l'achat
             $lMajAchat = true;
             $lIdOperationAchat = $lOperationService->set($pAchat->getOperationAchat());
             $lOperationZeybu = $lOperationService->getDetail($lIdOperationZeybu);
             $lOperationZeybu->setMontant($pAchat->getOperationAchat()->getMontant() * -1);
             $lOperationService->set($lOperationZeybu);
         } else {
             if ($lMontantAchat == 0) {
                 // Suppression de l'achat
                 $lOperationService->delete($lIdOperationAchat);
                 $lOperationService->delete($lIdOperationZeybu);
                 $lIdOperationAchat = NULL;
             }
         }
     } else {
         if (!empty($lTestCompteAchat) && !is_null($lTestCompteAchat)) {
             // Ajout Achat
             $lIdCompte = $pAchat->getOperationAchat()->getIdCompte();
             $ltestChampComplementaire = $pAchat->getOperationAchat()->getChampComplementaire();
             if (isset($ltestChampComplementaire[1])) {
                 $lIdMarche = $ltestChampComplementaire[1]->getValeur();
                 $lMarcheService = new MarcheService();
                 $lMarche = $lMarcheService->getInfoMarche($lIdMarche);
                 $lLibelleOperation = "Marché N°" . $lMarche->getNumero();
             } else {
                 $lLibelleOperation = "Achat du " . StringUtils::dateAujourdhuiFr();
             }
             $pAchat->getOperationAchat()->setLibelle($lLibelleOperation);
             $lIdOperationAchat = $lOperationService->set($pAchat->getOperationAchat());
             // Operation d'achat
             $lOperationZeybu = new OperationDetailVO();
             $lOperationZeybu->setIdCompte(-1);
             $lOperationZeybu->setMontant($pAchat->getOperationAchat()->getMontant() * -1);
             $lOperationZeybu->setLibelle($lLibelleOperation);
             $lOperationZeybu->setTypePaiement($pAchat->getOperationAchat()->getTypePaiement());
             $lOperationZeybuChampComplementaire = $pAchat->getOperationAchat()->getChampComplementaire();
             $lOperationZeybuChampComplementaire[8] = new OperationChampComplementaireVO(null, 8, $lIdOperationAchat);
             $lOperationZeybu->setChampComplementaire($lOperationZeybuChampComplementaire);
             $lIdOperationZeybu = $lOperationService->set($lOperationZeybu);
             // Operation Zeybu
         }
     }
     // Achat Solidaire
     $lIdOperationAchatSolidaire = $pAchat->getOperationAchatSolidaire()->getId();
     $lTestCompteAchatSolidaire = $pAchat->getOperationAchatSolidaire()->getIdCompte();
     $lMajAchatSolidaire = false;
     if (!empty($lIdOperationAchatSolidaire) && !is_null($lIdOperationAchatSolidaire)) {
         if (is_null($lAchatActuel)) {
             $lAchatActuel = $this->select($lIdOperationAchatSolidaire);
         }
         $lIdOperationAchatSolidaireActuel = $lIdOperationAchatSolidaire;
         $lMontantAchatSolidaire = $pAchat->getOperationAchatSolidaire()->getMontant();
         $ltestChampComplementaire = $pAchat->getOperationAchatSolidaire()->getChampComplementaire();
         $lIdOperationZeybuSolidaire = $ltestChampComplementaire[8]->getValeur();
         $lLibelleOperationSolidaire = $pAchat->getOperationAchatSolidaire()->getLibelle();
         $lIdCompte = $pAchat->getOperationAchatSolidaire()->getIdCompte();
         if (isset($ltestChampComplementaire[1])) {
             $lIdMarche = $ltestChampComplementaire[1]->getValeur();
         }
         if (!empty($lMontantAchatSolidaire) && !is_null($lMontantAchatSolidaire)) {
             // Maj de l'achat
             $lMajAchatSolidaire = true;
             $lIdOperationAchatSolidaire = $lOperationService->set($pAchat->getOperationAchatSolidaire());
             $lOperationZeybuSolidaire = $lOperationService->getDetail($lIdOperationZeybuSolidaire);
             $lOperationZeybuSolidaire->setMontant($pAchat->getOperationAchatSolidaire()->getMontant() * -1);
             $lOperationService->set($lOperationZeybuSolidaire);
         } else {
             if ($lMontantAchatSolidaire == 0) {
                 // Suppression de l'achat
                 $lOperationService->delete($lIdOperationAchatSolidaire);
                 $lOperationService->delete($lIdOperationZeybuSolidaire);
                 $lIdOperationAchatSolidaire = NULL;
             }
         }
     } else {
         if (!empty($lTestCompteAchatSolidaire) && !is_null($lTestCompteAchatSolidaire)) {
             $lIdCompte = $pAchat->getOperationAchatSolidaire()->getIdCompte();
             $ltestChampComplementaire = $pAchat->getOperationAchatSolidaire()->getChampComplementaire();
             if (isset($ltestChampComplementaire[1])) {
                 if (!isset($lMarche)) {
                     // Pour éviter de lancer 2 fois la requête
                     $lIdMarche = $ltestChampComplementaire[1]->getValeur();
                     $lMarcheService = new MarcheService();
                     $lMarche = $lMarcheService->getInfoMarche($lIdMarche);
                 }
                 $lLibelleOperationSolidaire = "Marché Solidaire N°" . $lMarche->getNumero();
             } else {
                 $lLibelleOperationSolidaire = "Achat Solidaire du " . StringUtils::dateAujourdhuiFr();
             }
             $pAchat->getOperationAchatSolidaire()->setLibelle($lLibelleOperationSolidaire);
             $lIdOperationAchatSolidaire = $lOperationService->set($pAchat->getOperationAchatSolidaire());
             // Operation d'achat Solidaire
             $lOperationZeybuSolidaire = new OperationDetailVO();
             $lOperationZeybuSolidaire->setIdCompte(-1);
             $lOperationZeybuSolidaire->setMontant($pAchat->getOperationAchatSolidaire()->getMontant() * -1);
             $lOperationZeybuSolidaire->setLibelle($lLibelleOperationSolidaire);
             $lOperationZeybuSolidaire->setTypePaiement($pAchat->getOperationAchatSolidaire()->getTypePaiement());
             $lOperationZeybuSolidaireChampComplementaire = $pAchat->getOperationAchatSolidaire()->getChampComplementaire();
             $lOperationZeybuSolidaireChampComplementaire[8] = new OperationChampComplementaireVO(null, 8, $lIdOperationAchatSolidaire);
             $lOperationZeybuSolidaire->setChampComplementaire($lOperationZeybuSolidaireChampComplementaire);
             $lIdOperationZeybuSolidaire = $lOperationService->set($lOperationZeybuSolidaire);
             // Operation Zeybu solidaire
         }
     }
     // Liaison Rechargement
     if (!is_null($lIdRechargement)) {
         $lMaj = false;
         $lRechargementChampComplementaire = $pAchat->getRechargement()->getChampComplementaire();
         if (!is_null($lIdOperationAchat)) {
             $lMaj = true;
             $lRechargementChampComplementaire[12] = new OperationChampComplementaireVO(null, 12, $lIdOperationAchat);
         } else {
             if (is_null($lIdOperationAchat)) {
                 unset($lRechargementChampComplementaire[12]);
             }
         }
         if (!is_null($lIdOperationAchatSolidaire)) {
             $lMaj = true;
             $lRechargementChampComplementaire[13] = new OperationChampComplementaireVO(null, 13, $lIdOperationAchatSolidaire);
         } else {
             if (is_null($lIdOperationAchatSolidaire)) {
                 unset($lRechargementChampComplementaire[13]);
             }
         }
         if ($lMaj) {
             $pAchat->getRechargement()->setChampComplementaire($lRechargementChampComplementaire);
             $lOperationService->set($pAchat->getRechargement());
         }
     }
     // Liaison achat
     if (!is_null($lIdOperationAchat)) {
         $lChampComplementaire = $pAchat->getOperationAchat()->getChampComplementaire();
         $lChampComplementaire[8] = new OperationChampComplementaireVO(null, 8, $lIdOperationZeybu);
         if (!is_null($lIdRechargement)) {
             $lChampComplementaire[14] = new OperationChampComplementaireVO(null, 14, $lIdRechargement);
         } else {
             if (is_null($lIdRechargement)) {
                 unset($lChampComplementaire[14]);
             }
         }
         if (!is_null($lIdOperationAchatSolidaire)) {
             $lChampComplementaire[13] = new OperationChampComplementaireVO(null, 13, $lIdOperationAchatSolidaire);
         } else {
             if (is_null($lIdOperationAchatSolidaire)) {
                 unset($lChampComplementaire[13]);
             }
         }
         $pAchat->getOperationAchat()->setChampComplementaire($lChampComplementaire);
         $lOperationService->set($pAchat->getOperationAchat());
         // Operation d'achat avec lien operation zeybu
     }
     // Liaison Achat Solidaire
     if (!is_null($lIdOperationAchatSolidaire)) {
         $lChampComplementaireSolidaire = $pAchat->getOperationAchatSolidaire()->getChampComplementaire();
         $lChampComplementaireSolidaire[8] = new OperationChampComplementaireVO(null, 8, $lIdOperationZeybuSolidaire);
         if (!is_null($lIdRechargement)) {
             $lChampComplementaireSolidaire[14] = new OperationChampComplementaireVO(null, 14, $lIdRechargement);
         } else {
             if (is_null($lIdRechargement)) {
                 unset($lChampComplementaireSolidaire[14]);
             }
         }
         if (!is_null($lIdOperationAchat)) {
             $lChampComplementaireSolidaire[12] = new OperationChampComplementaireVO(null, 12, $lIdOperationAchat);
         } else {
             if (is_null($lIdOperationAchat)) {
                 unset($lChampComplementaireSolidaire[12]);
             }
         }
         $pAchat->getOperationAchatSolidaire()->setChampComplementaire($lChampComplementaireSolidaire);
         $lOperationService->set($pAchat->getOperationAchatSolidaire());
         // Operation d'achat solidaire avec lien operation zeybu
     }
     // Ajout des produits
     $lIdModeleLot = array();
     $lIdDetailCommande = array();
     foreach ($pAchat->getProduits() as $lProduit) {
         $lTestModeleLot = $lProduit->getIdModeleLot();
         $lTestDetailCommande = $lProduit->getIdDetailCommande();
         if (!empty($lTestModeleLot) && !is_null($lTestModeleLot)) {
             array_push($lIdModeleLot, $lTestModeleLot);
         } else {
             if (!empty($lTestDetailCommande) && !is_null($lTestDetailCommande)) {
                 array_push($lIdDetailCommande, $lTestDetailCommande);
             }
         }
         $lTestModeleLotSolidaire = $lProduit->getIdModeleLotSolidaire();
         $lTestDetailCommandeSolidaire = $lProduit->getIdDetailCommandeSolidaire();
         if (!empty($lTestModeleLotSolidaire) && !is_null($lTestModeleLotSolidaire)) {
             array_push($lIdModeleLot, $lTestModeleLotSolidaire);
         } else {
             if (!empty($lTestDetailCommandeSolidaire) && !is_null($lTestDetailCommandeSolidaire)) {
                 array_push($lIdDetailCommande, $lTestDetailCommandeSolidaire);
             }
         }
     }
     if (!empty($lIdModeleLot)) {
         $lListeModeleLot = ModeleLotManager::selectByArray($lIdModeleLot);
     }
     if (!empty($lIdDetailCommande)) {
         $lListeDetailCommande = DetailCommandeManager::selectByArrayClassByDcomId($lIdDetailCommande);
     }
     // Suppression de l'ensemble des lignes de produit qui seront à nouveau insérées
     DetailAchatManager::delete($lIdOperationAchatActuel, $lIdOperationAchatSolidaireActuel);
     $lDetailOperationService = new DetailOperationService();
     $lStockService = new StockService();
     foreach ($lAchatActuel->getProduits() as $lProduitInital) {
         $lMaj = false;
         foreach ($pAchat->getProduits() as $lProduitMaj) {
             if ($lProduitInital->getIdStock() == $lProduitMaj->getIdStock() && $lProduitInital->getIdDetailOperation() == $lProduitMaj->getIdDetailOperation() && $lProduitInital->getIdStockSolidaire() == $lProduitMaj->getIdStockSolidaire() && $lProduitInital->getIdDetailOperationSolidaire() == $lProduitMaj->getIdDetailOperationSolidaire()) {
                 // Modification
                 $lMaj = true;
                 // Stock
                 $lIdStock = 0;
                 $lIdDetailOperation = 0;
                 if ($lProduitInital->getIdStock() == 0 && $lProduitMaj->getQuantite() < 0) {
                     // Ajout
                     $lUnite = '';
                     $lTestModeleLot = $lProduitMaj->getIdModeleLot();
                     $lTestDetailCommande = $lProduitMaj->getIdDetailCommande();
                     if (!empty($lTestModeleLot) && !is_null($lTestModeleLot)) {
                         $lUnite = $lListeModeleLot[$lTestModeleLot]->getUnite();
                     } else {
                         if (!empty($lTestDetailCommande) && !is_null($lTestDetailCommande)) {
                             $lUnite = $lListeDetailCommande[$lTestDetailCommande]->getUnite();
                         }
                     }
                     $lIdStock = $lStockService->set(new StockVO(null, null, $lProduitMaj->getQuantite(), 1, $lIdCompte, $lProduitMaj->getIdDetailCommande(), $lProduitMaj->getIdModeleLot(), $lIdOperationAchat, $lProduitMaj->getIdNomProduit(), $lUnite));
                     // Prix
                     $lIdDetailOperation = $lDetailOperationService->set(new DetailOperationVO(null, $lIdOperationAchat, $lIdCompte, $lProduitMaj->getMontant(), $lLibelleOperation, null, 7, $lProduitMaj->getIdDetailCommande(), $lProduitMaj->getIdModeleLot(), $lProduitMaj->getIdNomProduit(), null));
                 } else {
                     if ($lProduitInital->getIdStock() != 0 && $lProduitMaj->getQuantite() < 0) {
                         // Modification
                         $lStockInitial = $lStockService->get($lProduitInital->getIdStock());
                         $lIdStock = $lStockInitial->getId();
                         $lStockInitial->setQuantite($lProduitMaj->getQuantite());
                         $lStockService->set($lStockInitial);
                         // Prix
                         $lDetailOperationInitial = $lDetailOperationService->get($lProduitInital->getIdDetailOperation());
                         $lIdDetailOperation = $lDetailOperationInitial->getId();
                         $lDetailOperationInitial->setMontant($lProduitMaj->getMontant());
                         $lDetailOperationService->set($lDetailOperationInitial);
                     } else {
                         // Suppression
                         $lStockService->delete($lProduitInital->getIdStock());
                         $lDetailOperationService->delete($lProduitInital->getIdDetailOperation());
                     }
                 }
                 // Stock Solidaire
                 $lIdStockSolidaire = 0;
                 $lIdDetailOperationSolidaire = 0;
                 if ($lProduitInital->getIdStockSolidaire() == 0 && $lProduitMaj->getQuantiteSolidaire() < 0) {
                     $lUniteSolidaire = '';
                     $lTestModeleLotSolidaire = $lProduitMaj->getIdModeleLotSolidaire();
                     $lTestDetailCommandeSolidaire = $lProduitMaj->getIdDetailCommandeSolidaire();
                     if (!empty($lTestModeleLotSolidaire) && !is_null($lTestModeleLotSolidaire)) {
                         $lUniteSolidaire = $lListeModeleLot[$lTestModeleLotSolidaire]->getUnite();
                     } else {
                         if (!empty($lTestDetailCommandeSolidaire) && !is_null($lTestDetailCommandeSolidaire)) {
                             $lUniteSolidaire = $lListeDetailCommande[$lTestDetailCommandeSolidaire]->getUnite();
                         }
                     }
                     $lIdStockSolidaire = $lStockService->set(new StockVO(null, null, $lProduitMaj->getQuantiteSolidaire(), 2, $lIdCompte, $lProduitMaj->getIdDetailCommandeSolidaire(), $lProduitMaj->getIdModeleLotSolidaire(), $lIdOperationAchatSolidaire, $lProduitMaj->getIdNomProduit(), $lUniteSolidaire));
                     // Prix
                     $lIdDetailOperationSolidaire = $lDetailOperationService->set(new DetailOperationVO(null, $lIdOperationAchatSolidaire, $lIdCompte, $lProduitMaj->getMontantSolidaire(), $lLibelleOperationSolidaire, null, 8, $lProduitMaj->getIdDetailCommandeSolidaire(), $lProduitMaj->getIdModeleLotSolidaire(), $lProduitMaj->getIdNomProduit(), null));
                 } else {
                     if ($lProduitInital->getIdStockSolidaire() != 0 && $lProduitMaj->getQuantiteSolidaire() < 0) {
                         // Modification
                         $lStockInitialSolidaire = $lStockService->get($lProduitInital->getIdStockSolidaire());
                         $lIdStockSolidaire = $lStockInitialSolidaire->getId();
                         $lStockInitialSolidaire->setQuantite($lProduitMaj->getQuantiteSolidaire());
                         $lStockService->set($lStockInitialSolidaire);
                         // Prix
                         $lDetailOperationInitialSolidaire = $lDetailOperationService->get($lProduitInital->getIdDetailOperationSolidaire());
                         $lIdDetailOperationSolidaire = $lDetailOperationInitialSolidaire->getId();
                         $lDetailOperationInitialSolidaire->setMontant($lProduitMaj->getMontantSolidaire());
                         $lDetailOperationService->set($lDetailOperationInitialSolidaire);
                     } else {
                         // Suppression
                         $lStockService->delete($lProduitInital->getIdStockSolidaire());
                         $lDetailOperationService->delete($lProduitInital->getIdDetailOperationSolidaire());
                     }
                 }
                 if ($lProduitMaj->getQuantiteSolidaire() < 0 || $lProduitMaj->getQuantite() < 0) {
                     // Pas d'ajout de ligne vide
                     DetailAchatManager::insert(new DetailAchatVO($lIdOperationAchat, $lIdOperationAchatSolidaire, $lProduitMaj->getIdNomProduit(), $lIdStock, $lIdDetailOperation, $lIdStockSolidaire, $lIdDetailOperationSolidaire));
                 }
             }
         }
         if (!$lMaj) {
             // Suppression
             $lStockService->delete($lProduitInital->getIdStock());
             $lDetailOperationService->delete($lProduitInital->getIdDetailOperation());
             $lStockService->delete($lProduitInital->getIdStockSolidaire());
             $lDetailOperationService->delete($lProduitInital->getIdDetailOperationSolidaire());
         }
     }
     foreach ($pAchat->getProduits() as $lProduitMaj) {
         $lMaj = false;
         foreach ($lAchatActuel->getProduits() as $lProduitInital) {
             if ($lProduitInital->getIdStock() == $lProduitMaj->getIdStock() && $lProduitInital->getIdDetailOperation() == $lProduitMaj->getIdDetailOperation() && $lProduitInital->getIdStockSolidaire() == $lProduitMaj->getIdStockSolidaire() && $lProduitInital->getIdDetailOperationSolidaire() == $lProduitMaj->getIdDetailOperationSolidaire()) {
                 // Modification
                 $lMaj = true;
             }
         }
         if (!$lMaj) {
             // Ajout
             // Stock
             $lIdStock = 0;
             $lIdDetailOperation = 0;
             if ($lProduitMaj->getQuantite() < 0) {
                 $lUnite = '';
                 $lTestModeleLot = $lProduitMaj->getIdModeleLot();
                 $lTestDetailCommande = $lProduitMaj->getIdDetailCommande();
                 if (!empty($lTestModeleLot) && !is_null($lTestModeleLot)) {
                     $lUnite = $lListeModeleLot[$lTestModeleLot]->getUnite();
                 } else {
                     if (!empty($lTestDetailCommande) && !is_null($lTestDetailCommande)) {
                         $lUnite = $lListeDetailCommande[$lTestDetailCommande]->getUnite();
                     }
                 }
                 $lIdStock = $lStockService->set(new StockVO(null, null, $lProduitMaj->getQuantite(), 1, $lIdCompte, $lProduitMaj->getIdDetailCommande(), $lProduitMaj->getIdModeleLot(), $lIdOperationAchat, $lProduitMaj->getIdNomProduit(), $lUnite));
                 // Prix
                 $lIdDetailOperation = $lDetailOperationService->set(new DetailOperationVO(null, $lIdOperationAchat, $lIdCompte, $lProduitMaj->getMontant(), $lLibelleOperation, null, 7, $lProduitMaj->getIdDetailCommande(), $lProduitMaj->getIdModeleLot(), $lProduitMaj->getIdNomProduit(), null));
             }
             // Stock Solidaire
             $lIdStockSolidaire = 0;
             $lIdDetailOperationSolidaire = 0;
             if ($lProduitMaj->getQuantiteSolidaire() < 0) {
                 $lUniteSolidaire = '';
                 $lTestModeleLotSolidaire = $lProduitMaj->getIdModeleLotSolidaire();
                 $lTestDetailCommandeSolidaire = $lProduitMaj->getIdDetailCommandeSolidaire();
                 if (!empty($lTestModeleLotSolidaire) && !is_null($lTestModeleLotSolidaire)) {
                     $lUniteSolidaire = $lListeModeleLot[$lTestModeleLotSolidaire]->getUnite();
                 } else {
                     if (!empty($lTestDetailCommandeSolidaire) && !is_null($lTestDetailCommandeSolidaire)) {
                         $lUniteSolidaire = $lListeDetailCommande[$lTestDetailCommandeSolidaire]->getUnite();
                     }
                 }
                 $lIdStockSolidaire = $lStockService->set(new StockVO(null, null, $lProduitMaj->getQuantiteSolidaire(), 2, $lIdCompte, $lProduitMaj->getIdDetailCommandeSolidaire(), $lProduitMaj->getIdModeleLotSolidaire(), $lIdOperationAchatSolidaire, $lProduitMaj->getIdNomProduit(), $lUniteSolidaire));
                 // Prix
                 $lIdDetailOperationSolidaire = $lDetailOperationService->set(new DetailOperationVO(null, $lIdOperationAchatSolidaire, $lIdCompte, $lProduitMaj->getMontantSolidaire(), $lLibelleOperationSolidaire, null, 8, $lProduitMaj->getIdDetailCommandeSolidaire(), $lProduitMaj->getIdModeleLotSolidaire(), $lProduitMaj->getIdNomProduit(), null));
             }
             if ($lProduitMaj->getQuantiteSolidaire() < 0 || $lProduitMaj->getQuantite() < 0) {
                 // Pas d'ajout de ligne vide
                 DetailAchatManager::insert(new DetailAchatVO($lIdOperationAchat, $lIdOperationAchatSolidaire, $lProduitMaj->getIdNomProduit(), $lIdStock, $lIdDetailOperation, $lIdStockSolidaire, $lIdDetailOperationSolidaire));
             }
         }
     }
     // Retourne l'Id de l'achat ou à defaut celui de l'achat solidaire
     $lIdRetour = $lIdOperationAchat;
     if ($lIdRetour == 0) {
         if ($lIdOperationAchatSolidaire != 0) {
             $lIdRetour = $lIdOperationAchatSolidaire;
         } else {
             $lIdRetour = $lIdRechargement;
         }
     }
     return $lIdRetour;
 }
 /**
  * @name remplirOperationDetailEntete($pId, $pIdCompte, $pMontant, $pLibelle, $pDate, $pTypePaiement, $pType, $pDateMaj, $pIdLogin, $pTppId, $pTppType, $pTppChampComplementaire, $pTppVisible)
  * @param int(11)
  * @param int(11)
  * @param decimal(10,2)
  * @param varchar(100)
  * @param datetime
  * @param int(11)
  * @param int(11)
  * @param datetime
  * @param int(11)
  * @param int(11)
  * @param varchar(100)
  * @param tinyint(4)
  * @param tinyint(1)
  * @return OperationVO
  * @desc Retourne une OperationDetailVO remplie
  */
 private static function remplirOperationDetailEntete($pId, $pIdCompte, $pMontant, $pLibelle, $pDate, $pTypePaiement, $pType, $pDateMaj, $pIdLogin, $pTppId, $pTppType, $pTppChampComplementaire, $pTppVisible)
 {
     $lOperation = new OperationDetailVO();
     $lOperation->setId($pId);
     $lOperation->setIdCompte($pIdCompte);
     $lOperation->setMontant($pMontant);
     $lOperation->setLibelle($pLibelle);
     $lOperation->setDate($pDate);
     $lOperation->setTypePaiement($pTypePaiement);
     $lOperation->setType($pType);
     $lOperation->setDateMaj($pDateMaj);
     $lOperation->setIdLogin($pIdLogin);
     $lOperation->setTppId($pTppId);
     $lOperation->setTppType($pTppType);
     $lOperation->setTppChampComplementaire($pTppChampComplementaire);
     $lOperation->setTppVisible($pTppVisible);
     return $lOperation;
 }
 /**
  * @name enregistrerBonDeCommande($pParam)
  * @return AfficheListeProduitBonDeCommandeResponse
  * @desc Enregistre le bon de commande.
  */
 public function enregistrerBonDeCommande($pParam)
 {
     $lVr = ProduitsBonDeCommandeValid::validAjout($pParam);
     if ($lVr->getValid()) {
         $lIdMarche = $pParam["id_commande"];
         $lIdCompteFerme = $pParam["id_compte_ferme"];
         $lProduits = $pParam["produits"];
         // On enregistre uniquement les produits avec à minima quantité (même si prix à 0)
         // Calcul du total
         $lTotal = 0;
         $lProduitsValide = array();
         foreach ($lProduits as $lProduit) {
             if ($lProduit["quantite"] > 0) {
                 array_push($lProduitsValide, $lProduit);
             }
             $lTotal += $lProduit["prix"];
         }
         // Récupère l'opération Bon de commande si elle existe
         $lOperationService = new OperationService();
         $lOperations = $lOperationService->getBonCommande($lIdMarche, $lIdCompteFerme);
         $lIdOperation = $lOperations[0]->getId();
         if (is_null($lIdOperation)) {
             // Si il n'y a pas d'opération de Bon de commande
             $lOperation = new OperationDetailVO();
             $lOperation->setIdCompte($lIdCompteFerme);
             $lOperation->setLibelle('Bon de Commande');
             $lOperation->setTypePaiement(5);
             $lOperationChampComplementaire = new OperationChampComplementaireVO();
             $lOperationChampComplementaire->setChcpId(1);
             $lOperationChampComplementaire->setValeur($lIdMarche);
             $lOperation->setChampComplementaire(array($lOperationChampComplementaire));
         } else {
             $lOperation = $lOperations[0];
         }
         $lOperation->setMontant($lTotal);
         $lIdOperation = $lOperationService->set($lOperation);
         // Ajout ou mise à jour de l'operation
         $lBonCommande = InfoBonCommandeViewManager::selectInfoBonCommande($lIdMarche, $lIdCompteFerme);
         $lDetailOperationService = new DetailOperationService();
         $lStockService = new StockService();
         foreach ($lProduitsValide as $lProduit) {
             $lMaj = false;
             foreach ($lBonCommande as $lBon) {
                 if ($lProduit["dcomId"] == $lBon->getDcomId()) {
                     $lMaj = true;
                     //$lDcom = DetailCommandeManager::selectByIdProduit($lProduit["id"]);
                     $lStock = new StockVO();
                     $lStock->setId($lBon->getStoId());
                     $lStock->setQuantite($lProduit["quantite"]);
                     $lStock->setType(3);
                     $lStock->setIdCompte($lIdCompteFerme);
                     $lStock->setIdDetailCommande($lProduit["dcomId"]);
                     $lStock->setIdOperation($lIdOperation);
                     $lStockService->set($lStock);
                     $lDetailOperation = $lDetailOperationService->get($lBon->getDopeId());
                     $lDetailOperation->setIdOperation($lIdOperation);
                     $lDetailOperation->setIdCompte($lIdCompteFerme);
                     $lDetailOperation->setMontant($lProduit["prix"]);
                     $lDetailOperation->setLibelle('Bon de Commande');
                     $lDetailOperation->setTypePaiement(5);
                     $lDetailOperationService->set($lDetailOperation);
                 }
             }
             if (!$lMaj) {
                 //$lDcom = DetailCommandeManager::selectByIdProduit($lProduit["id"]);
                 $lStock = new StockVO();
                 $lStock->setQuantite($lProduit["quantite"]);
                 $lStock->setType(3);
                 $lStock->setIdCompte($lIdCompteFerme);
                 $lStock->setIdDetailCommande($lProduit["dcomId"]);
                 $lStock->setIdOperation($lIdOperation);
                 $lStockService->set($lStock);
                 $lDetailOperation = new DetailOperationVO();
                 $lDetailOperation->setIdOperation($lIdOperation);
                 $lDetailOperation->setIdCompte($lIdCompteFerme);
                 $lDetailOperation->setMontant($lProduit["prix"]);
                 $lDetailOperation->setLibelle('Bon de Commande');
                 $lDetailOperation->setTypePaiement(5);
                 //$lDetailOperation->setTypePaiementChampComplementaire($lProduit["id"]);
                 $lDetailOperation->setIdDetailCommande($lProduit["dcomId"]);
                 $lDetailOperationService->set($lDetailOperation);
             }
         }
         foreach ($lBonCommande as $lBon) {
             $lDelete = true;
             foreach ($lProduitsValide as $lProduit) {
                 if ($lProduit["dcomId"] == $lBon->getDcomId()) {
                     $lDelete = false;
                 }
             }
             if ($lDelete) {
                 $lStockService->delete($lBon->getStoId());
                 $lDetailOperationService->delete($lBon->getDopeId());
             }
         }
     }
     return $lVr;
 }