Añadir configuración de precios del café y formulario de edición en la página de administración
This commit is contained in:
6
.vscode/extensions.json
vendored
Normal file
6
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"tobermory.es6-string-html",
|
||||||
|
"esbenp.prettier-vscode"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,6 +3,28 @@ try {
|
|||||||
} catch {
|
} catch {
|
||||||
console.log('ScreenLock Failed');
|
console.log('ScreenLock Failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configuración de precios del café (cargado desde DB)
|
||||||
|
window.PRECIOS_CAFE = {
|
||||||
|
servicio_base: 10,
|
||||||
|
leche_pequena: 15,
|
||||||
|
leche_grande: 25,
|
||||||
|
cafe: 25,
|
||||||
|
colacao: 25,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cargar precios desde la base de datos al iniciar
|
||||||
|
if (typeof DB !== 'undefined') {
|
||||||
|
DB.get('config', 'precios_cafe').then((precios) => {
|
||||||
|
if (precios) {
|
||||||
|
Object.assign(window.PRECIOS_CAFE, precios);
|
||||||
|
console.log('Precios del café cargados:', window.PRECIOS_CAFE);
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
console.log('Usando precios por defecto');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const debounce = (id, callback, wait, args) => {
|
const debounce = (id, callback, wait, args) => {
|
||||||
// debounce with trailing callback
|
// debounce with trailing callback
|
||||||
// First call runs immediately, then locks for 'wait' ms
|
// First call runs immediately, then locks for 'wait' ms
|
||||||
@@ -700,36 +722,44 @@ function SC_parse(json) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SC_parse_short(json) {
|
function SC_parse_short(json) {
|
||||||
var valores = "<small style='font-size: 60%;'>Servicio base (10c)</small>\n";
|
const precios = window.PRECIOS_CAFE || {
|
||||||
|
servicio_base: 10,
|
||||||
|
leche_pequena: 15,
|
||||||
|
leche_grande: 25,
|
||||||
|
cafe: 25,
|
||||||
|
colacao: 25,
|
||||||
|
};
|
||||||
|
|
||||||
|
var valores = `<small style='font-size: 60%;'>Servicio base (${precios.servicio_base}c)</small>\n`;
|
||||||
|
|
||||||
Object.entries(json).forEach((entry) => {
|
Object.entries(json).forEach((entry) => {
|
||||||
valores += "<small style='font-size: 60%;'>" + entry[0] + ':</small> ' + entry[1] + ' ';
|
valores += "<small style='font-size: 60%;'>" + entry[0] + ':</small> ' + entry[1] + ' ';
|
||||||
var combo = entry[0] + ';' + entry[1];
|
var combo = entry[0] + ';' + entry[1];
|
||||||
switch (entry[0]) {
|
switch (entry[0]) {
|
||||||
case 'Leche':
|
case 'Leche':
|
||||||
// Leche pequeña = 10c
|
// Leche pequeña
|
||||||
if (
|
if (
|
||||||
json['Tamaño'] == 'Pequeño' &&
|
json['Tamaño'] == 'Pequeño' &&
|
||||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||||
) {
|
) {
|
||||||
valores += '<small>(P = 10c)</small>';
|
valores += `<small>(P = ${precios.leche_pequena}c)</small>`;
|
||||||
}
|
}
|
||||||
// Leche grande = 20c
|
// Leche grande
|
||||||
if (
|
if (
|
||||||
json['Tamaño'] == 'Grande' &&
|
json['Tamaño'] == 'Grande' &&
|
||||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||||
) {
|
) {
|
||||||
valores += '<small>(G = 20c)</small>';
|
valores += `<small>(G = ${precios.leche_grande}c)</small>`;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Selección':
|
case 'Selección':
|
||||||
// Café = 20c
|
// Café
|
||||||
if (['Café con leche', 'Solo café (sin leche)'].includes(json['Selección'])) {
|
if (['Café con leche', 'Solo café (sin leche)'].includes(json['Selección'])) {
|
||||||
valores += '<small>(20c)</small>';
|
valores += `<small>(${precios.cafe}c)</small>`;
|
||||||
}
|
}
|
||||||
// ColaCao = 20c
|
// ColaCao
|
||||||
if (json['Selección'] == 'ColaCao con leche') {
|
if (json['Selección'] == 'ColaCao con leche') {
|
||||||
valores += '<small>(20c)</small>';
|
valores += `<small>(${precios.colacao}c)</small>`;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -743,35 +773,50 @@ function SC_parse_short(json) {
|
|||||||
function SC_priceCalc(json) {
|
function SC_priceCalc(json) {
|
||||||
var precio = 0;
|
var precio = 0;
|
||||||
var valores = '';
|
var valores = '';
|
||||||
// Servicio base = 10c
|
|
||||||
precio += 10;
|
// Usar precios configurables
|
||||||
valores += 'Servicio base = 10c\n';
|
const precios = window.PRECIOS_CAFE || {
|
||||||
// Leche pequeña = 10c
|
servicio_base: 10,
|
||||||
|
leche_pequena: 15,
|
||||||
|
leche_grande: 25,
|
||||||
|
cafe: 25,
|
||||||
|
colacao: 25,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Servicio base
|
||||||
|
precio += precios.servicio_base;
|
||||||
|
valores += `Servicio base = ${precios.servicio_base}c\n`;
|
||||||
|
|
||||||
|
// Leche pequeña
|
||||||
if (
|
if (
|
||||||
json['Tamaño'] == 'Pequeño' &&
|
json['Tamaño'] == 'Pequeño' &&
|
||||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||||
) {
|
) {
|
||||||
precio += 15;
|
precio += precios.leche_pequena;
|
||||||
valores += 'Leche pequeña = 15c\n';
|
valores += `Leche pequeña = ${precios.leche_pequena}c\n`;
|
||||||
}
|
}
|
||||||
// Leche grande = 20c
|
|
||||||
|
// Leche grande
|
||||||
if (
|
if (
|
||||||
json['Tamaño'] == 'Grande' &&
|
json['Tamaño'] == 'Grande' &&
|
||||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||||
) {
|
) {
|
||||||
precio += 25;
|
precio += precios.leche_grande;
|
||||||
valores += 'Leche grande = 25c\n';
|
valores += `Leche grande = ${precios.leche_grande}c\n`;
|
||||||
}
|
}
|
||||||
// Café = 20c
|
|
||||||
|
// Café
|
||||||
if (['Café con leche', 'Solo café (sin leche)'].includes(json['Selección'])) {
|
if (['Café con leche', 'Solo café (sin leche)'].includes(json['Selección'])) {
|
||||||
precio += 25;
|
precio += precios.cafe;
|
||||||
valores += 'Café = 25c\n';
|
valores += `Café = ${precios.cafe}c\n`;
|
||||||
}
|
}
|
||||||
// ColaCao = 20c
|
|
||||||
|
// ColaCao
|
||||||
if (json['Selección'] == 'ColaCao con leche') {
|
if (json['Selección'] == 'ColaCao con leche') {
|
||||||
precio += 25;
|
precio += precios.colacao;
|
||||||
valores += 'ColaCao = 25c\n';
|
valores += `ColaCao = ${precios.colacao}c\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
valores += '<hr>Total: ' + precio + 'c\n';
|
valores += '<hr>Total: ' + precio + 'c\n';
|
||||||
return [precio, valores];
|
return [precio, valores];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ PAGES.dataman = {
|
|||||||
case 'labels':
|
case 'labels':
|
||||||
PAGES.dataman.__labels();
|
PAGES.dataman.__labels();
|
||||||
break;
|
break;
|
||||||
|
case 'precios':
|
||||||
|
PAGES.dataman.__precios();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Tab to edit
|
// Tab to edit
|
||||||
}
|
}
|
||||||
@@ -209,12 +212,88 @@ PAGES.dataman = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
__precios: function () {
|
||||||
|
var form = safeuuid();
|
||||||
|
|
||||||
|
// Cargar precios actuales desde DB
|
||||||
|
DB.get('config', 'precios_cafe').then((raw) => {
|
||||||
|
TS_decrypt(raw, SECRET, (precios) => {
|
||||||
|
container.innerHTML = html`
|
||||||
|
<h1>Configuración de Precios del Café</h1>
|
||||||
|
<form id="${form}">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Precios Base (en céntimos)</legend>
|
||||||
|
<label>
|
||||||
|
<b>Servicio base:</b>
|
||||||
|
<input type="number" name="servicio_base" value="${precios.servicio_base || 10}" min="0" step="1" />
|
||||||
|
céntimos
|
||||||
|
</label>
|
||||||
|
<br><br>
|
||||||
|
<label>
|
||||||
|
<b>Leche pequeña:</b>
|
||||||
|
<input type="number" name="leche_pequena" value="${precios.leche_pequena || 15}" min="0" step="1" />
|
||||||
|
céntimos
|
||||||
|
</label>
|
||||||
|
<br><br>
|
||||||
|
<label>
|
||||||
|
<b>Leche grande:</b>
|
||||||
|
<input type="number" name="leche_grande" value="${precios.leche_grande || 25}" min="0" step="1" />
|
||||||
|
céntimos
|
||||||
|
</label>
|
||||||
|
<br><br>
|
||||||
|
<label>
|
||||||
|
<b>Café:</b>
|
||||||
|
<input type="number" name="cafe" value="${precios.cafe || 25}" min="0" step="1" />
|
||||||
|
céntimos
|
||||||
|
</label>
|
||||||
|
<br><br>
|
||||||
|
<label>
|
||||||
|
<b>ColaCao:</b>
|
||||||
|
<input type="number" name="colacao" value="${precios.colacao || 25}" min="0" step="1" />
|
||||||
|
céntimos
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
<br>
|
||||||
|
<button type="submit">💾 Guardar precios</button>
|
||||||
|
<button type="button" onclick="setUrlHash('dataman')">🔙 Volver</button>
|
||||||
|
</form>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.getElementById(form).onsubmit = (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
var formData = new FormData(document.getElementById(form));
|
||||||
|
var nuevosPrecios = {
|
||||||
|
servicio_base: parseInt(formData.get('servicio_base')) || 10,
|
||||||
|
leche_pequena: parseInt(formData.get('leche_pequena')) || 15,
|
||||||
|
leche_grande: parseInt(formData.get('leche_grande')) || 25,
|
||||||
|
cafe: parseInt(formData.get('cafe')) || 25,
|
||||||
|
colacao: parseInt(formData.get('colacao')) || 25,
|
||||||
|
};
|
||||||
|
|
||||||
|
DB.put('config', 'precios_cafe', nuevosPrecios).then(() => {
|
||||||
|
toastr.success('Precios guardados correctamente');
|
||||||
|
// Actualizar variable global
|
||||||
|
if (window.PRECIOS_CAFE) {
|
||||||
|
Object.assign(window.PRECIOS_CAFE, nuevosPrecios);
|
||||||
|
}
|
||||||
|
setTimeout(() => setUrlHash('dataman'), 1000);
|
||||||
|
}).catch((e) => {
|
||||||
|
toastr.error('Error al guardar precios: ' + e.message);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
// Si no hay precios guardados, usar valores por defecto
|
||||||
|
PAGES.dataman.__precios();
|
||||||
|
});
|
||||||
|
},
|
||||||
index: function () {
|
index: function () {
|
||||||
container.innerHTML = html`
|
container.innerHTML = html`
|
||||||
<h1>Administración de datos</h1>
|
<h1>Administración de datos</h1>
|
||||||
<a class="button" href="#dataman,import">Importar datos</a>
|
<a class="button" href="#dataman,import">Importar datos</a>
|
||||||
<a class="button" href="#dataman,export">Exportar datos</a>
|
<a class="button" href="#dataman,export">Exportar datos</a>
|
||||||
<a class="button" href="#dataman,labels">Imprimir etiquetas</a>
|
<a class="button" href="#dataman,labels">Imprimir etiquetas</a>
|
||||||
|
<a class="button" href="#dataman,precios">⚙️ Precios del café</a>
|
||||||
<a class="button" href="#dataman,config">Ajustes</a>
|
<a class="button" href="#dataman,config">Ajustes</a>
|
||||||
`;
|
`;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user