Esempio n. 1
0
  @Check("isAdmin")
  public static void edit(String idSession) {
    Session sessions = Session.getSessionById(Long.parseLong(idSession));
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
    String dateDebut = sdf.format(sessions.dateDepart);
    String dateFin = sdf.format(sessions.dateFin);

    List<ProduitType> listProduitTypes = Arrays.asList(ProduitType.values());

    Circuit tempCircuit = sessions.circuit;

    sessions.circuit = null;
    sessions.save();

    sessions = Session.getSessionById(Long.parseLong(idSession));
    sessions.circuit = tempCircuit;

    boolean isAvailableCircuit =
        Circuit.isAvailableCircuitByAgence(sessions.dateDepart, sessions.dateFin, sessions.agence);

    Agence agence = sessions.agence;
    render(
        "Sessions/add.html",
        sessions,
        dateDebut,
        dateFin,
        isAvailableCircuit,
        listProduitTypes,
        agence);
  }
Esempio n. 2
0
  @Check("isAdmin")
  public static void save() {
    Session session;
    String idSession = params.get("session.id");
    System.out.println(idSession);
    if (idSession != null && !idSession.equals("")) {
      session = Session.getSessionById(Long.parseLong(params.get("session.id")));
    } else {
      session = new Session();
    }

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    try {
      session.dateDepart = sdf.parse(params.get("session.dateDebut"));
      session.dateFin = sdf.parse(params.get("session.dateFin"));
    } catch (ParseException ex) {
      Logger.getLogger(Disponibilites.class.getName()).log(Level.SEVERE, null, ex);
    }

    session.commentaires = params.get("session.commentaires");
    String nbPlace = params.get("session.nbMaxPlaces");
    if (nbPlace != null && !nbPlace.equals("")) {
      session.nbMaxPlaces = Integer.parseInt(nbPlace);
    }

    Agence agence = Agence.getAgenceById(Long.parseLong(params.get("session.agence").toString()));
    session.agence = agence;
    String resultCircuit = params.get("session.circuit");
    if (resultCircuit.equals("indisponible") || resultCircuit.equals("false")) {
      session.circuit = null;
    } else {
      session.circuit = Circuit.getCircuitByAgence(agence);
    }
    session.typeProduit = ProduitType.valueOf(params.get("session.type"));
    session.employe = Employe.getEmployeById(Long.parseLong(params.get("session.employe")));
    session.vehicule = Vehicule.getVehiculeById(Long.parseLong(params.get("session.vehicule")));

    validation.valid(session);

    if (Validation.hasErrors()) {
      params.flash();
      Validation.keep();
      if (idSession != null && !idSession.equals("")) {
        Sessions.edit(idSession);
      } else {
        Sessions.add(
            formatDateToCalendar(params.get("session.dateDebut").toString()),
            formatDateToCalendar(params.get("session.dateFin").toString()),
            params.get("session.agence").toString());
      }
    } else {
      session.save();
      Sessions.show();
    }
  }
Esempio n. 3
0
 @Check("isAdmin")
 public static void remove() {
   Session session;
   String idSession = params.get("session.id");
   session = Session.getSessionById(Long.parseLong(idSession));
   if (session != null) {
     session.delete();
   }
   Sessions.show();
 }
