modified: app.py

modified:   static/styleIndex.css
	modified:   templates/index.html
This commit is contained in:
2026-02-26 21:08:41 -03:00
parent 80bf539484
commit 4faee03762
3 changed files with 171 additions and 0 deletions

View File

@@ -56,11 +56,19 @@
<div class="column">
<div class="card">
<h3 style="text-align: left; margin-top:0;">Inventario</h3>
<div id="bulk-action-bar">
<span id="selected-count">0 seleccionados</span>
<input type="number" id="bulk-price-input" placeholder="Precio CLP">
<button onclick="applyBulkPrice()" class="btn-bulk-save">Actualizar Precio</button>
<button onclick="applyBulkDelete()" class="btn-bulk-del">Borrar</button>
</div>
<input type="text" id="searchInput" onkeyup="searchTable()" placeholder="Buscar por nombre o código...">
<table id="inventoryTable">
<thead>
<tr>
<th><input type="checkbox" id="select-all" onclick="toggleAll(this)"></th>
<th>Código</th>
<th>Nombre</th>
<th>Precio</th>
@@ -70,6 +78,8 @@
<tbody>
{% for p in products %}
<tr>
<td><input type="checkbox" class="product-checkbox" value="{{ p[0] }}"
onchange="updateBulkBar()"></td>
<td style="font-family: monospace;">{{ p[0] }}</td>
<td>{{ p[1] }}</td>
<td class="price-cell" data-value="{{ p[2] }}"></td>
@@ -194,6 +204,61 @@
tr[i].style.display = content.toUpperCase().indexOf(filter) > -1 ? "" : "none";
}
}
function toggleAll(source) {
document.querySelectorAll('.product-checkbox').forEach(cb => cb.checked = source.checked);
updateBulkBar();
}
function updateBulkBar() {
const selected = document.querySelectorAll('.product-checkbox:checked');
const bar = document.getElementById('bulk-action-bar');
const countDisplay = document.getElementById('selected-count');
if (selected.length > 0) {
bar.style.display = 'flex';
countDisplay.innerText = `${selected.length} seleccionados`;
} else {
bar.style.display = 'none';
}
}
function getSelectedBarcodes() {
return Array.from(document.querySelectorAll('.product-checkbox:checked')).map(cb => cb.value);
}
async function applyBulkPrice() {
const barcodes = getSelectedBarcodes();
const price = document.getElementById('bulk-price-input').value;
if (!price) return alert("Ingresa un precio");
const resp = await fetch('/bulk_edit_price', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ barcodes, price })
});
if (resp.ok) location.reload();
}
async function applyBulkDelete() {
if (!confirm("¿Eliminar todos los productos seleccionados?")) return;
const barcodes = getSelectedBarcodes();
const resp = await fetch('/bulk_delete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ barcodes })
});
if (resp.ok) location.reload();
}
// Clear checkboxes on reload to prevent ghost selections
window.addEventListener('load', () => {
document.querySelectorAll('.product-checkbox').forEach(cb => cb.checked = false);
const selectAll = document.getElementById('select-all');
if (selectAll) selectAll.checked = false;
updateBulkBar();
});
</script>
</body>