diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 5012bda2..aa04c45f 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -324,7 +324,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Cubierta $cubierta = [ - 'papel_generico_cubierta' => $modelPapelGenerico->getIdFromCode($cubierta['papelCubierta']), + 'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(), 'gramajeCubierta' => intval($cubierta['gramajeCubierta']), 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0), 'solapasCubierta' => intval($cubierta['solapas'] ?? 0), @@ -696,7 +696,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Cubierta $cubierta = [ - 'papel_generico_cubierta' => $modelPapelGenerico->getIdFromCode($cubierta['papelCubierta']), + 'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(), 'gramajeCubierta' => intval($cubierta['gramajeCubierta']), 'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0), 'solapasCubierta' => intval($cubierta['solapas'] ?? 0), diff --git a/ci4/app/Models/Configuracion/PapelGenericoModel.php b/ci4/app/Models/Configuracion/PapelGenericoModel.php index 34dacfe0..60257b83 100755 --- a/ci4/app/Models/Configuracion/PapelGenericoModel.php +++ b/ci4/app/Models/Configuracion/PapelGenericoModel.php @@ -394,6 +394,9 @@ class PapelGenericoModel extends \App\Models\BaseModel if ($papel_especial == true) { $builder->where("t1.show_in_client_special", 1); } + else{ + $builder->where("t1.show_in_client_special", 0); + } if ($tipo == 'colorhq' || $tipo == 'negrohq') { $builder->where("t2.rotativa", 0); diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php index 5850e258..fc3c3b6f 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/items/_disenioCubierta.php @@ -138,101 +138,29 @@ -
+

Papel cubierta

- -
- " - alt="Cartulina estucada"> - -
- -
- " alt="Estucado mate"> - -
+
+
+ + +
+
+
- - -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- Recomendado -
-
- -
-
- -
-
-
-
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index 84301d20..2c5ebec3 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -1,16 +1,40 @@ +import { getToken } from '../../common/common.js'; +import { capitalizeFirstLetter } from '../../common/common.js'; + +import Ajax from '../../components/ajax.js'; +import ClassSelect from '../../components/select2.js'; + + class DisenioCubierta { - constructor(domItem, wizardForm, validatorStepper) { - + constructor(domItem, wizardForm, validatorStepper, presupuestoCliente) { + this.domItem = domItem; this.allowNext = true; + this.presupuestoCliente = presupuestoCliente; + + this.csrf_token = getToken(); + this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); + this.wizardStep = wizardForm.querySelector('#cubierta-libro'); this.validatorStepper = validatorStepper; this.disenioCubierta = this.domItem.find(".tipo-cubierta"); this.solapasCubierta = this.domItem.find(".solapas-cubierta"); - this.papelCubierta = this.domItem.find(".papel-cubierta"); + this.textoPapelCubierta = this.domItem.find("#textoPapelCubierta"); + + this.divPapelEspecial = this.domItem.find("#divPapelEspecialCubierta"); + this.papelEspecial = new ClassSelect($("#papelEspecialCubiertaSel"), + '/papelesgenericos/selectpapelespecial', + window.translations["selectPapel"], + false, + { + [this.csrf_token]: this.csrf_hash, + tipo: 'colorhq', + cubierta: 1, + } + ); this.divSolapas = this.domItem.find("#divSolapasCubierta"); this.divCarasImpresion = this.domItem.find("#divCarasImpresion"); @@ -35,16 +59,7 @@ class DisenioCubierta { this.estucadoMate = this.domItem.find("#estucadoMate"); this.divPapelCubierta = this.domItem.find("#divPapelCubierta"); - this.divGramajeCubierta = this.domItem.find("#divGramajeCubierta"); - this.gramaje = this.domItem.find(".check-gramaje-cubierta"); - this.gramaje170 = $(this.domItem.find("#divGramaje170Cubierta")); - this.gramaje250 = $(this.domItem.find("#divGramaje250Cubierta")); - this.gramaje270 = $(this.domItem.find("#divGramaje270Cubierta")); - this.gramaje300 = $(this.domItem.find("#divGramaje300Cubierta")); - this.gramaje350 = $(this.domItem.find("#divGramaje350Cubierta")); - - this.checksGramaje = $('.check-gramaje-cubierta'); this.cubiertaPlastificado = this.domItem.find("#plastificado"); this.cubiertaBarniz = this.domItem.find("#barniz"); @@ -91,12 +106,14 @@ class DisenioCubierta { else if (targetElement.classList.contains('solapas-cubierta')) { this.#handleMenuSolapas(); } - else if (targetElement.classList.contains('papel-cubierta')) { - this.#handleMenuPapel(); - } } }); }); + + this.papelCubierta = null; + this.gramaje = null; + + this.cargando = true; } @@ -104,10 +121,12 @@ class DisenioCubierta { const self = this; + this.papelEspecial.init(); + $('#papelEspecialCubiertaSel').on("change", this.#handlePapelCubiertaEspecial.bind(this)); + // Eventos this.disenioCubierta.on('click', this.#handleDisenioCubierta.bind(this)); this.solapasCubierta.on('click', this.#handleSolapasCubierta.bind(this)); - this.papelCubierta.on('click', this.#handlePapelCubierta.bind(this)); this.tamanioSolapasCubierta.on('change', this.#handleTamanioSolapas.bind(this)); this.altoFaja.on('blur', this.#handleInputs); this.solapasSobrecubierta.on('blur', this.#handleInputs); @@ -129,23 +148,16 @@ class DisenioCubierta { this.observer.observe(this.tapaBlanda[0], { attributes: true }); this.observer.observe(this.tapaDuraLomoRecto[0], { attributes: true }); this.observer.observe(this.tapaDuraLomoRedondo[0], { attributes: true }); - this.observer.observe(this.cartulinaEstucada[0], { attributes: true }); - this.observer.observe(this.estucadoMate[0], { attributes: true }); this.observer.observe(this.conSolapas[0], { attributes: true }); this.observer.observe(this.sinSolapas[0], { attributes: true }); - - this.checksGramaje.each(function () { - - const customOptionEL = $(this); - customOptionEL.on('click', function () { - self.#handleClickGramaje(customOptionEL); - }); - }); } cargarDatos(datosCubierta, datosGuardas, datosSobrecubierta) { + this.papelCubierta = datosCubierta.papel.id; + this.gramaje = datosCubierta.gramaje; + if (datosCubierta.lomoRedondo) { this.tapaDuraLomoRedondo.trigger('click'); } @@ -259,17 +271,19 @@ class DisenioCubierta { validators: { callback: { callback: function (input) { - const div = $('#divPapelCubierta'); - if (div.hasClass("d-none")) return true; - div.find('.fv-plugins-message-container').remove(); - if ($('.papel-cubierta.selected').length > 0) { + $('#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 { - div.append(` + $('#divPapelCubierta').append(`
-
+
${window.translations["validation"].papel_interior}
@@ -280,20 +294,47 @@ class DisenioCubierta { } } }, + 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 div = $('#divGramajeCubierta'); // Selecciona el div - div.find('.fv-plugins-message-container').remove(); - if ($('.check-gramaje-cubierta:checked').length > 0) { + const divGramajeInterior = $('#divGramajeCubierta'); // Selecciona el div + + const gramajeSeleccionado = $('.custom-selector-gramaje-cubierta input[type="radio"]:checked'); + if (gramajeSeleccionado.length > 0) { return true; + } else { - div.append(` + divGramajeInterior.append(`
-
+
${window.translations["validation"].gramaje_interior}
@@ -319,6 +360,7 @@ class DisenioCubierta { case 'div_solapas_cubierta': case 'div_papel_cubierta': case 'div_gramaje_cubierta': + case 'div_papel_especial_cubierta': return '.col-sm-10'; default: return '.col-sm-3'; @@ -338,45 +380,48 @@ class DisenioCubierta { processMenuLateral() { let menu_off = true; - - if($('.papel-cubierta.selected').length>0 && this.getGramaje() != null){ - this.rl_papel_cubierta.text($($('.papel-cubierta.selected').find('.form-label')).text() + " " + - this.getGramaje() + " gr"); + + const papel = this.getPapel(true); + const gramaje = this.getGramaje(); + + if (papel != null && gramaje != null) { + + this.rl_papel_cubierta.text(papel + " " + gramaje + " gr"); this.rl_acabado_cubierta.text(this.domItem.find("#plastificado").children("option:selected").text()); this.rl_papel_cubierta.removeClass('d-none'); this.rl_acabado_cubierta.removeClass('d-none'); - if(this.carasCubierta.find('option:selected').length>0){ + if (this.carasCubierta.find('option:selected').length > 0) { this.rl_caras_cubierta.text("Impresa " + this.carasCubierta.find('option:selected').text()); this.rl_caras_cubierta.removeClass('d-none'); menu_off = false; } - else{ + else { this.rl_caras_cubierta.addClass('d-none'); } - + menu_off = false; } - else{ + else { this.rl_papel_cubierta.addClass('d-none'); this.rl_acabado_cubierta.addClass('d-none'); } - + if (!menu_off) this.rl_cubierta.removeClass('d-none'); else this.rl_cubierta.addClass('d-none'); // Sobrecubierta solo se muestra si cubierta ok - if(!this.rl_cubierta.hasClass('d-none')){ + if (!this.rl_cubierta.hasClass('d-none')) { this.rl_sobrecubierta.removeClass('d-none'); - if(!this.sobrecubierta.is(":checked")){ + if (!this.sobrecubierta.is(":checked")) { this.rl_no_sobrecubierta.removeClass('d-none'); this.rl_papel_sobrecubierta.addClass('d-none'); this.rl_tamanio_sobrecubierta.addClass('d-none'); this.rl_acabado_sobrecubierta.addClass('d-none'); } - else{ + else { this.rl_no_sobrecubierta.addClass('d-none'); this.rl_papel_sobrecubierta.removeClass('d-none'); this.rl_tamanio_sobrecubierta.removeClass('d-none'); @@ -386,12 +431,12 @@ class DisenioCubierta { this.rl_papel_sobrecubierta.text(sobrecubierta.papel + " " + sobrecubierta.gramaje + " gr") this.rl_tamanio_sobrecubierta.text("Solapas: " + sobrecubierta.solapas + " mm") let acabado_text = sobrecubierta.plastificado; - if(acabado_text.includes("Sin plastificar")) + if (acabado_text.includes("Sin plastificar")) acabado_text = "Sin plastificar"; this.rl_acabado_sobrecubierta.text(acabado_text); } } - else{ + else { this.rl_sobrecubierta.addClass('d-none'); } @@ -419,11 +464,30 @@ class DisenioCubierta { } - getPapel() { + getPapel(forResumen = false) { try { - if (this.papelCubierta.filter('.selected').length > 0) { - return this.papelCubierta.filter('.selected').attr('cod'); + let checkedPapel = $('.custom-selector-papel-cubierta input[type="radio"]:checked'); + if (this.papelCubierta != null && checkedPapel != null && checkedPapel.length > 0) { + if (forResumen) { + + if (checkedPapel.length == 0) + return null; + let radioButtonId = checkedPapel[0].id; + if (radioButtonId == 'papelEspecialCubierta') + return capitalizeFirstLetter(this.papelEspecial.getText()); + else { + let associatedLabel = $('label[for="' + radioButtonId + '"]'); + return capitalizeFirstLetter($(associatedLabel[0]).text().toLocaleLowerCase()); + } + } + else { + if (this.divPapelEspecial.hasClass('d-none')) + return this.papelCubierta; + else { + return this.papelEspecial.getVal(); + } + } } return null; } @@ -435,17 +499,13 @@ class DisenioCubierta { getGramaje() { + let checkedGramaje = $('.custom-selector-gramaje-cubierta input[type="radio"]:checked'); + try { - if (this.divGramajeCubierta.hasClass("d-none")) - return null; - - if (this.gramaje.filter(':checked').length > 0) - return this.gramaje.filter(':checked').attr('data-value'); - - else - return null; - + if (checkedGramaje.length == 0) + return null; + return checkedGramaje[0].id.split('_')[1]; } catch (e) { return null; } @@ -606,8 +666,6 @@ class DisenioCubierta { element.closest(class2Find).toggleClass('selected'); element.closest('.image-presupuesto').toggleClass('selected'); - $(".papel-cubierta").removeClass("selected"); - if (this.tapaBlanda.hasClass("selected")) { if (this.carasCubierta.val() == 2) { this.cartulinaEstucada.removeClass("d-none"); @@ -651,30 +709,10 @@ class DisenioCubierta { } - #handlePapelCubierta(event) { - // Accede al ID del elemento que disparó el evento - const element = $(event.target); - - let class2Find = '.papel-cubierta'; - - let containers = element.closest(class2Find).parent().find(class2Find); - for (let container of containers) { - if (container != element.closest(class2Find)[0]) { - $(container).removeClass('selected'); - $(container).find('.image-presupuesto').removeClass('selected'); - } - } - - element.closest(class2Find).toggleClass('selected'); - element.closest('.image-presupuesto').toggleClass('selected'); - - element.trigger('change'); - } - #handleMenuTipoCubierta() { if (this.tapaBlanda.hasClass("selected")) { - + this.divSolapas.removeClass("d-none"); this.divCarasImpresion.removeClass("d-none"); this.divConfigGuardas.addClass("d-none"); @@ -684,15 +722,14 @@ class DisenioCubierta { this.divSolapas.addClass("d-none"); this.divCarasImpresion.addClass("d-none"); this.divConfigGuardas.removeClass("d-none"); - this.#handleMenuPapel(); - } else { this.divSolapas.addClass("d-none"); this.divCarasImpresion.addClass("d-none"); this.divConfigGuardas.addClass("d-none"); - this.#handleMenuPapel(); } + + this.#handleMenuPapel(); } @@ -708,42 +745,228 @@ class DisenioCubierta { #handleMenuPapel() { - $(".check-gramaje-cubierta").prop("checked", false); + this.divGramajeCubierta.empty(); + new Ajax('/papelesgenericos/getpapelcliente', + { + [this.csrf_token]: this.csrf_hash, + tipo: 'colorhq', + cubierta: 1, + }, + {}, + (response) => { this.fillPapeles(response); }, + (response) => { console.log(response); } + ).get(); + } - if (!this.tapaBlanda.hasClass("selected") && !this.tapaDuraLomoRecto.hasClass("selected") && !this.tapaDuraLomoRedondo.hasClass("selected")) { - this.divGramajeCubierta.addClass("d-none"); - this.estucadoMate.removeClass("selected"); - this.cartulinaEstucada.removeClass("selected"); + + #handlePapelCubiertaEspecial() { + + const context = this; + + this.papelCubierta = this.papelEspecial.getVal(); + + new Ajax('/papelesgenericos/getpapelcliente', + { + [this.csrf_token]: this.csrf_hash, + papel: this.papelCubierta, + tipo: 'colorhq', + cubierta: 1, + }, + {}, + this.fillGramajes.bind(context), + (response) => { console.log(response); } + ).get(); + + } + + + fillPapeles(response) { + + this.divPapelCubierta.empty(); + this.divGramajeCubierta.empty(); + + if (response.papeles.length > 0) { + this.textoPapelCubierta.removeClass('d-none'); + } + else { + this.textoPapelCubierta.addClass("d-none"); + } + + response.papeles.forEach(papel => { + var container = $('
', { + class: 'custom-selector custom-selector-papel-cubierta d-flex flex-column align-items-center justify-content-center' + }); + + var radioButton = $('', { + type: 'radio', // Tipo de input + name: 'calcular-presupuesto papel-cubierta', + id: 'papelCubierta_' + papel.id, // ID único + value: 'option1' // Valor del radio button + }); + + // Crear una etiqueta para el radio button + var label = $('