예제 #1
0
  public static List<Vehicule> getAvailableVehiculesByAgence(
      Date startDate, Date endDate, Agence agence) {
    List<Vehicule> listVehiculesByAgence = Vehicule.getVehiculesByAgence(agence);
    List<Vehicule> listAvailableVehicules = new ArrayList<Vehicule>();
    List<Session> listSessionsByAgence = Session.getSessionsByAgence(agence);
    List<Revision> listRevisionsByVehicule;
    Calendar calendar = new GregorianCalendar();
    Date startRevision;
    Date endRevision;

    for (Vehicule vehicule : listVehiculesByAgence) {
      boolean isAvailable = true;
      listRevisionsByVehicule = Revision.getRevisionsByVehicule(vehicule);
      for (Revision revision : listRevisionsByVehicule) {
        startRevision = revision.date;
        calendar.setTime(revision.date);
        calendar.add(Calendar.DATE, 7);
        endRevision = calendar.getTime();

        if (startDate.equals(startRevision)
            || endDate.equals(startRevision)
            || startDate.equals(endRevision)
            || endDate.equals(endRevision)
            || (startDate.after(startRevision) && startDate.before(endRevision))
            || (endDate.after(startRevision) && endDate.before(endRevision))) {

          isAvailable = false;
        }
      }

      if (isAvailable) {
        for (Session session : listSessionsByAgence) {
          if (startDate.equals(session.dateDepart)
              || endDate.equals(session.dateDepart)
              || startDate.equals(session.dateFin)
              || endDate.equals(session.dateFin)
              || (startDate.after(session.dateDepart) && startDate.before(session.dateFin))
              || (endDate.after(session.dateDepart) && endDate.before(session.dateFin))) {
            if (session.vehicule.id == vehicule.id) {
              isAvailable = false;
            }
          }
        }
      }

      if (isAvailable) {
        listAvailableVehicules.add(vehicule);
      }
    }

    return listAvailableVehicules;
  }
예제 #2
0
  @Check("isAdmin")
  public static void findEvents(String idAgence) {
    Agence agence = Agence.getAgenceById(Long.parseLong(idAgence));
    List<Session> listSessions = Session.getSessionsByAgence(agence);

    List<FullCalendarEvent> listEvents = new ArrayList<FullCalendarEvent>();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    FullCalendarEvent event;
    for (Session session : listSessions) {
      event = new FullCalendarEvent();
      event.start = dateFormat.format(session.dateDepart);
      event.end = dateFormat.format(session.dateFin);
      event.id = session.id.toString();
      event.title = session.commentaires + " (" + session.id + ")";
      event.allDay = "";

      switch (session.typeProduit) {
        case CirculationMoto:
          event.color = "blue";
          break;
        case CirculationScooter125:
          event.color = "red";
          break;
        case CirculationScooter50:
          event.color = "yellow";
          event.textColor = "black";
          break;
        case CirculationVoiture:
          event.color = "green";
          break;
        case EvaluationAuto:
          event.color = "DarkOrchid";
          break;
        case PlateauMoto:
          event.color = "Orange";
          break;
        case PlateauScooter125:
          event.color = "Pink";
          event.textColor = "black";
          break;
        case PlateauScooter50:
          event.color = "Magenta";
          break;
        case PlateauScooterMP3:
          event.color = "Silver";
          break;
        case PlateauVoiture:
          event.color = "Turquoise";
          break;
        case Stage1:
          event.color = "Lime";
          break;
        case Stage2:
          event.color = "DeepSkyBlue";
          break;
        case Stage3:
          event.color = "Beige";
          break;
        case Code:
          event.color = "Maroon";
          break;
        default:
          event.color = "white";
      }

      listEvents.add(event);
    }

    Gson gson = new Gson();
    System.out.println(gson.toJson(listEvents));
    renderJSON(gson.toJson(listEvents));
  }
예제 #3
0
  @Check("isClient")
  public static void findEventsForClient() {
    Client utilisateur = Client.getClientByUsername(Security.connected());
    // Agence agence = Agence.getAgenceById(Long.parseLong(idAgence));
    List<Session> listSessions = Session.getSessionsByAgence(utilisateur.agence);
    System.out.println(listSessions.size());
    List<FullCalendarEvent> listEvents = new ArrayList<FullCalendarEvent>();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    FullCalendarEvent event;
    for (Session session : listSessions) {
      event = new FullCalendarEvent();
      event.start = dateFormat.format(session.dateDepart);
      event.end = dateFormat.format(session.dateFin);
      event.id = session.id.toString();

      event.allDay = "";

      if (Session.canAddClientToSession(session)) {
        event.title = session.commentaires + " (" + session.id + ")";
        event.url = "/sessions/positionSession/" + session.id.toString();
      } else {
        event.title = session.commentaires + " (" + session.id + ") - COMPLET";
        event.url = "";
      }

      switch (session.typeProduit) {
        case CirculationMoto:
          event.color = "blue";
          break;
        case CirculationScooter125:
          event.color = "red";
          break;
        case CirculationScooter50:
          event.color = "yellow";
          event.textColor = "black";
          break;
        case CirculationVoiture:
          event.color = "green";
          break;
        case EvaluationAuto:
          event.color = "DarkOrchid";
          break;
        case PlateauMoto:
          event.color = "Orange";
          break;
        case PlateauScooter125:
          event.color = "Pink";
          event.textColor = "black";
          break;
        case PlateauScooter50:
          event.color = "Magenta";
          break;
        case PlateauScooterMP3:
          event.color = "Silver";
          break;
        case PlateauVoiture:
          event.color = "Turquoise";
          break;
        case Stage1:
          event.color = "Lime";
          break;
        case Stage2:
          event.color = "DeepSkyBlue";
          break;
        case Stage3:
          event.color = "Beige";
          break;
        case Code:
          event.color = "Maroon";
          break;
        default:
          event.color = "white";
      }

      listEvents.add(event);
    }

    Gson gson = new Gson();
    System.out.println(gson.toJson(listEvents));
    renderJSON(gson.toJson(listEvents));
  }