From 505cc6fb31e9bf87dc065ae7f55bb48768f93e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Wed, 11 Jun 2025 20:08:17 +0200 Subject: [PATCH] terminados datos generales e interior --- ci4/app/Language/es/Presupuestos.php | 24 +- .../presupuestoCliente/datosGenerales.js | 514 +++++------------- .../presupuestoCliente/disenioInterior.js | 296 +++------- .../presupuestoCliente/presupuestoCliente.js | 44 +- httpdocs/themes/vuexy/css/safekat.css | 5 + 5 files changed, 248 insertions(+), 635 deletions(-) diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index dde98be6..8874b770 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -380,6 +380,17 @@ return [ ], 'validation' => [ + 'fix_errors' => 'Corrija los siguientes errores antes de continuar:', + 'titulo_requerido' => 'El campo "Título" es obligatorio.', + 'tirada_integer_greatherThan_0' => 'Los valores de las tiradas deben ser enteros mayores que 0.', + 'tirada_pod_nopod' => 'No se pueden mezclar tiradas POD (menor o igual que 30 unidades) con tiradas no POD (mayor que 30 unidades).', + 'papelFormatoAncho' => 'Seleccione un ancho de libro válido.', + 'papelFormatoAlto' => 'Seleccione un alto de libro válido.', + 'papelFormato' => 'Seleccione un formato de libro válido.', + 'paginasColor' => 'El número de páginas a color debe ser un número entero mayor o igual que 0.', + 'paginasNegro' => 'El número de páginas en negro debe ser un número entero mayor o igual que 0.', + 'paginas' => 'El total de páginas tiene que ser mayor que 0.', + 'tipo_libro' => 'Seleccione el tipo de libro que desea para el presupuesto.', 'decimal' => 'El campo {field} debe contener un número decimal.', 'integer' => 'El campo {field} debe contener un número entero.', 'requerido' => 'El campo {field} es obligatorio.', @@ -388,11 +399,12 @@ return [ 'no_lp_for_merma' => 'Inserte líneas de presupuesto para calcular la merma', 'ejemplares_envio' => 'El número de ejemplares enviados no coincide con la tirada', 'cliente' => 'Debe seleccionar un cliente', - 'papelFormato' => 'Seleccione un formato', - 'tipo_libro' => 'Seleccione un tipo de libro', - 'disenio_interior' => 'Seleccione el diseño del interior', - 'papel_interior' => 'Seleccione el tipo de papel', - 'gramaje_interior' => 'Seleccione el gramaje', + + 'disenio_interior' => 'Seleccione el tipo de impresión del interior', + 'papel_interior' => 'Seleccione el tipo de papel para el interior', + 'papel_interior_especial' => 'Seleccione el papel especial en el desplegable para el interior', + 'gramaje_interior' => 'Seleccione el gramaje para el interior', + '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', @@ -400,7 +412,7 @@ return [ '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 de páginas para cosido o grapado debe ser múltiplo de 4', + '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', 'extras_cubierta' => 'Rellene todos los campos', ], diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js index 23736d72..4e40022f 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js @@ -5,7 +5,6 @@ class DatosGenerales { constructor(domItem, wizardForm, validatorStepper) { this.domItem = domItem; - this.allowNext = true; this.wizardStep = wizardForm.querySelector('#datos-generales'); this.validatorStepper = validatorStepper; @@ -78,7 +77,7 @@ class DatosGenerales { this.cargando = false; - this.initValidation(); + this.errores = []; } @@ -88,7 +87,6 @@ class DatosGenerales { this.formatoLibro.init(); this.cliente.init(); - // Inicializa el tipo de impresion this.#handlePaginas(); @@ -111,303 +109,147 @@ class DatosGenerales { this.retractilado5.on('change', this.#eventRetractilado.bind(this)); } - initValidation() { - const stepper = this.validatorStepper; + validate(goToNext = true) { - this.formValidation = FormValidation.formValidation(this.wizardStep, { - fields: { - titulo: { - validators: { - notEmpty: { - message: window.translations["validation"].requerido_short - }, - } - }, - cliente_id: { - validators: { - callback: { - message: window.translations["validation"].cliente, - callback: function (input) { - // Get the selected options - if (!$(this.excluirRotativa).prop('hidden')) - return true; - const options = $("#clienteId").select2('data'); - const hasValidOption = options.some(option => parseInt(option.id) > 0); - return options !== null && options.length > 0 && hasValidOption; - }, - } - } - }, - tirada: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - const value = $("#tirada").val(); - const value2 = $("#tirada2").val(); - const value3 = $("#tirada3").val(); - const value4 = $("#tirada4").val(); - let tiradas = [value]; + this.errores = []; - if (!(value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0)) { - return { - valid: false, - message: window.translations["validation"].integer_greatherThan_0, - }; - } - if (value2.length > 0 && Number.isInteger(parseInt(value2)) && parseInt(value2) > 0) { - tiradas.push(value2); - } - if (value3.length > 0 && Number.isInteger(parseInt(value3)) && parseInt(value3) > 0) { - tiradas.push(value3); - } - if (value4.length > 0 && Number.isInteger(parseInt(value4)) && parseInt(value4) > 0) { - tiradas.push(value4); - } - // comprobar si hay valores > 30 - const noPOD = (tiradas.some(tirada => parseInt(tirada) > 30)); - const siPOD = (tiradas.some(tirada => parseInt(tirada) <= 30)); - if (noPOD && siPOD) { - return { - valid: false, - message: "No se pueden mezclar tiradas <30 con >30", - } - } + // Titulo + if (this.titulo.val().trim() === '') { + this.errores.push(window.translations["validation"].titulo_requerido); + this.titulo.addClass('is-invalid'); + } else { + this.titulo.removeClass('is-invalid'); + } - return true; - }, - } - } - }, - tirada2: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - let field = $("#tirada2"); - field.val(field.val().replace(/[^0-9]/g, '')); - let value = field.value; - if (value == '') - return true; - return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; - }, - } - } - }, - tirada3: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - let field = $("#tirada3"); - field.val(field.val().replace(/[^0-9]/g, '')); - let value = field.value; - if (value == '') - return true; - return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; - }, - } - } - }, - tirada4: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - let field = $("#tirada4"); - field.val(field.val().replace(/[^0-9]/g, '')); - let value = field.value; - if (value == '') - return true; - return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; - }, - } - } - }, - papel_formato_id: { - validators: { - callback: { - message: window.translations["validation"].papelFormato, - callback: function (input) { - // Get the selected options - const options = $("#papelFormatoId").select2('data'); - const hasValidOption = options.some(option => parseInt(option.id) > 0); - const custom_format = $("#papelFormatoPersonalizado").is(":checked"); - if (custom_format) - return true; - return options !== null && options.length > 0 && hasValidOption; - }, - } - } - }, - papel_formato_ancho: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - // Get the selected options - const custom_format = $("#papelFormatoPersonalizado").is(":checked"); - if (!custom_format) - return true; - const value = $("#papelFormatoAncho").val(); - return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; - }, - } - } - }, - papel_formato_alto: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - // Get the selected options - const custom_format = $("#papelFormatoPersonalizado").is(":checked"); - if (!custom_format) - return true; - const value = $("#papelFormatoAlto").val(); - return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; - }, - } - } - }, - paginasColor: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - // Get the selected options - const value = $("#paginasColor").val(); - if (value.length >= 0 && Number.isInteger(parseInt(value)) && parseInt(value) >= 0) { + // Cliente + if ($(this.excluirRotativa).prop('hidden')) { + if ($('#clienteId').val() === null || $('#clienteId').val().length === 0) { + this.errores.push(window.translations["validation"].cliente); + $('#clienteId').addClass('is-invalid'); + } else { + $('#clienteId').removeClass('is-invalid'); + } + } else { + if (this.cliente.getVal() <= 0) { + this.errores.push(window.translations["validation"].cliente); + this.cliente.item.addClass('is-invalid'); + } else { + this.cliente.item.removeClass('is-invalid'); + } + } - if (parseInt(value) % 2 != 0) { - return { - valid: false, - message: window.translations["validation"].paginas_pares - }; - } - return true; - } - return false; - }, - } - } - }, - paginasNegro: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - // Get the selected options - const value = $("#paginasNegro").val(); - if (value.length >= 0 && Number.isInteger(parseInt(value)) && parseInt(value) >= 0) { + // Tirada + let tiradas = this.getTiradas(); + if (tiradas.length === 0 || tiradas.some(tirada => + !Number.isInteger(tirada) || + parseInt(tirada) <= 0 || + tirada == "")) { - if (parseInt(value) % 2 != 0) { - return { - valid: false, - message: window.translations["validation"].paginas_pares - }; - } - return true; - } - return false; - }, - } - } - }, - paginas: { - validators: { - callback: { - message: window.translations["validation"].integer_greatherThan_0, - callback: function (input) { - // Get the selected options - const value = $("#paginas").val(); - return value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0; - }, - } - } - }, - div_tipo_libro: { - validators: { - callback: { - callback: function (input) { - const divTipoLibro = $('#divTipoLibro'); // Selecciona el div + this.errores.push(window.translations["validation"].tirada_integer_greatherThan_0); + this.tirada1.addClass('is-invalid'); - divTipoLibro.find('.fv-plugins-message-container').remove(); - if ($('.tipo-libro.selected').length > 0) { - if ($('#cosido').hasClass('selected') || $('#grapado').hasClass('selected')) { - const value = parseInt($("#paginas").val()); - if (value % 4 != 0) { - divTipoLibro.append(` -
-
- ${window.translations["validation"].paginas_multiplo_4} -
-
- `); - return false; - } - return true; - } + } else { + this.tirada1.removeClass('is-invalid'); + // Comprobar tiradas POD + const noPOD = tiradas.some(tirada => parseInt(tirada) > 30); + const siPOD = tiradas.some(tirada => parseInt(tirada) <= 30); + if (noPOD && siPOD) { + this.errores.push(window.translations["validation"].tirada_pod_nopod); + this.tirada1.addClass('is-invalid'); + } + else { + this.tirada1.removeClass('is-invalid'); + } + } - return true; - } - else { - divTipoLibro.append(` -
-
- ${window.translations["validation"].tipo_libro} -
-
- `); - return false; - } + // formato libro + if (this.checkFormatoPersonalizado.is(':checked')) { + if (this.anchoPersonalizado.val().length === 0 || isNaN(this.anchoPersonalizado.val()) || + parseFloat(this.anchoPersonalizado.val()) <= 0) { + this.errores.push(window.translations["validation"].papelFormatoAncho); + this.anchoPersonalizado.addClass('is-invalid'); + } else { + this.anchoPersonalizado.removeClass('is-invalid'); + } + if (this.altoPersonalizado.val().length === 0 || isNaN(this.altoPersonalizado.val()) || + parseFloat(this.altoPersonalizado.val()) <= 0) { + this.errores.push(window.translations["validation"].papelFormatoAlto); + this.altoPersonalizado.addClass('is-invalid'); + } else { + this.altoPersonalizado.removeClass('is-invalid'); + } + } else { + const options = $("#papelFormatoId").select2('data'); + const hasValidOption = options.some(option => parseInt(option.id) > 0); + if (options !== null && options.length > 0 && hasValidOption) { + this.papelFormatoId.removeClass('is-invalid'); + } else { + this.errores.push(window.translations["validation"].papelFormato); + this.papelFormatoId.addClass('is-invalid'); + } + } - }, - } + // Paginas + if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) { + this.errores.push(window.translations["validation"].paginasColor); + this.paginasColor.addClass('is-invalid'); + } else { + this.paginasColor.removeClass('is-invalid'); + } + if (this.paginasNegro.val() == '' || isNaN(this.paginasNegro.val()) || parseInt(this.paginasNegro.val()) < 0) { + this.errores.push(window.translations["validation"].paginasNegro); + this.paginasNegro.addClass('is-invalid'); + } else { + this.paginasNegro.removeClass('is-invalid'); + } + if (this.paginas.val() == '' || isNaN(this.paginas.val()) || parseInt(this.paginas.val()) <= 0) { + this.errores.push(window.translations["validation"].paginas); + this.paginas.addClass('is-invalid'); + } else { + this.paginas.removeClass('is-invalid'); + } + + // Tipo de libro + if ($('.tipo-libro.selected').length > 0) { + if ($('#cosido').hasClass('selected') || $('#grapado').hasClass('selected')) { + const value = parseInt($("#paginas").val()); + if (value % 4 != 0) { + if (parseInt(this.paginas.val()) % 4 != 0) { + this.errores.push(window.translations["validation"].paginas_multiplo_4); + this.paginas.addClass('is-invalid'); + } else { + this.paginas.removeClass('is-invalid'); } } - }, - 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_libro': - return '.col-sm-10'; - case 'titulo': - return '.col-sm-8'; - case 'cliente_id': - return '.col-sm-5'; - case 'papel_formato_id': - return '.col-sm-4'; - case 'papel_formato_ancho': - case 'papel_formato_ancho': - return '.col-sm-3'; - case 'tirada': - case 'tirada2': - case 'tirada3': - case 'tirada4': - return '.col-sm-2'; - - default: - return '.col-sm-3'; - } - } - }), - autoFocus: new FormValidation.plugins.AutoFocus(), - submitButton: new FormValidation.plugins.SubmitButton() } - }).on('core.form.valid', () => { - if (this.allowNext) + this.domItem.find('#divTipoLibro').removeClass('is-invalid'); + } else { + this.errores.push(window.translations["validation"].tipo_libro); + this.domItem.find('#divTipoLibro').addClass('is-invalid'); + } - stepper.next(); - }); + const skAlert = document.getElementById('sk-alert'); + skAlert.innerHTML = ''; + const uniqueErrors = [...new Set(this.errores)]; + + if (uniqueErrors.length > 0) { + const message = window.translations["validation"].fix_errors + + ``; + popErrorAlert(message, 'sk-alert', false); + this.errores = []; + return false; + } + else { + document.getElementById('sk-alert').innerHTML = ''; + this.errores = []; + if (goToNext) + this.validatorStepper.next(); + else + return true; + } } @@ -425,11 +267,11 @@ class DatosGenerales { else { this.rl_tipo.addClass('d-none'); } - if($('.tipo-cubierta.selected').length>0){ + if ($('.tipo-cubierta.selected').length > 0) { this.rl_tipo_cubierta.text($($('.tipo-cubierta.selected').find('.form-label')).text()); this.rl_tipo_cubierta.removeClass('d-none'); } - else{ + else { this.rl_tipo_cubierta.addClass('d-none'); } if (this.checkFormatoPersonalizado.is(':checked')) { @@ -478,33 +320,9 @@ class DatosGenerales { // servicios extra menu_off = true; - /*if(this.prototipo.is(':checked')){ - this.rl_prototipo.removeClass("d-none"); - menu_off = false; - } - else{ - this.rl_prototipo.addClass('d-none'); - } - - if(this.ferro.is(':checked')){ - this.rl_ferro.removeClass("d-none"); - menu_off = false; - } - else{ - this.rl_ferro.addClass('d-none'); - } - - if(this.ferroDigital.is(':checked')){ - this.rl_ferroDigital.removeClass("d-none"); - menu_off = false; - } - else{ - this.rl_ferroDigital.addClass('d-none'); - } -*/ $('#rl-servicios-extra-items').empty(); - if(this.marcapaginas.is(':checked')){ + if (this.marcapaginas.is(':checked')) { let $ul = $('