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 {
|
||||
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) => {
|
||||
// debounce with trailing callback
|
||||
// First call runs immediately, then locks for 'wait' ms
|
||||
@@ -700,36 +722,44 @@ function SC_parse(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) => {
|
||||
valores += "<small style='font-size: 60%;'>" + entry[0] + ':</small> ' + entry[1] + ' ';
|
||||
var combo = entry[0] + ';' + entry[1];
|
||||
switch (entry[0]) {
|
||||
case 'Leche':
|
||||
// Leche pequeña = 10c
|
||||
// Leche pequeña
|
||||
if (
|
||||
json['Tamaño'] == 'Pequeño' &&
|
||||
['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 (
|
||||
json['Tamaño'] == 'Grande' &&
|
||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||
) {
|
||||
valores += '<small>(G = 20c)</small>';
|
||||
valores += `<small>(G = ${precios.leche_grande}c)</small>`;
|
||||
}
|
||||
break;
|
||||
case 'Selección':
|
||||
// Café = 20c
|
||||
// Café
|
||||
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') {
|
||||
valores += '<small>(20c)</small>';
|
||||
valores += `<small>(${precios.colacao}c)</small>`;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -743,35 +773,50 @@ function SC_parse_short(json) {
|
||||
function SC_priceCalc(json) {
|
||||
var precio = 0;
|
||||
var valores = '';
|
||||
// Servicio base = 10c
|
||||
precio += 10;
|
||||
valores += 'Servicio base = 10c\n';
|
||||
// Leche pequeña = 10c
|
||||
|
||||
// Usar precios configurables
|
||||
const precios = window.PRECIOS_CAFE || {
|
||||
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 (
|
||||
json['Tamaño'] == 'Pequeño' &&
|
||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||
) {
|
||||
precio += 15;
|
||||
valores += 'Leche pequeña = 15c\n';
|
||||
precio += precios.leche_pequena;
|
||||
valores += `Leche pequeña = ${precios.leche_pequena}c\n`;
|
||||
}
|
||||
// Leche grande = 20c
|
||||
|
||||
// Leche grande
|
||||
if (
|
||||
json['Tamaño'] == 'Grande' &&
|
||||
['de Vaca', 'Sin lactosa', 'Vegetal', 'Almendras'].includes(json['Leche'])
|
||||
) {
|
||||
precio += 25;
|
||||
valores += 'Leche grande = 25c\n';
|
||||
precio += precios.leche_grande;
|
||||
valores += `Leche grande = ${precios.leche_grande}c\n`;
|
||||
}
|
||||
// Café = 20c
|
||||
|
||||
// Café
|
||||
if (['Café con leche', 'Solo café (sin leche)'].includes(json['Selección'])) {
|
||||
precio += 25;
|
||||
valores += 'Café = 25c\n';
|
||||
precio += precios.cafe;
|
||||
valores += `Café = ${precios.cafe}c\n`;
|
||||
}
|
||||
// ColaCao = 20c
|
||||
|
||||
// ColaCao
|
||||
if (json['Selección'] == 'ColaCao con leche') {
|
||||
precio += 25;
|
||||
valores += 'ColaCao = 25c\n';
|
||||
precio += precios.colacao;
|
||||
valores += `ColaCao = ${precios.colacao}c\n`;
|
||||
}
|
||||
|
||||
valores += '<hr>Total: ' + precio + 'c\n';
|
||||
return [precio, valores];
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ PAGES.dataman = {
|
||||
case 'labels':
|
||||
PAGES.dataman.__labels();
|
||||
break;
|
||||
case 'precios':
|
||||
PAGES.dataman.__precios();
|
||||
break;
|
||||
default:
|
||||
// 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 () {
|
||||
container.innerHTML = html`
|
||||
<h1>Administración de datos</h1>
|
||||
<a class="button" href="#dataman,import">Importar 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,precios">⚙️ Precios del café</a>
|
||||
<a class="button" href="#dataman,config">Ajustes</a>
|
||||
`;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user