Files
Autoparts-DB/pos/templates/quotations.html
consultoria-as 042acd6207 OPCIÓN C + A1: Consolidación técnica + orjson
C1: Materialized view part_vehicle_preview (creación en progreso)
- Migración v3.3_materialized_view.sql
- catalog_service.py y dashboard/server.py ahora usan la MV
- Script refresh_part_vehicle_preview.py + warm_vehicle_cache.py actualizado

C2: Fix cache warming script (autónomo)
- Auto-re-ejecuta con sudo -u postgres si peer auth falla
- Args CLI: --dsn, --batch-size, --ttl, --dry-run

C3: CSS dinámico residual extraído
- sidebar.js → sidebar.css (nuevo)
- pos-utils.js → common.css (nuevo)
- Links agregados a 14 templates POS

C4: Script de load testing básico
- scripts/load_test.py: métricas p50/p95/p99, throughput, errores

C5: Documentación actualizada
- FASES_IMPLEMENTADAS.md: test count real, FASE 7 completa
- performance_audit_2026.md: anexo post-FASE 7, métricas actualizadas

A1: Serialización orjson
- pos/json_provider.py: DefaultJSONProvider con orjson.dumps/loads
- Aplicado a POS app y Dashboard server
- Fix indentation error en pos_bp.py

Tests: 73/73 pasando
2026-04-27 09:36:03 +00:00

152 lines
8.4 KiB
HTML

