From 4fefdcaf3d3b904e79f68ab0670fad0f5310a3c8 Mon Sep 17 00:00:00 2001 From: Naiel <109038805+naielv@users.noreply.github.com> Date: Thu, 13 Nov 2025 12:16:19 +0000 Subject: [PATCH] updated --- src/page/pagos.js | 253 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 224 insertions(+), 29 deletions(-) diff --git a/src/page/pagos.js b/src/page/pagos.js index 4662502..c4628f8 100644 --- a/src/page/pagos.js +++ b/src/page/pagos.js @@ -41,7 +41,7 @@ PAGES.pagos = { var numpad_display = safeuuid(); var div_persona_destino = safeuuid(); var btn_confirm = safeuuid(); - var btn_correct = safeuuid(); + var btn_back = safeuuid(); var btn_cancel = safeuuid(); var scan_qr_btn = safeuuid(); var currentStep = 1; @@ -54,8 +54,8 @@ PAGES.pagos = { Terminal de pago TeleSec -
-

Paso 1 de 2

+
+

Paso 1 de 3

@@ -64,7 +64,8 @@ PAGES.pagos = {
- + -
+
+
+
@@ -146,37 +193,130 @@ PAGES.pagos = { document.getElementById(field_tipo).addEventListener('change', function() { var tipo = this.value; var divDestino = document.getElementById(div_persona_destino); + var metodoSelect = document.getElementById(field_metodo); + if (tipo === 'Transferencia') { divDestino.style.display = 'block'; } else { divDestino.style.display = 'none'; } + + // Restrict Ingreso to Efectivo only + if (tipo === 'Ingreso') { + metodoSelect.value = 'Efectivo'; + metodoSelect.disabled = true; + } else { + metodoSelect.disabled = false; + } }); - // Confirm button + // Confirm/Next button document.getElementById(btn_confirm).onclick = () => { if (currentStep === 1) { - // Move to step 2 + // Validate step 1 + var tipo = document.getElementById(field_tipo).value; + var metodo = document.getElementById(field_metodo).value; var monto = parseFloat(document.getElementById(numpad_display).value); + + if (!tipo) { + alert("Por favor selecciona el tipo de transacción"); + return; + } + if (!metodo) { + alert("Por favor selecciona el método de pago"); + return; + } + if (tipo === 'Ingreso' && metodo !== 'Efectivo') { + alert("Los ingresos solo pueden ser en Efectivo"); + return; + } if (isNaN(monto) || monto <= 0) { alert("Por favor ingresa un monto válido"); return; } + // Move to step 2 document.getElementById('step1').style.display = 'none'; document.getElementById('step2').style.display = 'block'; document.getElementById('stepIndicator').innerText = '2'; - document.getElementById('confirmAmount').innerText = monto.toFixed(2) + '€'; + document.getElementById('step2Amount').innerText = monto.toFixed(2) + '€'; currentStep = 2; // Load personas for selection loadPersonaSelector(); - if (document.getElementById(field_tipo).value === 'Transferencia') { + if (tipo === 'Transferencia') { loadPersonaDestinoSelector(); } - } else { - // Process transaction - processTransaction(); + } else if (currentStep === 2) { + // Validate step 2 + var personaId = document.getElementById(field_persona).value; + if (!personaId) { + alert("Por favor selecciona un monedero"); + return; + } + + var tipo = document.getElementById(field_tipo).value; + if (tipo === 'Transferencia') { + var personaDestinoId = document.getElementById(field_persona_destino).value; + if (!personaDestinoId) { + alert("Por favor selecciona el monedero destino"); + return; + } + if (personaId === personaDestinoId) { + alert("No puedes transferir al mismo monedero"); + return; + } + } + + // Move to step 3 - confirmation + document.getElementById('step2').style.display = 'none'; + document.getElementById('step3').style.display = 'block'; + document.getElementById('stepIndicator').innerText = '3'; + + var monto = parseFloat(document.getElementById(numpad_display).value); + document.getElementById('confirmAmount').innerText = monto.toFixed(2) + '€'; + + // Populate confirmation data + var tipoText = document.getElementById(field_tipo).selectedOptions[0].text; + var metodoText = document.getElementById(field_metodo).selectedOptions[0].text; + var personaName = SC_Personas[personaId]?.Nombre || personaId; + var notas = document.getElementById(field_notas).value || "(sin notas)"; + + document.getElementById('confirmTipo').innerText = tipoText; + document.getElementById('confirmMetodo').innerText = metodoText; + document.getElementById('confirmPersona').innerText = personaName; + document.getElementById('confirmNotas').innerText = notas; + + if (tipo === 'Transferencia') { + var personaDestinoId = document.getElementById(field_persona_destino).value; + var personaDestinoName = SC_Personas[personaDestinoId]?.Nombre || personaDestinoId; + document.getElementById('confirmPersonaDestinoName').innerText = personaDestinoName; + document.getElementById('confirmPersonaDestino').style.display = 'block'; + } + + // Switch to final button layout + document.getElementById('buttonContainer').style.display = 'none'; + document.getElementById('buttonContainerFinal').style.display = 'grid'; + + currentStep = 3; + } + }; + + // Confirm final transaction button + document.getElementById(btn_confirm + "2").onclick = () => { + processTransaction(); + }; + + // Back button + document.getElementById(btn_back).onclick = () => { + if (currentStep === 3) { + // Go back to step 2 + document.getElementById('step3').style.display = 'none'; + document.getElementById('step2').style.display = 'block'; + document.getElementById('stepIndicator').innerText = '2'; + document.getElementById('buttonContainer').style.display = 'grid'; + document.getElementById('buttonContainerFinal').style.display = 'none'; + currentStep = 2; } }; @@ -336,6 +476,14 @@ PAGES.pagos = { handleSuperCafePayment(data); } + // Check for promotional bonus on Ingreso transactions (Efectivo only) + if (data.Tipo === 'Ingreso' && data.Metodo === 'Efectivo') { + var bonusAmount = calculatePromoBonus(data.Monto); + if (bonusAmount > 0) { + createPromoBonusTransaction(data.Persona, bonusAmount, data.Monto); + } + } + toastr.success("¡Transacción completada!"); setTimeout(() => { document.getElementById("actionStatus").style.display = "none"; @@ -344,6 +492,56 @@ PAGES.pagos = { }); } + function calculatePromoBonus(monto) { + var amount = parseFloat(monto); + + if (amount >= 5) { + return 0.20; // 20% bonus + } else if (amount >= 4) { + return 0.15; // 15% bonus + } else if (amount >= 3) { + return 0.10; // 10% bonus + } else if (amount >= 2) { + return 0.05; // 5% bonus + } + + return 0; // No bonus for amounts under 2€ + } + + function createPromoBonusTransaction(personaId, bonusAmount, originalAmount) { + var bonusTicketId = safeuuid(""); + var bonusData = { + Ticket: bonusTicketId, + Fecha: CurrentISOTime(), + Tipo: "Ingreso", + Monto: bonusAmount, + Persona: personaId, + Metodo: "Efectivo", + Notas: "Promo Bono - " + bonusAmount.toFixed(2) + "€ extra por recarga de " + originalAmount.toFixed(2) + "€", + Estado: "Completado", + Origen: "Promo Bono" + }; + + // Update wallet balance with bonus + var persona = SC_Personas[personaId]; + if (persona) { + var currentBalance = parseFloat(persona.Monedero_Balance || 0); + var newBalance = currentBalance + bonusAmount; + persona.Monedero_Balance = newBalance; + + TS_encrypt(persona, SECRET, (encrypted) => { + betterGunPut(gun.get(TABLE).get("personas").get(personaId), encrypted); + }); + } + + // Save bonus transaction + TS_encrypt(bonusData, SECRET, (encrypted) => { + betterGunPut(gun.get(TABLE).get("pagos").get(bonusTicketId), encrypted); + }); + + toastr.success("🎉 ¡Promo Bono aplicado! +" + bonusAmount.toFixed(2) + "€ extra"); + } + function handleSuperCafePayment(transactionData) { // Mark the SuperCafé order as paid and delete it betterGunPut(gun.get(TABLE).get("supercafe").get(transactionData.OrigenID), null); @@ -776,18 +974,16 @@ PAGES.pagos = { const tipo = data.Tipo; const metodo = data.Metodo || ""; - // Only count Tarjeta Monedero transactions in balance totals - const isMonedero = metodo === "Tarjeta"; - + // Count all Ingresos and Gastos in totals (excluding Transferencias) // Reset entries on every call for this ID - if (isMonedero && tipo === "Ingreso") { + if (tipo === "Ingreso") { totalData.gastos[id] = 0; totalData.ingresos[id] = monto; - } else if (isMonedero && tipo === "Gasto") { + } else if (tipo === "Gasto") { totalData.ingresos[id] = 0; totalData.gastos[id] = monto; } else { - // For non-Monedero transactions or Transferencias, don't count in totals + // For Transferencias, don't count in totals totalData.ingresos[id] = 0; totalData.gastos[id] = 0; } @@ -943,7 +1139,6 @@ PAGES.pagos = {