From d53681a7ad7e1a99bc61107106e1be41b934bb16 Mon Sep 17 00:00:00 2001 From: "e.elhjoujy" Date: Mon, 23 Oct 2023 20:00:10 +0100 Subject: [PATCH] =?UTF-8?q?Annuler=20R=C3=A9servation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yaml | 15 +++ .../Client/MainReservation.java | 2 +- .../ma/yc/airafraik/core/EmailProvider.java | 2 +- src/main/java/ma/yc/airafraik/core/Util.java | 7 ++ .../dao/Impl/ReservationDaoImpl.java | 28 ++++- .../ma/yc/airafraik/dao/Impl/VolDaoImpl.java | 24 ++++ .../ma/yc/airafraik/dao/ReservationDao.java | 6 +- src/main/java/ma/yc/airafraik/dao/VolDao.java | 2 + .../yc/airafraik/entities/BagageEntity.java | 18 +++ .../yc/airafraik/enums/ReservationStatus.java | 2 +- .../airafraik/service/ReservationService.java | 8 +- ...earchVolsService.java => VolsService.java} | 5 +- .../service/impl/ReservationServiceImpl.java | 98 ++++++++++++++- .../service/impl/VolServiceImpl.java | 8 +- ...sServiceImpl.java => VolsServiceImpl.java} | 14 ++- .../airafraik/web/Admin/AvionController.java | 2 - .../web/Admin/DashboardController.java | 73 ++++++++++- .../yc/airafraik/web/Admin/VolController.java | 13 +- .../web/AnnulerReservationController.java | 35 ++++++ .../airafraik/web/RechercheVolController.java | 10 +- .../web/RservationConfirmationController.java | 12 +- .../web/RservationDetailsController.java | 11 +- src/main/resources/META-INF/persistence.xml | 10 +- src/main/webapp/annuler-reservation.jsp | 44 +++++++ src/main/webapp/templates/footer.jsp | 18 +-- src/main/webapp/templates/head.jsp | 1 - src/main/webapp/views/admin/dashboard.jsp | 114 ++++++++++++------ 27 files changed, 464 insertions(+), 118 deletions(-) create mode 100644 src/main/java/ma/yc/airafraik/entities/BagageEntity.java rename src/main/java/ma/yc/airafraik/service/{SearchVolsService.java => VolsService.java} (79%) rename src/main/java/ma/yc/airafraik/service/impl/{SearchVolsServiceImpl.java => VolsServiceImpl.java} (81%) create mode 100644 src/main/java/ma/yc/airafraik/web/AnnulerReservationController.java create mode 100644 src/main/webapp/annuler-reservation.jsp diff --git a/docker-compose.yaml b/docker-compose.yaml index b314006..9abb225 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,6 +16,21 @@ services: networks: - db restart: unless-stopped + airafraik_test: + image: postgres + environment: + POSTGRES_USER: ${USER} + POSTGRES_PASSWORD: ${PASSWORD} + POSTGRES_DB: ${DATABASE} + PGUSER: ${USER} + PGDATA: /data/postgres + volumes: + - db:/data/postgres + ports: + - "5331:5431" + networks: + - db + restart: unless-stopped networks: db: diff --git a/src/main/java/ma/yc/airafraik/FunctionalTest/Client/MainReservation.java b/src/main/java/ma/yc/airafraik/FunctionalTest/Client/MainReservation.java index 7314be8..5d3eb85 100644 --- a/src/main/java/ma/yc/airafraik/FunctionalTest/Client/MainReservation.java +++ b/src/main/java/ma/yc/airafraik/FunctionalTest/Client/MainReservation.java @@ -100,7 +100,7 @@ public static void confirmationReservation(){ // //TODO : CONFIRMATION if (false){ - reservationEntity.setStatus(ReservationStatus.CONFIRMED); + reservationEntity.setStatus(ReservationStatus.CONFIRMER); } diff --git a/src/main/java/ma/yc/airafraik/core/EmailProvider.java b/src/main/java/ma/yc/airafraik/core/EmailProvider.java index b6cd7ab..9aba1ed 100644 --- a/src/main/java/ma/yc/airafraik/core/EmailProvider.java +++ b/src/main/java/ma/yc/airafraik/core/EmailProvider.java @@ -43,7 +43,7 @@ protected PasswordAuthentication getPasswordAuthentication() { message.setFrom(new InternetAddress(username)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject(subject); - message.setText("Here is the code of verification authentic: "+body); + message.setText(body); Transport.send(message); return true; } catch (MessagingException e) { diff --git a/src/main/java/ma/yc/airafraik/core/Util.java b/src/main/java/ma/yc/airafraik/core/Util.java index 965b38d..219639d 100644 --- a/src/main/java/ma/yc/airafraik/core/Util.java +++ b/src/main/java/ma/yc/airafraik/core/Util.java @@ -151,6 +151,13 @@ public static VolEntity getVolEntity() { return vol; } + public static Date addHours(int i) { + Print.log("i : "+i); + Date date =new Date(new Date().getTime() + i * 60 * 60 * 1000); + return date; + + } + //add more helper method //todo : work with local storage to store information public boolean storeInformation(String key , String value){ diff --git a/src/main/java/ma/yc/airafraik/dao/Impl/ReservationDaoImpl.java b/src/main/java/ma/yc/airafraik/dao/Impl/ReservationDaoImpl.java index f2414dd..8e6bd19 100644 --- a/src/main/java/ma/yc/airafraik/dao/Impl/ReservationDaoImpl.java +++ b/src/main/java/ma/yc/airafraik/dao/Impl/ReservationDaoImpl.java @@ -57,7 +57,9 @@ public Collection consulterReservations() { @Override public Collection consulterReservations(String code) { - return null; + Query query = entityManager.createNativeQuery("SELECT * FROM reservation where code = :code",ReservationEntity.class); + query.setParameter("code",code); + return (Collection) query.getResultList(); } @@ -78,7 +80,7 @@ public ArrayList AfficheLesStatistiques(HashMap reservationEntities = (ArrayList) query.getResultList(); return reservationEntities; @@ -93,4 +95,26 @@ public ArrayList AfficheLesStatistiques(HashMap reservationEntities = (ArrayList) query.getResultList(); return reservationEntities; } + + @Override + public int statisticsReservation(ReservationStatus reservationStatus, String mois) { + this.entityManager.createNativeQuery("SELECT count(*) FROM reservation WHERE status = :status AND date_reservation LIKE :mois") + .setParameter("status",reservationStatus.toString()) + .setParameter("mois",mois) + .getSingleResult(); + return 0; + } + + @Override + public boolean annulerReservation(ReservationEntity reservationEntity) { + if (reservationEntity == null){ + return false; + } + + this.transaction.begin(); + ReservationEntity reservationEntity1 = entityManager.find(ReservationEntity.class, reservationEntity.getId()); + reservationEntity1.setStatus(ReservationStatus.ANNULER); + this.transaction.commit(); + return false; + } } diff --git a/src/main/java/ma/yc/airafraik/dao/Impl/VolDaoImpl.java b/src/main/java/ma/yc/airafraik/dao/Impl/VolDaoImpl.java index d36e7d7..61d1932 100644 --- a/src/main/java/ma/yc/airafraik/dao/Impl/VolDaoImpl.java +++ b/src/main/java/ma/yc/airafraik/dao/Impl/VolDaoImpl.java @@ -236,5 +236,29 @@ public Collection consulterVols() { return volEntities; } + @Override + public boolean deleteVol(String idVol) { + Integer id = Integer.parseInt(idVol); + String jpql = "DELETE FROM VolEntity v WHERE v.id = :code"; + Query query = entityManager.createQuery(jpql); + query.setParameter("code", id); + try { + transaction.begin(); + if (query.executeUpdate() > 0) { + Print.log("Vol supprimé avec succès"); + transaction.commit(); + return true; + } + Print.log("Erreur lors de la suppression du vol"); + transaction.rollback(); + }catch (Exception e){ + if (transaction != null && transaction.isActive()) { + transaction.rollback(); // Rollback the transaction in case of an exception + } + + } + return false; + } + } diff --git a/src/main/java/ma/yc/airafraik/dao/ReservationDao.java b/src/main/java/ma/yc/airafraik/dao/ReservationDao.java index bf2c234..4e136b3 100644 --- a/src/main/java/ma/yc/airafraik/dao/ReservationDao.java +++ b/src/main/java/ma/yc/airafraik/dao/ReservationDao.java @@ -26,9 +26,7 @@ public interface ReservationDao { public ArrayList AfficheLesStatistiques(HashMap conditions, ReservationStatus reservationStatus); public ArrayList lesRservationConfirmésPendantMoisOuAns(HashMap conditions); public ArrayList lesRservationAnnulésPendantMoisOuAns(HashMap conditions); + int statisticsReservation(ReservationStatus reservationStatus, String mois); - - - - + boolean annulerReservation(ReservationEntity reservationEntity); } diff --git a/src/main/java/ma/yc/airafraik/dao/VolDao.java b/src/main/java/ma/yc/airafraik/dao/VolDao.java index 9f6ab6a..c81b5b0 100644 --- a/src/main/java/ma/yc/airafraik/dao/VolDao.java +++ b/src/main/java/ma/yc/airafraik/dao/VolDao.java @@ -25,4 +25,6 @@ public interface VolDao { public VolEntity consulterVol(String id); public ArrayList consulterVols(HashMap conditions); public Collection consulterVols(); + + boolean deleteVol(String idVol); } diff --git a/src/main/java/ma/yc/airafraik/entities/BagageEntity.java b/src/main/java/ma/yc/airafraik/entities/BagageEntity.java new file mode 100644 index 0000000..29f0c9d --- /dev/null +++ b/src/main/java/ma/yc/airafraik/entities/BagageEntity.java @@ -0,0 +1,18 @@ +package ma.yc.airafraik.entities; + +import jakarta.persistence.*; + +@Entity +@Table(name = "bagage") +public class BagageEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id ; + + private double poids ; + @ManyToOne + private ReservationEntity reservation ; + + +} diff --git a/src/main/java/ma/yc/airafraik/enums/ReservationStatus.java b/src/main/java/ma/yc/airafraik/enums/ReservationStatus.java index f31a9b9..4b68fb5 100644 --- a/src/main/java/ma/yc/airafraik/enums/ReservationStatus.java +++ b/src/main/java/ma/yc/airafraik/enums/ReservationStatus.java @@ -1,7 +1,7 @@ package ma.yc.airafraik.enums; public enum ReservationStatus { - CONFIRMED, + CONFIRMER, EN_ATTENTE, ANNULER , EXPIRE diff --git a/src/main/java/ma/yc/airafraik/service/ReservationService.java b/src/main/java/ma/yc/airafraik/service/ReservationService.java index d297364..b20f40c 100644 --- a/src/main/java/ma/yc/airafraik/service/ReservationService.java +++ b/src/main/java/ma/yc/airafraik/service/ReservationService.java @@ -1,9 +1,15 @@ package ma.yc.airafraik.service; import ma.yc.airafraik.entities.ReservationEntity; +import ma.yc.airafraik.enums.ReservationStatus; + +import java.util.HashMap; public interface ReservationService { public double confirmationReservation(ReservationEntity reservationEntity); - public double annulationReservation(ReservationEntity reservationEntity); + public ReservationEntity annulationReservation(ReservationEntity reservationEntity); + public boolean annulationReservation(String numeroReservation); public boolean envoyerEmail(ReservationEntity reservationEntity); + + int statisticsReservation(ReservationStatus reservationStatus, HashMap conditions); } diff --git a/src/main/java/ma/yc/airafraik/service/SearchVolsService.java b/src/main/java/ma/yc/airafraik/service/VolsService.java similarity index 79% rename from src/main/java/ma/yc/airafraik/service/SearchVolsService.java rename to src/main/java/ma/yc/airafraik/service/VolsService.java index 205e353..4b59e3e 100644 --- a/src/main/java/ma/yc/airafraik/service/SearchVolsService.java +++ b/src/main/java/ma/yc/airafraik/service/VolsService.java @@ -1,11 +1,10 @@ package ma.yc.airafraik.service; -import ma.yc.airafraik.entities.ReservationEntity; import ma.yc.airafraik.entities.VolEntity; import java.util.Collection; -public interface SearchVolsService { +public interface VolsService { public Collection searchVols(String villeDepart, String villeArrivee, String dateDepart, String dateArrivee, String nombrePassagers); @@ -13,4 +12,6 @@ public interface SearchVolsService { VolEntity searchVolParId(String id); Collection consulterVols(); + + boolean deleteVol(String idVol); } diff --git a/src/main/java/ma/yc/airafraik/service/impl/ReservationServiceImpl.java b/src/main/java/ma/yc/airafraik/service/impl/ReservationServiceImpl.java index c2b7a27..c66a826 100644 --- a/src/main/java/ma/yc/airafraik/service/impl/ReservationServiceImpl.java +++ b/src/main/java/ma/yc/airafraik/service/impl/ReservationServiceImpl.java @@ -1,14 +1,23 @@ package ma.yc.airafraik.service.impl; import ma.yc.airafraik.FunctionalTest.Client.ConfirmationReservationEtEnvoyeEmail; +import ma.yc.airafraik.core.EmailProvider; +import ma.yc.airafraik.core.Print; import ma.yc.airafraik.core.Util; import ma.yc.airafraik.dao.Impl.ReservationDaoImpl; import ma.yc.airafraik.dao.ReservationDao; import ma.yc.airafraik.entities.ReservationEntity; +import ma.yc.airafraik.entities.VolEntity; +import ma.yc.airafraik.enums.ReservationStatus; import ma.yc.airafraik.enums.ReserveType; import ma.yc.airafraik.service.PaiementService; import ma.yc.airafraik.service.ReservationService; +import java.awt.font.TextHitInfo; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; + public class ReservationServiceImpl implements ReservationService { private PaiementService paiementService ; @@ -59,7 +68,13 @@ public double confirmationReservation(ReservationEntity reservationEntity) { return 0; }else { //TODO : SEEND EMAIL TO CLIENT WITH HIS RESERVATION CODE AND PDF FILE - this.envoyerEmail(reservationEntity); + if (this.envoyerEmail(reservationEntity)) + { + Print.log("Email sent successfully"); + }else { + Print.log("Email not sent"); + throw new RuntimeException("Email not sent"); + } } @@ -67,16 +82,91 @@ public double confirmationReservation(ReservationEntity reservationEntity) { } @Override - public double annulationReservation(ReservationEntity reservationEntity) { + public ReservationEntity annulationReservation(ReservationEntity reservationEntity) { //TODO : annuler sa réservation après la confirmation de son vol dans le cas d'annulation: // 8% des frais est retenue pour la société AirAfrika > 24h avant le vol - return 1; + return null; } @Override - public boolean envoyerEmail(ReservationEntity reservationEntity) { + public boolean annulationReservation(String numeroReservation) { + + if (numeroReservation == null){ + return false; + } + //TODO : annuler sa réservation après la confirmation de son vol dans le cas d'annulation: + // 8% des frais est retenue pour la société AirAfrika > 24h avant le vol + + Collection reservationEntities = this.reservationDao.consulterReservations(numeroReservation); + if (reservationEntities == null){ + return false; + } + for (ReservationEntity reservationEntity : reservationEntities){ + if (reservationEntity == null){ + return false; + } + if (reservationEntity.getStatus() == ReservationStatus.CONFIRMER || reservationEntity.getStatus() == ReservationStatus.EN_ATTENTE){ + //TODO : THE CLIENT CAN'T CANCEL HIS RESERVATION AFTER 24H BEFORE THE FLIGHT + reservationEntity.setStatus(ReservationStatus.ANNULER); + + for (VolEntity vol : reservationEntity.getVolEntities()){ + if (vol == null){ + return false; + } + if (vol.getDateDepart().before(Util.addHours(24))){ + return false; + }else { + //TODO : THE CLIENT WILL PAY 8% OF THE TOTAL COST OF THE FLIGHT + double totalCost = reservationEntity.getPrixTotal(); + double cost = totalCost * 0.08; + reservationEntity.setPrixTotal(totalCost - cost); + return this.reservationDao.annulerReservation(reservationEntity); + } + } + + } + } + return false; } + + @Override + public boolean envoyerEmail(ReservationEntity reservationEntity) { + if (reservationEntity == null){ + return false; + } + String email = "souirimehdi311@gmail.com"; + String subject = "Confirmation de votre réservation"; + String message = "Bonjour Mr/Mme "+reservationEntity.getClient().getNom()+" "+reservationEntity.getClient().getPrenom()+"\n" + + "Nous vous confirmons votre réservation de vol avec la compagnie Air Afraik\n" + + "Votre code de réservation est : "+reservationEntity.getCode()+"\n" + + "Merci de votre confiance\n" + + "Cordialement\n" + + "Air Afraik"; + + + return EmailProvider.sendMail(message,subject,email); + + } + + @Override + public int statisticsReservation(ReservationStatus reservationStatus,HashMap conditions) { + + + //TODO : THE CLIENT WIL CHOOSE TWO DATE CALLED DATE_1 AND DATE_2 FROM THE CALENDER + + + if (reservationStatus == null || conditions == null){ + return 0; + } + + ArrayList reservationEntities = + reservationDao.AfficheLesStatistiques(conditions, reservationStatus); + + + return reservationEntities.size(); + + } } diff --git a/src/main/java/ma/yc/airafraik/service/impl/VolServiceImpl.java b/src/main/java/ma/yc/airafraik/service/impl/VolServiceImpl.java index 731e307..1f4d154 100644 --- a/src/main/java/ma/yc/airafraik/service/impl/VolServiceImpl.java +++ b/src/main/java/ma/yc/airafraik/service/impl/VolServiceImpl.java @@ -3,18 +3,18 @@ import ma.yc.airafraik.dao.Impl.VolDaoImpl; import ma.yc.airafraik.dao.VolDao; import ma.yc.airafraik.entities.VolEntity; -import ma.yc.airafraik.service.SearchVolsService; +import ma.yc.airafraik.service.VolsService; import ma.yc.airafraik.service.VolService; public class VolServiceImpl implements VolService { private VolDao volDao; - private SearchVolsService searchVolsService; + private VolsService volsService; public VolServiceImpl() { this.volDao = new VolDaoImpl(); - this.searchVolsService = new SearchVolsServiceImpl(); + this.volsService = new VolsServiceImpl(); } @Override @@ -25,7 +25,7 @@ public boolean ajouterVol(VolEntity vol) { @Override public boolean supprimerVol(String id) { - VolEntity vol = this.searchVolsService.searchVolParId(id); + VolEntity vol = this.volsService.searchVolParId(id); return this.volDao.supprimerVol(vol); } } diff --git a/src/main/java/ma/yc/airafraik/service/impl/SearchVolsServiceImpl.java b/src/main/java/ma/yc/airafraik/service/impl/VolsServiceImpl.java similarity index 81% rename from src/main/java/ma/yc/airafraik/service/impl/SearchVolsServiceImpl.java rename to src/main/java/ma/yc/airafraik/service/impl/VolsServiceImpl.java index 62ccbbc..79798b3 100644 --- a/src/main/java/ma/yc/airafraik/service/impl/SearchVolsServiceImpl.java +++ b/src/main/java/ma/yc/airafraik/service/impl/VolsServiceImpl.java @@ -2,18 +2,17 @@ import ma.yc.airafraik.dao.Impl.VolDaoImpl; import ma.yc.airafraik.dao.VolDao; -import ma.yc.airafraik.entities.ReservationEntity; import ma.yc.airafraik.entities.VolEntity; +import ma.yc.airafraik.service.VolsService; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -public class SearchVolsServiceImpl implements ma.yc.airafraik.service.SearchVolsService{ +public class VolsServiceImpl implements VolsService { private VolDao volDao ; - public SearchVolsServiceImpl() { + public VolsServiceImpl() { this.volDao = new VolDaoImpl(); } @@ -45,4 +44,11 @@ public VolEntity searchVolParId(String id) { public Collection consulterVols() { return this.volDao.consulterVols(); } + + @Override + public boolean deleteVol(String idVol) { + + if (idVol == null) return false; + return this.volDao.deleteVol(idVol); + } } diff --git a/src/main/java/ma/yc/airafraik/web/Admin/AvionController.java b/src/main/java/ma/yc/airafraik/web/Admin/AvionController.java index cd64eee..3d99e10 100644 --- a/src/main/java/ma/yc/airafraik/web/Admin/AvionController.java +++ b/src/main/java/ma/yc/airafraik/web/Admin/AvionController.java @@ -5,11 +5,9 @@ import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import ma.yc.airafraik.core.Print; import ma.yc.airafraik.entities.AvionEntity; import ma.yc.airafraik.entities.VolEntity; import ma.yc.airafraik.service.AvionService; -import ma.yc.airafraik.service.SearchVolsService; import ma.yc.airafraik.service.VolService; import ma.yc.airafraik.service.impl.VolServiceImpl; diff --git a/src/main/java/ma/yc/airafraik/web/Admin/DashboardController.java b/src/main/java/ma/yc/airafraik/web/Admin/DashboardController.java index 22ad65a..c739305 100644 --- a/src/main/java/ma/yc/airafraik/web/Admin/DashboardController.java +++ b/src/main/java/ma/yc/airafraik/web/Admin/DashboardController.java @@ -6,45 +6,105 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import ma.yc.airafraik.entities.VolEntity; +import ma.yc.airafraik.enums.ReservationStatus; import ma.yc.airafraik.service.AccountService; import ma.yc.airafraik.service.AvionService; -import ma.yc.airafraik.service.SearchVolsService; +import ma.yc.airafraik.service.ReservationService; +import ma.yc.airafraik.service.VolsService; import ma.yc.airafraik.service.impl.AccountAdminServiceImpl; import ma.yc.airafraik.service.impl.AvionServiceImpl; -import ma.yc.airafraik.service.impl.SearchVolsServiceImpl; +import ma.yc.airafraik.service.impl.ReservationServiceImpl; +import ma.yc.airafraik.service.impl.VolsServiceImpl; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Collection; +import java.util.Date; +import java.util.HashMap; -@WebServlet(name = "DashboardController", value = "/admin-dashboard") +@WebServlet(name = "DashboardController", value = {"/admin-dashboard","/admin-delete-vol","/admin-add-vol","/admin-update-vol","/admin-add-avion","/admin-delete-avion","/admin-update-avion"}) public class DashboardController extends HttpServlet { private AccountService accountService ; private boolean isAccountValid = true; private String message; - private SearchVolsService searchVolsService; + private VolsService volsService; private AvionService avionService; + private ReservationService reservationService; @Override public void init() throws ServletException { this.accountService = new AccountAdminServiceImpl(); - this.searchVolsService = new SearchVolsServiceImpl(); + this.volsService = new VolsServiceImpl(); this.avionService = new AvionServiceImpl(); + this.reservationService = new ReservationServiceImpl(); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // this.verifyAccount(req,resp); + if (req.getServletPath().equals("/admin-delete-vol")){ + String idVol = req.getParameter("idVol"); + boolean IsDeleted = this.volsService.deleteVol(idVol); + + if (IsDeleted){ + message = "Vol supprimé avec succès"; + }else{ + message = "Erreur lors de la suppression du vol"; + } + } + req.setAttribute("message",message); - Collection volEntities = this.searchVolsService.consulterVols(); + Collection volEntities = this.volsService.consulterVols(); req.setAttribute("vols",volEntities); req.setAttribute("avions",this.avionService.consulterAvions()); + + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Calendar calendar = Calendar.getInstance(); + +// Get the current year + int currentYear = calendar.get(Calendar.YEAR); + +// Calculate dynamic dates for the current year + String currentYearStartDate = currentYear + "-01-01"; + String currentYearEndDate = currentYear + "-12-31"; + + int nbrReservationAnullerAnnee = this.reservationService.statisticsReservation(ReservationStatus.ANNULER, generateConditions(currentYearStartDate, currentYearEndDate)); + int nbrReservationConfirmerAnnee = this.reservationService.statisticsReservation(ReservationStatus.CONFIRMER, generateConditions(currentYearStartDate, currentYearEndDate)); + + Date currentDate = new Date(); + calendar.setTime(currentDate); + + String currentMonthStartDate = dateFormat.format(calendar.getTime()); + calendar.add(Calendar.MONTH, 1); // Add one month to get the end of the current month + calendar.add(Calendar.DATE, -1); // Subtract one day to get the last day of the current month + String currentMonthEndDate = dateFormat.format(calendar.getTime()); + + int nbrReservationConfirmerMois = this.reservationService.statisticsReservation(ReservationStatus.CONFIRMER, generateConditions(currentMonthStartDate, currentMonthEndDate)); + int nbrReservationAnullerMois = this.reservationService.statisticsReservation(ReservationStatus.ANNULER, generateConditions(currentYearStartDate, currentMonthEndDate)); + + + + req.setAttribute("nbrReservationAnullerMois",nbrReservationAnullerMois); + req.setAttribute("nbrReservationAnullerAnnee",nbrReservationAnullerAnnee); + req.setAttribute("nbrReservationConfirmerMois",nbrReservationConfirmerMois); + req.setAttribute("nbrReservationConfirmerAnnee",nbrReservationConfirmerAnnee); + req.setAttribute("message",message); req.getRequestDispatcher("views/admin/dashboard.jsp").forward(req,resp); } + public HashMap generateConditions(String startDate, String endDate) { + HashMap conditions = new HashMap<>(); + conditions.put("date_1", startDate); + conditions.put("date_2", endDate); + return conditions; + } + private void verifyAccount(HttpServletRequest req, HttpServletResponse resp) { // ma.yc.airafraik.dto.Account account = (ma.yc.airafraik.dto.Account) req.getSession().getAttribute("account"); // if(account != null){ @@ -70,6 +130,7 @@ protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws S @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + super.doPost(req, resp); } diff --git a/src/main/java/ma/yc/airafraik/web/Admin/VolController.java b/src/main/java/ma/yc/airafraik/web/Admin/VolController.java index aae2b4c..828b5f5 100644 --- a/src/main/java/ma/yc/airafraik/web/Admin/VolController.java +++ b/src/main/java/ma/yc/airafraik/web/Admin/VolController.java @@ -90,12 +90,15 @@ protected void doPost(HttpServletRequest request, HttpServletResponse resp) thro vol.setPrix(prix); - if (this.volService.ajouterVol(vol)) - request.setAttribute("message","Avion ajouté avec succès"); - else - request.setAttribute("message","Erreur lors de l'ajout de l'avion"); -// req.getRequestDispatcher("views/admin/dashboard.jsp").forward(req,resp); + if (this.volService.ajouterVol(vol)) { + message = "Vol ajouté avec succès"; + request.setAttribute("message", message); + }else { + message = "Erreur lors de l'ajout du vol"; + request.setAttribute("message", message); + } +// request.getRequestDispatcher("views/admin/dashboard.jsp").forward(request,resp); resp.sendRedirect("admin-dashboard"); } } diff --git a/src/main/java/ma/yc/airafraik/web/AnnulerReservationController.java b/src/main/java/ma/yc/airafraik/web/AnnulerReservationController.java new file mode 100644 index 0000000..ea16e1d --- /dev/null +++ b/src/main/java/ma/yc/airafraik/web/AnnulerReservationController.java @@ -0,0 +1,35 @@ +package ma.yc.airafraik.web; + + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import ma.yc.airafraik.service.ReservationService; +import ma.yc.airafraik.service.impl.ReservationServiceImpl; + +import java.io.IOException; + +@WebServlet(name = "annulerReservationController", urlPatterns = "/annulerReservation") +public class AnnulerReservationController extends HttpServlet { + private ReservationService reservationService ; + @Override + public void init() throws ServletException { + this.reservationService = new ReservationServiceImpl(); + super.init(); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + req.getRequestDispatcher("annuler-reservation.jsp").forward(req, resp); + super.doGet(req, resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String numeroReservation = req.getParameter("reservationNumber"); + boolean isCannled = this.reservationService.annulationReservation(numeroReservation); + req.getRequestDispatcher("thank-you.jsp").forward(req, resp); + } +} diff --git a/src/main/java/ma/yc/airafraik/web/RechercheVolController.java b/src/main/java/ma/yc/airafraik/web/RechercheVolController.java index 46d51d9..5e655ff 100644 --- a/src/main/java/ma/yc/airafraik/web/RechercheVolController.java +++ b/src/main/java/ma/yc/airafraik/web/RechercheVolController.java @@ -9,8 +9,8 @@ import jakarta.servlet.http.HttpServletResponse; import ma.yc.airafraik.core.Print; import ma.yc.airafraik.entities.VolEntity; -import ma.yc.airafraik.service.SearchVolsService; -import ma.yc.airafraik.service.impl.SearchVolsServiceImpl; +import ma.yc.airafraik.service.VolsService; +import ma.yc.airafraik.service.impl.VolsServiceImpl; import java.io.IOException; import java.util.Collection; @@ -18,12 +18,12 @@ @WebServlet(name = "RechercheVolController", value = "/recherche") public class RechercheVolController extends HttpServlet { - private SearchVolsService searchVolsService ; + private VolsService volsService; private ServletContext context; @Override public void init(ServletConfig config) throws ServletException { - this.searchVolsService = new SearchVolsServiceImpl(); + this.volsService = new VolsServiceImpl(); this.context = config.getServletContext(); } @@ -56,7 +56,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se req.getRequestDispatcher("index.jsp").forward(req, resp); }else{ //TODO : if those information are not null then we will search for the vols - Collection vols = searchVolsService.searchVols(origin,depart,departuredate,retourdate,"1"); + Collection vols = volsService.searchVols(origin,depart,departuredate,retourdate,"1"); req.setAttribute("vols",vols); req.getRequestDispatcher("recherche-page.jsp").forward(req, resp); } diff --git a/src/main/java/ma/yc/airafraik/web/RservationConfirmationController.java b/src/main/java/ma/yc/airafraik/web/RservationConfirmationController.java index aeacee5..48326a8 100644 --- a/src/main/java/ma/yc/airafraik/web/RservationConfirmationController.java +++ b/src/main/java/ma/yc/airafraik/web/RservationConfirmationController.java @@ -14,25 +14,23 @@ import ma.yc.airafraik.entities.VolEntity; import ma.yc.airafraik.enums.ReservationStatus; import ma.yc.airafraik.service.ReservationService; -import ma.yc.airafraik.service.SearchVolsService; +import ma.yc.airafraik.service.VolsService; import ma.yc.airafraik.service.impl.ReservationServiceImpl; -import ma.yc.airafraik.service.impl.SearchVolsServiceImpl; -import org.hibernate.Session; +import ma.yc.airafraik.service.impl.VolsServiceImpl; import java.io.IOException; import java.sql.Timestamp; -import java.util.Collection; @WebServlet(name = "RservationConfirmationController", value = "/reservation-confirmation") public class RservationConfirmationController extends HttpServlet { - private SearchVolsService searchVolsService ; + private VolsService volsService; private ReservationService reservationService; private HttpSession session; private ServletContext context; @Override public void init(ServletConfig config) throws ServletException { - this.searchVolsService = new SearchVolsServiceImpl(); + this.volsService = new VolsServiceImpl(); this.context = config.getServletContext(); this.reservationService = new ReservationServiceImpl(); } @@ -46,7 +44,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se if (id != null) { Print.log("id : " + id); - VolEntity vols = searchVolsService.searchVolParId(id); + VolEntity vols = volsService.searchVolParId(id); req.setAttribute("vols",vols); // reservationEntity.setVolEntities((Collection) req.getSession().getAttribute("vols")); // reservationEntity.setPrixTotal((Double) req.getSession().getAttribute("prixTotal")); diff --git a/src/main/java/ma/yc/airafraik/web/RservationDetailsController.java b/src/main/java/ma/yc/airafraik/web/RservationDetailsController.java index 2b55c16..8b41b79 100644 --- a/src/main/java/ma/yc/airafraik/web/RservationDetailsController.java +++ b/src/main/java/ma/yc/airafraik/web/RservationDetailsController.java @@ -7,12 +7,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import ma.yc.airafraik.core.Print; -import ma.yc.airafraik.entities.ReservationEntity; import ma.yc.airafraik.entities.VolEntity; import ma.yc.airafraik.service.ReservationService; -import ma.yc.airafraik.service.SearchVolsService; +import ma.yc.airafraik.service.VolsService; import ma.yc.airafraik.service.impl.ReservationServiceImpl; -import ma.yc.airafraik.service.impl.SearchVolsServiceImpl; +import ma.yc.airafraik.service.impl.VolsServiceImpl; import java.io.IOException; @@ -20,12 +19,12 @@ public class RservationDetailsController extends HttpServlet { private ReservationService reservationService ; - private SearchVolsService searchVolsService; + private VolsService volsService; @Override public void init(ServletConfig config) throws ServletException { reservationService = new ReservationServiceImpl(); - searchVolsService = new SearchVolsServiceImpl(); + volsService = new VolsServiceImpl(); super.init(config); } @@ -36,7 +35,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se String id = req.getParameter("id"); Print.log("id : " + id); - VolEntity vol = searchVolsService.searchVolParId(id); + VolEntity vol = volsService.searchVolParId(id); req.setAttribute("vol",vol); //TODO : we will use this attribute in the jsp page req.getSession().setAttribute("vol",vol); diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 4e42545..2f98b9a 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -10,19 +10,13 @@ org.hibernate.jpa.HibernatePersistenceProvider false - - - - - - - - + + diff --git a/src/main/webapp/annuler-reservation.jsp b/src/main/webapp/annuler-reservation.jsp new file mode 100644 index 0000000..c043200 --- /dev/null +++ b/src/main/webapp/annuler-reservation.jsp @@ -0,0 +1,44 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<% response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); %> + + + + + + + +
+ +
+
+
+
+
+ Annuler Reservation +
+
+
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+ + + + + + + diff --git a/src/main/webapp/templates/footer.jsp b/src/main/webapp/templates/footer.jsp index 4cdfd0d..b752409 100644 --- a/src/main/webapp/templates/footer.jsp +++ b/src/main/webapp/templates/footer.jsp @@ -45,8 +45,8 @@ @@ -61,19 +61,5 @@ -
-
-

- - Copyright © - - All rights reserved | This template is made with - by elhjoujy - -

-
- -
diff --git a/src/main/webapp/templates/head.jsp b/src/main/webapp/templates/head.jsp index 656282f..11b962d 100644 --- a/src/main/webapp/templates/head.jsp +++ b/src/main/webapp/templates/head.jsp @@ -4,7 +4,6 @@ AriAfarik - diff --git a/src/main/webapp/views/admin/dashboard.jsp b/src/main/webapp/views/admin/dashboard.jsp index 27f1014..3c0e77c 100644 --- a/src/main/webapp/views/admin/dashboard.jsp +++ b/src/main/webapp/views/admin/dashboard.jsp @@ -12,51 +12,89 @@ <%-- --%> + + + + + +

Show some statistics here

-
-
-
-
-
-
-
- cancelled yearly and monthly -
-
- 50 cancelled -
-
-
- -
-
-
+<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%-- cancelled yearly and monthly--%> +<%--
--%> +<%--
--%> +<%-- 10 mensuels et 20 annuels--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%-- --%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%-- confirmed yearly and monthly--%> +<%--
--%> +<%--
--%> +<%-- 50 confirmed--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%-- --%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> +<%--
--%> + +
+
+
+
+
+
Cancelled Reservations
+

+ Monthly: + ${nbrReservationAnullerMois} +
+ Yearly: ${nbrReservationAnullerAnnee} +

-
-
-
-
-
-
- confirmed yearly and monthly -
-
- 50 confirmed -
-
-
- -
-
-
+
+
+
+
+
Confirmed Reservations
+

+ Monthly: + ${nbrReservationConfirmerMois} +
+ Yearly: ${nbrReservationConfirmerAnnee} +

-
@@ -98,10 +136,10 @@ ${vol.nomberDePlaces} - Delete + Delete - update + update