From 1ccade47a3736f0e4515c63b91f686932421e911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 27 Dec 2024 18:10:35 +0100 Subject: [PATCH] trabajando en lineas presupuesto --- ci4/app/Config/Routes.php | 1 + .../Presupuestos/Presupuestoadmin.php | 62 +- .../Presupuestos/Presupuestocliente.php | 12 +- .../Services/PresupuestoClienteService.php | 10 +- .../admin/_datosPresupuestoClienteItems.php | 65 +- .../admin/_lineasPresupuestoItems.js | 277 +------ .../form/presupuestos/admin/comparador.js | 49 -- .../presupuestoAdmin/presupuestoAdminEdit.js | 10 +- .../presupuestoAdmin/sections/comparador.js | 549 ++++---------- .../presupuestoAdmin/sections/datosLibro.js | 2 +- .../sections/lineasPresupuesto.js | 689 ++++++++++++++++++ .../presupuestoCliente/presupuestoCliente.js | 14 +- 12 files changed, 974 insertions(+), 766 deletions(-) delete mode 100644 ci4/app/Views/themes/vuexy/form/presupuestos/admin/comparador.js create mode 100644 httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index b4171b03..37d0bb7c 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -582,6 +582,7 @@ $routes->group('presupuestoadmin', ['namespace' => 'App\Controllers\Presupuestos $routes->get('cargar/(:any)', 'Presupuestoadmin::cargar/$1'); $routes->post('comparadorinterior', 'Presupuestoadmin::obtenerComparadorInterior'); $routes->post('comparadorexteriores', 'Presupuestoadmin::obtenerComparadorExteriores'); + $routes->post('comparadorguardas', 'Presupuestoadmin::obtenerComparadorGuardas'); $routes->get('papelgenerico', 'Presupuestoadmin::getPapelGenerico'); $routes->get('papelgramaje', 'Presupuestoadmin::getGramaje'); }); diff --git a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php index 5b3d4b82..b436fe5c 100644 --- a/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestoadmin.php @@ -538,6 +538,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController $item['papel_nombre'] = $modelPapelGenerico->getNombre($item['papel_id'])['nombre']; } $data['comparador']['posPagColor'] = $presupuesto->comp_pos_paginas_color; + $data['comparador']['lomoRedondo'] = $presupuesto->lomo_redondo; + $data['comparador']['cabezada'] = $presupuesto->cabezada; /* @@ -689,8 +691,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController 'papel_generico' => $papel_generico, 'gramaje' => $gramaje, 'paginas_color' => $paginas_color, - 'isColor' => $isColor, - 'isHq' => $isHq, + 'isColor' => 1, // cubierta y sobre cubierta colorhq + 'isHq' => 1, // cubierta y sobre cubierta colorhq 'tipo_impresion_id' => $tipo_impresion_id, 'uso' => $uso, 'lomoRedondo' => $lomoRedondo @@ -714,8 +716,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController 'papel_generico' => $papel_generico, 'gramaje' => $gramaje, 'paginas_color' => $paginas_color, - 'isColor' => $isColor, - 'isHq' => $isHq, + 'isColor' => 1, // cubierta y sobre cubierta colorhq + 'isHq' => 1, // cubierta y sobre cubierta colorhq 'tipo_impresion_id' => $tipo_impresion_id, 'uso' => $uso ); @@ -737,6 +739,58 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController } + public function obtenerComparadorGuardas() + { + + if ($this->request->isAJAX()) { + + $cliente_id = $this->request->getPost('cliente_id'); + $datosPedido = $this->request->getPost('datosPedido'); + $papel_generico = $this->request->getPost('papel_generico'); + $gramaje = $this->request->getPost('gramaje'); + $paginas_color = $this->request->getPost('paginas_color'); + $isColor = $this->request->getPost('isColor'); + $isHq = $this->request->getPost('isHq'); + $tipo_impresion_id = $this->request->getPost('tipo_impresion_id'); + $uso = $this->request->getPost('uso'); + + // Para el caso de Fresado y Cosido tapa dura, las guardas son un diptico + // y hay que imprimirlas como "cosido" (dos hojas pegadas). En el caso de espiral + // o wire-o tapa dura, las guardas se imprimen como hojas sueltas + if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3) { + $datosPedido['isCosido'] = true; + } else if ($tipo_impresion_id == 5 || $tipo_impresion_id == 7) { + $datosPedido['isCosido'] = false; + } + + $datosPedido['paginas_impresion'] = $datosPedido['paginas']; + + $data = array( + 'cliente_id' => $cliente_id, + 'datosPedido' => (object) $datosPedido, + 'papel_generico' => $papel_generico, + 'gramaje' => $gramaje, + 'papelInteriorDiferente' => true, + 'paginas_color' => $paginas_color, + 'isColor' => $isColor, + 'isHq' => $isHq, + 'tipo_impresion_id' => $tipo_impresion_id, + 'uso' => $uso + ); + + $lineas = PresupuestoClienteService::obtenerGuardas($data, true); + return $this->respond( + [ + 'status' => 1, + 'data' => $lineas + ] + ); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function datatable() { if ($this->request->isAJAX()) { diff --git a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php index 3effc193..253ce34d 100755 --- a/ci4/app/Controllers/Presupuestos/Presupuestocliente.php +++ b/ci4/app/Controllers/Presupuestos/Presupuestocliente.php @@ -1205,9 +1205,17 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController $data['datosGenerales']['retractilado5'] = $presupuesto->retractilado5; $datos_papel = $this->obtenerDatosPapel($presupuesto->id); - $data['interior'] = $datos_papel['interior'] ? $datos_papel['interior'] : []; + if (array_key_exists('interior', $datos_papel)) { + $data['interior'] = $datos_papel['interior']; + } else { + $data['interior'] = []; + } - $data['cubierta'] = $datos_papel['cubierta'] ? $datos_papel['cubierta'] : []; + if (array_key_exists('cubierta', $datos_papel)) { + $data['cubierta'] = $datos_papel['cubierta']; + } else { + $data['cubierta'] = []; + } $data['cubierta']['tapa'] = $this->obtenerTipoTapa($presupuesto->tipo_impresion_id ?? null); $data['cubierta']['lomoRedondo'] = $presupuesto->lomo_redondo ? 1 : 0; $data['cubierta']['solapas'] = $presupuesto->solapas ? 1 : 0; diff --git a/ci4/app/Services/PresupuestoClienteService.php b/ci4/app/Services/PresupuestoClienteService.php index a4a3c491..17c4acc8 100644 --- a/ci4/app/Services/PresupuestoClienteService.php +++ b/ci4/app/Services/PresupuestoClienteService.php @@ -186,7 +186,7 @@ class PresupuestoClienteService extends BaseService return $lineas_sobrecubierta; } - public static function obtenerGuardas($data) + public static function obtenerGuardas($data, $return_raw=false) { $uso = $data['uso']; @@ -220,6 +220,14 @@ class PresupuestoClienteService extends BaseService } if (count($lineas_guardas) > 0) { + if($return_raw){ + $lineas_guardas = array_values(array_unique($lineas_guardas, SORT_REGULAR)); + + return[ + 'guardas' => $lineas_guardas + ]; + } + usort( $lineas_guardas, function ($a, $b) { 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 9f5a062e..eb45cbe1 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoClienteItems.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_datosPresupuestoClienteItems.php @@ -222,27 +222,46 @@ -
+
+
-
-
- - -
+
+ + +
+
+ + +

@@ -322,9 +341,11 @@
- +
+

diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.js b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.js index 185aacd1..19e5920c 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.js +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/_lineasPresupuestoItems.js @@ -652,270 +652,8 @@ function format(d) { return $(value).toArray(); } -const lastColNr_lp = $('#tableLineasPresupuesto').find("tr:first th").length - 1; -const actionBtns_lp = function(data) { - return ` - - `; -}; -var tableLineasPresupuesto = new DataTable('#tableLineasPresupuesto',{ - scrollX: true, - searching: false, - paging: false, - info: false, - ordering: true, - responsive: true, - select: false, - rowId: 'row_id', - language: { - url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" - }, - columnDefs: [ - { - targets: 0, - className: 'dt-control', - orderable: false, - data: null, - defaultContent: '' - }, - { - targets: [1,2,3,4,5,6,7,8,9], - orderable: false, - visible: false, - }, - { - targets: [11,12,13,14,15,16,17,18,19,20], - orderable: false, - }, - { - targets: [10], - orderable: true, - visible: false, - }, - { - orderable: false, - searchable: false, - targets: [lastColNr_lp] - }, - ], - columns: [ - {data: null}, - {data: 'tarifa_impresion_id'}, - {data: 'maquina_ancho'}, - {data: 'maquina_alto'}, - {data: 'maquina_impresion_ancho'}, - {data: 'maquina_impresion_alto'}, - {data: 'formas'}, - {data: 'formas_v'}, - {data: 'formas_h'}, - {data: 'formas_orientacion'}, - {data: 'position', - type: "num" , - render: function (data, type, row, meta){ - if(row.row_id.includes('_bn')){ - return 0; - } - else if(row.row_id.includes('_color')){ - return 1; - } - else if(row.row_id.includes('_cubierta')){ - return 2; - } - else if(row.row_id.includes('_sobrecubierta')){ - return 3; - } - else if(row.row_id.includes('_guardas')){ - return 4; - } - } - }, - {data: 'icon', - render: function ( data, type, row, meta ){ - return '' - } - }, - {data: 'paginas', - render: function ( data, type, row, meta ) { - if(row.row_id != "lp_cubierta" && row.row_id != "lp_sobrecubierta" && row.row_id != "lp_guardas") - return ''; - else if(row.row_id == "lp_cubierta"){ - select = '' - - return select; - } - else if(row.row_id == "lp_guardas"){ - select = '' - - return select; - - } - else{ - return ''; - } - } - }, - {data: 'papel', - render: function ( data, type, row, meta ) { - var select = $('') - .attr('id', row.row_id + '_gramaje') - .attr('name', row.row_id + '_gramaje') - .addClass('form-control form-select-sm lp-cell lp-select ' )//+ row.row_class + '-select') - .css('min-width', '40px') - - var option = ''; - select.append(option); - - return select[0].outerHTML - } - }, - {data: 'papel_impresion', - render: function ( data, type, row, meta ) { - var select = $('') - .attr('id', row.row_id + '_maquina') - .attr('name', row.row_id + '_maquina') - .addClass('form-control form-select-sm lp-cell lp-select ' + row.row_class + '-select') - .css('min-width', '110px') - - var option = ''; - select.append(option); - - return select[0].outerHTML - } - }, - {data: 'tiempo', - render: function ( data, type, row, meta ) { - return ''; - } - }, - {data: 'lomo', - render: function ( data, type, row, meta ) { - return ''; - } - }, - {data: 'peso', - render: function ( data, type, row, meta ) { - return ''; - } - }, - {data: 'total_linea', - render: function ( data, type, row, meta ) { - return ''; - } - }, - { - data: actionBtns_lp, - className: 'row-edit dt-center' - } - ], - "order": [ 10, 'asc' ] -}); tableLineasPresupuesto.on( 'draw.dt', function () { checkPaginasPresupuesto() @@ -949,20 +687,7 @@ $(document).on('click', '.btn-delete-lp', function(e) { -// Add event listener for opening and closing details -tableLineasPresupuesto.on('click', 'td.dt-control', function (e) { - let tr = e.target.closest('tr'); - let row = tableLineasPresupuesto.row(tr); - - if (row.child.isShown()) { - // This row is already open - close it - row.child.hide(); - } - else { - // Open this row - row.child(format(row.data())).show(); - } -}); + function processRowData(row, rowId, rowClass){ diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/comparador.js b/ci4/app/Views/themes/vuexy/form/presupuestos/admin/comparador.js deleted file mode 100644 index bb1e770f..00000000 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/admin/comparador.js +++ /dev/null @@ -1,49 +0,0 @@ - - - - - -/******************************* - * Metodos - *******************************/ - - - -function selectGuardasLineas() { - - $("#tableCompGuardas").DataTable().rows('.selected').deselect(); - - let value_total = 0.00; - - if ($("#tableCompGuardas").DataTable().rows().count() > 0) { - - $("#tableCompGuardas").DataTable().row(0).nodes().to$().toggleClass('selected'); - value_total = parseFloat($("#tableCompGuardas").DataTable().rows(0).data()[0]['total']) - }; - - - $('#total_comp_guardas').html(value_total.toFixed(2)); -} - - - - - - - - -function fillGuardas(data) { - - let sorted = data.lineas.sort( - (p1, p2) => ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) < (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? - -1 : ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) > (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? 1 : 0); - sorted.forEach(function (linea) { - if (typeof linea.error == "undefined") - $('#tableCompGuardas').DataTable().row - .add(getRowFromLineaInt('guardas', linea)) - .draw() - }) -} - - - diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 7dfaf2eb..0b281814 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -21,12 +21,12 @@ class PresupuestoAdminEdit { this.cosido = $("#isCosido"); this.datosGenerales = new DatosGenerales(this.domItem.find('#accordionDatosPresupuestoTip')); - this.datosLibro = new DatosLibro(this.domItem.find('#accordionDatosLibroTip', + this.datosLibro = new DatosLibro(this.domItem.find('#accordionDatosLibroTip'), { addService: this.addService, removeService: this.removeService, checkPaginasPresupuesto: this.checkPaginasPresupuesto, - })); + }); this.comparador = new Comparador(this.domItem.find('#accordionDatosPresupuestoClienteTip')); this.calcularPresupuesto = false; @@ -126,8 +126,10 @@ class PresupuestoAdminEdit { checkPaginasPresupuesto() { - cantidad_total = 0 + let cantidad_total = 0; + // TO-DO + /* tableLineasPresupuesto.rows().every(function (rowIdx, tableLoop, rowLoop) { var rowData = this.data(); if (rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta' && rowData.row_id != 'lp_guardas') @@ -148,7 +150,7 @@ class PresupuestoAdminEdit { `; } - $('#divAlarmasLineasPresupuesto').html(htmlString) + $('#divAlarmasLineasPresupuesto').html(htmlString)*/ } getDimensionLibro() { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js index 25005b4b..61c553f2 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js @@ -145,13 +145,28 @@ class Comparador { [this.csrf_token]: this.csrf_hash, tipo_impresion: this.tipo_impresion_id, tirada: () => $('#tirada').val(), - tipo: 'guardas', + tipo: 'colorhq', + uso: 'guardas', + }); + this.gramajeGuardas = new ClassSelect($('#compGramajeGuardas'), + '/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false, + { + [this.csrf_token]: this.csrf_hash, + papel_generico: () => this.papelCubierta.getVal(), + tipo_impresion: this.tipo_impresion_id, + tirada: () => $('#tirada').val(), + tipo: 'colorhq', + uso: 'guardas', }); this.carasGuardas = $('#compCarasGuardas'); - this.gramajeGuardas = $('#compGramajeGuardas'); this.btnInsertarGuardas = $('#insertarGuardasBtn'); } + if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){ + this.lomoRedondo = $('#compLomoRedondo'); + this.cabezada = $('#cabezada'); + } + this.posPagColor = $('#compPosPaginasColor'); this.calculatedColorPages = $('#compCalPaginasColor'); @@ -188,9 +203,7 @@ class Comparador { if ($('#tipo_impresion_id').val() == 1 || $('#tipo_impresion_id').val() == 3 || $('#tipo_impresion_id').val() == 5 || $('#tipo_impresion_id').val() == 7) { - this.papelGuardas.select2({ - allowClear: false, - }); + this.papelGuardas.init(); this.carasGuardas.select2({ allowClear: false, @@ -207,6 +220,18 @@ class Comparador { this.gramajeColorhq.init(); this.papelCubierta.init(); this.gramajeCubierta.init(); + + if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){ + this.lomoRedondo.select2({ + allowClear: false, + minimumResultsForSearch: Infinity, + }); + this.cabezada.select2({ + allowClear: false, + minimumResultsForSearch: Infinity, + }); + } + if (this.tipo_impresion_id != 5 && this.tipo_impresion_id != 6 && this.tipo_impresion_id != 7 && this.tipo_impresion_id != 8 && this.tipo_impresion_id != 21) { this.sobrecubierta.select2({ @@ -233,6 +258,8 @@ class Comparador { if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) { this.papelGuardas.init(); + this.gramajeGuardas.init(); + this.papelGuardas.onChange(() => this.gramajeGuardas.setVal(0)) } this.papelNegro.onChange(() => this.gramajeNegro.setVal(0)) @@ -282,6 +309,10 @@ class Comparador { $('.comp_sobrecubierta_items').on('change', this.obtenerComparadorExteriores.bind(this)); } + if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) { + $('.comp_guardas_items').on('change', this.obtenerComparadorGuardas.bind(this)); + } + } #changePaginasComparador(element) { @@ -349,8 +380,18 @@ class Comparador { this.papelSobrecubierta.setOption(datos.json_data.sobrecubierta.papel_id, datos.json_data.sobrecubierta.papel_nombre); this.gramajeSobrecubierta.setOption(datos.json_data.sobrecubierta.gramaje, datos.json_data.sobrecubierta.gramaje); } + if (datos.json_data.guardas) { + this.carasGuardas.val(datos.json_data.guardas.paginas).trigger('change'); + this.papelGuardas.setOption(datos.json_data.guardas.papel_id, datos.json_data.guardas.papel_nombre); + this.gramajeGuardas.setOption(datos.json_data.guardas.gramaje, datos.json_data.guardas.gramaje); + } - if (datos.posPagColor.length > 0) { + if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3){ + this.lomoRedondo.val(datos.lomoRedondo?1:0).trigger('change'); + this.cabezada.val(datos.cabezada).trigger('change'); + } + + if (datos.posPagColor != null && datos.posPagColor.length > 0) { this.posPagColor.val(datos.posPagColor); this.#computarPaginasColor(datos.posPagColor); } @@ -358,6 +399,10 @@ class Comparador { this.cargando = false; this.paginasNegro.trigger('change'); this.paginasCubierta.trigger('change'); + if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) { + this.carasGuardas.trigger('change'); + } + } @@ -743,6 +788,9 @@ class Comparador { $('#total_comp_plana').html("0.00"); } } + + if(!this.cargando) + $('#paginas').trigger('change'); } getDataForComp(uso = 'interior') { @@ -874,6 +922,22 @@ class Comparador { } + else if (uso == 'guardas') { + if (this.papelGuardas.getVal() == 0 || this.papelGuardas.getVal() == null) { + popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador'); + return { error: true, data: {} }; + } + if (this.gramajeGuardas.getVal() == 0 || this.gramajeGuardas.getVal() == null) { + popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador'); + return { error: true, data: {} }; + } + + papel_generico = { id: this.papelGuardas.getVal(), nombre: this.papelGuardas.getText() }; + gramaje = this.gramajeGuardas.getVal(); + paginas = this.carasGuardas.val(); + + } + const datosPedido = { paginas: paginas, tirada: $('#tirada').val(), @@ -906,20 +970,24 @@ class Comparador { datos.datosPedido.lomo = this.getLomoLineasPresupuesto('interior'); datos.datosPedido.solapas = $('#solapas').prop('checked') ? 1 : 0; datos.datosPedido.solapas_ancho = $('#solapas').prop('checked') ? parseInt($('#solapas_ancho').val()) : 0; - // TO-DO - datos.lomoRedondo = false; + datos.lomoRedondo = this.lomoRedondo.val(); } else if (uso == 'sobrecubierta') { datos.datosPedido.lomo = this.getLomoLineasPresupuesto() + this.getLomoLineasPresupuesto('cubierta'); datos.datosPedido.solapas = $('#solapas_sobrecubierta').prop('checked') ? 1 : 0; datos.datosPedido.solapas_ancho = $('#solapas_sobrecubierta').prop('checked') ? parseInt($('#solapas_ancho_sobrecubierta').val()) : 0; } + else if (uso == 'guardas') { + datos.datosPedido.isCosido = 1; + datos.datosPedido.isHq = 1; + datos.paginas_color = datos.datosPedido.paginas; + } return { error: false, data: datos }; } - getLomoLineasPresupuesto(tipo_lomo='interior') { + getLomoLineasPresupuesto(tipo_lomo = 'interior') { let lomoTotal = 0 try { @@ -1163,6 +1231,66 @@ class Comparador { } } + obtenerComparadorGuardas(event, actualizarLineaPlana = false, actualizarLineaRot = false) { + + try { + + const self = this; + + if (this.cargando) { + return + } + + this.tableCompGuardas.clear().draw(); + this.btnInsertarGuardas.addClass('d-none'); + $('#title_guardas').html(window.language.Presupuestos.Guardas); + + let datosComp = {}; + datosComp = this.getDataForComp('guardas'); + if (datosComp.error) { + return; + } + + datosComp.data[this.csrf_token] = this.csrf_hash; + + new Ajax('/presupuestoadmin/comparadorguardas', + datosComp.data, + {}, + (response) => { + if (response.data && Object.keys(response.data).length > 0) { + let sorted = Object.values(response.data).sort( + (p1, p2) => ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) < (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? + -1 : ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) > (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? 1 : 0); + + sorted[0].forEach(function (linea) { + if (typeof linea.error == "undefined") + self.tableCompGuardas.row + .add(self.getRowFromLinea('guardas', linea)) + .draw(); + }); + } + + self.selectLineas('guardas'); + if (self.tableCompGuardas.rows().count() > 0) { + $('#title_guardas').html(window.language.Presupuestos.Guardas + + (' (' + self.tableCompGuardas.rows().count() + ')')); + self.btnInsertarGuardas.removeClass('d-none'); + } + else { + $('#title_guardas').html(window.language.Presupuestos.Guardas); + self.btnInsertarGuardas.addClass('d-none'); + } + }, + (error) => { + console.log(error); + } + ).post(); + + } catch (e) { + console.log(e) + } + } + selectLineas(tabla) { @@ -1173,6 +1301,12 @@ class Comparador { let tipo2 = 'color'; let total_label = '#total_comp_plana' switch (tabla) { + case 'guardas': + table = this.tableCompGuardas; + tipo1 = 'guardas'; + total_label = '#total_comp_guardas'; + break; + case 'cubierta': table = this.tableCompCubierta; tipo1 = 'cubierta'; @@ -1407,402 +1541,7 @@ class Comparador { data_str = JSON.stringify(data) $('#comparador_json_data').val(data_str) } -} -/* - - - - - function checkComparadorGuardas(actualizarLinea = false){ - - if ($('#compPapelGuardas').select2('data')[0].id > 0 ){ - - const dimension = getDimensionLibro(); - - let datos = { - tipo_impresion_id: , - type: 'guardas', - paginas: 8, - paginas_impresion: parseInt($('#compCarasGuardas').select2('data')[0].id), - tirada: parseInt($('#tirada').val()), - merma: parseInt($('#mermacubierta').val()), - color: 1, - hq: 1, - ancho: dimension.ancho, - alto: dimension.alto, - papel_generico_id: $('#compPapelGuardas').select2('data')[0].id, - papel_generico: $('#compPapelGuardas').select2('data')[0].text.trim(), - gramaje: parseInt($('#compGramajeGuardas').val()), - cliente_id: $('#clienteId').find(":selected").val(), - : v - }; - - $.ajax({ - type: "POST", - url: "/presupuestoadmin/datatable", - data: datos, - success: function (data) { - - clearGuardas(); - - if(data.lineas.length >0){ - fillGuardas(data); - selectGuardasLineas(); - $('#title_guardas').html('' + ' (' + tableCompGuardas.rows().count() + ')'); - $('#insertarGuardasBtn').removeClass('d-none') - if(actualizarLinea){ - var rows = $("#tableCompCubierta").DataTable().rows( '.selected' ).data().toArray(); - for(row of rows){ - fill_lp_guardas(row, true); - } - } - } - else{ - $('#title_guardas').html(''); - $('#insertarGuardasBtn').addClass('d-none') - $('#total_comp_guardas').html('0.00') - - } - yeniden(data.); - return true; - }, - error: function(e){ - return false; - } - }) - } - - else{ - clearGuardas(); - } - } +} - $('.comp_guardas_items').on('change', function (e) { - - checkComparadorGuardas(false); - }); - - - - async function getLineasIntPlana(is_color, is_hq, actualizarLinea){ - - const dimension = getDimensionLibro(); - - let datos = { - tipo_impresion_id: , - type: 'interior', - color: is_color?1:0, - hq: is_hq?1:0, - paginas: parseInt($(''+ elementos.paginas).val()), - tirada: parseInt($('#tirada').val()), - merma: parseInt($('#merma').val()), - ancho: dimension.ancho, - alto: dimension.alto, - papel_generico_id: $(''+ elementos.papel).select2('data')[0].id, - papel_generico: $(''+ elementos.papel).select2('data')[0].text.trim(), - gramaje: $(''+ elementos.gramaje).select2('data')[0].text.trim() , - cliente_id: $('#clienteId').find(":selected").val(), - : v - }; - - $.ajax({ - type: "POST", - url: "/presupuestoadmin/datatable", - data: datos, - success: function (data) { - - clearIntLineas(is_color); - - if(data.lineas.length >0){ - - fillIntPlana(data, is_color, is_hq); - selectIntLineas(); - $('#title_int_plana').html('' + ' (' + tableCompIntPlana.rows().count() + ')'); - $('#insertarPlanaBtn').removeClass('d-none') - if(actualizarLinea){ - var rows = $("#tableCompIntPlana").DataTable().rows( '.selected' ).data().toArray(); - for(row of rows){ - - if(row['tipo'] =='bn' && !is_color && !is_hq){ - if($('#lp_bn').css('display')!='none') - fill_lp_bn(row, true); - } - else if(row['tipo'] =='bnhq' && !is_color && is_hq){ - if($('#lp_bnhq').css('display')!='none') - fill_lp_bnhq(row, true); - } - else if(row['tipo'] =='color' && is_color && !is_hq){ - if($('#lp_color').css('display')!='none') - fill_lp_color(row, true); - } - else if(row['tipo'] =='colorhq' && is_color && is_hq){ - if($('#lp_colorhq').css('display')!='none') - fill_lp_colorhq(row, true); - } - } - } - } - else{ - $('#title_int_plana').html(''); - $('#insertarPlanaBtn').addClass('d-none') - $('#total_comp_plana').html('0.00'); - } - yeniden(data.); - return true; - }, - error: function(e){ - return false; - } - }) - return false; - } - - async function getLineasIntRot(is_hq, actualizarLinea=false){ - - const dimension = getDimensionLibro(); - - // Rotativa solo negro o color (no hq) - if ( is_hq==false){ - - if(checkInputsForRotativa()){ - - let datos = { - tipo_impresion_id: , - type: 'interior_rot', - paginas: parseInt($('#paginas').val()), - paginas_negro: parseInt($('#compPaginasNegro').val()), - paginas_color: parseInt($('#compPaginasColor').val()), - tirada: parseInt($('#tirada').val()), - merma: parseInt($('#merma').val()), - ancho: dimension.ancho, - alto: dimension.alto, - // el papel y el gramaje se coge del negro (siempre estará) - papel_generico_id: $('#compPapelNegro').select2('data')[0].id, - papel_generico: $('#compPapelNegro').select2('data')[0].text.trim(), - gramaje: $('#compGramajeNegro').select2('data')[0].text.trim() , - cliente_id: $('#clienteId').find(":selected").val(), - : v - }; - - $.ajax({ - type: "POST", - url: "/presupuestoadmin/datatable", - data: datos, - success: function (data) { - - clearIntRot(); - - if(data.lineas.length >0){ - - fillIntRot(data); - selectIntRotLineas(); - $('#title_int_rot').html('' + ' (' + tableCompIntRotativa.rows().count() + ')'); - $('#insertarRotativaBtn').removeClass('d-none') - if(actualizarLinea){ - var rows = $("#tableCompIntRotativa").DataTable().rows( '.selected' ).data().toArray(); - for(row of rows){ - if(row['paginasColor'] ==0){ - if($('#lp_rot_bn').css('display')!='none') - fill_lp_rot_bn(row, true); - } - else if(row['paginasColor'] >0){ - if($('#lp_rot_color').css('display')!='none') - fill_lp_rot_color(row, true); - } - } - } - } - else{ - $('#title_int_rot').html(''); - $('#insertarRotativaBtn').addClass('d-none') - $('#total_comp_rot').html('0.00') - - } - yeniden(data.); - return true; - }, - error: function(e){ - return false; - } - }) - } - } - return false; - } - - $('.comp_cubierta_items').on('change', function (){ - - checkComparadorCubierta() - }); - - - function checkComparadorCubierta(actualizarLinea = false){ - - if ($('#compCarasCubierta option:selected').val().length > 0 && - $('#compPapelCubierta').select2('data').length > 0 && - $('#compGramajeCubierta').select2('data').length > 0 ){ - - const dimension = getDimensionLibro(); - - let datos = { - tipo_impresion_id: , - type: 'cubierta', - paginas: parseInt($('#compCarasCubierta option:selected').val()), - tirada: parseInt($('#tirada').val()), - merma: parseInt($('#mermacubierta').val()), - color: 1, - ancho: dimension.ancho, - alto: dimension.alto, - lomo: getLomoLineasPresupuesto(), - solapas: $('#solapas').is(':checked')?1:0, - solapas_ancho: $('#solapas').is(':checked')?parseInt($('#solapas_ancho').val()):0, - papel_generico_id: $('#compPapelCubierta').select2('data')[0].id, - papel_generico: $('#compPapelCubierta').select2('data')[0].text.trim(), - gramaje: $('#compGramajeCubierta').select2('data')[0].text.trim() , - cliente_id: $('#clienteId').find(":selected").val(), - : v - }; - - $.ajax({ - type: "POST", - url: "/presupuestoadmin/datatable", - data: datos, - success: function (data) { - - clearCubierta(); - - if(data.lineas.length >0){ - fillCubierta(data); - selectCubiertaLineas(); - tableCompCubierta.order([0, 'asc']).draw() - $('#title_cubierta').html('' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):'')); - $('#insertarCubiertaBtn').removeClass('d-none') - if(actualizarLinea){ - var rows = $("#tableCompCubierta").DataTable().rows( '.selected' ).data().toArray(); - for(row of rows){ - if (row.tipo=='cubierta') - fill_lp_cubierta(row, true); - } - } - } - else{ - $('#title_cubierta').html('' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):'')); - if(tableCompCubierta.rows().count()==0){ - $('#insertarCubiertaBtn').addClass('d-none') - $('#total_comp_cubierta').html('0.00') - } - else{ - selectCubiertaLineas(); - } - - } - yeniden(data.); - return true; - }, - error: function(e){ - return false; - } - }) - } - - else{ - clearCubierta(); - } - } - - $('.comp_sobrecubierta_items').on('change', function (){ - - checkComparadorSobrecubierta() - }); - - - function checkComparadorSobrecubierta(actualizarLinea = false){ - - if ($('#compSobrecubierta option:selected').val() == 1 && - $('#compPapelSobrecubierta').select2('data').length > 0 && - $('#compGramajeSobrecubierta').select2('data').length > 0 ){ - - - const dimension = getDimensionLibro(); - - let datos = { - tipo_impresion_id: , - type: 'sobrecubierta', - paginas: 4, - tirada: parseInt($('#tirada').val()), - merma: parseInt($('#mermacubierta').val()), - color: 1, - ancho: dimension.ancho, - alto: dimension.alto, - lomo: getLomoLineasPresupuesto() + getLomoCubiertaLineasPresupuesto(), - solapas: $('#solapas_sobrecubierta').is(':checked')?1:0, - solapas_ancho: $('#solapas_sobrecubierta').is(':checked')?parseInt($('#solapas_ancho_sobrecubierta').val()):0, - papel_generico_id: $('#compPapelSobrecubierta').select2('data')[0].id, - papel_generico: $('#compPapelSobrecubierta').select2('data')[0].text.trim(), - gramaje: $('#compGramajeSobrecubierta').select2('data')[0].text.trim() , - cliente_id: $('#clienteId').find(":selected").val(), - : v - }; - - $.ajax({ - type: "POST", - url: "/presupuestoadmin/datatable", - data: datos, - success: function (data) { - - clearSobrecubierta(); - - if(data.lineas.length >0){ - - fillSobrecubierta(data); - selectCubiertaLineas(); - tableCompCubierta.order([ [0, 'asc'],[15, 'asc'] ]).draw() - $('#title_cubierta').html('' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):'')); - $('#insertarCubiertaBtn').removeClass('d-none') - if(actualizarLinea){ - var rows = $("#tableCompCubierta").DataTable().rows( '.selected' ).data().toArray(); - for(row of rows){ - if (row.tipo=='sobrecubierta') - fill_lp_sobrecubierta(row, true); - } - } - } - else{ - $('#title_cubierta').html('' + (tableCompCubierta.rows().count()>0 ?(' (' + tableCompCubierta.rows().count() + ')'):'')); - if(tableCompCubierta.rows().count()==0){ - $('#insertarCubiertaBtn').addClass('d-none') - $('#total_comp_cubierta').html('0.00') - } - else{ - selectCubiertaLineas(); - } - - } - yeniden(data.); - return true; - }, - error: function(e){ - return false; - } - }) - } - - else{ - clearSobrecubierta(); - } - } - - - - - - $('#tipoImpresion').on("select2:close", function () { - - $('#paginas').change() - }) - - - -*/ 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 fb852a7c..65637230 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -228,7 +228,7 @@ class DatosLibro { if(window.location.href.includes('edit')){ - checkPaginasPresupuesto() + this.checkPaginasPresupuesto(); // Si es negro o color if ($('#tipoImpresion').select2('data')[0].id == 'negro' || diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js new file mode 100644 index 00000000..1e655a47 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/lineasPresupuesto.js @@ -0,0 +1,689 @@ +import Ajax from "../../../components/ajax"; +import ClassSelect from "../../../components/select2"; + + +class LineasPresupuesto { + + constructor(domItem, functions = {}) { + this.domItem = domItem; + this.functions = functions; + + this.table = null; + + this.addLineaManual = this.domItem.find("#btn_addLinea"); + } + + init() { + this.#initTable(); + + this.addLineaManual.on('click', + } + + #initTable() { + + const lastColNr_lp = $('#tableLineasPresupuesto').find("tr:first th").length - 1; + + const actionBtns_lp = function (data) { + return ` + + `; + }; + + this.table = new DataTable('#tableLineasPresupuesto', { + scrollX: true, + searching: false, + paging: false, + info: false, + ordering: true, + responsive: true, + select: false, + rowId: 'row_id', + language: { + url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + columnDefs: [ + { + targets: 0, + className: 'dt-control', + orderable: false, + data: null, + defaultContent: '' + }, + { + targets: [1, 2, 3, 4, 5, 6, 7, 8, 9], + orderable: false, + visible: false, + }, + { + targets: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], + orderable: false, + }, + { + targets: [10], + orderable: true, + visible: false, + }, + { + orderable: false, + searchable: false, + targets: [lastColNr_lp] + }, + ], + columns: [ + { data: null }, + { data: 'tarifa_impresion_id' }, + { data: 'maquina_ancho' }, + { data: 'maquina_alto' }, + { data: 'maquina_impresion_ancho' }, + { data: 'maquina_impresion_alto' }, + { data: 'formas' }, + { data: 'formas_v' }, + { data: 'formas_h' }, + { data: 'formas_orientacion' }, + { + data: 'position', + type: "num", + render: function (data, type, row, meta) { + if (row.row_id.includes('_bn')) { + return 0; + } + else if (row.row_id.includes('_color')) { + return 1; + } + else if (row.row_id.includes('_cubierta')) { + return 2; + } + else if (row.row_id.includes('_sobrecubierta')) { + return 3; + } + else if (row.row_id.includes('_guardas')) { + return 4; + } + } + }, + { + data: 'icon', + render: function (data, type, row, meta) { + return '' + } + }, + { + data: 'paginas', + render: function (data, type, row, meta) { + if (row.row_id != "lp_cubierta" && row.row_id != "lp_sobrecubierta" && row.row_id != "lp_guardas") + return ''; + else if (row.row_id == "lp_cubierta") { + select = '' + + return select; + } + else if (row.row_id == "lp_guardas") { + select = '' + + return select; + + } + else { + return ''; + } + } + }, + { + data: 'papel', + render: function (data, type, row, meta) { + var select = $('') + .attr('id', row.row_id + '_gramaje') + .attr('name', row.row_id + '_gramaje') + .addClass('form-control form-select-sm lp-cell lp-select ')//+ row.row_class + '-select') + .css('min-width', '40px') + + var option = ''; + select.append(option); + + return select[0].outerHTML + } + }, + { + data: 'papel_impresion', + render: function (data, type, row, meta) { + var select = $('') + .attr('id', row.row_id + '_maquina') + .attr('name', row.row_id + '_maquina') + .addClass('form-control form-select-sm lp-cell lp-select ' + row.row_class + '-select') + .css('min-width', '110px') + + var option = ''; + select.append(option); + + return select[0].outerHTML + } + }, + { + data: 'tiempo', + render: function (data, type, row, meta) { + return ''; + } + }, + { + data: 'lomo', + render: function (data, type, row, meta) { + return ''; + } + }, + { + data: 'peso', + render: function (data, type, row, meta) { + return ''; + } + }, + { + data: 'total_linea', + render: function (data, type, row, meta) { + return ''; + } + }, + { + data: actionBtns_lp, + className: 'row-edit dt-center' + } + ], + "order": [10, 'asc'] + }); + + this.table.on('click', 'td.dt-control', function (e) { + let tr = e.target.closest('tr'); + let row = tableLineasPresupuesto.row(tr); + + if (row.child.isShown()) { + // This row is already open - close it + row.child.hide(); + } + else { + // Open this row + row.child(format(row.data())).show(); + } + }); + } + + #insertLineaManual() { + + let dataRows = this.table.rows().data(); + + switch ($('#addLineasPresupuesto').val()) { + // Se chequean todas las lineas de negro y todas las de color + // (solo una de cada en interior) + + case 'lp_bn': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_bn' || + dataRows[number].row_id == 'lp_bnhq' || + dataRows[number].row_id == 'lp_rot_bn') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_bn', 'lp-bn'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_bn() + break + + case 'lp_bnhq': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_bn' || + dataRows[number].row_id == 'lp_bnhq' || + dataRows[number].row_id == 'lp_rot_bn') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_bnhq', 'lp-bnhq'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_bnhq() + break + + case 'lp_color': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_color' || + dataRows[number].row_id == 'lp_colorhq' || + dataRows[number].row_id == 'lp_rot_color') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_color', 'lp-color'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_color() + break + + case 'lp_colorhq': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_color' || + dataRows[number].row_id == 'lp_colorhq' || + dataRows[number].row_id == 'lp_rot_color') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_colorhq', 'lp-colorhq'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_colorhq() + break + + case 'lp_rot_bn': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_bn' || + dataRows[number].row_id == 'lp_bnhq' || + dataRows[number].row_id == 'lp_rot_bn') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_rot_bn', 'lp-rot-bn'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_rot_bn() + break + + case 'lp_rot_color': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_color' || + dataRows[number].row_id == 'lp_colorhq' || + dataRows[number].row_id == 'lp_rot_color') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_rot_color', 'lp-rot-color'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_rot_color() + break + + case 'lp_cubierta': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_cubierta') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_cubierta', 'lp-cubierta'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_cubierta() + break + + case 'lp_sobrecubierta': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_sobrecubierta') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_sobrecubierta', 'lp-sobrecubierta'); + tableLineasPresupuesto.row.add(data).draw() + eventos_lp_sobrecubierta() + break + + case 'lp_guardas': + var hayLinea = false + for (let number = 0; number < dataRows.length; number++) { + if (dataRows[number].row_id == 'lp_guardas') { + hayLinea = true + continue + } + } + + if (hayLinea) { + popErrorAlert(window.language.Presupuestos.errores.lineaDuplicada, 'divAlarmasLineasPresupuesto'); + break + } + + var data = processRowData({ tipo_maquina: 'toner' }, 'lp_guardas', 'lp-guardas'); + tableLineasPresupuesto.row.add(data).draw() + $('#lp_guardas_gramaje').empty() + var o = new Option("170", "170"); + $('#lp_guardas_gramaje').append(o) + eventos_lp_guardas() + servicioGuardas(true) + break + default: + break + } + $("#tableLineasPresupuesto").DataTable().columns.adjust(); + } + + #processRowData(row, rowId, rowClass) { + + var icon = "" + if (rowId == 'lp_bn') { + if (row.tipo_maquina == 'toner') + icon = '' + else + icon = '' + } + + else if (rowId == 'lp_bnhq') { + if (row.tipo_maquina == 'toner') + icon = '' + else + icon = '' + } + else if (rowId == 'lp_color') { + if (row.tipo_maquina == 'toner') + icon = '' + else + icon = '' + } + else if (rowId == 'lp_colorhq') { + if (row.tipo_maquina == 'toner') + icon = '' + else + icon = '' + } + + else if (rowId == 'lp_cubierta') + icon = '' + else if (rowId == 'lp_sobrecubierta') + icon = '' + else if (rowId == 'lp_guardas') + icon = '' + else if (rowId == 'lp_rot_bn') + icon = '' + else if (rowId == 'lp_rot_color') + icon = '' + + const blank_line = (typeof row.tarifa_impresion_id === 'undefined') ? 1 : 0; + var data = { + 'row_id': rowId, + 'row_class': rowClass, + + 'tarifa_impresion_id': blank_line ? 0 : isNaN(parseInt(row.tarifa_impresion_id)) ? "" : parseInt(row.tarifa_impresion_id), + 'maquina_ancho': blank_line ? 0 : isNaN(parseFloat(row.dimensiones_maquina[0])) ? "" : parseFloat(row.dimensiones_maquina[0]), + 'maquina_alto': blank_line ? 0 : isNaN(parseFloat(row.dimensiones_maquina[1])) ? "" : parseFloat(row.dimensiones_maquina[1]), + 'maquina_impresion_ancho': blank_line ? 0 : isNaN(parseFloat(row.dimensiones_maquina_impresion[0])) ? "" : parseFloat(row.dimensiones_maquina_impresion[0]), + 'maquina_impresion_alto': blank_line ? 0 : isNaN(parseFloat(row.dimensiones_maquina_impresion[1])) ? "" : parseFloat(row.dimensiones_maquina_impresion[1]), + 'formas': blank_line ? 0 : isNaN(parseInt(row.num_formas.value)) ? 0 : parseInt(row.num_formas.value), + 'formas_v': blank_line ? 0 : isNaN(parseInt(row.num_formas.num_formas_verticales)) ? 0 : parseInt(row.num_formas.num_formas_verticales), + 'formas_h': blank_line ? 0 : isNaN(parseInt(row.num_formas.num_formas_horizontales)) ? 0 : parseInt(row.num_formas.num_formas_horizontales), + 'formas_orientacion': blank_line ? 0 : row.num_formas.posicion_formas, + + 'icon': icon, + 'paginas': blank_line ? 0 : row.paginas, + 'paginas_impresion': rowId == 'lp_guardas' ? row.paginas_impresion : 0, + 'papel': blank_line ? "" : row.papel_generico_id, + 'gramaje': blank_line ? "" : row.gramaje, + 'papel_impresion': blank_line ? "" : row.papel_impresion, + 'papel_impresion_id': blank_line ? "" : row.papel_impresion_id, + 'maquina': blank_line ? "" : row.maquina, + 'maquina_id': blank_line ? "" : row.maquina_id, + + 'tiempo': blank_line ? "" : row.tiempo_maquina, + 'lomo': isNaN(parseFloat(row.mano)) ? "" : parseFloat(row.mano).toFixed(2), + 'peso': isNaN(parseFloat(row.peso)) ? "" : parseFloat(row.peso).toFixed(2), + + 'total_linea': isNaN(parseFloat(row.total_impresion)) ? "" : parseFloat(row.total_impresion).toFixed(2), + + 'numeroPliegos': isNaN(parseFloat(row.pliegos_libro)) ? "" : parseFloat(row.pliegos_libro).toFixed(0), + 'pliegosPedido': isNaN(parseFloat(row.pliegos_pedido)) ? "" : parseFloat(row.pliegos_pedido).toFixed(0), + 'precioPliego': isNaN(parseFloat(row.precios_pliegos)) ? "" : parseFloat(row.precios_pliegos).toFixed(6), + 'libro': isNaN(parseFloat(row.precio_libro)) ? "" : parseFloat(row.precio_libro).toFixed(2), + 'totalPapelPedido': isNaN(parseFloat(row.precio_pedido)) ? "" : parseFloat(row.precio_pedido).toFixed(2), + 'margenPapelPedido': isNaN(parseFloat(row.margen_papel_pedido)) ? "" : parseFloat(row.margen_papel_pedido).toFixed(2), + 'click': isNaN(parseFloat(row.precio_click)) ? "" : parseFloat(row.precio_click).toFixed(6), + 'totalClicks': isNaN(parseFloat(row.precio_click_pedido)) ? "" : parseFloat(row.precio_click_pedido).toFixed(2), + 'margenClicks': isNaN(parseFloat(row.margen_click_pedido)) ? "" : parseFloat(row.margen_click_pedido).toFixed(2), + 'horasMaquina': isNaN(parseFloat(row.horas_maquina)) ? "" : parseFloat(row.horas_maquina).toFixed(4), + 'precioHora': isNaN(parseFloat(row.precio_hora)) ? "" : parseFloat(row.precio_hora).toFixed(2), + 'precioImpresion': isNaN(parseFloat(row.precio_impresion_horas)) ? "" : parseFloat(row.precio_impresion_horas).toFixed(2), + 'margenImpresion': isNaN(parseFloat(row.margen_impresion_horas)) ? "" : parseFloat(row.margen_impresion_horas).toFixed(2), + 'maquinaTipo': row.tipo_maquina, + 'check_papel_total': row.check_papel_total, + 'check_impresion_total': row.check_impresion_total, + } + + if (row.tipo_maquina == 'inkjet') { + + data.numPagColor = row.paginas_color + data.aFavorFibra = row.a_favor_fibra + data.cobNegro = isNaN(parseFloat(row.datosTipologias.negro)) ? "" : parseFloat(row.datosTipologias.negro).toFixed(2) + data.cobCyan = isNaN(parseFloat(row.datosTipologias.cyan)) ? "" : parseFloat(row.datosTipologias.cyan).toFixed(2) + data.cobMagenta = isNaN(parseFloat(row.datosTipologias.magenta)) ? "" : parseFloat(row.datosTipologias.magenta).toFixed(2) + data.cobAmarillo = isNaN(parseFloat(row.datosTipologias.amarillo)) ? "" : parseFloat(row.datosTipologias.amarillo).toFixed(2) + data.gotaNegro = isNaN(parseFloat(row.datosTipologias.gota_negro)) ? "" : parseFloat(row.datosTipologias.gota_negro).toFixed(2) + data.gotaColor = isNaN(parseFloat(row.datosTipologias.gota_color)) ? "" : parseFloat(row.datosTipologias.gota_color).toFixed(2) + + data.resolucion = isNaN(parseFloat(row.resolucion)) ? "" : parseFloat(row.resolucion).toFixed(0) + data.areaPaginas = isNaN(parseFloat(row.superficie)) ? "" : parseFloat(row.superficie).toFixed(2) + + data.gotasNegro = isNaN(parseFloat(row.num_gotas_negro)) ? "" : parseFloat(row.num_gotas_negro).toFixed(0) + data.gotasCyan = isNaN(parseFloat(row.num_gotas_cyan)) ? "" : parseFloat(row.num_gotas_cyan).toFixed(0) + data.gotasMagenta = isNaN(parseFloat(row.num_gotas_magenta)) ? "" : parseFloat(row.num_gotas_magenta).toFixed(0) + data.gotasAmarillo = isNaN(parseFloat(row.num_gotas_amarillo)) ? "" : parseFloat(row.num_gotas_amarillo).toFixed(0) + data.precioPagNegro = isNaN(parseFloat(row.precio_pagina_negro)) ? "" : parseFloat(row.precio_pagina_negro).toFixed(6) + data.precioPagColor = isNaN(parseFloat(row.precio_pagina_color)) ? "" : parseFloat(row.precio_pagina_color).toFixed(6) + data.factorAltura = isNaN(parseFloat(row.factor_altura)) ? "" : parseFloat(row.factor_altura).toFixed(2) + data.factorAnchura = isNaN(parseFloat(row.factor_anchura)) ? "" : parseFloat(row.factor_anchura).toFixed(2) + data.paginasPliego = isNaN(parseFloat(row.paginas_por_pliego)) ? "" : parseFloat(row.paginas_por_pliego).toFixed(2) + + if (rowId.includes('rot')) { + data.metrosMinuto = isNaN(parseFloat(row.maquina_velocidad)) ? "" : parseFloat(row.maquina_velocidad).toFixed(2) + data.metrosPapelLibro = isNaN(parseFloat(row.metros_papel_libro)) ? "" : parseFloat(row.metros_papel_libro).toFixed(2) + data.metrosPapelTotal = isNaN(parseFloat(row.metros_papel_total)) ? "" : parseFloat(row.metros_papel_total).toFixed(2) + data.velocidadCorte = isNaN(parseFloat(row.velocidad_corte)) ? "" : parseFloat(row.velocidad_corte).toFixed(2) + data.precioHoraCorte = isNaN(parseFloat(row.precio_hora_corte)) ? "" : parseFloat(row.precio_hora_corte).toFixed(2) + data.tiempoCorte = isNaN(parseFloat(row.tiempo_corte)) ? "" : parseFloat(row.tiempo_corte).toFixed(2) + data.totalCorte = isNaN(parseFloat(row.total_corte)) ? "" : parseFloat(row.total_corte).toFixed(2) + } + else { + data.totalCorte = 0 + } + + data.clicksLibro = isNaN(parseFloat(row.clicks_libro)) ? "" : parseFloat(row.clicks_libro).toFixed(0) + data.gTintaNegro = isNaN(parseFloat(row.peso_gotas_negro)) ? "" : parseFloat(row.peso_gotas_negro).toFixed(2) + data.gTintaCyan = isNaN(parseFloat(row.peso_gotas_cyan)) ? "" : parseFloat(row.peso_gotas_cyan).toFixed(2) + data.gTintaMagenta = isNaN(parseFloat(row.peso_gotas_magenta)) ? "" : parseFloat(row.peso_gotas_magenta).toFixed(2) + data.gTintaAmarillo = isNaN(parseFloat(row.peso_gotas_amarillo)) ? "" : parseFloat(row.peso_gotas_amarillo).toFixed(2) + data.clicksPedido = isNaN(parseFloat(row.clicks_pedido)) ? "" : parseFloat(row.clicks_pedido).toFixed(0) + data.totalClicksPedido = isNaN(parseFloat(row.precio_click_pedido)) ? "" : parseFloat(row.precio_click_pedido).toFixed(2) + data.totalTinta = isNaN(parseFloat(row.precio_tinta)) ? "" : parseFloat(row.precio_tinta).toFixed(2) + + data.totalImpresion = isNaN(parseFloat(row.precio_click_pedido + row.precio_tinta + data.totalCorte)) ? "" : parseFloat(row.precio_click_pedido + row.precio_tinta + data.totalCorte).toFixed(2) + + data.gTintaNegroPed = isNaN(parseFloat(row.peso_gotas_negro_pedido)) ? "" : parseFloat(row.peso_gotas_negro_pedido).toFixed(2) + data.gTintaCyanPed = isNaN(parseFloat(row.peso_gotas_cyan_pedido)) ? "" : parseFloat(row.peso_gotas_cyan_pedido).toFixed(2) + data.gTintaMagentaPed = isNaN(parseFloat(row.peso_gotas_magenta_pedido)) ? "" : parseFloat(row.peso_gotas_magenta_pedido).toFixed(2) + data.gTintaAmarilloPed = isNaN(parseFloat(row.peso_gotas_amarillo_pedido)) ? "" : parseFloat(row.peso_gotas_amarillo_pedido).toFixed(2) + + if (!rowId.includes('rot')) { + data.cobCG = isNaN(parseFloat(row.datosTipologias.cg)) ? "" : parseFloat(row.datosTipologias.cg).toFixed(2) + data.gotasCG = isNaN(parseFloat(row.num_gotas_cg)) ? "" : parseFloat(row.num_gotas_cg).toFixed(2) + data.gTintaCG = isNaN(parseFloat(row.peso_gotas_cg)) ? "" : parseFloat(row.peso_gotas_cg).toFixed(2) + data.gTintaCGPed = isNaN(parseFloat(row.peso_gotas_cg_pedido)) ? "" : parseFloat(row.peso_gotas_cg_pedido).toFixed(2) + } + + + data.alto_click = row.alto_click + } + + return data + } + + #addEventosLineas(tipoLinea, isInkjet = false) { + + $('#' + tipoLinea + '_papel').on("change", change_papelGenerico_lp_bn); + $('#' + tipoLinea + '_gramaje').on("focus", { mantenerSeleccion: true }, set_lp_bn_gramaje); + $('#' + tipoLinea + '_gramaje').on('change', function () { + var previous = $(this).data('val'); + const selected = $("select#lp_bn_gramaje option:selected"); + if (selected.text() != previous) { + clear_lp_bn(true) + } + }); + $('#' + tipoLinea + '_papelImpresion').on("focus", set_lp_bn_papelImpresion); + $('#' + tipoLinea + '_maquina').on("focus", set_lp_bn_maquina); + $('#' + tipoLinea + '_maquina').on("change", change_lp_bn_maquina); + $('#' + tipoLinea + '_vercalculos').on("click", { rowId: 'lp_bn' }, verCalculosInkjet); + + if (isInkjet) { + $('.' + tipoLinea + '-tipologia').on("change", change_lp_bn_tipologia); + $('#' + tipoLinea + '_defecto').on("click", por_defecto_lp_bn); + $('#' + tipoLinea + '_aFavorFibra').on("change", change_lp_bn_aFavorFibra); + } + } +} + +export default LineasPresupuesto; \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index 577190f2..b096a520 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -780,8 +780,18 @@ class PresupuestoCliente { self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales); - self.disenioInterior.cargarDatos(response.data.interior, response.data.datosGenerales.papelInteriorDiferente); - self.disenioCubierta.cargarDatos(response.data.cubierta, response.data.guardas, response.data.sobrecubierta); + try{ + self.disenioInterior.cargarDatos(response.data.interior, response.data.datosGenerales.papelInteriorDiferente); + } + catch(e){ + console.log("Error al cargar diseño interior: " + e); + } + try{ + self.disenioCubierta.cargarDatos(response.data.cubierta, response.data.guardas, response.data.sobrecubierta); + } + catch(e){ + console.log("Error al cargar diseño cubierta: " + e); + } setTimeout(() => {