@@ -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}`;