- Add QWEN (qwen3.6) as primary AI backend with short system prompt - Hermes remains as fallback with 45s timeout - Increase QWEN timeout to 35s, max_tokens to 4000 - Add conversation history loading from whatsapp_messages (last 4 msgs) - Persist detected vehicle in whatsapp_sessions table - Add 'limpiar chat' / 'nuevo chat' / 'reset' commands to clear history - Fix CSS conflict: rename whatsapp chat-panel classes to wa-chat-panel - Fix JS ID conflicts with chat.js widget (waChatPanel, waChatMessages, etc.) - Improve no-stock response: conversational with alternatives - Split search_query by | for multi-part lookups - Add DEMO_PROMPTS.md and DEMO_PROMPTS_V2.md
221 lines
11 KiB
HTML
221 lines
11 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;flex-wrap:wrap;">';
|
|
if (q.status === 'active') {
|
|
html += '<button class="btn btn--ghost" onclick="editQuote(' + q.id + ')" style="color:#4f46e5;">Editar</button>';
|
|
html += '<button class="btn btn--ghost" onclick="convertQuote(' + q.id + ')" style="color:#059669;">Convertir a venta</button>';
|
|
html += '<button class="btn btn--ghost" onclick="shareQuote(' + q.id + ')">Compartir link</button>';
|
|
}
|
|
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'));
|
|
}
|
|
});
|
|
};
|
|
|
|
window.editQuote = function(id) {
|
|
fetch(API + '/quotations/' + id, { headers: headers() })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(q) {
|
|
if (!q.items) { alert('Error cargando cotización'); return; }
|
|
var cartItems = q.items.map(function(it) {
|
|
return {
|
|
inventory_id: it.inventory_id,
|
|
part_number: it.part_number,
|
|
name: it.name,
|
|
quantity: it.quantity,
|
|
unit_price: it.unit_price,
|
|
discount_pct: it.discount_pct,
|
|
tax_rate: it.tax_rate
|
|
};
|
|
});
|
|
localStorage.setItem('pos_edit_quote_id', id);
|
|
localStorage.setItem('pos_edit_quote_customer_id', q.customer_id || '');
|
|
localStorage.setItem('pos_edit_quote_notes', q.notes || '');
|
|
localStorage.setItem('pos_cart', JSON.stringify(cartItems));
|
|
window.location.href = '/pos';
|
|
});
|
|
};
|
|
|
|
window.convertQuote = function(id) {
|
|
fetch(API + '/quotations/' + id, { headers: headers() })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(q) {
|
|
if (!q.items) { alert('Error cargando cotización'); return; }
|
|
var cartItems = q.items.map(function(it) {
|
|
return {
|
|
inventory_id: it.inventory_id,
|
|
part_number: it.part_number,
|
|
name: it.name,
|
|
quantity: it.quantity,
|
|
unit_price: it.unit_price,
|
|
discount_pct: it.discount_pct,
|
|
tax_rate: it.tax_rate
|
|
};
|
|
});
|
|
localStorage.setItem('pos_convert_quote_id', id);
|
|
localStorage.setItem('pos_cart', JSON.stringify(cartItems));
|
|
window.location.href = '/pos';
|
|
});
|
|
};
|
|
|
|
window.shareQuote = function(id) {
|
|
fetch(API + '/quotations/' + id + '/share', { method: 'POST', headers: headers() })
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(d) {
|
|
if (d.url) {
|
|
navigator.clipboard.writeText(d.url).then(function() {
|
|
alert('Link copiado al portapapeles:\n' + d.url);
|
|
}).catch(function() {
|
|
prompt('Copia este link:', d.url);
|
|
});
|
|
} 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>
|