diff --git a/pos/static/js/dashboard.js b/pos/static/js/dashboard.js index f5e8205..96c8591 100644 --- a/pos/static/js/dashboard.js +++ b/pos/static/js/dashboard.js @@ -495,16 +495,15 @@ const Dashboard = (() => { buckets[label] = { total: 0, date: d }; }); } else if (period === 'mes') { - const start = new Date(); - start.setDate(start.getDate() - 27); - dateFrom = start.toISOString().slice(0, 10); - dateTo = todayStr(); - for (let i = 3; i >= 0; i--) { - const d = new Date(); - d.setDate(d.getDate() - (i * 7 + 6)); - const label = weekLabel(d); + const year = now.getFullYear(); + const month = now.getMonth(); + const lastDay = new Date(year, month + 1, 0).getDate(); + dateFrom = new Date(year, month, 1).toISOString().slice(0, 10); + dateTo = new Date(year, month, lastDay).toISOString().slice(0, 10); + for (let i = 1; i <= 4; i++) { + const label = `Sem ${i}`; labelOrder.push(label); - buckets[label] = 0; + buckets[label] = { total: 0, week: i }; } } else if (period === 'año') { for (let i = 11; i >= 0; i--) { @@ -558,17 +557,9 @@ const Dashboard = (() => { if (period === 'hoy') key = 'Hoy'; else if (period === 'semana') key = DAY_NAMES_SHORT[date.getDay()]; else if (period === 'mes') { - // Find which week bucket this date belongs to - for (let i = 0; i < 4; i++) { - const bucketStart = new Date(); - bucketStart.setDate(bucketStart.getDate() - ((3 - i) * 7 + 6)); - const bucketEnd = new Date(bucketStart); - bucketEnd.setDate(bucketEnd.getDate() + 6); - if (date >= bucketStart && date <= bucketEnd) { - key = labelOrder[i]; - break; - } - } + const day = date.getDate(); + const weekNum = day <= 7 ? 1 : day <= 14 ? 2 : day <= 21 ? 3 : 4; + key = `Sem ${weekNum}`; } else { key = monthLabel(date); } diff --git a/pos/templates/dashboard.html b/pos/templates/dashboard.html index 66183e0..2ad7b7d 100644 --- a/pos/templates/dashboard.html +++ b/pos/templates/dashboard.html @@ -568,7 +568,7 @@ - +