Update script.js
Browse files
script.js
CHANGED
|
@@ -6,7 +6,7 @@ function render() {
|
|
| 6 |
app.innerHTML = '';
|
| 7 |
|
| 8 |
const addButton = document.createElement('button');
|
| 9 |
-
addButton.className = '
|
| 10 |
addButton.textContent = '+ Añadir Mesa';
|
| 11 |
addButton.onclick = () => {
|
| 12 |
let mesaNumero = 1;
|
|
@@ -14,11 +14,11 @@ function render() {
|
|
| 14 |
mesaInput.className = 'mesa-input';
|
| 15 |
mesaInput.innerHTML = `
|
| 16 |
<div class="mesa-controls">
|
| 17 |
-
<button id="decreaseMesa" class="
|
| 18 |
<span id="mesaNumero" class="mesa-number">${mesaNumero}</span>
|
| 19 |
-
<button id="increaseMesa" class="
|
| 20 |
</div>
|
| 21 |
-
<button id="confirmMesa" class="
|
| 22 |
`;
|
| 23 |
app.innerHTML = '';
|
| 24 |
app.appendChild(mesaInput);
|
|
@@ -47,8 +47,10 @@ function render() {
|
|
| 47 |
const mesaDiv = document.createElement('div');
|
| 48 |
mesaDiv.className = 'mesa-card';
|
| 49 |
mesaDiv.innerHTML = `
|
| 50 |
-
<div class="
|
| 51 |
-
<
|
|
|
|
|
|
|
| 52 |
</div>
|
| 53 |
`;
|
| 54 |
mesaDiv.style.cursor = 'pointer';
|
|
@@ -66,11 +68,11 @@ function gestionarMesa(index) {
|
|
| 66 |
|
| 67 |
const titulo = document.createElement('h1');
|
| 68 |
titulo.textContent = `Mesa ${mesa.numero}`;
|
| 69 |
-
titulo.className = '
|
| 70 |
app.appendChild(titulo);
|
| 71 |
|
| 72 |
const pedidosContainer = document.createElement('div');
|
| 73 |
-
pedidosContainer.className = 'pedidos-container';
|
| 74 |
pedidosContainer.innerHTML = mesa.pedidos.map(p => `${p.item} (${p.opcion || ''}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('<br>');
|
| 75 |
app.appendChild(pedidosContainer);
|
| 76 |
|
|
@@ -86,7 +88,7 @@ function gestionarMesa(index) {
|
|
| 86 |
|
| 87 |
categorias.forEach(categoria => {
|
| 88 |
const button = document.createElement('button');
|
| 89 |
-
button.className = '
|
| 90 |
button.textContent = `+ ${categoria.nombre} (€${categoria.precio.toFixed(2)})`;
|
| 91 |
button.onclick = () => {
|
| 92 |
const opcionesContainer = document.createElement('div');
|
|
@@ -98,9 +100,9 @@ function gestionarMesa(index) {
|
|
| 98 |
opcionDiv.innerHTML = `
|
| 99 |
<span>${opcion}</span>
|
| 100 |
<div class="cantidad-controls" data-opcion="${opcion}" data-categoria="${categoria.nombre}" data-precio="${categoria.precio}">
|
| 101 |
-
<button class="
|
| 102 |
<span class="cantidad">0</span>
|
| 103 |
-
<button class="
|
| 104 |
</div>
|
| 105 |
`;
|
| 106 |
opcionesContainer.appendChild(opcionDiv);
|
|
@@ -125,7 +127,7 @@ function gestionarMesa(index) {
|
|
| 125 |
|
| 126 |
const confirmarButton = document.createElement('button');
|
| 127 |
confirmarButton.textContent = '✔ Confirmar';
|
| 128 |
-
confirmarButton.className = '
|
| 129 |
confirmarButton.onclick = () => {
|
| 130 |
const cantidadControls = document.querySelectorAll('.cantidad-controls');
|
| 131 |
cantidadControls.forEach(control => {
|
|
@@ -146,7 +148,7 @@ function gestionarMesa(index) {
|
|
| 146 |
|
| 147 |
const volverButton = document.createElement('button');
|
| 148 |
volverButton.textContent = '← Volver';
|
| 149 |
-
volverButton.className = '
|
| 150 |
volverButton.onclick = () => gestionarMesa(index);
|
| 151 |
app.appendChild(volverButton);
|
| 152 |
};
|
|
@@ -155,23 +157,19 @@ function gestionarMesa(index) {
|
|
| 155 |
|
| 156 |
const atrasButton = document.createElement('button');
|
| 157 |
atrasButton.textContent = '← Atrás';
|
| 158 |
-
atrasButton.className = '
|
| 159 |
atrasButton.onclick = () => render();
|
| 160 |
app.appendChild(atrasButton);
|
| 161 |
|
| 162 |
const finalizarButton = document.createElement('button');
|
| 163 |
finalizarButton.textContent = 'Finalizar';
|
| 164 |
-
finalizarButton.className = '
|
| 165 |
finalizarButton.onclick = () => {
|
| 166 |
const total = mesa.pedidos.reduce((sum, p) => sum + p.precio * p.cantidad, 0);
|
| 167 |
if (total > 0) {
|
| 168 |
-
|
| 169 |
-
<h2>Total de la cuenta: €${total.toFixed(2)}</h2>
|
| 170 |
-
<button onclick="generarTicket(${index}, ${total})">Generar Ticket</button>
|
| 171 |
-
`;
|
| 172 |
} else {
|
| 173 |
-
alert("
|
| 174 |
-
render();
|
| 175 |
}
|
| 176 |
};
|
| 177 |
app.appendChild(finalizarButton);
|
|
@@ -185,7 +183,11 @@ function generarTicket(index, total) {
|
|
| 185 |
qrContent += `${pedido.item} (${pedido.opcion || ''}) x${pedido.cantidad} - €${(pedido.precio * pedido.cantidad).toFixed(2)}\n`;
|
| 186 |
});
|
| 187 |
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
text: qrContent,
|
| 190 |
width: 256,
|
| 191 |
height: 256,
|
|
@@ -193,8 +195,15 @@ function generarTicket(index, total) {
|
|
| 193 |
colorLight: "#ffffff",
|
| 194 |
correctLevel: QRCode.CorrectLevel.H
|
| 195 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
}
|
| 197 |
|
|
|
|
| 198 |
render();
|
| 199 |
|
| 200 |
|
|
|
|
| 6 |
app.innerHTML = '';
|
| 7 |
|
| 8 |
const addButton = document.createElement('button');
|
| 9 |
+
addButton.className = 'btn btn-success';
|
| 10 |
addButton.textContent = '+ Añadir Mesa';
|
| 11 |
addButton.onclick = () => {
|
| 12 |
let mesaNumero = 1;
|
|
|
|
| 14 |
mesaInput.className = 'mesa-input';
|
| 15 |
mesaInput.innerHTML = `
|
| 16 |
<div class="mesa-controls">
|
| 17 |
+
<button id="decreaseMesa" class="btn btn-outline-primary">-</button>
|
| 18 |
<span id="mesaNumero" class="mesa-number">${mesaNumero}</span>
|
| 19 |
+
<button id="increaseMesa" class="btn btn-outline-primary">+</button>
|
| 20 |
</div>
|
| 21 |
+
<button id="confirmMesa" class="btn btn-primary">Confirmar</button>
|
| 22 |
`;
|
| 23 |
app.innerHTML = '';
|
| 24 |
app.appendChild(mesaInput);
|
|
|
|
| 47 |
const mesaDiv = document.createElement('div');
|
| 48 |
mesaDiv.className = 'mesa-card';
|
| 49 |
mesaDiv.innerHTML = `
|
| 50 |
+
<div class="card">
|
| 51 |
+
<div class="card-body">
|
| 52 |
+
<h5 class="card-title">Mesa ${mesa.numero}</h5>
|
| 53 |
+
</div>
|
| 54 |
</div>
|
| 55 |
`;
|
| 56 |
mesaDiv.style.cursor = 'pointer';
|
|
|
|
| 68 |
|
| 69 |
const titulo = document.createElement('h1');
|
| 70 |
titulo.textContent = `Mesa ${mesa.numero}`;
|
| 71 |
+
titulo.className = 'text-center mb-4';
|
| 72 |
app.appendChild(titulo);
|
| 73 |
|
| 74 |
const pedidosContainer = document.createElement('div');
|
| 75 |
+
pedidosContainer.className = 'pedidos-container mb-4';
|
| 76 |
pedidosContainer.innerHTML = mesa.pedidos.map(p => `${p.item} (${p.opcion || ''}) x${p.cantidad} - €${(p.precio * p.cantidad).toFixed(2)}`).join('<br>');
|
| 77 |
app.appendChild(pedidosContainer);
|
| 78 |
|
|
|
|
| 88 |
|
| 89 |
categorias.forEach(categoria => {
|
| 90 |
const button = document.createElement('button');
|
| 91 |
+
button.className = 'btn btn-info btn-block';
|
| 92 |
button.textContent = `+ ${categoria.nombre} (€${categoria.precio.toFixed(2)})`;
|
| 93 |
button.onclick = () => {
|
| 94 |
const opcionesContainer = document.createElement('div');
|
|
|
|
| 100 |
opcionDiv.innerHTML = `
|
| 101 |
<span>${opcion}</span>
|
| 102 |
<div class="cantidad-controls" data-opcion="${opcion}" data-categoria="${categoria.nombre}" data-precio="${categoria.precio}">
|
| 103 |
+
<button class="btn btn-outline-secondary decrease">-</button>
|
| 104 |
<span class="cantidad">0</span>
|
| 105 |
+
<button class="btn btn-outline-secondary increase">+</button>
|
| 106 |
</div>
|
| 107 |
`;
|
| 108 |
opcionesContainer.appendChild(opcionDiv);
|
|
|
|
| 127 |
|
| 128 |
const confirmarButton = document.createElement('button');
|
| 129 |
confirmarButton.textContent = '✔ Confirmar';
|
| 130 |
+
confirmarButton.className = 'btn btn-warning btn-block';
|
| 131 |
confirmarButton.onclick = () => {
|
| 132 |
const cantidadControls = document.querySelectorAll('.cantidad-controls');
|
| 133 |
cantidadControls.forEach(control => {
|
|
|
|
| 148 |
|
| 149 |
const volverButton = document.createElement('button');
|
| 150 |
volverButton.textContent = '← Volver';
|
| 151 |
+
volverButton.className = 'btn btn-danger btn-block';
|
| 152 |
volverButton.onclick = () => gestionarMesa(index);
|
| 153 |
app.appendChild(volverButton);
|
| 154 |
};
|
|
|
|
| 157 |
|
| 158 |
const atrasButton = document.createElement('button');
|
| 159 |
atrasButton.textContent = '← Atrás';
|
| 160 |
+
atrasButton.className = 'btn btn-outline-danger btn-block';
|
| 161 |
atrasButton.onclick = () => render();
|
| 162 |
app.appendChild(atrasButton);
|
| 163 |
|
| 164 |
const finalizarButton = document.createElement('button');
|
| 165 |
finalizarButton.textContent = 'Finalizar';
|
| 166 |
+
finalizarButton.className = 'btn btn-primary btn-block';
|
| 167 |
finalizarButton.onclick = () => {
|
| 168 |
const total = mesa.pedidos.reduce((sum, p) => sum + p.precio * p.cantidad, 0);
|
| 169 |
if (total > 0) {
|
| 170 |
+
generarTicket(index, total);
|
|
|
|
|
|
|
|
|
|
| 171 |
} else {
|
| 172 |
+
alert("La mesa no tiene productos");
|
|
|
|
| 173 |
}
|
| 174 |
};
|
| 175 |
app.appendChild(finalizarButton);
|
|
|
|
| 183 |
qrContent += `${pedido.item} (${pedido.opcion || ''}) x${pedido.cantidad} - €${(pedido.precio * pedido.cantidad).toFixed(2)}\n`;
|
| 184 |
});
|
| 185 |
|
| 186 |
+
const qrContainer = document.createElement('div');
|
| 187 |
+
qrContainer.className = 'text-center';
|
| 188 |
+
app.appendChild(qrContainer);
|
| 189 |
+
|
| 190 |
+
new QRCode(qrContainer, {
|
| 191 |
text: qrContent,
|
| 192 |
width: 256,
|
| 193 |
height: 256,
|
|
|
|
| 195 |
colorLight: "#ffffff",
|
| 196 |
correctLevel: QRCode.CorrectLevel.H
|
| 197 |
});
|
| 198 |
+
|
| 199 |
+
const volverButton = document.createElement('button');
|
| 200 |
+
volverButton.textContent = '← Volver';
|
| 201 |
+
volverButton.className = 'btn btn-outline-danger btn-block';
|
| 202 |
+
volverButton.onclick = () => render();
|
| 203 |
+
app.appendChild(volverButton);
|
| 204 |
}
|
| 205 |
|
| 206 |
+
// Inicializar la aplicación
|
| 207 |
render();
|
| 208 |
|
| 209 |
|