Esempio n. 4
0
 @Check("isAdmin")
 public static void move() {
   try {
     Session session = Session.getSessionById(Long.parseLong(params.get("id")));
     SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyHHmm");
     session.dateDepart = sdf.parse(params.get("start"));
     session.dateFin = sdf.parse(params.get("end"));
     session.save();
   } catch (ParseException ex) {
     Logger.getLogger(Disponibilites.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
Esempio n. 5
0
  @Check("isClient")
  public static void validPosition() {
    Session session = Session.getSessionById(Long.parseLong(params.get("session_id")));
    String result = params.get("positionSession");
    Client client = Client.getClientByUsername(Security.connected());

    Calendar calendar1 = new GregorianCalendar();
    calendar1.setTime(session.dateDepart);

    Calendar calendar2 = new GregorianCalendar();
    calendar2.setTime(session.dateFin);

    int nbrH = (int) calendar2.get(Calendar.HOUR) - calendar1.get(Calendar.HOUR);

    boolean alreadyPosition = false;
    for (Session s : client.sessions) {
      if (s.id == session.id) {
        alreadyPosition = true;
      }
    }

    if (result.equals("true")) {
      if (!alreadyPosition) {
        client.sessions.add(session);
        switch (session.typeProduit) {
          case CirculationMoto:
            client.heureCirculationMoto -= nbrH;
            break;
          case CirculationScooter125:
            client.heureCirculationScooter -= nbrH;
            break;
          case CirculationScooter50:
            client.heureCirculationScooter -= nbrH;
            break;
          case CirculationVoiture:
            client.heureCirculationVoiture -= nbrH;
            break;
          case EvaluationAuto:
            client.heureEvaluationAuto -= nbrH;
            break;
          case PlateauMoto:
            client.heurePlateauMoto -= nbrH;
            break;
          case PlateauScooter125:
            client.heurePlateauScooter -= nbrH;
            break;
          case PlateauScooter50:
            client.heurePlateauScooter -= nbrH;
            break;
          case PlateauScooterMP3:
            client.heurePlateauScooter -= nbrH;
            break;
          case PlateauVoiture:
            client.heurePlateauVoiture -= nbrH;
            break;
          case Stage1:
            client.heureStage1 -= nbrH;
            break;
          case Stage2:
            client.heureStage2 -= nbrH;
            break;
          case Stage3:
            client.heureStage3 -= nbrH;
            break;
          case Code:
            client.heureCode -= nbrH;
            break;
        }
      }
    } else {
      if (alreadyPosition) {
        client.sessions.remove(session);
        switch (session.typeProduit) {
          case CirculationMoto:
            client.heureCirculationMoto += nbrH;
            break;
          case CirculationScooter125:
            client.heureCirculationScooter += nbrH;
            break;
          case CirculationScooter50:
            client.heureCirculationScooter += nbrH;
            break;
          case CirculationVoiture:
            client.heureCirculationVoiture += nbrH;
            break;
          case EvaluationAuto:
            client.heureEvaluationAuto += nbrH;
            break;
          case PlateauMoto:
            client.heurePlateauMoto += nbrH;
            break;
          case PlateauScooter125:
            client.heurePlateauScooter += nbrH;
            break;
          case PlateauScooter50:
            client.heurePlateauScooter += nbrH;
            break;
          case PlateauScooterMP3:
            client.heurePlateauScooter += nbrH;
            break;
          case PlateauVoiture:
            client.heurePlateauVoiture += nbrH;
            break;
          case Stage1:
            client.heureStage1 += nbrH;
            break;
          case Stage2:
            client.heureStage2 += nbrH;
            break;
          case Stage3:
            client.heureStage3 += nbrH;
            break;
          case Code:
            client.heureCode += nbrH;
            break;
        }
      }
    }

    client.save();
    Sessions.showSessions();
  }
Esempio n. 6
0
  @Check("isClient")
  public static void positionSession(String idSession) {
    long nbrH = 0;
    Session sessions = Session.getSessionById(Long.parseLong(idSession));

    Calendar calendar1 = new GregorianCalendar();
    calendar1.setTime(sessions.dateDepart);

    Calendar calendar2 = new GregorianCalendar();
    calendar2.setTime(sessions.dateFin);

    nbrH = calendar2.get(Calendar.HOUR) - calendar1.get(Calendar.HOUR);

    Client client = Client.getClientByUsername(Security.connected());

    boolean alreadyPosition = false;

    for (Session s : client.sessions) {
      if (s.id == sessions.id) {
        alreadyPosition = true;
      }
    }

    boolean canPositionSession = false;
    switch (sessions.typeProduit) {
      case CirculationMoto:
        if (client.heureCirculationMoto >= nbrH) {
          canPositionSession = true;
        }
        break;
      case CirculationScooter125:
        if (client.heureCirculationScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case CirculationScooter50:
        if (client.heureCirculationScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case CirculationVoiture:
        if (client.heureCirculationVoiture >= nbrH) {
          canPositionSession = true;
        }
        break;
      case EvaluationAuto:
        if (client.heureEvaluationAuto >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauMoto:
        if (client.heurePlateauMoto >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauScooter125:
        if (client.heurePlateauScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauScooter50:
        if (client.heurePlateauScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauScooterMP3:
        if (client.heurePlateauScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauVoiture:
        if (client.heurePlateauVoiture >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Stage1:
        if (client.heureStage1 >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Stage2:
        if (client.heureStage2 >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Stage3:
        if (client.heureStage3 >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Code:
        if (client.heureCode >= nbrH) {
          canPositionSession = true;
        }
        break;
    }

    render(canPositionSession, alreadyPosition, sessions);
  }