diff --git a/templates/sales.html b/templates/sales.html index b6482ec..6f80916 100644 --- a/templates/sales.html +++ b/templates/sales.html @@ -4,11 +4,52 @@ {% block title %}Ventas{% endblock %} {% block head %} - + {% endblock %} {% block content %} +
+
+

SekiPOS

+
Re-impresión de Comprobante
+
+ Ticket Nº +
+
+
+ + + + + + + + + + +
CantDescTotal
+
+ TOTAL: + +
+
¡Gracias por su compra!
+
+
@@ -115,9 +156,15 @@
@@ -173,12 +220,15 @@ const localDate = new Date(rawDate + " UTC").toLocaleString('es-CL'); document.getElementById('modal-date').innerText = localDate !== "Invalid Date" ? localDate : rawDate; + // Configure the Anular button + document.getElementById('btn-reverse-sale').setAttribute('onclick', `reverseSale(${id})`); + + // Configure the Print button + document.getElementById('btn-print-modal').setAttribute('onclick', `reprintSale(${id}, ${total}, '${rawDate}')`); + const tbody = document.getElementById('receipt-items'); tbody.innerHTML = 'Cargando...'; - // Attach the ID to the delete button - document.getElementById('btn-reverse-sale').setAttribute('onclick', `reverseSale(${id})`); - const modal = new bootstrap.Modal(document.getElementById('receiptModal')); modal.show(); @@ -187,20 +237,46 @@ const items = await res.json(); tbody.innerHTML = items.map(item => ` - - - ${item.name}
- ${item.barcode} - - ${item.qty} - ${clp.format(item.subtotal)} - - `).join(''); + + + ${item.name}
+ ${item.barcode} + + ${item.qty} + ${clp.format(item.subtotal)} + + `).join(''); } catch (err) { tbody.innerHTML = 'Error cargando productos'; } } + async function reprintSale(id, total, rawDate) { + const tbody = document.getElementById('receipt-items-print'); + + try { + const res = await fetch(`/api/sale/${id}`); + const items = await res.json(); + + tbody.innerHTML = items.map(item => ` + + ${item.qty} + ${item.name} + ${clp.format(item.subtotal)} + + `).join(''); + + document.getElementById('receipt-ticket-id').innerText = id; + document.getElementById('receipt-total-print').innerText = clp.format(total); + document.getElementById('receipt-date').innerText = new Date(rawDate + " UTC").toLocaleString('es-CL'); + + window.print(); + } catch (err) { + console.error(err); + alert("Error al preparar la impresión."); + } + } + function filterByDate(dateVal) { if (dateVal) { window.location.href = `/sales?date=${dateVal}`;