diff --git a/ci4/app/Services/PresupuestoService.php b/ci4/app/Services/PresupuestoService.php index a4294cf4..a27bf71e 100755 --- a/ci4/app/Services/PresupuestoService.php +++ b/ci4/app/Services/PresupuestoService.php @@ -2077,18 +2077,21 @@ class PresupuestoService extends BaseService $merma = 0; - if ($tirada == 0) { + if ($tirada == 1) { $merma = 0; } - else if ($tirada > $POD) { + else if ($tirada > intval($POD)) { $merma = $tirada * 0.1; } else { $merma_lineas = []; foreach ($formas_lineas_interior as $formas_linea) { if ($formas_linea > $tirada) array_push($merma_lineas, $formas_linea - $tirada); - else - array_push($merma_lineas, $tirada % $formas_linea); + else{ + $total_pliegos = ceil($tirada / $formas_linea); + $total_formas = $total_pliegos * $formas_linea; + array_push($merma_lineas, $total_formas - $tirada); + } } if (count($merma_lineas) > 0) $merma = max($merma_lineas); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js index 135d0d4f..fce19d6d 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js @@ -64,6 +64,49 @@ class PresupuestoAdminAdd { this.tamanioPersonalizado.on('change', this.changeTipoTamanio.bind(this)); this.guardar.on('click', this.guardarPresupuesto.bind(this)); this.tirada.on('change', this.calcular_mermas.bind(this)); + + actualizarLimitesPaginas(); + } + + actualizarLimitesPaginas() { + let min = 1; + let max = null; + + switch (this.tipo_impresion.val()) { + case 1: // Fresado + case 2: + case 3: // Cosido + case 4: + min = 32; + max = null; // Sin límite superior + break; + case 5: // Espiral + case 6: + case 7: // Wire-O + case 8: + min = 1; + max = null; // Sin límite superior + break; + case 21: // Grapado + min = 12; + max = 4; + break; + default: + min = 1; + max = null; + } + + this.paginas.attr('min', min); + this.paginas.attr('max', max); + + // Verificamos y corregimos el valor actual si está fuera de rango + let valorActual = parseInt(this.paginas.val(), 10); + + if (isNaN(valorActual) || valorActual < min) { + this.paginas.val(min); + } else if (valorActual > max) { + this.paginas.val(max); + } } changeTipoTamanio() { diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js index 5c52998e..14ac7ff7 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/datosLibro.js @@ -14,6 +14,8 @@ class DatosLibro { this.csrf_token = getToken(); this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); + this.tipo_impresion_id = parseInt($("#tipo_impresion_id").val()); + this.paginas = this.domItem.find('#paginas'); this.tirada = this.domItem.find('#tirada'); this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language.Presupuestos.formatoLibro); @@ -77,6 +79,8 @@ class DatosLibro { const self = this; + this.actualizarLimitesPaginas(); + this.tamanio.init(); this.acabadoCubierta.init(); this.acabadoSobrecubierta.init(); @@ -84,7 +88,7 @@ class DatosLibro { this.acabadoCubierta.item.on('select2:select', function () { - if (this.cargando){ + if (this.cargando) { return; } @@ -106,9 +110,9 @@ class DatosLibro { this.acabadoSobrecubierta.item.on('select2:select', function () { - if (this.cargando){ + if (this.cargando) { return; - } + } if (self.acabadoCubierta.getVal() == 0) { $(document).trigger('remove-servicio-lineas', 'acabadoSobrecubierta'); @@ -125,7 +129,7 @@ class DatosLibro { } } }); - + this.acabadoFaja.item.on('select2:select', function () { if (this.cargando) @@ -245,7 +249,7 @@ class DatosLibro { } else { $(document).trigger('remove-servicio-lineas', 'ferro'); - if(!this.prototipo.prop('checked')){ + if (!this.prototipo.prop('checked')) { const table = $('#tableOfDireccionesEnvio').DataTable(); const rows = table.rows().data(); for (let i = 0; i < rows.length; i++) { @@ -297,7 +301,7 @@ class DatosLibro { } else { $(document).trigger('remove-servicio-lineas', 'prototipo'); - if(!this.ferro.prop('checked')){ + if (!this.ferro.prop('checked')) { const table = $('#tableOfDireccionesEnvio').DataTable(); const rows = table.rows().data(); for (let i = 0; i < rows.length; i++) { @@ -601,7 +605,7 @@ class DatosLibro { this.updateComparador(); const url = window.location.href; - + if (url.includes('edit')) { $(document).trigger('update-presupuesto', { @@ -754,6 +758,47 @@ class DatosLibro { this.ferroDigital.prop('checked', datos.ferroDigital); this.marcapaginas.prop('checked', datos.marcapaginas); } + + actualizarLimitesPaginas() { + let min = 1; + let max = null; + + switch (this.tipo_impresion_id) { + case 1: // Fresado + case 2: + case 3: // Cosido + case 4: + min = 32; + max = null; // Sin límite superior + break; + case 5: // Espiral + case 6: + case 7: // Wire-O + case 8: + min = 1; + max = null; // Sin límite superior + break; + case 21: // Grapado + min = 12; + max = 4; + break; + default: + min = 1; + max = null; + } + + this.paginas.attr('min', min); + this.paginas.attr('max', max); + + // Verificamos y corregimos el valor actual si está fuera de rango + let valorActual = parseInt(this.paginas.val(), 10); + + if (isNaN(valorActual) || valorActual < min) { + this.paginas.val(min); + } else if (valorActual > max) { + this.paginas.val(max); + } + } }