feat(reports/dashboard): integrate historical sales viewer
- Add 'Histórico' tab inside Reports page with date/customer filters - Show historical sales KPIs and detail table in reports - Add historical sales summary cards to Dashboard - Load current month totals and total imported records
This commit is contained in:
@@ -205,6 +205,50 @@ const Dashboard = (() => {
|
||||
return data;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 1b. Historical sales KPIs (imported data)
|
||||
// -------------------------------------------------------------------------
|
||||
async function loadHistoricalSummary() {
|
||||
try {
|
||||
const now = new Date();
|
||||
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1).toISOString().slice(0, 10);
|
||||
const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0).toISOString().slice(0, 10);
|
||||
|
||||
// All historical sales
|
||||
const all = await apiFetch('/pos/api/historical-sales?per_page=1');
|
||||
const totalRecords = all.pagination ? all.pagination.total : 0;
|
||||
|
||||
// Current month historical sales
|
||||
const month = await apiFetch(`/pos/api/historical-sales?date_from=${firstDay}&date_to=${lastDay}&per_page=200`);
|
||||
const monthRows = month.data || [];
|
||||
const monthTotal = monthRows.reduce((a, r) => a + (r.total || 0), 0);
|
||||
|
||||
const totalEl = document.getElementById('kpi-historico-total-value');
|
||||
const totalMetaEl = document.getElementById('kpi-historico-total-meta');
|
||||
if (totalEl) totalEl.textContent = fmt(monthTotal);
|
||||
if (totalMetaEl) totalMetaEl.innerHTML = `<span class="kpi-meta-text">${fmtInt(totalRecords)} tickets importados</span>`;
|
||||
|
||||
const mesEl = document.getElementById('kpi-historico-mes-value');
|
||||
const mesMetaEl = document.getElementById('kpi-historico-mes-meta');
|
||||
if (mesEl) mesEl.textContent = fmt(monthTotal);
|
||||
if (mesMetaEl) mesMetaEl.innerHTML = `<span class="kpi-meta-text">${monthRows.length} tickets este mes</span>`;
|
||||
|
||||
const countEl = document.getElementById('kpi-historico-count-value');
|
||||
const countMetaEl = document.getElementById('kpi-historico-count-meta');
|
||||
if (countEl) countEl.textContent = fmtInt(totalRecords);
|
||||
if (countMetaEl) countMetaEl.innerHTML = `<span class="kpi-meta-text">Registros históricos</span>`;
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error loading historical summary:', err);
|
||||
const ids = [
|
||||
['kpi-historico-total-value', 'kpi-historico-total-meta'],
|
||||
['kpi-historico-mes-value', 'kpi-historico-mes-meta'],
|
||||
['kpi-historico-count-value', 'kpi-historico-count-meta'],
|
||||
];
|
||||
ids.forEach(([v, m]) => setKpiError(v, m));
|
||||
}
|
||||
}
|
||||
|
||||
function setKpiError(valueId, metaId) {
|
||||
const v = document.getElementById(valueId);
|
||||
const m = document.getElementById(metaId);
|
||||
@@ -533,6 +577,7 @@ const Dashboard = (() => {
|
||||
|
||||
// Load all data in parallel
|
||||
loadDailySummary();
|
||||
loadHistoricalSummary();
|
||||
loadAlerts();
|
||||
loadTopProducts();
|
||||
loadWeeklyChart();
|
||||
|
||||
Reference in New Issue
Block a user