<!DOCTYPE html>
<html lang="es" data-theme="industrial">
<head>
<script>/*pos_theme_early*/(function(){var t=localStorage.getItem("pos_theme")||"industrial";document.documentElement.setAttribute("data-theme",t);})()</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cotizaciones — Nexus Autoparts POS</title>
<link rel="stylesheet" href="/pos/static/css/tokens.css" />
<link rel="stylesheet" href="/pos/static/css/common.css" />
<link rel="stylesheet" href="/pos/static/css/sidebar.css" />
<link rel="stylesheet" href="/pos/static/css/pos-glass.css" />
<link rel="stylesheet" href="/pos/static/css/quotations.css">
</head>
<body>
<script src="/pos/static/js/pos-utils.js" defer></script>
<script src="/pos/static/js/sidebar.js" defer></script>
<script src="/pos/static/js/app-init.js" defer></script>
<div class="page">
<h1 class="page-title">Cotizaciones</h1>
<div id="quoteList">Cargando...</div>
</div>
<div class="modal-overlay" id="quoteModal">
<div class="modal-content">
<button class="modal-close" onclick="document.getElementById('quoteModal').classList.remove('open')">&times;</button>
<div id="quoteDetail">Cargando...</div>
</div>
</div>
<script>
(function() {
var token = localStorage.getItem('pos_token');
if (!token) { window.location.href = '/pos/login'; return; }
var API = '/pos/api';
function headers() { return { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json' }; }
function esc(s) { var d = document.createElement('div'); d.textContent = s || ''; return d.innerHTML; }
function fmt(n) { return (n || 0).toLocaleString('es-MX', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }
function loadQuotes() {
fetch(API + '/quotations?per_page=50', { headers: headers() })
.then(function(r) { return r.json(); })
.then(function(d) {
var quotes = d.data || [];
if (!quotes.length) {
document.getElementById('quoteList').innerHTML = '<div class="empty"><h3>Sin cotizaciones</h3><p>Las cotizaciones creadas desde el POS (F4) o desde WhatsApp aparecen aqui.</p></div>';
return;
}
var html = '<table class="quote-table"><thead><tr>';
html += '<th>#</th><th>Origen</th><th>Cliente</th><th>Total</th><th>Estado</th><th>Fecha</th><th></th>';
html += '</tr></thead><tbody>';
quotes.forEach(function(q) {
var srcBadge = q.source === 'whatsapp'
? '<span class="badge badge--wa">📱 WA</span>'
: '<span class="badge badge--pos">🖥️ POS</span>';
var statusBadge = '<span class="badge badge--' + q.status + '">' + q.status + '</span>';
var client = q.customer_name || (q.wa_phone ? '📱 ' + q.wa_phone : 'Sin cliente');
var dateStr = q.created_at ? new Date(q.created_at).toLocaleDateString('es-MX') : '';
html += '<tr>';
html += '<td onclick="openQuote(' + q.id + ')" style="cursor:pointer;"><strong>#' + q.id + '</strong></td>';
html += '<td onclick="openQuote(' + q.id + ')" style="cursor:pointer;">' + srcBadge + '</td>';
html += '<td onclick="openQuote(' + q.id + ')" style="cursor:pointer;">' + esc(client) + '</td>';
html += '<td onclick="openQuote(' + q.id + ')" style="cursor:pointer;font-family:var(--font-mono);font-weight:700;">$' + fmt(q.total) + '</td>';
html += '<td onclick="openQuote(' + q.id + ')" style="cursor:pointer;">' + statusBadge + '</td>';
html += '<td onclick="openQuote(' + q.id + ')" style="cursor:pointer;color:var(--color-text-muted);">' + dateStr + '</td>';
html += '<td><button onclick="deleteQuote(' + q.id + ', event)" style="background:none;border:none;color:var(--color-text-muted);cursor:pointer;font-size:16px;padding:4px 8px;border-radius:4px;" onmouseover="this.style.color=\'#F85149\';this.style.background=\'rgba(248,81,73,0.1)\'" onmouseout="this.style.color=\'var(--color-text-muted)\';this.style.background=\'none\'">🗑️</button></td>';
html += '</tr>';
});
html += '</tbody></table>';
document.getElementById('quoteList').innerHTML = html;
})
.catch(function() {
document.getElementById('quoteList').innerHTML = '<div class="empty">Error cargando cotizaciones</div>';
});
}
window.openQuote = function(id) {
var modal = document.getElementById('quoteModal');
modal.classList.add('open');
document.getElementById('quoteDetail').innerHTML = 'Cargando...';
fetch(API + '/quotations/' + id, { headers: headers() })
.then(function(r) { return r.json(); })
.then(function(q) {
if (q.error) { document.getElementById('quoteDetail').innerHTML = 'Error: ' + esc(q.error); return; }
var src = (q.notes || '').startsWith('WA:') ? 'WhatsApp' : 'POS';
var waPhone = src === 'WhatsApp' ? q.notes.replace('WA:', '') : null;
var html = '<h3 style="font-family:var(--font-heading);margin-bottom:var(--space-4);">Cotización #' + q.id + '</h3>';
html += '<div style="display:flex;gap:var(--space-6);margin-bottom:var(--space-4);font-size:var(--text-body-sm);">';
html += '<div><span style="color:var(--color-text-muted);">Origen:</span> ' + src + '</div>';
if (waPhone) html += '<div><span style="color:var(--color-text-muted);">WhatsApp:</span> +' + esc(waPhone) + '</div>';
if (q.customer_name) html += '<div><span style="color:var(--color-text-muted);">Cliente:</span> ' + esc(q.customer_name) + '</div>';
html += '<div><span style="color:var(--color-text-muted);">Estado:</span> <span class="badge badge--' + q.status + '">' + q.status + '</span></div>';
html += '<div><span style="color:var(--color-text-muted);">Vigencia:</span> ' + (q.valid_until || '—') + '</div>';
html += '</div>';
html += '<table class="detail-table"><thead><tr><th>#Parte</th><th>Nombre</th><th>Cant</th><th>Precio</th><th>Subtotal</th></tr></thead><tbody>';
(q.items || []).forEach(function(it) {
html += '<tr>';
html += '<td style="font-family:var(--font-mono);">' + esc(it.part_number) + '</td>';
html += '<td>' + esc(it.name) + '</td>';
html += '<td>' + it.quantity + '</td>';
html += '<td>$' + fmt(it.unit_price) + '</td>';
html += '<td style="font-weight:700;">$' + fmt(it.subtotal) + '</td>';
html += '</tr>';
});
html += '</tbody></table>';
html += '<div style="text-align:right;margin-top:var(--space-4);font-size:var(--text-body);">';
html += '<div>Subtotal: $' + fmt(q.subtotal) + '</div>';
html += '<div>IVA: $' + fmt(q.tax_total) + '</div>';
html += '<div style="font-size:var(--text-h5);font-weight:700;color:var(--color-text-accent);">Total: $' + fmt(q.total) + '</div>';
html += '</div>';
html += '<div style="margin-top:var(--space-5);display:flex;gap:var(--space-3);justify-content:flex-end;">';
html += '<button class="btn btn--ghost" onclick="deleteQuote(' + q.id + ')" style="color:#F85149;">Eliminar</button>';
html += '<button class="btn btn--ghost" onclick="exportVisibleTableCSV(\'cotizacion_' + q.id + '\')">Exportar CSV</button>';
html += '<button class="btn btn--ghost" onclick="window.print()">Imprimir</button>';
html += '</div>';
document.getElementById('quoteDetail').innerHTML = html;
});
};
window.deleteQuote = function(id, event) {
if (event) event.stopPropagation();
if (!confirm('¿Eliminar cotización #' + id + '? Esta acción no se puede deshacer.')) return;
fetch(API + '/quotations/' + id, { method: 'DELETE', headers: headers() })
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.ok) {
document.getElementById('quoteModal').classList.remove('open');
loadQuotes();
if (typeof showToast === 'function') showToast('Cotización #' + id + ' eliminada', 'ok');
} else {
alert('Error: ' + (d.error || 'desconocido'));
}
});
};
// Close modal on outside click
document.getElementById('quoteModal').addEventListener('click', function(e) {
if (e.target === this) this.classList.remove('open');
});
loadQuotes();
})();
</script>
</body>
</html>