- Sin datos
+ {{ formatTotal(cosecha.totalALaFecha) }}
@@ -392,10 +389,6 @@
:key="`${cosecha.id}-${dia}`"
class="relative border-b cursor-pointer group"
:class="[
- // Marcador del día actual
- dia - 1 === diaActualRelativo
- ? 'border-l-2 border-l-blue-400'
- : '',
// Rango seleccionado (naranja)
isInSelectedRange(dia - 1)
? 'border-[#c08040] border-2 bg-[#c08040]/10'
@@ -411,6 +404,12 @@
@mouseenter="showTooltip($event, cosecha, dia - 1)"
@mouseleave="hideTooltip"
>
+
+
+
-
-
@@ -636,25 +630,45 @@ const tooltipX = ref(0)
const tooltipY = ref(0)
const tooltipData = ref({ cosecha: '', dia: 0, valor: '', fecha: '' })
-// Calcular el día actual relativo desde el inicio del año de cosecha (8 de septiembre)
-const diaActualRelativo = computed(() => {
+// Día y mes actual para comparar
+const fechaActual = computed(() => {
const hoy = new Date()
+ // Normalizar a medianoche para comparaciones
+ hoy.setHours(0, 0, 0, 0)
+ return {
+ dia: hoy.getDate(),
+ mes: hoy.getMonth(), // 0-11
+ fecha: hoy,
+ formatted: hoy.toLocaleDateString('es-HN', { day: 'numeric', month: 'short' })
+ }
+})
- // Fecha de inicio del año de cosecha actual (8 de septiembre del año correspondiente)
- let anioInicioCosecha = hoy.getFullYear()
- const inicioCosechaEsteAnio = new Date(anioInicioCosecha, 8, 8) // 8 de septiembre
+// Calcular cuántos días han pasado desde el 7 de septiembre de este año
+const diasTranscurridosDesdeInicio = computed(() => {
+ const hoy = new Date()
+ hoy.setHours(0, 0, 0, 0)
- // Si aún no hemos llegado al 8 de septiembre de este año, el inicio fue el año pasado
- if (hoy < inicioCosechaEsteAnio) {
- anioInicioCosecha--
+ // 7 de septiembre del año actual
+ const inicioDelAnio = new Date(hoy.getFullYear(), 8, 7) // mes 8 = septiembre (0-indexed)
+ inicioDelAnio.setHours(0, 0, 0, 0)
+
+ // Si todavía no llegamos al 7 de septiembre de este año, usar el del año pasado
+ if (hoy < inicioDelAnio) {
+ inicioDelAnio.setFullYear(inicioDelAnio.getFullYear() - 1)
}
- const inicioCosecha = new Date(anioInicioCosecha, 8, 8) // 8 de septiembre
- const diaRelativo = Math.floor((hoy.getTime() - inicioCosecha.getTime()) / (1000 * 60 * 60 * 24))
+ // Calcular diferencia en días
+ const diffMs = hoy.getTime() - inicioDelAnio.getTime()
+ const diffDias = Math.floor(diffMs / (1000 * 60 * 60 * 24))
- return diaRelativo
+ return diffDias
})
+// Función para verificar si un día ya pasó (basado en días desde el inicio, no en año)
+function isDiaPasado(cosechaId: string, diaIndex: number): boolean {
+ return diaIndex <= diasTranscurridosDesdeInicio.value
+}
+
// Calcular datos por cosecha usando vista_resumen_ingresos
const datosCosechas = computed(() => {
return props.cosechasSeleccionadas.map(cosechaId => {
@@ -747,13 +761,25 @@ const datosCosechas = computed(() => {
}
}
- // Calcular total acumulado hasta la fecha actual (día relativo de hoy)
+ // Calcular total acumulado hasta la fecha actual (mismo día/mes pero del año de cada cosecha)
let totalALaFecha: number | null = null
- // Solo calcular si el día actual está dentro del rango de datos disponibles
- if (diaActualRelativo.value >= 0 && diaActualRelativo.value < valoresPorDia.length) {
- totalALaFecha = 0
- for (let i = 0; i <= diaActualRelativo.value; i++) {
+ // Obtener el año de inicio de esta cosecha
+ const anioInicioCosecha = fechaInicio.getFullYear()
+
+ // Construir la fecha objetivo: mismo día y mes de hoy, pero del año de inicio de esta cosecha
+ // Ej: Si hoy es 1 oct 2025 y la cosecha inició en sep 2023, usamos 1 oct 2023
+ const fechaObjetivoCosecha = new Date(anioInicioCosecha, fechaActual.value.mes, fechaActual.value.dia)
+
+ // Calcular el día relativo desde el inicio de la cosecha hasta esa fecha objetivo
+ const diaObjetivo = Math.floor((fechaObjetivoCosecha.getTime() - fechaInicio.getTime()) / (1000 * 60 * 60 * 24))
+
+ // Acumular desde el inicio de la cosecha hasta la fecha objetivo
+ totalALaFecha = 0
+ if (diaObjetivo >= 0) {
+ // Sumar todos los días desde el inicio hasta la fecha objetivo (o hasta donde haya datos)
+ const limiteSuperior = Math.min(diaObjetivo, valoresPorDia.length - 1)
+ for (let i = 0; i <= limiteSuperior; i++) {
totalALaFecha += valoresPorDia[i] || 0
}
}
diff --git a/nuxt4-app/app/components/ingresos/VistaTablaIngresos.vue b/nuxt4-app/app/components/ingresos/VistaTablaIngresos.vue
index 00e4c79..aea4d37 100644
--- a/nuxt4-app/app/components/ingresos/VistaTablaIngresos.vue
+++ b/nuxt4-app/app/components/ingresos/VistaTablaIngresos.vue
@@ -8,13 +8,15 @@
{{ props.records.length }} registros filtrados
-
+