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 };
|
buckets[label] = { total: 0, date: d };
|
||||||
});
|
});
|
||||||
} else if (period === 'mes') {
|
} else if (period === 'mes') {
|
||||||
const start = new Date();
|
const year = now.getFullYear();
|
||||||
start.setDate(start.getDate() - 27);
|
const month = now.getMonth();
|
||||||
dateFrom = start.toISOString().slice(0, 10);
|
const lastDay = new Date(year, month + 1, 0).getDate();
|
||||||
dateTo = todayStr();
|
dateFrom = new Date(year, month, 1).toISOString().slice(0, 10);
|
||||||
for (let i = 3; i >= 0; i--) {
|
dateTo = new Date(year, month, lastDay).toISOString().slice(0, 10);
|
||||||
const d = new Date();
|
for (let i = 1; i <= 4; i++) {
|
||||||
d.setDate(d.getDate() - (i * 7 + 6));
|
const label = `Sem ${i}`;
|
||||||
const label = weekLabel(d);
|
|
||||||
labelOrder.push(label);
|
labelOrder.push(label);
|
||||||
buckets[label] = 0;
|
buckets[label] = { total: 0, week: i };
|
||||||
}
|
}
|
||||||
} else if (period === 'año') {
|
} else if (period === 'año') {
|
||||||
for (let i = 11; i >= 0; i--) {
|
for (let i = 11; i >= 0; i--) {
|
||||||
@@ -558,17 +557,9 @@ const Dashboard = (() => {
|
|||||||
if (period === 'hoy') key = 'Hoy';
|
if (period === 'hoy') key = 'Hoy';
|
||||||
else if (period === 'semana') key = DAY_NAMES_SHORT[date.getDay()];
|
else if (period === 'semana') key = DAY_NAMES_SHORT[date.getDay()];
|
||||||
else if (period === 'mes') {
|
else if (period === 'mes') {
|
||||||
// Find which week bucket this date belongs to
|
const day = date.getDate();
|
||||||
for (let i = 0; i < 4; i++) {
|
const weekNum = day <= 7 ? 1 : day <= 14 ? 2 : day <= 21 ? 3 : 4;
|
||||||
const bucketStart = new Date();
|
key = `Sem ${weekNum}`;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
key = monthLabel(date);
|
key = monthLabel(date);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -568,7 +568,7 @@
|
|||||||
<script src="/pos/static/js/pos-utils.js?v=2" defer></script>
|
<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/sidebar.js" defer></script>
|
||||||
<script src="/pos/static/js/dashboard-stats.js?v=3" 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 src="/pos/static/js/sync-engine.js" defer></script>
|
||||||
<script>if('serviceWorker' in navigator){navigator.serviceWorker.register('/pos/sw.js',{scope:'/pos/'});}</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>
|
<script src="/pos/static/js/pwa-install.js" defer></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user