Exemplo n.º 1
0
 /**
  * Ajoute une échéance à la réservation en cours
  *
  * @param Echeance $echeance
  *
  * @throws ErrorSQLException
  */
 public static function addEcheance(Echeance $echeance)
 {
     $conn = MConnexion::getBdd();
     try {
         $conn->beginTransaction();
         $req = $conn->prepare('INSERT INTO echeance (numRes, montant, dateEcheance) VALUES (?,?,?)');
         $req->execute([$echeance->getReservation()->getId(), $echeance->getMontant(), $echeance->getDate()->format('Y-m-d H:i:s')]);
         $conn->commit();
     } catch (\PDOException $e) {
         $conn->rollBack();
         throw new ErrorSQLException($e->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * Met à jour le stock de l'article passé en paramètre
  * lorsqu'un client finalise sa commande
  *
  * @param Article $article
  * @param int $qteCommande
  * @throws ErrorSQLException
  */
 public static function updateQteStock(Article $article, $qteCommande)
 {
     $conn = MConnexion::getBdd();
     try {
         $conn->beginTransaction();
         $req = $conn->prepare('UPDATE article SET qteStock = ? WHERE numArt = ?');
         $qte = $article->getQteStock() - $qteCommande < 0 ? 0 : $article->getQteStock() - $qteCommande;
         $req->execute([$qte, $article->getNumArt()]);
         $conn->commit();
         $conn = null;
     } catch (PDOException $e) {
         $conn->rollBack();
         throw new ErrorSQLException($e->getMessage());
     }
 }
Exemplo n.º 3
0
 /**
  * Enregistre la commande finalisée du client
  *
  * @param Commande $uneCommande
  * @throws ErrorSQLException
  */
 public static function ajouterCommande(Commande $uneCommande)
 {
     try {
         $conn = MConnexion::getBdd();
         $conn->beginTransaction();
         $reqPrepare = $conn->prepare('INSERT INTO commande
             (numClt,date,pointsUtilise)
             VALUES (?,?,?)');
         $reqPrepare->execute([$uneCommande->getUnClient()->getId(), $uneCommande->getUneDate(), $uneCommande->getPointsUtilise()]);
         $conn->commit();
         $conn = null;
     } catch (PDOException $ex) {
         $conn->rollBack();
         throw new ErrorSQLException('Impossible de continuer la validation de la commande. Détails : ' . $ex->getMessage());
     }
 }
Exemplo n.º 4
0
 /**
  * Enregistre les articles d'une commande du client en cours
  *
  * @param Commander $unCommander
  *
  * @throws ErrorSQLException
  */
 public static function ajouterArticleCommande(Commander $unCommander)
 {
     try {
         $conn = MConnexion::getBdd();
         $conn->beginTransaction();
         $reqPrepare = $conn->prepare('INSERT INTO commander
             (numArt, numCde, qte)
             VALUES (?,?,?)');
         $reqPrepare->execute([$unCommander->getUnArticle()->getNumArt(), $unCommander->getUneCommande()->getId(), $unCommander->getQte()]);
         $conn->commit();
         $conn = null;
     } catch (PDOException $ex) {
         $conn->rollBack();
         throw new ErrorSQLException('Impossible de continuer la validation de la commande. Détails : ' . $ex->getMessage());
     }
 }
Exemplo n.º 5
0
 /**
  * Récupère la réservation en cours du client
  *
  * @param Utilisateur $unClient
  *
  * @return Reservation
  *
  * @throws CollectionException
  * @throws ErrorSQLException
  */
 public static function getReservationClient(Utilisateur $unClient)
 {
     $uneReservation = new Reservation();
     try {
         $conn = MConnexion::getBdd();
         $reqPrepare = $conn->prepare('SELECT reservation.numVol,
                                         reservation.numRes,
                                         dateRes, nbPers, montant,
                                         dateEcheance
                                         FROM reservation
                                         LEFT JOIN echeance ON reservation.numRes = echeance.numRes
                                         INNER JOIN vol ON reservation.numVol = vol.numVol
                                         WHERE NumClt = ? AND curdate() < vol.dateVol');
         $reqPrepare->execute([$unClient->getId()]);
         $fetch = $reqPrepare->fetch();
         $unVol = MVol::getUnVol($fetch['numVol']);
         $uneReservation->setId($fetch['numRes'])->setUnVol($unVol)->setUnClient($unClient)->setDateRes($fetch['dateRes'])->setNbPers($fetch['nbPers'])->setValid(true);
         $lesEcheances = MEcheance::getEcheances($uneReservation);
         $uneReservation->setLesEcheance($lesEcheances);
         $conn = null;
     } catch (PDOException $e) {
         echo $e->getMessage();
         throw new ErrorSQLException('Impossible de récupérer la réservation de ' . $unClient->getMail() . ' Détails : ' . $e->getMessage());
     }
     return $uneReservation;
 }
Exemplo n.º 6
0
 /**
  * Met à jour le nombre de points d'un client
  *
  * @param Utilisateur $user
  * @param int $points
  *
  * @throws ErrorSQLException
  */
 public static function setPoints(Utilisateur $user, $points)
 {
     try {
         $conn = MConnexion::getBdd();
         $reqPrepare = $conn->prepare('UPDATE client SET pointsClt = ? WHERE numClt = ?');
         $reqPrepare->execute([$points, $user->getId()]);
         $user->setPoints($points);
         $conn = null;
     } catch (PDOException $ex) {
         throw new ErrorSQLException("L'utilisateur n°{$user->getId()} n'existe pas.");
     }
 }
Exemplo n.º 7
0
 /**
  * Récupère le temps avant qu'un vol ne parte
  *
  * @param Vol $unVol
  *
  * @return string
  *
  * @throws ErrorSQLException
  * @throws InvalidArgumentException
  */
 public static function getTimer(Vol $unVol)
 {
     if (null === $unVol) {
         throw new InvalidArgumentException('Le vol ne peut pas être null');
     }
     try {
         $conn = MConnexion::getBdd();
         $req = $conn->prepare('SELECT * FROM vol WHERE dateVol = ?');
         $req->execute([$unVol->getNonFormatDate()]);
         $fetch = $req->fetch();
         $tmp = new \DateTime($fetch['dateVol'] . ' ' . $fetch['heureVol']);
         $tmp->modify('-1 months');
         return $tmp->format('Y, m, d, H, i, s');
     } catch (PDOException $e) {
         throw new ErrorSQLException($e->getMessage());
     }
 }