diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php
index d9bcb9ed..54741c39 100755
--- a/ci4/app/Language/es/Presupuestos.php
+++ b/ci4/app/Language/es/Presupuestos.php
@@ -417,6 +417,8 @@ return [
'papel_faja' => 'Seleccione el tipo de papel para la faja',
'gramaje_faja' => 'Seleccione el gramaje para la faja',
+ 'unidades_envio_mayor_tirada' => 'El número de unidades enviadas debe ser igual a {field} unidades.',
+
'pais' => 'Debe seleccionar un país',
'integer_greatherThan_0' => 'Número entero > 0 requerido',
'greater_than_0' => 'El campo {field} debe ser mayor que 0',
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php
index eef7b00a..3da39f38 100755
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php
+++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_datosGenerales.php
@@ -78,7 +78,7 @@
-
@@ -86,7 +86,7 @@
-
@@ -94,7 +94,7 @@
-
@@ -102,7 +102,7 @@
-
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php
index a35d6b5e..3dc42fdc 100755
--- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php
+++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_direcciones.php
@@ -62,8 +62,6 @@
-
-
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js
index 4e40022f..c49b5236 100644
--- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js
+++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js
@@ -83,6 +83,8 @@ class DatosGenerales {
init() {
+ const self = this;
+
// Selects
this.formatoLibro.init();
this.cliente.init();
@@ -100,6 +102,18 @@ class DatosGenerales {
this.pagColorConsecutivas.on('change', this.#handPaginasConsecutivas.bind(this));
this.papelDiferente.on('change', this.#handlePapelDiferente.bind(this));
+ $('.tirada-presupuesto').on('change', () => {
+ let tiradas = self.getTiradas();
+ if (!Array.isArray(tiradas)) {
+ tiradas = [tiradas];
+ }
+ const data = {
+ tiradas: self.getTiradas(),
+ tiradaSeleccionada: self.selectedTirada || parseInt(self.tirada1.val())
+ };
+ $(document).trigger('update-tiradas-envios', data);
+ });
+
this.anchoPersonalizado.on("change", this.#checkValue.bind(this));
this.altoPersonalizado.on("change", this.#checkValue.bind(this));
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js
index 1ee81bad..9720cd8c 100644
--- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js
+++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js
@@ -33,14 +33,13 @@ class Direcciones {
this.tiradaSeleccionada = null;
this.direcciones.calcularPresupuesto = false;
-
- this.initValidation();
-
}
init() {
+ const self = this;
+
$("#clienteId").on('change', this.handleChangeCliente.bind(this));
this.recogidaTaller.on('change', () => {
@@ -60,6 +59,27 @@ class Direcciones {
this.direccionesCliente.init();
this.btnAdd.on('click', this.#insertDireccion.bind(this));
this.btnNew.on('click', this.#nuevaDireccion.bind(this));
+
+ // evento para actualizar el selector de tiradas
+ $(document).on('update-tiradas-envios', (event, data) => {
+ self.divTiradas.empty();
+ if (data.tiradas.length > 0) {
+ data.tiradas.forEach(tirada => {
+ self.insertTirada(tirada);
+ });
+
+ if (data.tiradaSeleccionada) {
+ self.divTiradas.find('.check-tirada-envio[tirada="' + data.tiradaSeleccionada + '"]').trigger('click');
+ self.selectedTirada = data.tiradaSeleccionada;
+ }
+ else {
+ self.tiradaSeleccionada = null;
+ }
+
+
+ self.divTiradas.trigger('change');
+ }
+ });
}
@@ -161,6 +181,48 @@ class Direcciones {
}
}
+
+ validate(goToNext = true) {
+
+ let errores = [];
+
+ $('#divDirecciones').removeClass('is-invalid');
+ if ($('.check-tirada-envio:checked').length > 0) {
+ let unidades = parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada'));
+ let total_envio = 0;
+ // se recorre el array this.direcciones
+ this.direcciones.forEach(direccion => {
+ total_envio += parseInt(direccion.getUnidades());
+ });
+ if (total_envio > unidades) {
+ $('#divDirecciones').addClass('is-invalid');
+ errores.push(window.translations["validation"].unidades_envio_mayor_tirada.replace('{field}', total_envio));
+ }
+ }
+
+ const skAlert = document.getElementById('sk-alert');
+ skAlert.innerHTML = '';
+ const uniqueErrors = [...new Set(errores)];
+
+ if (uniqueErrors.length > 0) {
+ const message = window.translations["validation"].fix_errors +
+ `
+ ${uniqueErrors.map(err => `- ${err}
`).join('')}
+
`;
+ popErrorAlert(message, 'sk-alert', false);
+ errores = [];
+ return false;
+ }
+ else {
+ document.getElementById('sk-alert').innerHTML = '';
+ errores = [];
+ if (goToNext)
+ this.validatorStepper.next();
+ else
+ return true;
+ }
+ }
+
initValidation() {
const stepper = this.validatorStepper;
@@ -171,7 +233,7 @@ class Direcciones {
validators: {
callback: {
callback: () => {
- const div = $('#divErrorEnvios'); // Selecciona el div
+
div.find('.fv-plugins-message-container').remove();
@@ -244,7 +306,7 @@ class Direcciones {
let direcciones = [];
this.direcciones.forEach(direccion => {
let dir = {
- direccion: direccion.getDireccion(),
+ direccion: direccion.getDireccion(),
unidades: direccion.getUnidades(),
entregaPalets: direccion.getEntregaPalets()
};
@@ -340,7 +402,7 @@ class Direcciones {
popErrorAlert("Tiene que seleccionar una tirada para insertar una dirección");
return;
}
-
+
if (unidades > this.getSelectedTirada()) {
popErrorAlert("El total de unidades enviadas tiene que ser menor que " + this.getSelectedTirada());
return;
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js
index 6c8b8285..f36042f2 100644
--- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js
+++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js
@@ -114,12 +114,14 @@ class PresupuestoCliente {
}
else {
this.calcularPresupuesto = true;
+ $('.tirada-presupuesto').trigger('change');
}
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
$(".calcular-solapas").on('change', this.calcularSolapas.bind(this));
$(".calcular-lomo").on('change', this.checkLomoInterior.bind(this));
+
}
@@ -198,11 +200,9 @@ class PresupuestoCliente {
}
else {
this.actualizarTiradasEnvio = true;
- this.direcciones.divTiradas.empty();
+ //this.direcciones.divTiradas.empty();
}
- this.divTiradasPrecios.empty();
-
let datos_to_check = this.#prepareData();
if (Object.values(datos_to_check).every(this.#isValidDataForm)) {
@@ -213,8 +213,6 @@ class PresupuestoCliente {
$('#loader').modal('show');
}, 0);
-
-
// Si se está ejecutando la petición, abortar la petición anterior
this.ajax_calcular.abort();
@@ -249,9 +247,6 @@ class PresupuestoCliente {
if (currentElement !== 'resumen-libro') {
this.#validateCurrentForm(currentElement, nextElement);
- if (currentElement === 'cubierta-libro' && this.disenioCubierta.acabadoCubierta.getVal() == 0) {
- alertWarningMessage(window.translations.cubiertaSinAcabado, window.translations.cubiertaSinAcabadoText);
- }
//this.#goToForm(nextElement);
}
else {
@@ -312,21 +307,9 @@ class PresupuestoCliente {
break;
case 'direcciones-libro':
- this.direcciones.allowNext = false;
- validateForm(this.direcciones.formValidation).then((status) => {
- if (status !== 'Valid') {
- this.direcciones.allowNext = true;
- return false;
- }
+ if (this.direcciones.validate(false)) {
this.#goToForm(nextForm);
- this.direcciones.allowNext = true;
- return true;
}
- ).catch(error => {
- this.direcciones.allowNext = true;
- console.error('Error al validar:', error);
- return false;
- });
break;
default:
@@ -524,7 +507,10 @@ class PresupuestoCliente {
let tiradas = { ...response.tiradas };
tiradas = Object.keys(tiradas).map((key) => tiradas[key]);
tiradas.sort((a, b) => a - b);
- this.divTiradasPrecios.empty();
+
+ if (this.actualizarTiradasEnvio) {
+ this.direcciones.divTiradas.empty();
+ }
popAlert2Hide();
@@ -559,20 +545,20 @@ class PresupuestoCliente {
$('.is-invalid').removeClass('is-invalid');
const skAlert = document.getElementById('sk-alert');
skAlert.innerHTML = '';
-
+
if (this.datos.cubierta && this.datos.cubierta.acabado && this.datos.cubierta.acabado > 0) {
-
+
$('#alert-cubierta-sin-acabado').addClass('d-none');
}
- else{
+ else {
$('#alert-cubierta-sin-acabado').removeClass('d-none');
$(window).scrollTop(0);
}
-
- if( this.datos.cubierta.acabado )
- setTimeout(() => {
- $(`#containerTiradasEnvios .tirada-envio input[tirada="${this.direcciones.tiradaSeleccionada}"]`).trigger('click');
- }, 0);
+
+ if (this.datos.cubierta.acabado)
+ setTimeout(() => {
+ $(`#containerTiradasEnvios .tirada-envio input[tirada="${this.direcciones.tiradaSeleccionada}"]`).trigger('click');
+ }, 0);
}
$('#loader').modal('hide');
// DEBUG
@@ -597,7 +583,7 @@ class PresupuestoCliente {
break;
case 3:
- this.direcciones.formValidation.validate();
+ this.direcciones.validate();
break;
default:
@@ -608,13 +594,27 @@ class PresupuestoCliente {
#prevtStep() {
- if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4) {
- /*if (this.validationStepper._currentIndex == 2) {
- if (this.disenioCubierta.acabadoCubierta.getVal() == 0) {
- alertWarningMessage(window.translations.cubiertaSinAcabado, window.translations.cubiertaSinAcabadoText);
- }
- }*/
- this.validationStepper.previous();
+ switch (this.validationStepper._currentIndex) {
+
+ case 1:
+ if (this.disenioInterior.validate(false))
+ this.validationStepper.previous();
+ break;
+
+
+ case 2:
+ if (this.disenioCubierta.validate(false))
+ this.validationStepper.previous();
+ break;
+
+ case 3:
+ if (this.direcciones.formValidation.validate(false))
+ this.validationStepper.previous();
+ break;
+
+ default:
+ this.validationStepper.previous();
+ break;
}
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
@@ -856,19 +856,6 @@ class PresupuestoCliente {
}
-
-
-async function validateForm(formValidation) {
- try {
- const validationResult = await formValidation.validate();
- return validationResult;
- } catch (error) {
- console.error('Error durante la validación:', error);
- throw error;
- }
-}
-
-
function isValid(value) {
if (value === null || value === undefined || value === '') {
return false;