fix(pos): wire buttons in contabilidad, facturacion, inventario, dashboard

- Contabilidad: Nueva Poliza modal + Exportar placeholder
- Facturacion: Nueva Factura modal (sale_id input) + Nota Credito placeholder
- Inventario: click en producto abre detalle con historial
- Dashboard: Ver Detalles navega a paginas relevantes, campana a alertas

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-01 22:36:49 +00:00
parent a74fe94187
commit e7376ddaed
6 changed files with 265 additions and 12 deletions

View File

@@ -70,7 +70,7 @@
}
tbody.innerHTML = items.map(function (it) {
return '<tr>' +
return '<tr style="cursor:pointer;" onclick="viewProductDetail(' + it.id + ')">' +
'<td class="td--mono">' + esc(it.barcode) + '</td>' +
'<td class="td--mono">' + esc(it.part_number) + '</td>' +
'<td class="td--primary">' + esc(it.name) + '</td>' +
@@ -82,8 +82,8 @@
'<td style="text-align:right" class="td--amount">$' + fmt(it.price_3) + '</td>' +
'<td>' + esc(it.location) + '</td>' +
'<td>' +
'<button class="btn btn--ghost btn--sm" onclick="viewHistory(' + it.id + ')">Historial</button> ' +
'<button class="btn btn--ghost btn--sm" onclick="printBarcode(\'' + esc(it.barcode) + '\',\'' + esc(it.part_number) + '\',\'' + esc(it.name) + '\')">Etiqueta</button>' +
'<button class="btn btn--ghost btn--sm" onclick="event.stopPropagation();viewHistory(' + it.id + ')">Historial</button> ' +
'<button class="btn btn--ghost btn--sm" onclick="event.stopPropagation();printBarcode(\'' + esc(it.barcode) + '\',\'' + esc(it.part_number) + '\',\'' + esc(it.name) + '\')">Etiqueta</button>' +
'</td></tr>';
}).join('');
@@ -439,6 +439,61 @@
w.print();
}
// =====================================================================
// PRODUCT DETAIL MODAL (shows item info + movement history)
// =====================================================================
function viewProductDetail(itemId) {
apiFetch(API + '/items/' + itemId).then(function (data) {
if (!data || data.error) {
alert(data ? data.error : 'Error de red');
return;
}
var history = data.history || [];
var html = '';
// Product info header
html += '<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:16px;padding-bottom:16px;border-bottom:1px solid var(--color-border);">';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">No. Parte</span><strong>' + esc(data.part_number) + '</strong></div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Nombre</span><strong>' + esc(data.name) + '</strong></div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Marca</span>' + esc(data.brand) + '</div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Codigo de Barras</span><span style="font-family:var(--font-mono);">' + esc(data.barcode) + '</span></div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Ubicacion</span>' + esc(data.location || '-') + '</div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Stock</span><strong style="font-size:1.2em;">' + (data.stock || 0) + '</strong></div>';
html += '</div>';
// Prices
html += '<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:16px;padding-bottom:16px;border-bottom:1px solid var(--color-border);">';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Costo</span><span class="td--amount">$' + fmt(data.cost) + '</span></div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Precio 1</span><span class="td--amount">$' + fmt(data.price_1) + '</span></div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Precio 2</span><span class="td--amount">$' + fmt(data.price_2) + '</span></div>';
html += '<div><span style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;display:block;">Precio 3</span><span class="td--amount">$' + fmt(data.price_3) + '</span></div>';
html += '</div>';
// Movement history
html += '<div style="font-size:var(--text-caption);color:var(--color-text-muted);text-transform:uppercase;letter-spacing:var(--tracking-widest);margin-bottom:8px;">Historial de Movimientos</div>';
if (!history.length) {
html += '<p style="color:var(--color-text-muted);text-align:center;padding:var(--space-4);">Sin movimientos</p>';
} else {
html += '<table class="data-table"><thead><tr><th>Fecha</th><th>Tipo</th><th>Cantidad</th><th>Costo</th><th>Empleado</th><th>Notas</th></tr></thead><tbody>';
history.forEach(function (h) {
var qtyColor = h.quantity > 0 ? 'var(--color-success)' : 'var(--color-error)';
html += '<tr>' +
'<td style="font-size:var(--text-caption);">' + esc(h.date) + '</td>' +
'<td>' + esc(h.type) + '</td>' +
'<td style="color:' + qtyColor + ';font-weight:600;">' + (h.quantity > 0 ? '+' : '') + h.quantity + '</td>' +
'<td class="td--amount">' + (h.cost ? '$' + fmt(h.cost) : '\u2014') + '</td>' +
'<td>' + esc(h.employee) + '</td>' +
'<td style="font-size:var(--text-caption);">' + esc(h.notes) + '</td>' +
'</tr>';
});
html += '</tbody></table>';
}
document.getElementById('historyContent').innerHTML = html;
document.getElementById('historyModal').classList.add('is-open');
});
}
// =====================================================================
// EXPOSE GLOBALS (for onclick handlers in HTML)
// =====================================================================
@@ -446,6 +501,7 @@
window._loadItems = function (p) { loadItems(p); };
window.loadItems = function (p, q) { loadItems(p, q); };
window.viewHistory = viewHistory;
window.viewProductDetail = viewProductDetail;
window.closeHistoryModal = closeHistoryModal;
window.showCreateModal = showCreateModal;
window.closeCreateModal = closeCreateModal;