diff --git a/pos/static/js/customers.js b/pos/static/js/customers.js index 0ab14d1..6296d28 100644 --- a/pos/static/js/customers.js +++ b/pos/static/js/customers.js @@ -107,7 +107,7 @@ const Customers = (() => { const num = String(c.id).padStart(5, '0'); const selClass = (currentCustomer && currentCustomer.id === c.id) ? 'selected' : ''; const isChecked = selectedCustomers.has(c.id) ? 'checked' : ''; - return '' + + return '' + '' + '' + num + '' + '' + @@ -121,6 +121,7 @@ const Customers = (() => { '' + fmt(available) + '' + '' + formatDate(c.last_purchase || c.created_at) + '' + '' + statusBadge(c) + '' + + '' + ''; } @@ -131,7 +132,7 @@ const Customers = (() => { if (!tbody) return; if (!customers || customers.length === 0) { - tbody.innerHTML = '' + renderEmptyState({ + tbody.innerHTML = '' + renderEmptyState({ icon: '', title: 'Sin clientes', subtitle: 'No se encontraron clientes registrados.', @@ -146,7 +147,7 @@ const Customers = (() => { rowHeight: 52, buffer: 3, renderRow: renderCustomerRow, - emptyHtml: '' + renderEmptyState({ title: 'Sin clientes', subtitle: 'No hay clientes registrados.' }) + '' + emptyHtml: '' + renderEmptyState({ title: 'Sin clientes', subtitle: 'No hay clientes registrados.' }) + '' }); } customersVS.setData(customers); @@ -415,9 +416,22 @@ const Customers = (() => { function editCurrent() { if (!currentCustomer) return; - const c = currentCustomer; + openEditModal(currentCustomer); + } + + async function editCustomer(id) { + try { + const c = await api(`/pos/api/customers/${id}`); + currentCustomer = c; + openEditModal(c); + } catch (e) { + alert('Error: ' + e.message); + } + } + + function openEditModal(c) { const modal = document.getElementById('customerModal'); - if (!modal) return; + if (!modal || !c) return; document.getElementById('modalTitle').textContent = 'Editar Cliente'; document.getElementById('editId').value = c.id; const safeSet = (id, v) => { const el = document.getElementById(id); if (el) el.value = v; }; @@ -802,7 +816,7 @@ const Customers = (() => { const publicApi = { search, goToPage, loadCustomers, showDetail, selectCustomer, closeDetail, - showCreateModal, editCurrent, closeModal, save, + showCreateModal, editCurrent, editCustomer, closeModal, save, showStatement, closeStatement, showPaymentModal, closePayment, recordPayment, }; diff --git a/pos/templates/customers.html b/pos/templates/customers.html index e2ce560..b149685 100644 --- a/pos/templates/customers.html +++ b/pos/templates/customers.html @@ -330,6 +330,7 @@ Crédito Disp. Última Compra Estado +