From db91776747ef1b8a2ce13f1ff9ac78d913e25001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 12 Jun 2025 13:49:56 +0200 Subject: [PATCH] =?UTF-8?q?terminada=20validaci=C3=B3n=20de=20cubierta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Language/es/Presupuestos.php | 14 +- .../presupuestoCliente/disenioCubierta.js | 382 ++++++------------ .../presupuestoCliente/disenioInterior.js | 31 +- .../presupuestoCliente/presupuestoCliente.js | 81 +--- 4 files changed, 186 insertions(+), 322 deletions(-) diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index 8874b770..d9bcb9ed 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -405,12 +405,24 @@ return [ 'papel_interior_especial' => 'Seleccione el papel especial en el desplegable para el interior', 'gramaje_interior' => 'Seleccione el gramaje para el interior', + 'tipo_cubierta' => 'Seleccione el tipo de cubierta', + 'papel_guardas' => 'Seleccione el tipo de papel para las guardas', + 'gramaje_guardas' => 'Seleccione el gramaje para las guardas', + 'papel_cubierta' => 'Seleccione el tipo de papel para la cubierta', + 'papel_cubierta_especial' => 'Seleccione el papel especial en el desplegable para la cubierta', + 'gramaje_cubierta' => 'Seleccione el gramaje para la cubierta', + + 'papel_sobrecubierta' => 'Seleccione el tipo de papel para la sobrecubierta', + 'gramaje_sobrecubierta' => 'Seleccione el gramaje para la sobrecubierta', + 'papel_faja' => 'Seleccione el tipo de papel para la faja', + 'gramaje_faja' => 'Seleccione el gramaje para la faja', + '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', 'tirada_no_valida' => "Tirada no valida", 'sin_gramaje' => "Seleccione gramaje", - 'tipo_cubierta' => 'Seleccione tipo de cubierta', + 'opcion_solapas' => 'Seleccione la opción para las solapas', 'paginas_multiplo_4' => 'El número total de páginas para cosido y grapado debe ser múltiplo de 4', 'paginas_pares' => 'El número de páginas debe ser par', diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index 19ec8dc4..2550871c 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -237,7 +237,6 @@ class DisenioCubierta { } ); - this.initValidation(); // Creamos un nuevo observador que detecta cambios en los atributos this.observer = new MutationObserver(mutations => { @@ -355,7 +354,7 @@ class DisenioCubierta { this.sinSolapas.trigger('click'); } } - }, 0); + }, 0); this.divPapelCubierta.find(`[cod="${datosCubierta.papel.code}"]`).addClass('selected'); @@ -385,244 +384,114 @@ class DisenioCubierta { } - initValidation() { + validate(goToNext = true) { - const stepper = this.validatorStepper; + let errores = []; - this.formValidation = FormValidation.formValidation(this.wizardStep, { - fields: { - div_tipo_cubierta: { - validators: { - callback: { - callback: function (input) { - const div = $('#divTipoCubierta'); // Selecciona el div + let continueCheck = true; - div.find('.fv-plugins-message-container').remove(); - if ($('.tipo-cubierta.selected').length > 0) { - return true; - } - else { - div.append(` -
-
- ${window.translations["validation"].tipo_cubierta} -
-
- `); - } - return false; - }, - } - } - }, - div_solapas_cubierta: { - validators: { - callback: { - callback: function (input) { - const div = $('#divSolapasCubierta'); - if (div.hasClass("d-none")) return true; + // diseño cubierta + $('#divTipoCubierta').removeClass('is-invalid'); + if ($('.tipo-cubierta.selected').length == 0) { + $('#divTipoCubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].tipo_cubierta); + continueCheck = false; + } - div.find('.fv-plugins-message-container').remove(); - if ($('.solapas-cubierta.selected').length > 0) { - return true; - } - else { - div.append(` -
-
- ${window.translations["validation"].opcion_solapas} -
-
- `); - } - return false; - }, - } - } - }, - div_papel_cubierta: { - validators: { - callback: { - callback: function (input) { + // solapas cubierta + $('#divSolapasCubierta').removeClass('is-invalid'); + if (!$('#divSolapasCubierta').hasClass("d-none") && $('.solapas-cubierta.selected').length == 0 && continueCheck) { + $('#divSolapasCubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].opcion_solapas); + } - $('#divPapelCubierta').find('.fv-plugins-message-container').remove(); - $('#divPapelEspecialCubierta').find('.fv-plugins-message-container').remove(); - - const papelSeleccionado = $('.custom-selector-papel-cubierta input[type="radio"]:checked'); - if (papelSeleccionado.length > 0) { - return true; - - } - else { - $('#divPapelCubierta').append(` -
-
- ${window.translations["validation"].papel_interior} -
-
- `); - } - return false; - }, - } - } - }, - div_papel_especial_cubierta: { - validators: { - callback: { - callback: function (input) { - - $('#divPapelEspecialCubierta').find('.fv-plugins-message-container').remove(); - if ($('#divPapelEspecialCubierta').hasClass("d-none")) return true; - - if ($('#papelEspecialCubiertaSel').select2('data').length > 0) - return true; - else { - $('#divPapelEspecialCubierta').append(` -
-
- ${window.translations["validation"].papel_interior} -
-
- `); - return false; - } - - } - } - } - }, - div_gramaje_cubierta: { - validators: { - callback: { - callback: function (input) { - - const divGramajeInterior = $('#divGramajeCubierta'); // Selecciona el div - divGramajeInterior.find('.fv-plugins-message-container').remove(); - - const gramajeSeleccionado = $('.custom-selector-gramaje-cubierta input[type="radio"]:checked'); - if (gramajeSeleccionado.length > 0) { - return true; - - } - else { - divGramajeInterior.append(` -
-
- ${window.translations["validation"].gramaje_interior} -
-
- `); - } - return false; - }, - } - } - }, - div_config_tapa_dura: { - validators: { - callback: { - callback: function (input) { - - const div = $('#divConfigTapaDura'); // Selecciona el div - div.find('.fv-plugins-message-container').remove(); - - if ($('divConfigTapaDura').hasClass('d-none')) - return true; - - const papelGuardas = $('#papelGuardas').select2('data').length > 0; - const gramajeGuardas = $('#gramajeGuardas').select2('data').length > 0; - if (papelGuardas && gramajeGuardas) { - return true; - - } - else { - div.append(` -
-
- ${window.translations["validation"].extras_cubierta} -
-
- `); - return false; - } - }, - } - } - }, - div_extras: { - validators: { - callback: { - callback: function (input) { - - const div = $('#divExtras'); // Selecciona el div - div.find('.fv-plugins-message-container').remove(); - - let error = false; - - if ($("#addFaja").prop("checked") == true) { - const papelFaja = $('#papelFaja').select2('data').length > 0; - const gramajeFaja = $('#gramajeFaja').select2('data').length > 0; - if (!papelFaja || !gramajeFaja) { - error = true; - } - } - - if ($("#addSobrecubierta").prop("checked") == true) { - const papelSobrecubierta = $('#papelSobrecubierta').select2('data').length > 0; - const gramajeSobrecubierta = $('#gramajeSobrecubierta').select2('data').length > 0; - if (!papelSobrecubierta || !gramajeSobrecubierta) { - error = true; - } - } - - - if (error) { - div.append(` -
-
- ${window.translations["validation"].extras_cubierta} -
-
- `); - return false; - } - }, - } - } - }, - }, - plugins: { - trigger: new FormValidation.plugins.Trigger(), - bootstrap5: new FormValidation.plugins.Bootstrap5({ - // Use this for enabling/changing valid/invalid class - // eleInvalidClass: '', - eleValidClass: '', - rowSelector: function (field, ele) { - // field is the field name - // ele is the field element - switch (field) { - case 'div_tipo_cubierta': - case 'div_solapas_cubierta': - case 'div_papel_cubierta': - case 'div_gramaje_cubierta': - case 'div_papel_especial_cubierta': - case 'div_config_tapa_dura': - return '.col-sm-10'; - case 'div_extras': - return '.col-sm-12'; - default: - return '.col-sm-3'; - } - } - }), - autoFocus: new FormValidation.plugins.AutoFocus(), - submitButton: new FormValidation.plugins.SubmitButton() + // opciones tapa dura y lomo redondo + $('#papelGuardas').removeClass('is-invalid'); + $('#gramajeGuardas').removeClass('is-invalid'); + if (!$('#divConfigTapaDura').hasClass('d-none') && continueCheck) { + if ($('#papelGuardas').select2('data').length == 0) { + $('#papelGuardas').addClass('is-invalid'); + errores.push(window.translations["validation"].papel_guardas); } - }).on('core.form.valid', () => { - if (this.allowNext) - stepper.next(); - }); + if ($('#gramajeGuardas').select2('data').length == 0) { + $('#gramajeGuardas').addClass('is-invalid'); + errores.push(window.translations["validation"].gramaje_guardas); + } + } + + // papel + $('#divPapelCubierta').removeClass('is-invalid'); + if ($('.custom-selector-papel-cubierta input[type="radio"]:checked').length == 0 && continueCheck) { + + $('#divPapelCubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].papel_cubierta); + continueCheck = false; + } + else if (!$('#divPapelEspecialCubierta').hasClass("d-none")) { + if ($('#papelEspecialCubiertaSel').select2('data').length == 0 && continueCheck) { + $('#divPapelEspecialCubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].papel_cubierta_especial); + continueCheck = false; + } + } + + // gramaje + $('#divGramajeCubierta').removeClass('is-invalid'); + if ($('.custom-selector-gramaje-cubierta input[type="radio"]:checked').length == 0 && continueCheck) { + $('#divGramajeCubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].gramaje_cubierta); + } + + // sobrecubierta + $('#papelSobrecubierta').removeClass('is-invalid'); + $('#gramajeSobrecubierta').removeClass('is-invalid'); + if ($("#addSobrecubierta").prop("checked") == true) { + if($('#papelSobrecubierta').select2('data').length == 0){ + $('#papelSobrecubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].papel_sobrecubierta); + } + if($('#gramajeSobrecubierta').select2('data').length == 0){ + $('#gramajeSobrecubierta').addClass('is-invalid'); + errores.push(window.translations["validation"].gramaje_sobrecubierta); + } + } + + // faja + $('#papelFaja').removeClass('is-invalid'); + $('#gramajeFaja').removeClass('is-invalid'); + if ($("#addFaja").prop("checked") == true) { + if($('#papelFaja').select2('data').length == 0){ + $('#papelFaja').addClass('is-invalid'); + errores.push(window.translations["validation"].papel_faja); + } + if($('#gramajeFaja').select2('data').length == 0){ + $('#gramajeFaja').addClass('is-invalid'); + errores.push(window.translations["validation"].gramaje_faja); + } + } + + const skAlert = document.getElementById('sk-alert'); + skAlert.innerHTML = ''; + const uniqueErrors = [...new Set(errores)]; + + if (uniqueErrors.length > 0) { + const message = window.translations["validation"].fix_errors + + ``; + popErrorAlert(message, 'sk-alert', false); + errores = []; + return false; + } + else { + document.getElementById('sk-alert').innerHTML = ''; + errores = []; + if (goToNext) + this.validatorStepper.next(); + else + return true; + } + } getLomoCubierta() { @@ -903,6 +772,14 @@ class DisenioCubierta { // Accede al ID del elemento que disparó el evento const element = $(event.target); + this.divPapelCubierta.removeClass('is-invalid'); + this.divGramajeCubierta.removeClass('is-invalid'); + + this.divGramajeCubierta.empty(); + this.divPapelCubierta.empty(); + + this.textoPapelCubierta.addClass('d-none'); + let class2Find = '.tipo-cubierta'; let containers = element.closest(class2Find).parent().find(class2Find); @@ -987,23 +864,26 @@ class DisenioCubierta { #handleMenuPapel() { this.divGramajeCubierta.empty(); - const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1; - new Ajax('/configuracion/papelesgenericos/getpapelcliente', - { - [this.csrf_token]: this.csrf_hash, - tipo: 'colorhq', - cubierta: 1, - ancho: this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho, - alto: this.presupuestoCliente.datosGenerales.getDimensionLibro().alto, - solapas: $('#solapas_cubierta').hasClass("d-none") ? 0 : $('#solapas_cubierta').val(), - lomo: $('#lc').val(), - tapa_dura: tapa_dura, - tirada: this.presupuestoCliente.datosGenerales.getTiradas()[0], - }, - {}, - (response) => { this.fillPapeles(response); }, - (response) => { console.log(response); } - ).get(); + this.divGramajeCubierta.removeClass("is-invalid"); + if ($('.tipo-cubierta.selected').length > 0) { + const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1; + new Ajax('/configuracion/papelesgenericos/getpapelcliente', + { + [this.csrf_token]: this.csrf_hash, + tipo: 'colorhq', + cubierta: 1, + ancho: this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho, + alto: this.presupuestoCliente.datosGenerales.getDimensionLibro().alto, + solapas: $('#solapas_cubierta').hasClass("d-none") ? 0 : $('#solapas_cubierta').val(), + lomo: $('#lc').val(), + tapa_dura: tapa_dura, + tirada: this.presupuestoCliente.datosGenerales.getTiradas()[0], + }, + {}, + (response) => { this.fillPapeles(response); }, + (response) => { console.log(response); } + ).get(); + } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js index 1fa37a22..5e69213c 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js @@ -682,6 +682,10 @@ class DisenioInterior { // Accede al ID del elemento que disparó el evento const element = $(event.target); + $('#divImpresionInterior').removeClass('is-invalid'); + $('#divPapelInterior').removeClass('is-invalid'); + $('#divGramajeInterior').removeClass('is-invalid'); + let class2Find = '.disenio-interior'; if (element[0].closest('.image-container').id.includes('Color')) { this.divGramajeInteriorColor.empty(); @@ -692,6 +696,8 @@ class DisenioInterior { this.papelInteriorColor = null; this.gramajeColor = null; class2Find = '.disenio-interior-color'; + this.divPapelInteriorColor.empty(); + } else { this.divGramajeInterior.empty(); @@ -701,6 +707,7 @@ class DisenioInterior { $('#papelEspecialInterior').on("change", this.#handlePapelInteriorEspecial.bind(this)); this.papelInterior = null; this.gramaje = null; + this.divPapelInterior.empty(); } let containers = element.closest(class2Find).parent().find(class2Find); @@ -717,10 +724,12 @@ class DisenioInterior { // Para recalcular el presupuesto element.trigger('change'); - if (class2Find == '.disenio-interior-color') - this.updatePapeles('color'); - else - this.updatePapeles(); + if ($('.disenio-interior.selected').length != 0) { + if (class2Find == '.disenio-interior-color') + this.updatePapeles('color'); + else + this.updatePapeles(); + } } @@ -728,6 +737,9 @@ class DisenioInterior { const context = this; + $('#divPapelInterior').removeClass('is-invalid'); + $('#divGramajeInterior').removeClass('is-invalid'); + // Accede al ID del elemento que disparó el evento const element = $(event.target); const papel = element[0].id.split('_')[1]; @@ -779,6 +791,9 @@ class DisenioInterior { const context = this; + $('#divPapelInterior').removeClass('is-invalid'); + $('#divGramajeInterior').removeClass('is-invalid'); + this.papelInterior = this.papelEspecial.getVal(); let tipo = this.getTipoImpresion(); @@ -806,6 +821,9 @@ class DisenioInterior { const context = this; + $('#divPapelInterior').removeClass('is-invalid'); + $('#divGramajeInterior').removeClass('is-invalid'); + // Accede al ID del elemento que disparó el evento const element = $(event.target); const papel = element[0].id.split('_')[1]; @@ -857,6 +875,9 @@ class DisenioInterior { const context = this; + $('#divPapelInterior').removeClass('is-invalid'); + $('#divGramajeInterior').removeClass('is-invalid'); + this.papelInteriorColor = this.papelEspecialColor.getVal(); let tipo = this.getTipoImpresionColor(); @@ -883,6 +904,7 @@ class DisenioInterior { fillGramajes(response) { + $('#divGramajeInterior').removeClass('is-invalid'); this.divGramajeInterior.empty() let showGramaje = false; @@ -945,6 +967,7 @@ class DisenioInterior { fillGramajesColor(response) { + $('#divGramajeInterior').removeClass('is-invalid'); this.divGramajeInteriorColor.empty() let showGramaje = false; diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index d509aa05..19b175bb 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -130,39 +130,6 @@ class PresupuestoCliente { this.disenioCubierta.processMenuLateral(); } -/* - #checkTiradas() { - - let tiradas = [parseInt(this.datosGenerales.tirada1.val())]; - - if (this.datosGenerales.tirada2.val().length > 0 && - Number.isInteger(parseInt(this.datosGenerales.tirada2.val())) && - parseInt(this.datosGenerales.tirada2.val()) > 0 && - this.datosGenerales.tirada2.val() != "") { - - tiradas.push(parseInt(this.datosGenerales.tirada2.val())); - } - if (this.datosGenerales.tirada3.val().length > 0 && - Number.isInteger(parseInt(this.datosGenerales.tirada3.val())) && - parseInt(this.datosGenerales.tirada3.val()) > 0 && - this.datosGenerales.tirada3.val() != "") { - - tiradas.push(parseInt(this.datosGenerales.tirada3.val())); - } - if (this.datosGenerales.tirada4.val().length > 0 && - Number.isInteger(parseInt(this.datosGenerales.tirada4.val())) && - parseInt(this.datosGenerales.tirada4.val()) > 0 && - this.datosGenerales.tirada4.val() != "") { - - tiradas.push(parseInt(this.datosGenerales.tirada4.val())); - } - - const noPOD = (tiradas.some(tirada => parseInt(tirada) > 30)); - const siPOD = (tiradas.some(tirada => parseInt(tirada) <= 30)); - - this.datosGenerales.formValidation.validateField('tirada'); - return !(noPOD && siPOD); - }*/ calcularSolapas() { @@ -241,10 +208,6 @@ class PresupuestoCliente { if (Object.values(datos_to_check).every(this.#isValidDataForm)) { try { - if (!this.datosGenerales.checkPaginasMultiplo4()) { - popErrorAlert("Compruebe que todos los campos son correctos."); - return; - } setTimeout(function () { $('#loader').modal('show'); @@ -334,31 +297,18 @@ class PresupuestoCliente { switch (form) { case 'datos-generales': - if(this.datosGenerales.validate(false)) + if (this.datosGenerales.validate(false)) this.#goToForm(nextForm); break; case 'interior-libro': - if(this.disenioInterior.validate(false)) + if (this.disenioInterior.validate(false)) this.#goToForm(nextForm); break; case 'cubierta-libro': - this.disenioCubierta.allowNext = false; - validateForm(this.disenioCubierta.formValidation).then((status) => { - if (status !== 'Valid') { - this.disenioCubierta.allowNext = true; - return false; - } + if (this.disenioCubierta.validate(false)) this.#goToForm(nextForm); - this.disenioCubierta.allowNext = true; - return true; - } - ).catch(error => { - this.disenioCubierta.allowNext = true; - console.error('Error al validar:', error); - return false; - }); break; case 'direcciones-libro': @@ -505,12 +455,6 @@ class PresupuestoCliente { return; } - if (!this.datosGenerales.checkPaginasMultiplo4()) { - popErrorAlert("Compruebe que todos los campos son correctos."); - $('#loader').modal('hide'); - return; - } - this.#getDatos(true); if (confirmar) { @@ -538,8 +482,13 @@ class PresupuestoCliente { if (response.error) { popErrorAlert("Presupuesto no válido, corrija los errores antes de guardar."); } - else + else { popSuccessAlert(response.message); + $('.is-invalid').removeClass('is-invalid'); + const skAlert = document.getElementById('sk-alert'); + skAlert.innerHTML = ''; + } + } }, () => { $('#loader').modal('hide'); } @@ -607,6 +556,9 @@ class PresupuestoCliente { this.lc.val(parseFloat(response.info.lomo_cubierta).toFixed(2)); this.lsc.val(parseFloat(response.info.lomo_sobrecubierta).toFixed(2)); + $('.is-invalid').removeClass('is-invalid'); + const skAlert = document.getElementById('sk-alert'); + skAlert.innerHTML = ''; setTimeout(() => { $(`#containerTiradasEnvios .tirada-envio input[tirada="${this.direcciones.tiradaSeleccionada}"]`).trigger('click'); }, 0); @@ -630,10 +582,7 @@ class PresupuestoCliente { case 2: - if (this.disenioCubierta.acabadoCubierta.getVal() == 0) { - alertWarningMessage(window.translations.cubiertaSinAcabado, window.translations.cubiertaSinAcabadoText); - } - this.disenioCubierta.formValidation.validate(); + this.disenioCubierta.validate(); break; case 3: @@ -866,8 +815,8 @@ class PresupuestoCliente { $('#menu_resumen_button').trigger('click'); setTimeout(() => { self.resumen.init_dropzone(); - self.resumen.generate_total(response.data.resumen.base, - response.data.resumen.precio_unidad, + self.resumen.generate_total(response.data.resumen.base, + response.data.resumen.precio_unidad, response.data.resumen.total_envio, response.data.datosGenerales.ivaReducido); }, 0);