no letras D:
This commit is contained in:
@@ -202,47 +202,44 @@
|
|||||||
|
|
||||||
function calcularVentaProductos() {
|
function calcularVentaProductos() {
|
||||||
let granTotal = 0;
|
let granTotal = 0;
|
||||||
|
|
||||||
const filas = document.querySelectorAll('tbody tr');
|
const filas = document.querySelectorAll('tbody tr');
|
||||||
|
|
||||||
filas.forEach(fila => {
|
filas.forEach(fila => {
|
||||||
const inputQty = fila.querySelector('input[name^="qty_"]');
|
const inputQty = fila.querySelector('input[name^="qty_"]');
|
||||||
if (inputQty) {
|
if (inputQty) {
|
||||||
// Prevenir valores negativos visualmente
|
|
||||||
if (parseInt(inputQty.value) < 0) {
|
if (parseInt(inputQty.value) < 0) {
|
||||||
inputQty.value = 0;
|
inputQty.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cantidad = parseInt(inputQty.value) || 0;
|
const cantidad = parseInt(inputQty.value) || 0;
|
||||||
const precioTexto = fila.cells[1].innerText.replace(/\D/g, '');
|
const precioTexto = fila.cells[1].innerText.replace(/\D/g, '');
|
||||||
const precio = parseInt(precioTexto) || 0;
|
const precio = parseInt(precioTexto) || 0;
|
||||||
|
|
||||||
granTotal += (cantidad * precio);
|
granTotal += (cantidad * precio);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
displayTotalProductos.value = granTotal.toLocaleString('es-CL');
|
displayTotalProductos.value = granTotal.toLocaleString('es-CL');
|
||||||
}
|
}
|
||||||
|
|
||||||
inputsCantidad.forEach(input => {
|
inputsCantidad.forEach(input => {
|
||||||
// Bloquear tecla "-" y signos negativos
|
|
||||||
input.addEventListener('keydown', function(e) {
|
input.addEventListener('keydown', function(e) {
|
||||||
if (e.key === '-' || e.key === 'Subtract') {
|
if (['Backspace', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete', 'Enter'].includes(e.key) || e.ctrlKey || e.metaKey) return;
|
||||||
|
if (e.key < '0' || e.key > '9') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Recalcular y validar al ingresar datos
|
input.addEventListener('input', function() {
|
||||||
input.addEventListener('input', calcularVentaProductos);
|
this.value = this.value.replace(/\D/g, '');
|
||||||
|
calcularVentaProductos();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const submitModal = document.getElementById('confirmSubmitModal');
|
const submitModal = document.getElementById('confirmSubmitModal');
|
||||||
const mainForm = document.querySelector('form');
|
const mainForm = document.querySelector('form');
|
||||||
const alertModalEl = document.getElementById('globalAlertModal');
|
const alertModalEl = document.getElementById('globalAlertModal');
|
||||||
const alertModal = new bootstrap.Modal(alertModalEl);
|
const alertModal = new bootstrap.Modal(alertModalEl);
|
||||||
|
|
||||||
const confirmBtn = submitModal.querySelector('button[type="submit"]');
|
const confirmBtn = submitModal.querySelector('button[type="submit"]');
|
||||||
|
|
||||||
function mostrarError(mensaje) {
|
function mostrarError(mensaje) {
|
||||||
@@ -256,7 +253,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
requiredInputs.forEach(input => {
|
requiredInputs.forEach(input => {
|
||||||
const isMoney = input.classList.contains('money-input');
|
const isMoney = input.classList.contains('money-input');
|
||||||
// Validamos solo si está vacío y NO es un campo de dinero (que ya tiene '0')
|
|
||||||
if (!input.value.trim() || (isMoney && input.value === '')) {
|
if (!input.value.trim() || (isMoney && input.value === '')) {
|
||||||
input.classList.add('is-invalid');
|
input.classList.add('is-invalid');
|
||||||
valid = false;
|
valid = false;
|
||||||
@@ -269,17 +265,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
confirmBtn.addEventListener('click', function(e) {
|
confirmBtn.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (validarFormulario()) {
|
if (validarFormulario()) {
|
||||||
mainForm.submit();
|
mainForm.submit();
|
||||||
} else {
|
} else {
|
||||||
// Cerramos el modal de confirmación antes de mostrar el de error
|
|
||||||
bootstrap.Modal.getInstance(submitModal).hide();
|
bootstrap.Modal.getInstance(submitModal).hide();
|
||||||
mostrarError("Por favor, rellena los campos obligatorios (Fecha y Turno) antes de enviar.");
|
mostrarError("Por favor, rellena los campos obligatorios (Fecha y Turno) antes de enviar.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Inicializar campos de dinero en 0 para que no se queje la validación
|
|
||||||
document.querySelectorAll('.money-input').forEach(input => {
|
document.querySelectorAll('.money-input').forEach(input => {
|
||||||
if (!input.value.trim()) input.value = '0';
|
if (!input.value.trim()) input.value = '0';
|
||||||
});
|
});
|
||||||
@@ -294,7 +287,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
function calcularTotales() {
|
function calcularTotales() {
|
||||||
const getVal = (id) => {
|
const getVal = (id) => {
|
||||||
const el = document.getElementById(id);
|
const el = document.getElementById(id);
|
||||||
// Si no hay valor, asumimos 0 para que el cálculo no de NaN
|
|
||||||
if (!el || !el.value.trim() || el.value === '0') return 0;
|
if (!el || !el.value.trim() || el.value === '0') return 0;
|
||||||
return parseInt(el.value.replace(/\D/g, '')) || 0;
|
return parseInt(el.value.replace(/\D/g, '')) || 0;
|
||||||
};
|
};
|
||||||
@@ -316,14 +308,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
input.addEventListener('input', calcularTotales);
|
input.addEventListener('input', calcularTotales);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validación antes de enviar el formulario
|
|
||||||
document.querySelector('form').addEventListener('submit', function(e) {
|
document.querySelector('form').addEventListener('submit', function(e) {
|
||||||
const requiredInputs = this.querySelectorAll('[required]');
|
const requiredInputs = this.querySelectorAll('[required]');
|
||||||
let valid = true;
|
let valid = true;
|
||||||
|
|
||||||
requiredInputs.forEach(input => {
|
requiredInputs.forEach(input => {
|
||||||
const isMoney = input.classList.contains('money-input');
|
const isMoney = input.classList.contains('money-input');
|
||||||
// Si está vacío y no es campo de dinero (o el campo de dinero está totalmente vacío)
|
|
||||||
if (!input.value.trim() || (isMoney && input.value === '')) {
|
if (!input.value.trim() || (isMoney && input.value === '')) {
|
||||||
input.classList.add('is-invalid');
|
input.classList.add('is-invalid');
|
||||||
valid = false;
|
valid = false;
|
||||||
@@ -334,21 +324,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Usamos la función del modal bonito en lugar del alert
|
|
||||||
const alertModalEl = document.getElementById('globalAlertModal');
|
const alertModalEl = document.getElementById('globalAlertModal');
|
||||||
if (alertModalEl) {
|
if (alertModalEl) {
|
||||||
const alertModal = bootstrap.Modal.getOrCreateInstance(alertModalEl);
|
const alertModal = bootstrap.Modal.getOrCreateInstance(alertModalEl);
|
||||||
document.getElementById('globalAlertModalBody').textContent = "Por favor, rellena todos los campos obligatorios antes de enviar.";
|
document.getElementById('globalAlertModalBody').textContent = "Por favor, rellena todos los campos obligatorios antes de enviar.";
|
||||||
alertModal.show();
|
alertModal.show();
|
||||||
} else {
|
} else {
|
||||||
// Respaldo por si el modal no carga por alguna razón mística
|
|
||||||
alert("Por favor, rellena todos los campos obligatorios.");
|
alert("Por favor, rellena todos los campos obligatorios.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll('.money-input').forEach(function(input) {
|
document.querySelectorAll('.money-input').forEach(function(input) {
|
||||||
|
input.addEventListener('keydown', function(e) {
|
||||||
|
if (['Backspace', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete', 'Enter'].includes(e.key) || e.ctrlKey || e.metaKey) return;
|
||||||
|
if (e.key < '0' || e.key > '9') {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
input.addEventListener('focus', function() {
|
input.addEventListener('focus', function() {
|
||||||
if (this.value === '0') this.value = '';
|
if (this.value === '0') this.value = '';
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user