diff --git a/NetBeans_Proyecto_1_Parqueo/src/main/java/servicios/ReporteParqueo.java b/NetBeans_Proyecto_1_Parqueo/src/main/java/servicios/ReporteParqueo.java new file mode 100644 index 0000000..9c7781f --- /dev/null +++ b/NetBeans_Proyecto_1_Parqueo/src/main/java/servicios/ReporteParqueo.java @@ -0,0 +1,100 @@ +package servicios; + +import java.time.LocalDate; +import java.time.Duration; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; + +public class ReporteParqueo { + + private static final DateTimeFormatter soloFecha = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + + // Listado de vehiculos del presente día + public String listVehic(GestorParqueo gestorParqueo, LocalDate fecha) { + + ArrayList tiquetes = gestorParqueo.getTiquetesDia(fecha); + + String fechaFormateada = fecha.format(soloFecha); + + if (tiquetes.isEmpty()) { + String resultado = "No hay vehículos registrados para la fecha: " + fechaFormateada; + return resultado; + } + + StringBuilder sb = new StringBuilder(); + sb.append("Vehículos que usaron el parqueo el día " + fechaFormateada + ":" + "\n"); + for (TiqueteParqueo tiquete : tiquetes) { + + String placa = tiquete.getVehiculo().getPlaca(); + String entrada = tiquete.getHoraEntrada().format(soloFecha); + String salida = "Aún parqueado"; + if (tiquete.getHoraSalida() != null) { + salida = tiquete.getHoraSalida().format(soloFecha); + } + + String lineaVehic = "Placa: " + placa + " | Tipo: " + tiquete.getVehiculo().getNombre() + " | Entrada: " + entrada + " | Salida: " + salida; + sb.append(lineaVehic).append("\n"); + } + + String resultado = sb.toString(); + + return resultado; + } + + // Total recaudado por tipo de servicio + public String totalRecaudado(GestorParqueo gestorParqueo, LocalDate fecha) { + + ArrayList tiquetes = gestorParqueo.getTiquetesDia(fecha); + int totalPorHora = 0; + int totalPorDia = 0; + + for (TiqueteParqueo tiquete : tiquetes) { + if (tiquete.getHoraSalida() == null) { + continue; + } + + if (tiquete.getModalidad() == TiqueteParqueo.TipoServicio.POR_HORA) { + totalPorHora += tiquete.getMontoTotal(); + } else { + totalPorDia += tiquete.getMontoTotal(); + } + } + + StringBuilder sb = new StringBuilder(); + String fechaFormateada = fecha.format(soloFecha); + sb.append("Total recaudado por servicio el día " + fechaFormateada + ":" + "\n"); + sb.append("Servicio por hora: CRC " + totalPorHora + "\n"); + sb.append("Servicio por día: CRC " + totalPorDia + "\n"); + + String resultado = sb.toString(); + return resultado; + } + + public String estadisticasBasicas(GestorParqueo gestorParqueo, LocalDate fecha) { + ArrayList tiquetes = gestorParqueo.getTiquetesDia(fecha); + int vehiculosAtendidos = tiquetes.size(); + long minutosTotales = 0; + + for (TiqueteParqueo tiquete : tiquetes) { + if (tiquete.getHoraSalida() != null) { + minutosTotales += Duration.between(tiquete.getHoraEntrada(), tiquete.getHoraSalida()).toMinutes(); + } + } + + double horasTotales = minutosTotales / 60.0; + int capacidad = gestorParqueo.getCapacidadMaxima(); + int ocupadosActuales = capacidad - gestorParqueo.espaciosDisponibles(); + double ocupacionActual = (ocupadosActuales * 100.0) / capacidad; + + StringBuilder sb = new StringBuilder(); + String fechaFormateada = fecha.format(soloFecha); + sb.append("Estadísticas básicas del día " + fechaFormateada + ":" + "\n"); + sb.append("Sumatoria de horas de uso: " + String.format("%.2f", horasTotales) + "\n"); + sb.append("Cantidad de vehículos atendidos: " + vehiculosAtendidos + "\n"); + sb.append("Porcentaje de ocupación actual: " + String.format("%.2f", ocupacionActual) + "%" + "\n"); + + String resultado = sb.toString(); + return resultado; + } + +}