/** * @name remplirProduit($pId, $pIdCommande, $pIdNomProduit, $pUniteMesure, $pMaxProduitCommande, $pIdCompteFerme, $pStockReservation, $pStockInitial, $pType, $pEtat) * @param int(11) * @param int(11) * @param int(11) * @param varchar(20) * @param decimal(10,2) * @param int(11) * @param decimal(10,2) * @param decimal(10,2) * @param tinyint(4) * @param int(11) * @return ProduitVO * @desc Retourne une ProduitVO remplie */ private static function remplirProduit($pId, $pIdCommande, $pIdNomProduit, $pUniteMesure, $pMaxProduitCommande, $pIdCompteFerme, $pStockReservation, $pStockInitial, $pType, $pEtat) { $lProduit = new ProduitVO(); $lProduit->setId($pId); $lProduit->setIdCommande($pIdCommande); $lProduit->setIdNomProduit($pIdNomProduit); $lProduit->setUniteMesure($pUniteMesure); $lProduit->setMaxProduitCommande($pMaxProduitCommande); $lProduit->setIdCompteFerme($pIdCompteFerme); $lProduit->setStockReservation($pStockReservation); $lProduit->setStockInitial($pStockInitial); $lProduit->setType($pType); $lProduit->setEtat($pEtat); return $lProduit; }
/** * @name ajoutProduit($pProduit) * @param ProduitMarcheVO * @desc Ajoute une produit au marche */ public function ajoutProduit($pProduit) { $lComptes = CompteNomProduitViewManager::select($pProduit->getIdNom()); $lComptes = $lComptes[0]; $lIdCompteFerme = $lComptes->getFerIdCompte(); // Insertion du produit $lProduit = new ProduitVO(); $lProduit->setIdCommande($pProduit->getId()); $lProduit->setIdNomProduit($pProduit->getIdNom()); $lProduit->setUniteMesure($pProduit->getUnite()); if ($pProduit->getQteMaxCommande() == "" || $pProduit->getQteMaxCommande() == -1) { $lProduit->setMaxProduitCommande(-1); } else { $lProduit->setMaxProduitCommande($pProduit->getQteMaxCommande()); } $lProduit->setIdCompteFerme($lIdCompteFerme); if ($pProduit->getQteRestante() == "" || $pProduit->getQteRestante() == -1) { $lProduit->setStockReservation(0); $lProduit->setStockInitial(-1); } else { $lProduit->setStockReservation($pProduit->getQteRestante()); $lProduit->setStockInitial($pProduit->getQteRestante()); } $lProduit->setType($pProduit->getType()); $lIdProduit = ProduitManager::insert($lProduit); //Insertion des lots $lCorrespondanceLotAbonnement = array(); foreach ($pProduit->getLots() as $lNouveauLot) { $lDetailCommande = new DetailCommandeVO(); $lDetailCommande->setIdProduit($lIdProduit); $lDetailCommande->setTaille($lNouveauLot->getTaille()); $lDetailCommande->setPrix($lNouveauLot->getPrix()); $lDcomId = DetailCommandeManager::insert($lDetailCommande); $lCorrespondanceLotAbonnement[$lNouveauLot->getId()] = $lDcomId; } $lStockService = new StockService(); //Insertion du stock -> Met à jour le stock reservation dans le produit $lStock = new StockVO(); if ($pProduit->getQteRestante() == "" || $pProduit->getQteRestante() == -1) { $lStock->setQuantite(0); } else { $lStock->setQuantite($pProduit->getQteRestante()); } $lStock->setType(0); $lStock->setIdCompte($lIdCompteFerme); $lStock->setIdDetailCommande($lDcomId); //$lStock->setIdOperation(0); $lStockService->set($lStock); // Ajout des réservations pour abonnement if ($lProduit->getType() == 2) { $lIdMarche = $lProduit->getIdCommande(); $lMarche = $this->getInfoMarche($lIdMarche); $lAbonnementService = new AbonnementService(); $lReservationService = new ReservationService(); $lIdNomProduit = $lProduit->getIdNomProduit(); $lAbonnes = $lAbonnementService->getAbonnesByIdNomProduit($lIdNomProduit); if (!is_null($lAbonnes[0]->getCptAboIdProduitAbonnement())) { // Si il y a des abonnés foreach ($lAbonnes as $lAbonne) { // Pas de suspension de l'abonnement if (!(TestFonction::dateTimeEstPLusGrandeEgale($lMarche->getDateMarcheDebut(), $lAbonne->getCptAboDateDebutSuspension(), 'db') && TestFonction::dateTimeEstPLusGrandeEgale($lAbonne->getCptAboDateFinSuspension(), $lMarche->getDateMarcheDebut(), 'db')) && !(TestFonction::dateTimeEstPLusGrandeEgale($lMarche->getDateMarcheFin(), $lAbonne->getCptAboDateDebutSuspension(), 'db') && TestFonction::dateTimeEstPLusGrandeEgale($lAbonne->getCptAboDateFinSuspension(), $lMarche->getDateMarcheFin(), 'db'))) { $lIdCompte = $lAbonne->getCptAboIdCompte(); $lIdReservationVO = new IdReservationVO(); $lIdReservationVO->setIdCompte($lIdCompte); $lIdReservationVO->setIdCommande($lIdMarche); $lReservationVO = new ReservationVO(); $lReservationVO->setId($lIdReservationVO); if ($lReservationService->enCours($lIdReservationVO)) { $lReservationVO = $lReservationService->get($lIdReservationVO); } $lDetailCommande = DetailCommandeManager::select($lCorrespondanceLotAbonnement[$lAbonne->getCptAboIdLotAbonnement()]); $lPrix = $lAbonne->getCptAboQuantite() / $lDetailCommande->getTaille() * $lDetailCommande->getPrix(); $lDetailReservation = new DetailReservationVO(); $lDetailReservation->setIdDetailCommande($lCorrespondanceLotAbonnement[$lAbonne->getCptAboIdLotAbonnement()]); $lDetailReservation->setQuantite($lAbonne->getCptAboQuantite() * -1); $lDetailReservation->setMontant($lPrix * -1); $lReservationVO->addDetailReservation($lDetailReservation); $lReservationService->set($lReservationVO); } } } } return $lIdProduit; }