se añaden los limites del numero de paginas en el presupuesto admin dependiendo del tipo de libro

This commit is contained in:
2025-06-17 10:40:33 +02:00
parent 7d1eef9b28
commit 73fe7e5097
3 changed files with 102 additions and 11 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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);
}
}
}