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
This commit is contained in:
@@ -453,14 +453,25 @@ const Dashboard = (() => {
|
|||||||
days.push(daysAgo(i));
|
days.push(daysAgo(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
const summaries = await Promise.all(
|
const [summaries, histData] = await Promise.all([
|
||||||
days.map(d => apiFetch(`/pos/api/register/daily-summary?date=${d}`))
|
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;
|
let weekTotal = 0;
|
||||||
const dayData = days.map((dateStr, i) => {
|
const dayData = days.map((dateStr, i) => {
|
||||||
const s = summaries[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;
|
weekTotal += total;
|
||||||
const d = new Date(dateStr + 'T12:00:00');
|
const d = new Date(dateStr + 'T12:00:00');
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -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=4" defer></script>
|
<script src="/pos/static/js/dashboard.js?v=5" 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