mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-18 23:00:21 +00:00
movidos los ficheros por funciones
This commit is contained in:
@ -0,0 +1,348 @@
|
||||
package com.imprimelibros.erp.presupuesto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.imprimelibros.erp.configurationERP.VariableService;
|
||||
import com.imprimelibros.erp.presupuesto.Presupuesto.TipoCubierta;
|
||||
import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestadorItems;
|
||||
|
||||
@Service
|
||||
public class PresupuestoService {
|
||||
|
||||
@Autowired
|
||||
protected VariableService variableService;
|
||||
|
||||
private final PresupuestadorItems presupuestadorItems;
|
||||
|
||||
public PresupuestoService(PresupuestadorItems presupuestadorItems) {
|
||||
this.presupuestadorItems = presupuestadorItems;
|
||||
}
|
||||
|
||||
public boolean validateDatosGenerales(int[] tiradas) {
|
||||
|
||||
for (int tirada : tiradas) {
|
||||
if (tirada <= 0) {
|
||||
return false; // Invalid tirada found
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Boolean isPOD(Presupuesto presupuesto) {
|
||||
|
||||
int pod_value = variableService.getValorEntero("POD");
|
||||
return (presupuesto.getTirada1() != null && presupuesto.getTirada1() <= pod_value) ||
|
||||
(presupuesto.getTirada2() != null && presupuesto.getTirada2() <= pod_value) ||
|
||||
(presupuesto.getTirada3() != null && presupuesto.getTirada3() <= pod_value) ||
|
||||
(presupuesto.getTirada4() != null && presupuesto.getTirada4() <= pod_value);
|
||||
}
|
||||
|
||||
public Map<String, Object> obtenerOpcionesColor(Presupuesto presupuesto, Locale locale) {
|
||||
|
||||
List<ImagenPresupuesto> opciones = new ArrayList<>();
|
||||
|
||||
if (presupuesto.getPaginasColor() > 0) {
|
||||
if (!this.isPOD(presupuesto)) {
|
||||
// POD solo color foto
|
||||
ImagenPresupuesto opcionColor = this.presupuestadorItems.getImpresionColor(locale);
|
||||
opcionColor.setSelected(Presupuesto.TipoImpresion.color.equals(presupuesto.getTipoImpresion()));
|
||||
opciones.add(opcionColor);
|
||||
}
|
||||
ImagenPresupuesto opcionColorHq = this.presupuestadorItems.getImpresionColorPremium(locale);
|
||||
if(Presupuesto.TipoImpresion.colorhq.equals(presupuesto.getTipoImpresion()))
|
||||
opcionColorHq.setSelected(true);
|
||||
opciones.add(opcionColorHq);
|
||||
} else {
|
||||
ImagenPresupuesto opcionNegro = this.presupuestadorItems.getImpresionNegro(locale);
|
||||
if(Presupuesto.TipoImpresion.negro.equals(presupuesto.getTipoImpresion()))
|
||||
opcionNegro.setSelected(true);
|
||||
opciones.add(opcionNegro);
|
||||
ImagenPresupuesto opcionNegroHq = this.presupuestadorItems.getImpresionNegroPremium(locale);
|
||||
if(Presupuesto.TipoImpresion.negrohq.equals(presupuesto.getTipoImpresion()))
|
||||
opcionNegroHq.setSelected(true);
|
||||
opciones.add(opcionNegroHq);
|
||||
}
|
||||
|
||||
boolean opcionSeleccionada = opciones.stream().anyMatch(ImagenPresupuesto::isSelected);
|
||||
if (!opcionSeleccionada) {
|
||||
opciones.get(0).setSelected(true);
|
||||
presupuesto.setTipoImpresion(Presupuesto.TipoImpresion.valueOf(opciones.get(0).getId()));
|
||||
}
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("opciones_color", opciones);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public Map<String, Object> obtenerOpcionesPapelInterior(Presupuesto presupuesto, Locale locale) {
|
||||
|
||||
List<ImagenPresupuesto> opciones = new ArrayList<>();
|
||||
|
||||
opciones.add(this.presupuestadorItems.getPapelOffsetBlanco(locale));
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
|
||||
opciones.add(this.presupuestadorItems.getPapelOffsetBlancoVolumen(locale));
|
||||
}
|
||||
opciones.add(this.presupuestadorItems.getPapelOffsetAhuesado(locale));
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
|
||||
opciones.add(this.presupuestadorItems.getPapelOffsetAhuesadoVolumen(locale));
|
||||
}
|
||||
opciones.add(this.presupuestadorItems.getPapelEstucadoMate(locale));
|
||||
|
||||
for (ImagenPresupuesto imagenPresupuesto : opciones) {
|
||||
imagenPresupuesto.setSelected(
|
||||
presupuesto.getPapelInteriorId() != null
|
||||
&& imagenPresupuesto.getExtra_data().get("sk-id").equals(
|
||||
String.valueOf(presupuesto.getPapelInteriorId())));
|
||||
}
|
||||
|
||||
boolean yaSeleccionado = opciones.stream().anyMatch(ImagenPresupuesto::isSelected);
|
||||
|
||||
if (!yaSeleccionado && !opciones.isEmpty()) {
|
||||
ImagenPresupuesto primeraOpcion = opciones.get(0);
|
||||
primeraOpcion.setSelected(true);
|
||||
presupuesto.setPapelInteriorId(Integer.parseInt(primeraOpcion.getExtra_data().get("sk-id")));
|
||||
}
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("opciones_papel_interior", opciones);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public Map<String, Object> obtenerOpcionesGramajeInterior(Presupuesto presupuesto) {
|
||||
|
||||
List<String> gramajes = new ArrayList<>();
|
||||
|
||||
final int BLANCO_OFFSET_ID = 3;
|
||||
final int BLANCO_OFFSET_VOLUMEN_ID = 7;
|
||||
final int AHUESADO_OFFSET_ID = 4;
|
||||
final int AHUESADO_OFFSET_VOLUMEN_ID = 6;
|
||||
final int ESTUCADO_MATE_ID = 2;
|
||||
|
||||
if (presupuesto.getPapelInteriorId() != null && presupuesto.getPapelInteriorId() == BLANCO_OFFSET_ID) {
|
||||
|
||||
gramajes.add("80");
|
||||
gramajes.add("90");
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negrohq ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.colorhq) {
|
||||
gramajes.add("100");
|
||||
gramajes.add("120");
|
||||
gramajes.add("150");
|
||||
gramajes.add("170");
|
||||
}
|
||||
} else if (presupuesto.getPapelInteriorId() != null
|
||||
&& presupuesto.getPapelInteriorId() == BLANCO_OFFSET_VOLUMEN_ID) {
|
||||
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
|
||||
gramajes.add("80");
|
||||
}
|
||||
|
||||
} else if (presupuesto.getPapelInteriorId() != null && presupuesto.getPapelInteriorId() == AHUESADO_OFFSET_ID) {
|
||||
|
||||
gramajes.add("80");
|
||||
gramajes.add("90");
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negrohq ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.colorhq) {
|
||||
gramajes.add("100");
|
||||
}
|
||||
|
||||
} else if (presupuesto.getPapelInteriorId() != null
|
||||
&& presupuesto.getPapelInteriorId() == AHUESADO_OFFSET_VOLUMEN_ID) {
|
||||
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
|
||||
gramajes.add("70");
|
||||
gramajes.add("80");
|
||||
}
|
||||
|
||||
} else if (presupuesto.getPapelInteriorId() != null && presupuesto.getPapelInteriorId() == ESTUCADO_MATE_ID) {
|
||||
|
||||
if (presupuesto.getTipoImpresion() != Presupuesto.TipoImpresion.color) {
|
||||
gramajes.add("90");
|
||||
}
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negrohq ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.colorhq) {
|
||||
gramajes.add("100");
|
||||
gramajes.add("115");
|
||||
}
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
|
||||
gramajes.add("120");
|
||||
}
|
||||
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negrohq ||
|
||||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.colorhq) {
|
||||
gramajes.add("125");
|
||||
gramajes.add("135");
|
||||
gramajes.add("150");
|
||||
gramajes.add("170");
|
||||
gramajes.add("200");
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("opciones_gramaje_interior", gramajes);
|
||||
return response;
|
||||
}
|
||||
|
||||
public Map<String, Object> obtenerOpcionesPapelCubierta(Presupuesto presupuesto, Locale locale) {
|
||||
|
||||
List<ImagenPresupuesto> opciones = new ArrayList<>();
|
||||
|
||||
if (presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaBlanda) {
|
||||
opciones.add(this.presupuestadorItems.getCartulinaGraficaCubierta(locale));
|
||||
}
|
||||
opciones.add(this.presupuestadorItems.getEstucadoMateCubierta(locale));
|
||||
|
||||
for (ImagenPresupuesto imagenPresupuesto : opciones) {
|
||||
imagenPresupuesto.setSelected(
|
||||
presupuesto.getPapelCubiertaId() != null
|
||||
&& imagenPresupuesto.getExtra_data().get("sk-id").equals(
|
||||
String.valueOf(presupuesto.getPapelCubiertaId())));
|
||||
}
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("opciones_papel_cubierta", opciones);
|
||||
return response;
|
||||
}
|
||||
|
||||
public Map<String, Object> obtenerOpcionesGramajeCubierta(Presupuesto presupuesto) {
|
||||
|
||||
List<String> gramajes = new ArrayList<>();
|
||||
|
||||
final int CARTULINA_GRAFICA_ID = 3;
|
||||
final int ESTUCADO_MATE_ID = 2;
|
||||
|
||||
if (presupuesto.getPapelCubiertaId() != null && presupuesto.getPapelCubiertaId() == CARTULINA_GRAFICA_ID) {
|
||||
gramajes.add("240");
|
||||
gramajes.add("270");
|
||||
gramajes.add("300");
|
||||
gramajes.add("350");
|
||||
} else if (presupuesto.getPapelCubiertaId() != null && presupuesto.getPapelCubiertaId() == ESTUCADO_MATE_ID) {
|
||||
if (presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaBlanda) {
|
||||
|
||||
gramajes.add("250");
|
||||
gramajes.add("300");
|
||||
gramajes.add("350");
|
||||
} else {
|
||||
gramajes.add("170");
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("opciones_gramaje_cubierta", gramajes);
|
||||
return response;
|
||||
}
|
||||
|
||||
public Map<String, Object> toSkApiRequest(Presupuesto presupuesto) {
|
||||
|
||||
final int SK_CLIENTE_ID = 1284;
|
||||
final int SK_PAGINAS_CUADERNILLO = 32;
|
||||
|
||||
Map<String, Object> tamanio = Map.of(
|
||||
"ancho", presupuesto.getAncho(),
|
||||
"alto", presupuesto.getAlto());
|
||||
Map<String, Object> interior = Map.of(
|
||||
"papelInterior", presupuesto.getPapelInteriorId(),
|
||||
"gramajeInterior", presupuesto.getGramajeInterior());
|
||||
Map<String, Object> cubierta = Map.of(
|
||||
"tipoCubierta", presupuesto.getTipoCubierta().name(),
|
||||
"papelCubierta", presupuesto.getPapelCubiertaId(),
|
||||
"gramajeCubierta", presupuesto.getGramajeCubierta(),
|
||||
"carasImpresion", presupuesto.getCubiertaCaras(),
|
||||
"solapas", presupuesto.getSolapasCubierta() ? presupuesto.getTamanioSolapasCubierta() : 0,
|
||||
"acabado", 0, //// Añadir acabados
|
||||
"cabezada", presupuesto.getCabezada(),
|
||||
"lomoRedondo", presupuesto.getTipoCubierta() == TipoCubierta.tapaDuraLomoRedondo ? 1 : 0);
|
||||
|
||||
/*
|
||||
* Map<String, Object> sobrecubierta = new HashMap<>();
|
||||
* sobrecubierta.put("papel", "2");
|
||||
* sobrecubierta.put("gramaje", 170);
|
||||
* sobrecubierta.put("solapas", 80);
|
||||
* sobrecubierta.put("acabado", null);
|
||||
*
|
||||
* Map<String, Object> servicios = Map.of(
|
||||
* "retractilado", 0,
|
||||
* "retractilado5", 0,
|
||||
* "ferro", 0,
|
||||
* "ferroDigital", 0,
|
||||
* "marcapaginas", 0,
|
||||
* "prototipo", 0);
|
||||
*/
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("tipo_impresion_id", this.getTipoImpresionId(presupuesto));
|
||||
body.put("tirada", Arrays.stream(presupuesto.getTiradas())
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
body.put("tamanio", tamanio);
|
||||
body.put("tipo", presupuesto.getTipoEncuadernacion());
|
||||
body.put("clienteId", SK_CLIENTE_ID);
|
||||
body.put("isColor", presupuesto.getTipoImpresion().name().contains("color") ? 1 : 0);
|
||||
body.put("isHq", presupuesto.getTipoImpresion().name().contains("hq") ? 1 : 0);
|
||||
body.put("paginas", presupuesto.getPaginasNegro() + presupuesto.getPaginasColor());
|
||||
body.put("paginasColor", presupuesto.getPaginasColor());
|
||||
body.put("paginasCuadernillo", SK_PAGINAS_CUADERNILLO);
|
||||
body.put("interior", interior);
|
||||
body.put("cubierta", cubierta);
|
||||
// body.put("sobrecubierta", sobrecubierta);
|
||||
body.put("guardas", null);
|
||||
body.put("faja", false);
|
||||
// body.put("servicios", servicios);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
public Integer getTipoImpresionId(Presupuesto presupuesto) {
|
||||
|
||||
if (presupuesto.getTipoEncuadernacion() == Presupuesto.TipoEncuadernacion.fresado) {
|
||||
if (presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDura ||
|
||||
presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDuraLomoRedondo) {
|
||||
return 1; // Fresado tapa dura
|
||||
} else {
|
||||
return 2; // Fresado tapa blanda
|
||||
}
|
||||
} else if (presupuesto.getTipoEncuadernacion() == Presupuesto.TipoEncuadernacion.cosido) {
|
||||
if (presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDura ||
|
||||
presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDuraLomoRedondo) {
|
||||
return 3; // Cosido tapa dura
|
||||
} else {
|
||||
return 4; // Cosido tapa blanda
|
||||
}
|
||||
} else if (presupuesto.getTipoEncuadernacion() == Presupuesto.TipoEncuadernacion.espiral) {
|
||||
if (presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDura ||
|
||||
presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDuraLomoRedondo) {
|
||||
return 5; // Espiral tapa dura
|
||||
} else {
|
||||
return 6; // Espiral tapa blanda
|
||||
}
|
||||
} else if (presupuesto.getTipoEncuadernacion() == Presupuesto.TipoEncuadernacion.wireo) {
|
||||
if (presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDura ||
|
||||
presupuesto.getTipoCubierta() == Presupuesto.TipoCubierta.tapaDuraLomoRedondo) {
|
||||
return 7; // Wireo tapa dura
|
||||
} else {
|
||||
return 8; // Wireo tapa blanda
|
||||
}
|
||||
} else if (presupuesto.getTipoEncuadernacion() == Presupuesto.TipoEncuadernacion.grapado) {
|
||||
return 21; // Grapado
|
||||
} else {
|
||||
return 0; // Default case, no valid type
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user