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:
@@ -388,11 +388,92 @@ const Accounting = (() => {
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
|
||||
// ---- Exportar placeholder ----
|
||||
function exportarContabilidad() {
|
||||
alert('Exportar: proximamente');
|
||||
}
|
||||
|
||||
// ---- Nueva Poliza modal ----
|
||||
function showNewEntryModal() {
|
||||
const overlay = document.getElementById('newEntryModalOverlay');
|
||||
if (!overlay) return;
|
||||
// Set default date to today
|
||||
const dateInput = overlay.querySelector('#entryDate');
|
||||
if (dateInput && !dateInput.value) {
|
||||
dateInput.value = new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
document.getElementById('entryResult').innerHTML = '';
|
||||
overlay.style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeNewEntryModal() {
|
||||
const overlay = document.getElementById('newEntryModalOverlay');
|
||||
if (overlay) overlay.style.display = 'none';
|
||||
}
|
||||
|
||||
function addEntryLine() {
|
||||
const container = document.getElementById('entryLines');
|
||||
if (!container) return;
|
||||
const line = document.createElement('div');
|
||||
line.className = 'entry-line';
|
||||
line.style.cssText = 'display:grid;grid-template-columns:2fr 1fr 1fr auto;gap:var(--space-2);margin-bottom:var(--space-2);align-items:center;';
|
||||
line.innerHTML =
|
||||
'<input type="text" placeholder="Cuenta contable" class="entry-account" style="padding:var(--space-2) var(--space-3);border:1px solid var(--color-border);border-radius:var(--radius-md);background:var(--color-surface-2);color:var(--color-text-primary);font-size:var(--text-body-sm);" />' +
|
||||
'<input type="number" placeholder="Debe" class="entry-debit" step="0.01" style="padding:var(--space-2) var(--space-3);border:1px solid var(--color-border);border-radius:var(--radius-md);background:var(--color-surface-2);color:var(--color-text-primary);font-size:var(--text-body-sm);" />' +
|
||||
'<input type="number" placeholder="Haber" class="entry-credit" step="0.01" style="padding:var(--space-2) var(--space-3);border:1px solid var(--color-border);border-radius:var(--radius-md);background:var(--color-surface-2);color:var(--color-text-primary);font-size:var(--text-body-sm);" />' +
|
||||
'<button class="btn btn--ghost btn--sm" onclick="this.closest(\'.entry-line\').remove()">×</button>';
|
||||
container.appendChild(line);
|
||||
}
|
||||
|
||||
async function submitNewEntry() {
|
||||
const date = document.getElementById('entryDate').value;
|
||||
const type = document.getElementById('entryType').value;
|
||||
const description = document.getElementById('entryDescription').value.trim();
|
||||
const resultEl = document.getElementById('entryResult');
|
||||
|
||||
if (!date || !description) {
|
||||
resultEl.innerHTML = '<span style="color:var(--color-error);">Fecha y descripcion son obligatorios.</span>';
|
||||
return;
|
||||
}
|
||||
|
||||
const lines = [];
|
||||
document.querySelectorAll('#entryLines .entry-line').forEach(row => {
|
||||
const account = row.querySelector('.entry-account').value.trim();
|
||||
const debit = parseFloat(row.querySelector('.entry-debit').value) || 0;
|
||||
const credit = parseFloat(row.querySelector('.entry-credit').value) || 0;
|
||||
if (account && (debit || credit)) {
|
||||
lines.push({ account, debit, credit });
|
||||
}
|
||||
});
|
||||
|
||||
if (!lines.length) {
|
||||
resultEl.innerHTML = '<span style="color:var(--color-error);">Agregue al menos una partida.</span>';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await api('/entries', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ date, type, description, lines }),
|
||||
});
|
||||
resultEl.innerHTML = '<span style="color:var(--color-success);">Poliza creada exitosamente.</span>';
|
||||
setTimeout(() => closeNewEntryModal(), 1200);
|
||||
} catch (e) {
|
||||
resultEl.innerHTML = '<span style="color:var(--color-error);">Error: ' + e.message + '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// Expose switchTab globally for onclick handlers in HTML
|
||||
window.switchTab = switchTab;
|
||||
window.exportarContabilidad = exportarContabilidad;
|
||||
window.showNewEntryModal = showNewEntryModal;
|
||||
window.closeNewEntryModal = closeNewEntryModal;
|
||||
window.addEntryLine = addEntryLine;
|
||||
window.submitNewEntry = submitNewEntry;
|
||||
|
||||
return {
|
||||
switchTab, loadAging, loadAccountsPayable, loadBalanceSheet,
|
||||
loadIncomeStatement, loadCashFlow, loadReconciliation, loadPeriodClose,
|
||||
exportarContabilidad, showNewEntryModal, closeNewEntryModal, addEntryLine, submitNewEntry,
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user