From 348dda9cd1defa75da59ace342c0420ccef0a839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sun, 9 Feb 2025 13:16:03 +0100 Subject: [PATCH] papel y gramaje sobrecubierta y guardas seleccionable --- .../Configuracion/Papelesgenericos.php | 5 +- .../Presupuestos/Presupuestocliente.php | 18 +- ci4/app/Language/es/Presupuestos.php | 4 +- .../Configuracion/PapelGenericoModel.php | 4 + .../cliente/items/_disenioCubierta.php | 59 +++--- .../assets/js/safekat/components/select2.js | 8 +- .../presupuestoCliente/disenioCubierta.js | 185 +++++++++++++++--- 7 files changed, 218 insertions(+), 65 deletions(-) diff --git a/ci4/app/Controllers/Configuracion/Papelesgenericos.php b/ci4/app/Controllers/Configuracion/Papelesgenericos.php index 43ef6206..899c318f 100755 --- a/ci4/app/Controllers/Configuracion/Papelesgenericos.php +++ b/ci4/app/Controllers/Configuracion/Papelesgenericos.php @@ -313,6 +313,7 @@ class Papelesgenericos extends \App\Controllers\BaseResourceController $cubierta = goSanitize($this->request->getGet('cubierta'))[0] ?? 0; $tapa_dura = goSanitize($this->request->getGet('tapa_dura'))[0] ?? null; $sobrecubierta = goSanitize($this->request->getGet('sobrecubierta'))[0] ?? 0; + $guardas = goSanitize($this->request->getGet('guardas'))[0] ?? 0; $ancho = floatval($this->request->getGet('ancho') ?? 0); $alto = floatval($this->request->getGet('alto') ?? 0); @@ -323,8 +324,8 @@ class Papelesgenericos extends \App\Controllers\BaseResourceController $anchoLibro = 2 * $ancho + 2 * $solapas + $lomo; - $menu = $this->model->getPapelCliente($tipo, $cubierta, $sobrecubierta, $selected_papel, $tapa_dura, false, $POD, $anchoLibro, $alto, $tirada); - $menu2 = $this->model->getPapelCliente($tipo, $cubierta, $sobrecubierta, $selected_papel, $tapa_dura, true, $POD, $anchoLibro, $alto, $tirada); + $menu = $this->model->getPapelCliente($tipo, $cubierta, $sobrecubierta, $guardas, $selected_papel, $tapa_dura, false, $POD, $anchoLibro, $alto, $tirada); + $menu2 = $this->model->getPapelCliente($tipo, $cubierta, $sobrecubierta, $guardas, $selected_papel, $tapa_dura, true, $POD, $anchoLibro, $alto, $tirada); if ($forSelect2) { $menu = array_map(function ($item) { diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 99b6622a..217d1a8d 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -353,7 +353,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $guardas = $reqData['guardas'] ?? []; if ($guardas != "false" && $guardas != null) { $datos_guardas = [ - 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']), + 'papel' => intval($guardas['papel']), 'gramaje' => intval($guardas['gramaje']), 'caras' => intval($guardas['caras']), ]; @@ -366,7 +366,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController if (count($datos_guardas) != 0 && $datos_guardas) { $guardas = $datos_guardas; - $input_data['papel_generico'] = $datos_guardas['papel'] ?? 0; + $input_data['papel_generico']['id'] = $datos_guardas['papel'] ?? 0; $input_data['gramaje'] = $datos_guardas['gramaje'] ?? 0; $input_data['datosPedido']->paginas = 8; $input_data['paginas_color'] = 8; @@ -508,7 +508,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Sobrecubierta if ($sobrecubierta != "false" && $sobrecubierta != null) { $sobrecubierta = [ - 'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']), + 'papel' => $modelPapelGenerico->where('id', $sobrecubierta['papel'])->first()->toArray(), 'gramaje' => intval($sobrecubierta['gramaje']), 'solapas' => intval($sobrecubierta['solapas'] ?? 0), 'acabado' => $sobrecubierta['acabado'] ?? 0, @@ -519,7 +519,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Guardas if ($guardas != "false" && $guardas != null) { $datos_guardas = [ - 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']), + 'papel' => $modelPapelGenerico->where('id', $guardas['papel'])->first()->toArray(), 'gramaje' => intval($guardas['gramaje']), 'caras' => intval($guardas['caras']), ]; @@ -1024,7 +1024,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Sobrecubierta if ($sobrecubierta != "false" && $sobrecubierta != null) { $sobrecubierta = [ - 'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']), + 'papel' => $modelPapelGenerico->where('id', $sobrecubierta['papel'])->first()->toArray(), 'gramaje' => intval($sobrecubierta['gramaje']), 'solapas' => intval($sobrecubierta['solapas'] ?? 0), 'acabado' => $sobrecubierta['acabado'] ?? 0, @@ -1035,7 +1035,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController // Guardas if ($guardas != "false" && $guardas != null) { $datos_guardas = [ - 'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']), + 'papel' => $modelPapelGenerico->where('id', $guardas['papel'])->first()->toArray(), 'gramaje' => intval($guardas['gramaje']), 'caras' => intval($guardas['caras']), ]; @@ -3161,7 +3161,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $return_data['cubierta']['gramaje'] = $linea->gramaje; $return_data['cubierta']['paginas'] = $linea->paginas; } else if ($linea->tipo == 'lp_sobrecubierta') { - $return_data['sobrecubierta']['papel'] = $modelPapelGenerico->getCodeFromId($linea->papel_id); + $return_data['sobrecubierta']['papel'] = $modelPapelGenerico->getNombre($linea->papel_id)['nombre']; + $return_data['sobrecubierta']['papel_id'] = $linea->papel_id; $return_data['sobrecubierta']['gramaje'] = $linea->gramaje; $return_data['sobrecubierta']['paginas'] = $linea->paginas; } else if ($linea->tipo == 'lp_faja') { @@ -3170,7 +3171,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $return_data['faja']['gramaje'] = $linea->gramaje; $return_data['faja']['paginas'] = $linea->paginas; } else if ($linea->tipo == 'lp_guardas') { - $return_data['guardas']['papel'] = $modelPapelGenerico->getCodeFromId($linea->papel_id); + $return_data['guardas']['papel'] = $modelPapelGenerico->getNombre($linea->papel_id)['nombre']; + $return_data['guardas']['papel_id'] = $linea->papel_id; $return_data['guardas']['gramaje'] = $linea->gramaje; $return_data['guardas']['paginas'] = $linea->paginas; } diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index 1aff544c..c1951b6e 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -94,7 +94,8 @@ return [ 'retractilado' => 'Retractilado individual', 'retractilado5' => 'Retractilado de 5', 'Guardas' => 'Guardas', - 'papelGuardas' => 'Papel de guardas', + 'papelGuardas' => 'Papel guardas', + 'gramajeGuardas' => 'Gramaje guardas', 'offsetBlancoGuardas' => 'Offset blanco 170 gr', 'offsetAhuesadoGuardas' => 'Offset ahuesado 170 gr', 'guardasImpresas' => "Guardas impresas", @@ -121,6 +122,7 @@ return [ 'bronce' => 'Bronce', 'retractiladoTitle' => 'Retractilado', 'papelSobrecubierta' => 'Papel sobrecubierta', + 'gramajeSobrecubierta' => 'Gramaje sobrecubierta', 'tamanioSolapasSobrecubierta' => 'TamaƱo solapas sobrecubierta', 'plastificadoSobrecubierta' => 'Plastificado sobrecubierta', 'faja' => 'Faja', diff --git a/ci4/app/Models/Configuracion/PapelGenericoModel.php b/ci4/app/Models/Configuracion/PapelGenericoModel.php index 619ae1ac..d2b6e316 100755 --- a/ci4/app/Models/Configuracion/PapelGenericoModel.php +++ b/ci4/app/Models/Configuracion/PapelGenericoModel.php @@ -414,6 +414,7 @@ class PapelGenericoModel extends \App\Models\BaseModel $tipo, $is_cubierta = false, $is_sobrecubierta = false, + $is_guardas = false, $selected_papel_id = null, $tapa_dura = null, $papel_especial = false, @@ -521,6 +522,9 @@ class PapelGenericoModel extends \App\Models\BaseModel } else if ($is_sobrecubierta == true) { $builder->where("t2.sobrecubierta", 1); $builder->where("t5.uso", 'sobrecubierta'); + } else if ($is_guardas == true) { + $builder->where("t2.guardas", 1); + $builder->where("t5.uso", 'interior'); } else { $builder->where("t2.interior", 1); $builder->where("t5.uso", 'interior'); 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 74bb1e12..30729a8a 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 @@ -98,17 +98,25 @@ -
+
-
- - +
+
+ + +
+
+ + +
@@ -188,8 +196,8 @@

Extras

-
- +
+
- - +
+ + +
+
+ + +
@@ -231,7 +245,7 @@
-
+
@@ -252,7 +266,7 @@
-
diff --git a/httpdocs/assets/js/safekat/components/select2.js b/httpdocs/assets/js/safekat/components/select2.js index 06bca1f8..c7fdfa51 100644 --- a/httpdocs/assets/js/safekat/components/select2.js +++ b/httpdocs/assets/js/safekat/components/select2.js @@ -4,11 +4,12 @@ * @param {String} url * @param {String} placeholder */ -let ClassSelect = function (domItem, url, placeholder, allowClear = false, params = {}, dropdownParent = "") { +let ClassSelect = function (domItem, url, placeholder, allowClear = false, params = {}, dropdownParent = "", hideSearch = false) { this.url = url; this.item = domItem; this.params = params; this.dropdownParent = dropdownParent; + this.hideSearch = hideSearch; this.config = { placeholder: placeholder, @@ -48,6 +49,11 @@ let ClassSelect = function (domItem, url, placeholder, allowClear = false, param }; this.init = function () { if (this.item.length) { + + if(this.hideSearch){ + this.config.minimumResultsForSearch = -1; + } + this.item = this.item.select2(this.config); // $.fn.modal.Constructor.prototype.enforceFocus = function () {}; } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index 029f54a4..1a5bcf44 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -58,7 +58,43 @@ class DisenioCubierta { this.textoSolapasCubierta = this.domItem.find("#textoSolapasCubierta"); this.tamanioSolapasCubierta = $(this.domItem.find("#solapasCubierta")); - this.papelGuardas = this.domItem.find("#papelGuardas"); + this.papelGuardas = new ClassSelect($("#papelGuardas"), + '/papelesgenericos/getpapelcliente', + window.translations["selectPapel"], + false, + { + [this.csrf_token]: this.csrf_hash, + tipo: () => 'colorhq', + tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, + ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, + alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, + solapas: 0, + lomo: 0, + guardas: 1, + forSelect2: 1, + }, + "", + true, + ); + this.gramajeGuardas = new ClassSelect($("#gramajeGuardas"), + '/papelesgenericos/getpapelcliente', + window.translations["selectGramaje"], + false, + { + [this.csrf_token]: this.csrf_hash, + tipo: 'colorhq', + papel: () => { return this.papelGuardas.getVal() }, + tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, + ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, + alto: () => { return $('#altoFaja').val() }, + solapas: 0, + lomo: 0, + guardas: 1, + forSelect2: 1, + }, + "", + true + ); this.guardasImpresas = this.domItem.find("#guardasImpresas"); this.cabezada = this.domItem.find("#cabezada"); @@ -72,7 +108,43 @@ class DisenioCubierta { this.configuracionSobrecubierta = this.domItem.find(".config-sobrecubierta"); this.sobrecubierta = this.domItem.find("#addSobrecubierta"); - this.papelSobrecubierta = this.domItem.find("#papelSobrecubierta"); + this.papelSobrecubierta = new ClassSelect($("#papelSobrecubierta"), + '/papelesgenericos/getpapelcliente', + window.translations["selectPapel"], + false, + { + [this.csrf_token]: this.csrf_hash, + tipo: 'colorhq', + sobrecubierta: 1, + ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, + alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, + solapas: () => { return $('#solapasSobrecubierta').val() }, + lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, + tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, + forSelect2: 1, + }, + "", + true, + ); + this.gramajeSobrecubierta = new ClassSelect($("#gramajeSobrecubierta"), + '/papelesgenericos/getpapelcliente', + window.translations["selectPapel"], + false, + { + [this.csrf_token]: this.csrf_hash, + tipo: 'colorhq', + sobrecubierta: 1, + papel: () => { return this.papelSobrecubierta.getVal() }, + ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, + alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, + solapas: () => { return $('#solapasSobrecubierta').val() }, + lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, + tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, + forSelect2: 1, + }, + "", + true, + ); this.acabadoSobrecubierta = this.domItem.find("#acabadoSobrecubierta"); this.configuracionFaja = this.domItem.find(".config-faja"); @@ -91,7 +163,9 @@ class DisenioCubierta { lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, forSelect2: 1, - } + }, + "", + true, ); this.gramajeFaja = new ClassSelect($("#gramajeFaja"), '/papelesgenericos/getpapelcliente', @@ -108,7 +182,9 @@ class DisenioCubierta { lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, forSelect2: 1, - } + }, + "", + true ); @@ -201,6 +277,12 @@ class DisenioCubierta { this.acabadoSobrecubierta.init(); this.acabadoFaja.init(); + this.papelGuardas.init(); + this.gramajeGuardas.init(); + + this.papelSobrecubierta.init(); + this.gramajeSobrecubierta.init(); + this.papelFaja.init(); this.gramajeFaja.init(); @@ -228,6 +310,8 @@ class DisenioCubierta { this.papelFaja.item.on('change', () => { this.gramajeFaja.empty(); }); + this.papelGuardas.item.on('change', () => { this.gramajeGuardas.empty(); }); + // Observadores this.observer.observe(this.tapaBlanda[0], { attributes: true }); this.observer.observe(this.tapaDuraLomoRecto[0], { attributes: true }); @@ -255,7 +339,8 @@ class DisenioCubierta { } if (datosCubierta.tapa == "dura") { - this.papelGuardas.val(datosGuardas.papel.code + "_" + datosGuardas.gramaje).trigger('change'); + this.papelGuardas.setOption(datosGuardas.papel_id, datosGuardas.papel); + this.gramajeGuardas.setOption(datosGuardas.gramaje, datosGuardas.gramaje); this.guardasImpresas.val(datosGuardas.paginas).trigger('change'); this.cabezada.val(datosCubierta.cabezada).trigger('change'); } @@ -281,7 +366,8 @@ class DisenioCubierta { if (datosSobrecubierta && datosSobrecubierta.papel) { this.sobrecubierta.trigger('click'); - this.papelSobrecubierta.val(datosSobrecubierta.papel.code + "_" + datosSobrecubierta.gramaje).trigger('change'); + this.papelSobrecubierta.setOption(datosSobrecubierta.papel_id, datosSobrecubierta.papel); + this.gramajeSobrecubierta.setOption(datosSobrecubierta.gramaje, datosSobrecubierta.gramaje); this.solapasSobrecubierta.val(datosSobrecubierta.solapas_ancho); this.acabadoSobrecubierta.setOption(datosSobrecubierta.acabado.id, datosSobrecubierta.acabado.text); } @@ -432,6 +518,37 @@ class DisenioCubierta { } } }, + 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: { @@ -440,22 +557,33 @@ class DisenioCubierta { const div = $('#divExtras'); // Selecciona el div div.find('.fv-plugins-message-container').remove(); - if($("#addFaja").prop("checked") == false) - return true; - const papelFaja = $('#papelFaja').select2('data').length > 0; - const gramajeFaja = $('#gramajeFaja').select2('data').length > 0; - if (papelFaja && gramajeFaja) { - return true; + 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; + } } - else { + + 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} +
+
+ ${window.translations["validation"].extras_cubierta} +
-
- `); + `); return false; } }, @@ -478,6 +606,7 @@ class DisenioCubierta { 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'; @@ -675,15 +804,13 @@ class DisenioCubierta { let guardas = {}; if (forResumen) { - let papelGuardas = this.domItem.find("#papelGuardas").children("option:selected").text(); - guardas.papel = papelGuardas.split(' ')[0] + ' ' + papelGuardas.split(' ')[1]; - guardas.gramaje = papelGuardas.split(' ')[2]; + guardas.papel = this.papelGuardas.getText(); + guardas.gramaje = this.gramajeGuardas.getText(); guardas.caras = this.domItem.find("#guardasImpresas").children("option:selected").text(); } else { - let papelGuardas = this.domItem.find("#papelGuardas").children("option:selected").val(); - guardas.papel = papelGuardas.split('_')[0]; - guardas.gramaje = papelGuardas.split('_')[1]; + guardas.papel = this.papelGuardas.getVal(); + guardas.gramaje = this.gramajeGuardas.getVal(); guardas.caras = this.domItem.find("#guardasImpresas").children("option:selected").val(); } return guardas; @@ -703,18 +830,16 @@ class DisenioCubierta { else { if (forResumen) { let sobrecubierta = {}; - const papel = this.domItem.find("#papelSobrecubierta").children("option:selected").text(); - sobrecubierta.papel = papel.split(' ')[0] + ' ' + papel.split(' ')[1]; - sobrecubierta.gramaje = papel.split(' ')[2]; + sobrecubierta.papel = this.papelSobrecubierta.getText(); + sobrecubierta.gramaje = this.gramajeSobrecubierta.getText(); sobrecubierta.solapas = this.domItem.find("#solapasSobrecubierta").val(); sobrecubierta.acabado = this.acabadoSobrecubierta.getText(); return sobrecubierta; } else { let sobrecubierta = {}; - let papel = this.domItem.find("#papelSobrecubierta").children("option:selected").val(); - sobrecubierta.papel = papel.split('_')[0]; - sobrecubierta.gramaje = papel.split('_')[1]; + sobrecubierta.papel = this.papelSobrecubierta.getVal(); + sobrecubierta.gramaje = this.gramajeSobrecubierta.getVal(); sobrecubierta.solapas = this.domItem.find("#solapasSobrecubierta").val(); sobrecubierta.acabado = this.acabadoSobrecubierta.getVal(); return sobrecubierta;