Update script.js
Browse files
script.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
const app = document.getElementById('app');
|
| 2 |
let mesas = [];
|
| 3 |
|
| 4 |
-
//
|
| 5 |
function render() {
|
| 6 |
app.innerHTML = '';
|
| 7 |
|
|
@@ -59,6 +59,7 @@ function render() {
|
|
| 59 |
app.appendChild(mesasContainer);
|
| 60 |
}
|
| 61 |
|
|
|
|
| 62 |
function gestionarMesa(index) {
|
| 63 |
const mesa = mesas[index];
|
| 64 |
app.innerHTML = '';
|
|
@@ -104,7 +105,6 @@ function gestionarMesa(index) {
|
|
| 104 |
`;
|
| 105 |
opcionesContainer.appendChild(opcionDiv);
|
| 106 |
|
| 107 |
-
// Añadir los controladores de cantidad
|
| 108 |
const cantidadControl = opcionDiv.querySelector('.cantidad-controls');
|
| 109 |
const cantidadSpan = cantidadControl.querySelector('.cantidad');
|
| 110 |
|
|
@@ -164,35 +164,37 @@ function gestionarMesa(index) {
|
|
| 164 |
finalizarButton.className = 'finalize-button';
|
| 165 |
finalizarButton.onclick = () => {
|
| 166 |
const total = mesa.pedidos.reduce((sum, p) => sum + p.precio * p.cantidad, 0);
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
};
|
| 172 |
app.appendChild(finalizarButton);
|
| 173 |
}
|
| 174 |
|
|
|
|
| 175 |
function generarTicket(index, total) {
|
| 176 |
const mesa = mesas[index];
|
| 177 |
-
const
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
app.appendChild(qrCodeContainer);
|
| 182 |
|
| 183 |
-
|
| 184 |
-
text:
|
| 185 |
width: 256,
|
| 186 |
height: 256,
|
|
|
|
|
|
|
|
|
|
| 187 |
});
|
|
|
|
| 188 |
|
| 189 |
-
|
| 190 |
-
volverButton.textContent = '← Volver';
|
| 191 |
-
volverButton.className = 'back-button';
|
| 192 |
-
volverButton.onclick = () => render();
|
| 193 |
-
app.appendChild(volverButton);
|
| 194 |
|
| 195 |
-
// Eliminar la mesa después de generar el ticket
|
| 196 |
-
mesas.splice(index, 1);
|
| 197 |
-
}
|
| 198 |
|
|
|
|
| 1 |
const app = document.getElementById('app');
|
| 2 |
let mesas = [];
|
| 3 |
|
| 4 |
+
// Función de renderizado principal
|
| 5 |
function render() {
|
| 6 |
app.innerHTML = '';
|
| 7 |
|
|
|
|
| 59 |
app.appendChild(mesasContainer);
|
| 60 |
}
|
| 61 |
|
| 62 |
+
// Función para gestionar los pedidos de una mesa
|
| 63 |
function gestionarMesa(index) {
|
| 64 |
const mesa = mesas[index];
|
| 65 |
app.innerHTML = '';
|
|
|
|
| 105 |
`;
|
| 106 |
opcionesContainer.appendChild(opcionDiv);
|
| 107 |
|
|
|
|
| 108 |
const cantidadControl = opcionDiv.querySelector('.cantidad-controls');
|
| 109 |
const cantidadSpan = cantidadControl.querySelector('.cantidad');
|
| 110 |
|
|
|
|
| 164 |
finalizarButton.className = 'finalize-button';
|
| 165 |
finalizarButton.onclick = () => {
|
| 166 |
const total = mesa.pedidos.reduce((sum, p) => sum + p.precio * p.cantidad, 0);
|
| 167 |
+
if (total > 0) {
|
| 168 |
+
app.innerHTML = `
|
| 169 |
+
<h2>Total de la cuenta: €${total.toFixed(2)}</h2>
|
| 170 |
+
<button onclick="generarTicket(${index}, ${total})">Generar Ticket</button>
|
| 171 |
+
`;
|
| 172 |
+
} else {
|
| 173 |
+
alert("No hay productos añadidos a esta mesa.");
|
| 174 |
+
render();
|
| 175 |
+
}
|
| 176 |
};
|
| 177 |
app.appendChild(finalizarButton);
|
| 178 |
}
|
| 179 |
|
| 180 |
+
// Generación del QR y ticket
|
| 181 |
function generarTicket(index, total) {
|
| 182 |
const mesa = mesas[index];
|
| 183 |
+
const qrContent = `Mesa ${mesa.numero} Total: €${total.toFixed(2)}\n`;
|
| 184 |
+
mesa.pedidos.forEach(pedido => {
|
| 185 |
+
qrContent += `${pedido.item} (${pedido.opcion || ''}) x${pedido.cantidad} - €${(pedido.precio * pedido.cantidad).toFixed(2)}\n`;
|
| 186 |
+
});
|
|
|
|
| 187 |
|
| 188 |
+
new QRCode(document.getElementById('qrcode'), {
|
| 189 |
+
text: qrContent,
|
| 190 |
width: 256,
|
| 191 |
height: 256,
|
| 192 |
+
colorDark: "#000000",
|
| 193 |
+
colorLight: "#ffffff",
|
| 194 |
+
correctLevel: QRCode.CorrectLevel.H
|
| 195 |
});
|
| 196 |
+
}
|
| 197 |
|
| 198 |
+
render();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
|
|
|
|
|
|
|
|
|
| 200 |
|