- Agrega TTS (speechSynthesis) a chat.js del POS para leer respuestas IA - Copia lógica de voz completa (STT + TTS) a dashboard/chat-public.js - Extiende estilos TTS en chat.css y chat-public.css - Agrega chat widget a 13 templates POS que no lo tenían - Corrige duplicado de chat.css en diagrams.html - Minifica assets actualizados - 73/73 tests pasan
154 lines
8.5 KiB
HTML
154 lines
8.5 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/chat.css" />
|
|
<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')">×</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>
|
|
<script src="/pos/static/js/chat.js" defer></script>
|
|
</body>
|
|
</html>
|