fix(dashboard): month chart shows Sem 1-4 of current month
- Month view now groups by weeks of the current calendar month - Labels are Sem 1, Sem 2, Sem 3, Sem 4 - Historical sales grouped by day-of-month into the 4 week buckets - Bump dashboard.js to ?v=7
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@
|
||||
<script src="/pos/static/js/pos-utils.js?v=2" defer></script>
|
||||
<script src="/pos/static/js/sidebar.js" defer></script>
|
||||
<script src="/pos/static/js/dashboard-stats.js?v=3" defer></script>
|
||||
<script src="/pos/static/js/dashboard.js?v=6" defer></script>
|
||||
<script src="/pos/static/js/dashboard.js?v=7" defer></script>
|
||||
<script src="/pos/static/js/sync-engine.js" defer></script>
|
||||
<script>if('serviceWorker' in navigator){navigator.serviceWorker.register('/pos/sw.js',{scope:'/pos/'});}</script>
|
||||
<script src="/pos/static/js/pwa-install.js" defer></script>
|
||||
|
||||
Reference in New Issue
Block a user