From 4e7f53ba6c318158d47538301122346f6430cbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Tue, 17 Dec 2024 12:55:44 +0100 Subject: [PATCH] trabajando en el comparador --- ci4/app/Controllers/Js_loader.php | 7 - .../Presupuestos/Presupuestoadmin.php | 4 +- .../presupuestos/admin/_datosLibroItems.js | 144 --------------- .../presupuestos/admin/_datosLibroItems.php | 13 +- .../admin/_datosPresupuestoClienteItems.php | 10 +- .../admin/viewPresupuestoadminForm.php | 1 - .../presupuestoAdmin/presupuestoAdminEdit.js | 3 + .../presupuestoAdmin/sections/comparador.js | 44 +++++ .../presupuestoAdmin/sections/datosLibro.js | 165 ++++++++++++++++-- 9 files changed, 217 insertions(+), 174 deletions(-) delete mode 100644 ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js create mode 100644 httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js diff --git a/ci4/app/Controllers/Js_loader.php b/ci4/app/Controllers/Js_loader.php index e402c125..c2c056ce 100755 --- a/ci4/app/Controllers/Js_loader.php +++ b/ci4/app/Controllers/Js_loader.php @@ -33,13 +33,6 @@ class Js_loader extends BaseController } - - function datosLibro_js() - { - $this->response->setHeader('Content-Type', 'text/javascript'); - return view('themes/vuexy/form/presupuestos/admin/_datosLibroItems.js'); - } - function previsualizador_js() { $this->response->setHeader('Content-Type', 'text/javascript'); diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 300c8677..4a8a9832 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -528,7 +528,6 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } else { $data['datosLibro']['acabadoSobrecubierta']['text'] = $modelAcabado->find($presupuesto->acabado_sobrecubierta_id)->nombre; } - $data['datosLibro']['prototipo'] = $presupuesto->prototipo; $data['datosLibro']['ferro'] = $presupuesto->ferro; $data['datosLibro']['ferroDigital'] = $presupuesto->ferro_digital; @@ -537,6 +536,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $data['datosLibro']['retractilado5'] = $presupuesto->retractilado5; $data['datosLibro']['fajaColor'] = $presupuesto->faja_color; + $data['comparador']['tipo_impresion'] = $presupuesto->comp_tipo_impresion; + $data['comparador']['json_data'] = $presupuesto->comparador_json_data; + /* $data['datosGenerales']['posPaginasColor'] = $presupuesto->comp_pos_paginas_color; $data['datosGenerales']['papelInteriorDiferente'] = $presupuesto->papel_interior_diferente; diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js deleted file mode 100644 index 2e974ab5..00000000 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.js +++ /dev/null @@ -1,144 +0,0 @@ -$('#paginas').on("change", function () { - - const url2 = window.location.href; - const url_parts2 = url2.split('/'); - - if($('#tipo_impresion_id').val() == 21){ - if(parseInt($('#paginas').val()) > 80){ - $('#paginas').val(80) - } - } - - if(url_parts2[url_parts2.length-2] == 'edit'){ - - checkPaginasPresupuesto() - - // Si es negro o color - if ($('#tipoImpresion').select2('data')[0].id == 'negro' || - $('#tipoImpresion').select2('data')[0].id == 'color') { - $('#compPaginasNegro').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColor').val())); - $('#compPaginasNegro').trigger('change') - } - // Si es negrohq o colorhq - if ($('#tipoImpresion').select2('data')[0].id == 'negrohq' || - $('#tipoImpresion').select2('data')[0].id == 'colorhq') { - $('#compPaginasNegrohq').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColorhq').val())); - $('#compPaginasNegrohq').trigger('change'); - } - - //update_servicios(false) - //updateLineasPresupuesto() - updatePresupuesto({ - update_lineas: true, - update_servicios: true, - update_envios: true, - update_resumen: true, - update_tiradas_alternativas: true - }) - } -}); - - -$('#tirada').on("change", function (update_tiradas_alternativas = true) { - - calcular_mermas() - - const url2 = window.location.href; - const url_parts2 = url2.split('/'); - - if(url_parts2[url_parts2.length-2] == 'edit'){ - //update_servicios(false) - //updateLineasPresupuesto() - if(update_tiradas_alternativas) - updatePresupuesto({ - update_lineas: true, - update_servicios: false, - update_envios: false, - update_resumen: false, - update_tiradas_alternativas: false - }) - else - updatePresupuesto({ - update_lineas: true, - update_servicios: false, - update_envios: false, - update_resumen: false, - update_tiradas_alternativas: false - }) - checkInsertar() - } -}) - -function calcular_mermas(){ - - const tirada = parseInt($('#tirada').val()) - var merma = 0 - htmlString = '' - - if(tirada> parseInt($('#POD').val())){ - merma = tirada*0.1<=30 ? tirada*0.1 : 30 - } - else{ - merma_lineas = [] - tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) { - var rowData = this.data(); - if(rowData.row_id != 'lp_guardas' && rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta'){ - const formas_linea = parseInt($('#isCosido').val())==0?parseInt(rowData.formas):parseInt(rowData.formas)/2 - if(formas_linea > tirada) - merma_lineas.push(formas_linea-tirada) - else - merma_lineas.push(tirada%formas_linea) - } - - }) - - - if(merma_lineas.length>0) - merma = Math.max(...merma_lineas) - else{ - htmlString = ` - `; - - - merma = 0 - - } - - } - $('#mermacubierta').val(parseInt(merma)) - $('#merma').val(parseInt(merma)) - $('#alert-datosLibro').html(htmlString) -} - - -$('#papelFormatoPersonalizado').on("click",function(){ - - if($('#papelFormatoPersonalizado').is(':checked')){ - document.getElementById("papelFormatoAncho").style.display = "block"; - document.getElementById("papelFormatoAlto").style.display = "block"; - $('#papelFormatoId').hide(); - $('#papelFormatoId').val(0).change(); - document.getElementById("label_papelFormatoId").innerHTML = - window.Presupuestos.papelFormatoId + " (" + - window.Presupuestos.papelFormatoAncho + " x " + window.Presupuestos.papelFormatoAncho + ")*"; - } - else{ - document.getElementById("papelFormatoAncho").value= ""; - document.getElementById("papelFormatoAlto").value= ""; - document.getElementById("papelFormatoAncho").style.display = "none"; - document.getElementById("papelFormatoAlto").style.display = "none"; - $('#papelFormatoId').show(); - document.getElementById("label_papelFormatoId").innerHTML = - window.Presupuestos.papelFormatoId + '*'; - } -}); - diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php index 9eac25d9..de44d064 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosLibroItems.php @@ -38,13 +38,14 @@
-
- - + +
+
+
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoClienteItems.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoClienteItems.php index bf952469..0022fc3a 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoClienteItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoClienteItems.php @@ -13,7 +13,7 @@
- +
@@ -23,16 +23,16 @@
diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php index 1a27ea3f..afd59484 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/viewPresupuestoadminForm.php @@ -303,7 +303,6 @@ - diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 8bfebb7b..e7f6ad1b 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -3,6 +3,7 @@ import Ajax from '../../components/ajax.js'; import DatosGenerales from './sections/datosGenerales.js'; import DatosLibro from './sections/datosLibro.js'; +import Comparador from './sections/comparador.js'; class PresupuestoAdminEdit { @@ -26,6 +27,7 @@ class PresupuestoAdminEdit { removeService: this.removeService, checkPaginasPresupuesto: this.checkPaginasPresupuesto, })); + this.comparador = new Comparador(this.domItem.find('#accordionDatosPresupuestoClienteTip')); this.calcularPresupuesto = false; } @@ -39,6 +41,7 @@ class PresupuestoAdminEdit { this.datosGenerales.init(); this.datosLibro.init(); + this.comparador.init(); if (window.location.href.includes("edit")) { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js new file mode 100644 index 00000000..f198aa96 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js @@ -0,0 +1,44 @@ +import ClassSelect from '../../../components/select2.js'; +import { getToken } from '../../../common/common.js'; + +class Comparador { + + constructor(domItem) { + + this.domItem = domItem; + + this.csrf_token = getToken(); + this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); + + this.comparador_json = this.domItem.find("#comparador_json_data"); + this.tipo_impresion = $("#tipoImpresion"); + + this.paginasNegro = $('#compPaginasNegro'); + this.papelNegro = new ClassSelect($('#compPapelNegro'), + '/papelesgenericos/getpapelcliente', 'Seleccione papel', false, + { + [this.csrf_token]: this.csrf_hash, + tirada: $('#tirada').val(), + tipo: 'negro', + cubierta: 0, + }); + + this.gramajeNegro = $('#compGramajeNegro'); + + } + + init() { + this.papelNegro.init(); + } + + cargarDatos(datos) { + + this.tipo_impresion.val(datos.tipo_impresion); + this.comparador_json.val(JSON.stringify(datos.json_data)); + + //if (datos.json_data.bn) + + } +} + +export default Comparador; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js index 04dbf433..cdc5d0ed 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -16,7 +16,7 @@ class DatosLibro { this.paginas = this.domItem.find('#paginas'); this.tirada = this.domItem.find('#tirada'); - this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language["formatoLibro"]); + this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language.Presupuestos.formatoLibro); this.tamanioPersonalizado = this.domItem.find('#papelFormatoPersonalizado'); this.anchoPersonalizado = this.domItem.find('#papelFormatoAncho'); this.altoPersonalizado = this.domItem.find('#papelFormatoAlto'); @@ -24,8 +24,8 @@ class DatosLibro { this.mermaCubierta = this.domItem.find('#mermacubierta'); this.solapasCubierta = this.domItem.find('#solapas'); this.solapasSobrecubierta = this.domItem.find('#solapas_sobrecubierta'); - this.anchoSolapasCubierta = this.domItem.find('#anchoSolapasCubierta'); - this.anchoSolapasSobrecubierta = this.domItem.find('#anchoSolapasSobrecubierta'); + this.anchoSolapasCubierta = this.domItem.find('#solapas_ancho'); + this.anchoSolapasSobrecubierta = this.domItem.find('#solapas_ancho_sobrecubierta'); this.divSolapasCubierta = this.domItem.find('#div_solapas_ancho'); this.divSolapasSobrecubierta = this.domItem.find('#div_solapas_ancho_sobrecubierta'); @@ -81,6 +81,10 @@ class DatosLibro { } this.solapasSobrecubierta.on('change', this.changeSolapasSobrecubierta.bind(this)); + this.tamanioPersonalizado.on('change', this.changeTipoTamanio.bind(this)); + + this.paginas.on('change', this.changePaginas.bind(this)); + this.tirada.on('change', this.changeTirada.bind(this)); } } @@ -166,9 +170,31 @@ class DatosLibro { })*/ } + + changeTipoTamanio(){ + + if(this.tamanioPersonalizado.prop('checked')){ + $('.tamanio-personalizado').removeClass('d-none'); + $('.tamanio-estandar').addClass('d-none'); + this.tamanio.setVal(''); + $("#label_papelFormatoId").text( + window.language.Presupuestos.papelFormatoId + " (" + + window.language.Presupuestos.papelFormatoAncho + " x " + window.language.Presupuestos.papelFormatoAncho + ")*"); + } + else{ + this.anchoPersonalizado.val(""); + this.altoPersonalizado.val(""); + $('.tamanio-personalizado').addClass('d-none'); + $('.tamanio-estandar').removeClass('d-none'); + $("#label_papelFormatoId").text( + window.language.Presupuestos.papelFormatoId + '*'); + } + } + + changeSolapasCubierta() { - if (this.solapasCubierta.prop('checked', true)) { + if (this.solapasCubierta.prop('checked')) { this.divSolapasCubierta.removeClass('d-none'); } else { @@ -181,7 +207,7 @@ class DatosLibro { changeSolapasSobrecubierta() { - if (this.solapasSobrecubierta.prop('checked', true)) { + if (this.solapasSobrecubierta.prop('checked')) { this.divSolapasSobrecubierta.removeClass('d-none'); } else { @@ -191,6 +217,125 @@ class DatosLibro { $('#serv_default').trigger('click'); } + changePaginas() { + + if($('#tipo_impresion_id').val() == 21){ + if(parseInt($('#paginas').val()) > 80){ + $('#paginas').val(80) + } + } + + if(window.location.href.includes('edit')){ + + checkPaginasPresupuesto() + + // Si es negro o color + if ($('#tipoImpresion').select2('data')[0].id == 'negro' || + $('#tipoImpresion').select2('data')[0].id == 'color') { + $('#compPaginasNegro').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColor').val())); + $('#compPaginasNegro').trigger('change') + } + // Si es negrohq o colorhq + if ($('#tipoImpresion').select2('data')[0].id == 'negrohq' || + $('#tipoImpresion').select2('data')[0].id == 'colorhq') { + $('#compPaginasNegrohq').val(parseInt($('#paginas').val())-parseInt($('#compPaginasColorhq').val())); + $('#compPaginasNegrohq').trigger('change'); + } + + // TO-DO + /* + updatePresupuesto({ + update_lineas: true, + update_servicios: true, + update_envios: true, + update_resumen: true, + update_tiradas_alternativas: true + }) + */ + } + } + + + changeTirada(update_tiradas_alternativas = true) { + + this.calcular_mermas() + + const url2 = window.location.href; + const url_parts2 = url2.split('/'); + + if(url_parts2[url_parts2.length-2] == 'edit'){ + //update_servicios(false) + //updateLineasPresupuesto() + if(update_tiradas_alternativas) + updatePresupuesto({ + update_lineas: true, + update_servicios: false, + update_envios: false, + update_resumen: false, + update_tiradas_alternativas: false + }) + else + updatePresupuesto({ + update_lineas: true, + update_servicios: false, + update_envios: false, + update_resumen: false, + update_tiradas_alternativas: false + }) + checkInsertar() + } + } + + calcular_mermas(){ + + const tirada = parseInt($('#tirada').val()) + var merma = 0 + htmlString = '' + + if(tirada> parseInt($('#POD').val())){ + merma = tirada*0.1<=30 ? tirada*0.1 : 30 + } + else{ + merma_lineas = [] + tableLineasPresupuesto.rows().every( function ( rowIdx, tableLoop, rowLoop ) { + var rowData = this.data(); + if(rowData.row_id != 'lp_guardas' && rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta'){ + const formas_linea = parseInt($('#isCosido').val())==0?parseInt(rowData.formas):parseInt(rowData.formas)/2 + if(formas_linea > tirada) + merma_lineas.push(formas_linea-tirada) + else + merma_lineas.push(tirada%formas_linea) + } + + }) + + + if(merma_lineas.length>0) + merma = Math.max(...merma_lineas) + else{ + htmlString = ` + `; + + + merma = 0 + + } + + } + $('#mermacubierta').val(parseInt(merma)) + $('#merma').val(parseInt(merma)) + $('#alert-datosLibro').html(htmlString) + } + cargarDatos(datos) { @@ -217,14 +362,14 @@ class DatosLibro { $(".impresion-con-solapas").addClass('d-none'); } else { - if (datos.solapas) { - this.solapasCubierta.val(datos.solapas); - this.anchoSolapasCubierta.val(datos.ancho_solapas); + if (datos.solapasCubierta) { + this.solapasCubierta.prop('checked', true); + this.anchoSolapasCubierta.val(datos.solapasCubiertaAncho); $('#div_solapas_ancho').removeClass('d-none'); } - if (datos.solapas_sobrecubierta) { + if (datos.solapasSobrecubierta) { this.solapasSobrecubierta.prop('checked', true); - this.anchoSolapasSobrecubierta.val(datos.ancho_solapas_sobrecubierta); + this.anchoSolapasSobrecubierta.val(datos.solapasSobrecubiertaAncho); $('#div_solapas_ancho_sobrecubierta').removeClass('d-none'); } }