trabajando en la pestaña cubierta

This commit is contained in:
Jaime Jiménez
2025-07-31 23:10:28 +02:00
parent eb0b5610d8
commit 29dbd21693
11 changed files with 752 additions and 111 deletions

View File

@ -15,7 +15,7 @@ public class PresupuestadorItems {
public ImagenPresupuesto getImpresionNegro(Locale locale) {
return new ImagenPresupuesto(
"negroEstandar",
"negro",
"/assets/images/imprimelibros/presupuestador/blancoYnegro.png",
"",
messageSource.getMessage("presupuesto.blanco-negro", null, locale),
@ -24,7 +24,7 @@ public class PresupuestadorItems {
public ImagenPresupuesto getImpresionNegroPremium(Locale locale) {
return new ImagenPresupuesto(
"negroPremium",
"negrohq",
"/assets/images/imprimelibros/presupuestador/negroFoto.png",
"",
messageSource.getMessage("presupuesto.blanco-negro-premium", null, locale),
@ -37,7 +37,7 @@ public class PresupuestadorItems {
String texto = messageSource.getMessage(clave, null, locale);
System.out.println("Clave: " + clave + " => Texto: " + texto);
return new ImagenPresupuesto(
"colorEstandar",
"color",
"/assets/images/imprimelibros/presupuestador/color.png",
"",
messageSource.getMessage("presupuesto.color", null, locale),
@ -46,7 +46,7 @@ public class PresupuestadorItems {
public ImagenPresupuesto getImpresionColorPremium(Locale locale) {
return new ImagenPresupuesto(
"colorPremium",
"colorhq",
"/assets/images/imprimelibros/presupuestador/colorFoto.png",
"",
messageSource.getMessage("presupuesto.color-premium", null, locale),
@ -96,4 +96,26 @@ public class PresupuestadorItems {
Map.of("sk-id", "2"),
false);
}
public ImagenPresupuesto getCartulinaGraficaCubierta(Locale locale) {
return new ImagenPresupuesto(
"cartulina-grafica-cubierta",
"/assets/images/imprimelibros/presupuestador/cartulina-grafica.png",
"",
messageSource.getMessage("presupuesto.cartulina-grafica-cubierta", null, locale),
Map.of("sk-id", "3"),
false);
}
public ImagenPresupuesto getEstucadoMateCubierta(Locale locale) {
return new ImagenPresupuesto(
"estucado-mate-cubierta",
"/assets/images/imprimelibros/presupuestador/estucado-mate-cubierta.png",
"",
messageSource.getMessage("presupuesto.estucado-mate-cubierta", null, locale),
Map.of("sk-id", "2"),
false);
}
}

View File

@ -21,11 +21,11 @@ public class SecurityConfig {
"/images/**",
"/public/**",
"/error",
"/presupuesto/validar/**")
"/presupuesto/public/**")
.permitAll()
.anyRequest().authenticated())
.csrf(csrf -> csrf
.ignoringRequestMatchers("/presupuesto/validar/**"))
.ignoringRequestMatchers("/presupuesto/public/**"))
.formLogin(login -> login
// .loginPage("/login") añadir cuando se tenga login personalizado
.permitAll())

View File

@ -6,20 +6,18 @@ import com.imprimelibros.erp.service.PresupuestoService;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import jakarta.validation.Valid; // o javax.validation.Valid según tu versión
import java.util.Map;
import com.imprimelibros.erp.config.validation.PresupuestoValidationGroups;
import com.imprimelibros.erp.entity.Presupuesto;
@ -31,7 +29,7 @@ public class PresupuestoController {
@Autowired
protected PresupuestoService presupuestoService;
@PostMapping("/validar/datos-generales")
@PostMapping("/public/validar/datos-generales")
public ResponseEntity<?> validarDatosGenerales(
@Validated(PresupuestoValidationGroups.DatosGenerales.class) Presupuesto presupuesto,
BindingResult result, Locale locale) {
@ -41,7 +39,7 @@ public class PresupuestoController {
// errores de campos individuales
result.getFieldErrors().forEach(error -> errores.put(error.getField(), error.getDefaultMessage()));
// errores globales (como tu @ConsistentTiradas)
// errores globales (@ConsistentTiradas...)
result.getGlobalErrors().forEach(error -> errores.put("global", error.getDefaultMessage()));
if (!errores.isEmpty()) {
@ -50,8 +48,60 @@ public class PresupuestoController {
// opciones color
Map<String, Object> resultado = presupuestoService.obtenerOpcionesColor(presupuesto, locale);
// opciones papel interior
resultado.putAll(presupuestoService.obtenerOpcionesPapelInterior(presupuesto, locale));
// opciones gramaje interior
resultado.putAll(presupuestoService.obtenerOpcionesGramajeInterior(presupuesto));
return ResponseEntity.ok(resultado);
}
@PostMapping("/public/validar/interior")
public ResponseEntity<?> validarInterior(
@Validated(PresupuestoValidationGroups.Interior.class) Presupuesto presupuesto,
BindingResult result, Locale locale) {
Map<String, String> errores = new HashMap<>();
// errores de campos individuales
result.getFieldErrors().forEach(error -> errores.put(error.getField(), error.getDefaultMessage()));
// errores globales (@ConsistentTiradas...)
result.getGlobalErrors().forEach(error -> errores.put("global", error.getDefaultMessage()));
if (!errores.isEmpty()) {
return ResponseEntity.badRequest().body(errores);
}
return ResponseEntity.ok(Collections.singletonMap("success", true));
}
@PostMapping("/public/get-gramaje-interior")
public ResponseEntity<?> getGramajeInterior(
@Validated(PresupuestoValidationGroups.Interior.class) Presupuesto presupuesto,
BindingResult result) {
Map<String, String> errores = new HashMap<>();
// errores de campos individuales
result.getFieldErrors().forEach(error -> errores.put(error.getField(), error.getDefaultMessage()));
if (!errores.isEmpty()) {
return ResponseEntity.badRequest().body(errores);
}
Map<String, Object> resultado = presupuestoService.obtenerOpcionesGramajeInterior(presupuesto);
return ResponseEntity.ok(resultado);
}
@PostMapping("/public/get-papel-cubierta")
public ResponseEntity<?> getPapelCubierta(
Presupuesto presupuesto,
BindingResult result, Locale locale) {
Map<String, Object> resultado = presupuestoService.obtenerOpcionesPapelCubierta(presupuesto, locale);
return ResponseEntity.ok(resultado);
}

View File

@ -17,17 +17,25 @@ import com.imprimelibros.erp.config.validation.Par;
@Table(name = "presupuesto")
public class Presupuesto {
public enum TipoImpresion {
public enum TipoEncuadernacion {
fresado, cosido, grapado, espiral, wireo
}
public enum TipoImpresion {
negro, negrohq, color, colorhq
}
public enum TipoCubierta{
tapaBlanda, tapaDuraLomoRecto, tapaDuraLomoRedondo
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull(message = "{presupuesto.errores.tipo-impresion}", groups = PresupuestoValidationGroups.DatosGenerales.class)
@Column(name = "tipo_impresion")
private TipoImpresion tipoImpresion;
@NotNull(message = "{presupuesto.errores.tipo-encuadernacion}", groups = PresupuestoValidationGroups.DatosGenerales.class)
@Column(name = "tipo_encuadernacion")
private TipoEncuadernacion tipoEncuadernacion = TipoEncuadernacion.fresado;
@NotBlank(message = "{presupuesto.errores.titulo}", groups = PresupuestoValidationGroups.DatosGenerales.class)
@Column(name = "titulo")
@ -73,16 +81,56 @@ public class Presupuesto {
@Column(name = "paginas_color")
private Integer paginasColor;
@NotNull(message = "El papel interior no puede estar vacío", groups = PresupuestoValidationGroups.Interior.class)
@Column(name = "papel_interior")
private Integer papelInterior;
@Column(name = "posicion_paginas_color")
private String posicionPaginasColor;
@Column(name = "paginas_color_total")
private Integer paginasColorTotal;
@NotNull(message = "{presupuesto.errores.tipo-impresion}", groups = PresupuestoValidationGroups.Interior.class)
@Column(name = "tipo_impresion")
private TipoImpresion tipoImpresion = TipoImpresion.negro;
@NotNull(message = "{presupuesto.errores.papel-interior}", groups = PresupuestoValidationGroups.Interior.class)
@Column(name = "papel_interior_id")
private Integer papelInteriorId;
@NotNull(message = "{presupuesto.errores.gramaje-interior}", groups = PresupuestoValidationGroups.Interior.class)
@Column(name = "gramaje_interior")
private Integer gramejeInterior;
@NotNull(message = "{presupuesto.errores.tipo-cubierta}", groups = PresupuestoValidationGroups.Cubierta.class)
@Column(name = "tipo_cubierta")
private TipoCubierta tipoCubierta = TipoCubierta.tapaBlanda;
@Column(name = "solapas_cubierta")
private Boolean solapasCubierta = false;
@Column(name = "tamanio_solapas_cubierta")
private Integer tamanioSolapasCubierta;
@Column(name = "cubierta_caras")
private Integer cubiertaCaras;
@Column(name = "papel_guardas_id")
private Integer papelGuardasId;
@Column(name = "gramaje_guardas")
private Integer gramajeGuardas;
@Column(name = "guardas_impresas")
private Boolean guardasImpresas;
@Column(name = "cabezada")
private String cabezada;
@NotNull(message = "{presupuesto.errores.papel-cubierta}", groups = PresupuestoValidationGroups.Cubierta.class)
@Column(name = "papel_cubierta_id")
private Integer papelCubiertaId = 2;
@NotNull(message = "{presupuesto.errores.gramaje-cubierta}", groups = PresupuestoValidationGroups.Cubierta.class)
@Column(name = "gramaje_cubierta")
private Integer gramajeCubierta = 240;
// Getters y Setters
@ -194,20 +242,12 @@ public class Presupuesto {
this.paginasColor = paginasColor;
}
public Integer getPapelInterior() {
return papelInterior;
public TipoEncuadernacion getTipoEncuadernacion() {
return tipoEncuadernacion;
}
public void setPapelInterior(Integer papelInterior) {
this.papelInterior = papelInterior;
}
public TipoImpresion getTipoImpresion() {
return tipoImpresion;
}
public void setTipoImpresion(TipoImpresion tipoImpresion) {
this.tipoImpresion = tipoImpresion;
public void setTipoEncuadernacion(TipoEncuadernacion tipoEncuadernacion) {
this.tipoEncuadernacion = tipoEncuadernacion;
}
public String getPosicionPaginasColor() {
@ -226,5 +266,110 @@ public class Presupuesto {
this.paginasColorTotal = paginasColorTotal;
}
public TipoImpresion getTipoImpresion() {
return tipoImpresion;
}
public void setTipoImpresion(TipoImpresion tipoImpresion) {
this.tipoImpresion = tipoImpresion;
}
public Integer getPapelInteriorId() {
return papelInteriorId;
}
public void setPapelInteriorId(Integer papelInteriorId) {
this.papelInteriorId = papelInteriorId;
}
public Integer getGramejeInterior() {
return gramejeInterior;
}
public void setGramejeInterior(Integer gramejeInterior) {
this.gramejeInterior = gramejeInterior;
}
public TipoCubierta getTipoCubierta() {
return tipoCubierta;
}
public void setTipoCubierta(TipoCubierta tipoCubierta) {
this.tipoCubierta = tipoCubierta;
}
public Boolean getSolapasCubierta() {
return solapasCubierta;
}
public void setSolapasCubierta(Boolean solapasCubierta) {
this.solapasCubierta = solapasCubierta;
}
public Integer getTamanioSolapasCubierta() {
return tamanioSolapasCubierta;
}
public void setTamanioSolapasCubierta(Integer tamanioSolapasCubierta) {
this.tamanioSolapasCubierta = tamanioSolapasCubierta;
}
public Integer getCubiertaCaras() {
return cubiertaCaras;
}
public void setCubiertaCaras(Integer cubiertaCaras) {
this.cubiertaCaras = cubiertaCaras;
}
public Integer getPapelGuardasId() {
return papelGuardasId;
}
public void setPapelGuardasId(Integer papelGuardasId) {
this.papelGuardasId = papelGuardasId;
}
public Integer getGramajeGuardas() {
return gramajeGuardas;
}
public void setGramajeGuardas(Integer gramajeGuardas) {
this.gramajeGuardas = gramajeGuardas;
}
public Boolean getGuardasImpresas() {
return guardasImpresas;
}
public void setGuardasImpresas(Boolean guardasImpresas) {
this.guardasImpresas = guardasImpresas;
}
public String getCabezada() {
return cabezada;
}
public void setCabezada(String cabezada) {
this.cabezada = cabezada;
}
public Integer getPapelCubiertaId() {
return papelCubiertaId;
}
public void setPapelCubiertaId(Integer papelCubiertaId) {
this.papelCubiertaId = papelCubiertaId;
}
public Integer getGramajeCubierta() {
return gramajeCubierta;
}
public void setGramajeCubierta(Integer gramajeCubierta) {
this.gramajeCubierta = gramajeCubierta;
}
}

View File

@ -26,39 +26,59 @@ public class PresupuestoService {
}
public boolean validateDatosGenerales(int[] tiradas) {
for (int tirada : tiradas) {
if (tirada <= 0) {
return false; // Invalid tirada found
}
}
return true;
return true;
}
public Boolean isPOD(Presupuesto presupuesto){
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);
(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<>();
ImagenPresupuesto opcion;
if (presupuesto.getPaginasColor() > 0) {
if (!this.isPOD(presupuesto)) {
// POD solo color foto
opciones.add(this.presupuestadorItems.getImpresionColor(locale));
opcion = this.presupuestadorItems.getImpresionColor(locale);
opcion.setSelected(presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color);
opciones.add(opcion);
}
opciones.add(this.presupuestadorItems.getImpresionColorPremium(locale));
opcion = this.presupuestadorItems.getImpresionColorPremium(locale);
opcion.setSelected(presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.colorhq);
opciones.add(opcion);
} else {
opciones.add(this.presupuestadorItems.getImpresionNegro(locale));
opciones.add(this.presupuestadorItems.getImpresionNegroPremium(locale));
opcion = this.presupuestadorItems.getImpresionNegro(locale);
opcion.setSelected(presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro);
opciones.add(opcion);
opcion = this.presupuestadorItems.getImpresionNegroPremium(locale);
opcion.setSelected(presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negrohq);
opciones.add(opcion);
}
boolean opcionSeleccionada = opciones.stream()
.findFirst()
.map(op -> {
op.setSelected(true);
return true;
})
.orElse(false);
if (!opcionSeleccionada) {
opciones.get(0).setSelected(true);
presupuesto.setPapelInteriorId(Integer.parseInt(opciones.get(0).getExtra_data().get("sk-id")));
}
Map<String, Object> response = new HashMap<>();
@ -67,8 +87,8 @@ public class PresupuestoService {
return response;
}
public Map<String, Object> obtenerOpcionesPapelInterior(Presupuesto presupuesto, Locale locale) {
List<ImagenPresupuesto> opciones = new ArrayList<>();
opciones.add(this.presupuestadorItems.getPapelOffsetBlanco(locale));
@ -76,9 +96,115 @@ public class PresupuestoService {
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 opcionSeleccionada = opciones.stream()
.findFirst()
.map(opcion -> {
opcion.setSelected(true);
return true;
})
.orElse(false);
if (!opcionSeleccionada) {
opciones.get(0).setSelected(true);
presupuesto.setPapelInteriorId(Integer.parseInt(opciones.get(0).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 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) {
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
gramajes.add("80");
}
gramajes.add("90");
} else if (presupuesto.getPapelInteriorId() != null && presupuesto.getPapelInteriorId() == AHUESADO_OFFSET_ID) {
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro ||
presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
gramajes.add("80");
}
gramajes.add("150");
gramajes.add("170");
} 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("90");
gramajes.add("100");
gramajes.add("150");
gramajes.add("170");
} else if (presupuesto.getPapelInteriorId() != null && presupuesto.getPapelInteriorId() == ESTUCADO_MATE_ID) {
gramajes.add("90");
gramajes.add("100");
gramajes.add("115");
if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
gramajes.add("120");
}
gramajes.add("135");
}
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())));
}
boolean opcionSeleccionada = opciones.stream()
.findFirst()
.map(opcion -> {
opcion.setSelected(true);
return true;
})
.orElse(false);
if (!opcionSeleccionada) {
opciones.get(0).setSelected(true);
presupuesto.setPapelInteriorId(Integer.parseInt(opciones.get(0).getExtra_data().get("sk-id")));
}
Map<String, Object> response = new HashMap<>();
response.put("opciones_papel_cubierta", opciones);
return response;
}
}