public function setUp() { $this->commande = new Commande(1, new Utilisateur(1, 'Kévin', 'Turmel', '26C Rue Pierre Brossolette', 53100, 'Mayenne', 'kdsjglkjdfklsjdfcgbnliuez', '*****@*****.**', 150), date('Y-m-d')); $articles = new Collection(); $article = new Article(); $article->setDescription('Bonjour')->setDesignation('ArticleTest 1')->setNumArt(2)->setPu(35)->setQte(5)->setQteStock(30)->setUrl('test'); $articles->ajouter($article); $article2 = new Article(); $article2->setDescription('Bo2')->setDesignation('ArticleTest 2')->setNumArt(1)->setPu(800)->setQte(8)->setQteStock(90)->setUrl('test'); $articles->ajouter($article2); $this->commande->setLesArticles($articles); }
/** * Retourne le prix total avec remise du contenu du panier * * @return float */ public function getPrixTotalWithRemise() { $prix = (double) 0; foreach ($this->collProduit->getCollection() as $unArticle) { /** @var Article $unArticle */ $prix += $unArticle->getMontant(); } return $prix * $this->getMultiplicateurRemise(); }
/** * Permet de récupérer les échéance de la Reservation passée en paramètre * * @param Reservation $reservation * * @return Collection * * @throws ErrorSQLException * @throws CollectionException */ public static function getEcheances(Reservation $reservation) { $lesEcheance = new Collection(); try { $conn = MConnexion::getBdd(); $req = $conn->prepare('SELECT * FROM echeance WHERE numRes = ?'); $req->execute([$reservation->getId()]); $fetchAll = $req->fetchAll(); foreach ($fetchAll as $fetch) { $echeance = new Echeance($reservation, $fetch['montant'], new \DateTime($fetch['dateEcheance'])); $echeance->setId($fetch['id']); $lesEcheance->ajouter($echeance); } } catch (\PDOException $e) { throw new ErrorSQLException($e->getMessage()); } return $lesEcheance; }
/** * Récupère les articles. * * @return Collection * * @throws ErrorSQLException * @throws CollectionException */ public static function getArticles() { $lesArticles = new Collection(); try { $conn = MConnexion::getBdd(); $reqPrepare = $conn->query('SELECT * FROM article'); $reqPrepare = $reqPrepare->fetchAll(); foreach ($reqPrepare as $unArticle) { $article = new Article(); $article->setNumArt($unArticle['numArt'])->setDesignation($unArticle['designation'])->setDescription($unArticle['description'])->setPu($unArticle['pu'])->setQteStock($unArticle['qteStock'])->setUrl($unArticle['url']); $lesArticles->ajouter($article); } $conn = null; return $lesArticles; } catch (PDOException $ex) { throw new ErrorSQLException('Aucun article trouvé.'); } }
/** * Récupère les commandes dont l'utilisateur est passé en paramètre. * * @param Utilisateur $unClient * @param bool $index * * @return Collection $lesCommandes * * @throws CollectionException * @throws ErrorSQLException */ public static function getCommandes(Utilisateur $unClient, $index = false) { $lesCommandes = new Collection(); try { $conn = MConnexion::getBdd(); $req = !$index ? $conn->prepare('SELECT * FROM commande WHERE numClt = ? ORDER BY date DESC') : $conn->prepare('SELECT * FROM commande WHERE numClt = ? ORDER BY date DESC LIMIT 2'); $req->execute(array($unClient->getId())); $req = $req->fetchAll(); foreach ($req as $tabs) { $uneCommande = new Commande($tabs['numCde'], $unClient, $tabs['date'], $tabs['pointsUtilise']); $uneCommande->setLesArticles(MCommander::getUneCommande($uneCommande)); $lesCommandes->ajouter($uneCommande); } } catch (PDOException $e) { throw new ErrorSQLException($e->getMessage()); } return $lesCommandes; }
/** * Récupère tous les vols disponibles (non partis) * * @return Collection * * @throws ErrorSQLException * @throws CollectionException */ public static function getVols() { $lesVols = new Collection(); try { $conn = MConnexion::getBdd(); $reqPrepare = $conn->query('SELECT * FROM vol WHERE DATE_ADD(CURDATE(), INTERVAL -1 DAY) < dateVol ORDER BY dateVol'); $conn = null; $reqPrepare = $reqPrepare->fetchAll(); foreach ($reqPrepare as $tabVol) { $unVol = new Vol(); $unVol->setNumVol($tabVol['numVol'])->setPrice($tabVol['prix'])->setDateVol($tabVol['dateVol'])->setHeureVol($tabVol['heureVol'])->setNbPlace($tabVol['nbPlace']); $lesVols->ajouter($unVol); } } catch (PDOException $ex) { throw new ErrorSQLException('Aucun vol n\'est disponible'); } return $lesVols; }
/** * Récupère les articles d'un commande via la commande. * * @param Commande $uneCommande numéro d'une commande * @param bool $index * * @return Collection * * @throws CollectionException * @throws ErrorSQLException */ public static function getUneCommande(Commande $uneCommande, $index = false) { $lesArticles = new Collection(); try { $conn = MConnexion::getBdd(); $conn->beginTransaction(); $req = !$index ? $conn->prepare('SELECT * FROM commander INNER JOIN article ON commander.numArt = article.numArt WHERE numCde = ? ORDER BY pu DESC') : $conn->prepare('SELECT * FROM commander INNER JOIN article ON commander.numArt = article.numArt WHERE numCde = ? ORDER BY pu DESC LIMIT 2'); $req->execute(array($uneCommande->getId())); $req = $req->fetchAll(); foreach ($req as $tabs) { $unArticle = MArticle::getArticle($tabs['numArt']); $unArticle->setQte($tabs['qte']); $lesArticles->ajouter($unArticle); } $conn->commit(); } catch (PDOException $e) { throw new ErrorSQLException('Impossible de récupérer la commande n°' . $uneCommande->getId() . ' Détails : ' . $e->getMessage()); } return $lesArticles; }
/** * Permet de valider la réservation en paramètre. Gère le paiement en plusieurs * échéances * * @param Utilisateur $unClient * @param Vol $unVol * @param Reservation $uneReservation * * @throws CollectionException * @throws ErrorSQLException */ public static function validerReservation(Utilisateur $unClient, Vol $unVol, Reservation $uneReservation) { $conn = MConnexion::getBdd(); try { $conn->beginTransaction(); $reqPrepare = $conn->prepare('INSERT INTO reservation (numClt,numVol,dateRes,nbPers) VALUES (?,?,?,?)'); $reqPrepare->execute([$unClient->getId(), $unVol->getNumVol(), $uneReservation->getDateRes()->format('Y-m-d H:i:s'), $uneReservation->getNbPers()]); $conn->commit(); $uneReservation->setValid(true); $conn->beginTransaction(); $lesEcheances = new Collection(); $uneAutreReservation = self::getReservationClient($unClient); if (array_key_exists('type', $_GET)) { if ($_GET['type'] === '3fois') { $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getFirstEcheancePrice(), new \DateTime()); MEcheance::addEcheance($echeance); $lesEcheances->ajouter($echeance); $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getOtherEcheancePrice(), new \DateTime('+1 months +1 days')); MEcheance::addEcheance($echeance); $lesEcheances->ajouter($echeance); $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getOtherEcheancePrice(), new \DateTime('+2 months +1 days')); MEcheance::addEcheance($echeance); $lesEcheances->ajouter($echeance); } else { $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getPriceReservation(), new \DateTime()); MEcheance::addEcheance($echeance); $lesEcheances->ajouter($echeance); } } $conn->commit(); $uneReservation->setLesEcheance($lesEcheances); $points = MUtilisateur::getPoints($unClient) - $uneReservation->getReduction(); MUtilisateur::setPoints($unClient, $points + Build::newPoints($uneReservation->getPriceReservation())); $conn = null; } catch (PDOException $e) { $conn->rollBack(); $uneReservation->setValid(false); throw new ErrorSQLException('Vous avez déjà une réservation. Veuillez contacter Nostromo pour annuler votre réservation.'); } }
/** * Récupère le nombre d'échéances de la réservation * * @return int */ public function getNbEcheance() { return $this->lesEcheance->taille(); }
require_once ROOT . 'src/Views/Panier/v_VoirPanier.php'; break; case 'enregistrerPanier': try { if (!array_key_exists('numCarte', $_POST)) { throw new \UnexpectedValueException('Les données saisies sont invalides. pas de post'); } if (strlen($_POST['numCarte']) !== 16) { throw new \UnexpectedValueException('Les données saisies sont invalides. 16 numéros carte'); } $datePost = new \DateTime($_POST['CBYear'] . '-' . $_POST['CBMonth'] . '-01'); if (new \DateTime() > $datePost) { throw new \UnexpectedValueException('Votre carte a expirée.'); } $uneCommande = new Commande(Connexion::getLastIdCommande(), $_SESSION['Utilisateur'], date('Y-m-d H:i:s')); $lesCommander = new Collection(); foreach ($_SESSION['Panier']->getProduitsPanier() as $unArticle) { $unCommander = new Commander(); $unCommander->setUnArticle($unArticle); $unCommander->setQte($unArticle->getQte()); $unCommander->setUneCommande($uneCommande); $lesCommander->ajouter($unCommander); } $uneCommande->setLesArticles($lesCommander); if ($_SESSION['Panier']->getPointsUtilise() > 0) { $uneCommande->setPointsUtilise($_SESSION['Panier']->getPointsUtilise()); } MCommande::ajouterCommande($uneCommande); foreach ($uneCommande->getLesArticles()->getCollection() as $unCommander) { MCommander::ajouterArticleCommande($unCommander); MArticle::updateQteStock($unCommander->getUnArticle(), $unCommander->getQte());