From c1e93ed52a6c308b7e5cd6537603fbc22e5c1358 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Fri, 12 Jun 2026 08:22:48 +0000 Subject: [PATCH] feat(dashboard): include historical sales in weekly chart - loadWeeklyChart now fetches historical_sales for the last 7 days - Sums normal daily sales + historical sales per day - Bump dashboard.js to ?v=5 --- pos/static/js/dashboard.js | 19 +++++++++++++++---- pos/templates/dashboard.html | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pos/static/js/dashboard.js b/pos/static/js/dashboard.js index c57dcbc..0c0b872 100644 --- a/pos/static/js/dashboard.js +++ b/pos/static/js/dashboard.js @@ -453,14 +453,25 @@ const Dashboard = (() => { days.push(daysAgo(i)); } - const summaries = await Promise.all( - days.map(d => apiFetch(`/pos/api/register/daily-summary?date=${d}`)) - ); + const [summaries, histData] = await Promise.all([ + Promise.all(days.map(d => apiFetch(`/pos/api/register/daily-summary?date=${d}`))), + apiFetch(`/pos/api/historical-sales?date_from=${days[0]}&date_to=${days[6]}&per_page=200`).catch(() => ({ data: [] })) + ]); + + // Group historical sales by day + const histRows = histData.data || []; + const histByDay = {}; + histRows.forEach(r => { + if (!r.sale_date) return; + histByDay[r.sale_date] = (histByDay[r.sale_date] || 0) + (r.total || 0); + }); let weekTotal = 0; const dayData = days.map((dateStr, i) => { const s = summaries[i]; - const total = s ? (s.total_sales || 0) : 0; + const normalTotal = s ? (s.total_sales || 0) : 0; + const histTotal = histByDay[dateStr] || 0; + const total = normalTotal + histTotal; weekTotal += total; const d = new Date(dateStr + 'T12:00:00'); return { diff --git a/pos/templates/dashboard.html b/pos/templates/dashboard.html index 3334254..6065a56 100644 --- a/pos/templates/dashboard.html +++ b/pos/templates/dashboard.html @@ -568,7 +568,7 @@ - +