Minga
Minga
// ════════════════════════════════════════════════════════════════ // LITROS POR CLIENTE × PRODUCTO × MES // ════════════════════════════════════════════════════════════════ async function litros() { document.getElementById('main').innerHTML = periodoHTML('litros') + '
Litros por cliente y producto
' + '
Ordenado de mayor a menor por volumen total · barriles
' + '
' + '' + '
' + '
Cargando…
'; const data = await apiGet('/pivot/litros?desde=' + DESDE + '&hasta=' + HASTA); renderPivot(data); } function renderPivot(data) { const meses = data.meses; const clientes = data.clientes; if (!clientes.length) { document.getElementById('pivot-wrap').innerHTML = '
Sin datos en el período
'; return; } const maxVal = Math.max.apply(null, clientes.flatMap(function(c) { return c.productos.flatMap(function(p) { return Object.values(p.meses); }); })); function heatStyle(v) { if (!v || !maxVal) return 'text-align:right;padding:5px 8px;font-size:11px;border-bottom:0.5px solid var(--border2)'; var a = (v / maxVal * 0.22).toFixed(3); return 'background:rgba(192,122,0,' + a + ');text-align:right;padding:5px 8px;font-size:11px;border-bottom:0.5px solid var(--border2)'; } var mesLabels = meses.map(function(m) { var parts = m.split('-'); return parts[1] + '/' + parts[0].slice(2); }); var html = '' + '' + '' + '' + mesLabels.map(function(m) { return ''; }).join('') + ''; var shown = 0; clientes.forEach(function(c) { var cliMes = {}; c.productos.forEach(function(p) { Object.entries(p.meses).forEach(function(e) { cliMes[e[0]] = (cliMes[e[0]] || 0) + e[1]; }); }); html += '' + '' + '' + meses.map(function(m) { var v = cliMes[m]; return ''; }).join('') + ''; c.productos.forEach(function(p) { html += '' + '' + '' + '' + meses.map(function(m) { var v = p.meses[m]; return ''; }).join('') + ''; }); shown++; }); html += '
ClienteProducto1Total L' + m + '
' + c.cliente + '' + fmt0(c.total) + '' + (v ? fmt0(v) : '–') + '
' + p.producto1 + '' + fmt0(p.total) + '' + (v ? fmt0(v) : '') + '
'; document.getElementById('pivot-wrap').innerHTML = html; document.getElementById('pivot-count').textContent = shown + ' clientes · ' + meses.length + ' meses'; window._pivotData = data; } function filtrarPivot(q) { var term = q.toLowerCase(); document.querySelectorAll('.pivot-cli').forEach(function(row) { var cli = row.dataset.cli || ''; var match = !term || cli.includes(term); row.style.display = match ? '' : 'none'; var next = row.nextElementSibling; while (next && next.classList.contains('pivot-prod')) { var prodMatch = !term || (next.dataset.prod || '').includes(term) || cli.includes(term); next.style.display = prodMatch ? '' : 'none'; next = next.nextElementSibling; } }); var shown = document.querySelectorAll('.pivot-cli:not([style*="none"])').length; document.getElementById('pivot-count').textContent = shown + ' clientes'; }