From 29dbd216935c5ad3eae35019d616272ffe8e7c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 31 Jul 2025 23:10:28 +0200 Subject: [PATCH] =?UTF-8?q?trabajando=20en=20la=20pesta=C3=B1a=20cubierta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presupuestador/PresupuestadorItems.java | 30 +- .../erp/config/SecurityConfig.java | 4 +- .../erp/controller/PresupuestoController.java | 62 +++- .../imprimelibros/erp/entity/Presupuesto.java | 185 +++++++++- .../erp/service/PresupuestoService.java | 154 +++++++- .../resources/i18n/presupuesto_es.properties | 16 +- .../presupuestador/imagen-presupuesto.js | 4 +- .../presupuestador/imagen-selector.js | 2 - .../presupuestador/presupuestador.js | 346 ++++++++++++++++-- .../presupuestador-items/_cubierta.html | 40 +- .../presupuestador-items/_interior.html | 20 +- 11 files changed, 752 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/imprimelibros/erp/config/Presupuestador/PresupuestadorItems.java b/src/main/java/com/imprimelibros/erp/config/Presupuestador/PresupuestadorItems.java index 7f01df2..1a09795 100644 --- a/src/main/java/com/imprimelibros/erp/config/Presupuestador/PresupuestadorItems.java +++ b/src/main/java/com/imprimelibros/erp/config/Presupuestador/PresupuestadorItems.java @@ -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); + } } diff --git a/src/main/java/com/imprimelibros/erp/config/SecurityConfig.java b/src/main/java/com/imprimelibros/erp/config/SecurityConfig.java index b3fb0d8..681b323 100644 --- a/src/main/java/com/imprimelibros/erp/config/SecurityConfig.java +++ b/src/main/java/com/imprimelibros/erp/config/SecurityConfig.java @@ -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()) diff --git a/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java b/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java index fc6d652..1f7122c 100644 --- a/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java +++ b/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java @@ -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 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 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 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 resultado = presupuestoService.obtenerOpcionesGramajeInterior(presupuesto); + return ResponseEntity.ok(resultado); + } + + @PostMapping("/public/get-papel-cubierta") + public ResponseEntity getPapelCubierta( + Presupuesto presupuesto, + BindingResult result, Locale locale) { + + Map resultado = presupuestoService.obtenerOpcionesPapelCubierta(presupuesto, locale); return ResponseEntity.ok(resultado); } diff --git a/src/main/java/com/imprimelibros/erp/entity/Presupuesto.java b/src/main/java/com/imprimelibros/erp/entity/Presupuesto.java index 954eb42..1dfda69 100644 --- a/src/main/java/com/imprimelibros/erp/entity/Presupuesto.java +++ b/src/main/java/com/imprimelibros/erp/entity/Presupuesto.java @@ -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; + } + + } diff --git a/src/main/java/com/imprimelibros/erp/service/PresupuestoService.java b/src/main/java/com/imprimelibros/erp/service/PresupuestoService.java index 5e8febd..1e40d69 100644 --- a/src/main/java/com/imprimelibros/erp/service/PresupuestoService.java +++ b/src/main/java/com/imprimelibros/erp/service/PresupuestoService.java @@ -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 obtenerOpcionesColor(Presupuesto presupuesto, Locale locale) { List 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 response = new HashMap<>(); @@ -67,8 +87,8 @@ public class PresupuestoService { return response; } - public Map obtenerOpcionesPapelInterior(Presupuesto presupuesto, Locale locale) { + List 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 response = new HashMap<>(); response.put("opciones_papel_interior", opciones); return response; } + + public Map obtenerOpcionesGramajeInterior(Presupuesto presupuesto) { + + List 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 response = new HashMap<>(); + response.put("opciones_gramaje_interior", gramajes); + return response; + } + + public Map obtenerOpcionesPapelCubierta(Presupuesto presupuesto, Locale locale) { + + List 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 response = new HashMap<>(); + response.put("opciones_papel_cubierta", opciones); + return response; + } + } diff --git a/src/main/resources/i18n/presupuesto_es.properties b/src/main/resources/i18n/presupuesto_es.properties index 9d2b41d..fdfebfd 100644 --- a/src/main/resources/i18n/presupuesto_es.properties +++ b/src/main/resources/i18n/presupuesto_es.properties @@ -37,8 +37,8 @@ presupuesto.encuadernacion-descripcion=Seleccione la encuadernación del libro presupuesto.continuar-interior=Continuar a diseño interior # Pestaña interior de presupuesto -presupuesto.tipo-impresion=Tipo de impresión -presupuesto.tipo-impresion-descripcion=Seleccione entre calidad estándar o premium +presupuesto.tipo-encuadernacion=Tipo de impresión +presupuesto.tipo-encuadernacion-descripcion=Seleccione entre calidad estándar o premium presupuesto.papel-interior=Papel interior presupuesto.papel-interior-descripcion=Seleccione el papel para el interior presupuesto.gramaje-interior=Gramaje interior @@ -80,6 +80,7 @@ presupuesto.cabezada-roja-amarilla=Roja-Amarilla presupuesto.papel-cubierta=Papel cubierta presupuesto.papel-cubierta-descripcion=Seleccione el papel para la cubierta presupuesto.cartulina-grafica-cubierta=Cartulina gráfica estucada a una cara +presupuesto.estucado-mate-cubierta=Estucado mate presupuesto.gramaje-cubierta=Gramaje cubierta presupuesto.gramaje-cubierta-descripcion=Seleccione el gramaje para la cubierta presupuesto.volver-interior=Volver a diseño interior @@ -95,8 +96,15 @@ presupuesto.errores.paginasNegro.required=El número de páginas en negro es obl presupuesto.errores.paginasNegro.par=El número de páginas en negro debe ser par presupuesto.errores.paginasColor.required=El número de páginas en color es obligatorio presupuesto.errores.paginasColor.par=El número de páginas en color debe ser par -presupuesto.errores.tipo-impresion=Seleccione el tipo de libro +presupuesto.errores.tipo-encuadernacion=Seleccione el tipo de libro presupuesto.errores.ancho=El ancho no puede estar vacío presupuesto.errores.ancho.min_max=El ancho tiene que estar en el rango [{0}, {1}] mm; presupuesto.errores.alto=El alto no puede estar vacío -presupuesto.errores.alto.min_max=El alto tiene que estar en el rango [{0}, {1}] mm \ No newline at end of file +presupuesto.errores.alto.min_max=El alto tiene que estar en el rango [{0}, {1}] mm +presupuesto.errores.tipo-impresion=Seleccione el tipo de impresion +presupuesto.errores.papel-interior=Seleccione el tipo de papel para el interior +presupuesto.errores.gramaje-interior=Seleccione el gramaje del papel para el interior +presupuesto.errores.tipo-cubierta=Seleccione el tipo de cubierta +presupuesto.errores.solapas-cubierta=Seleccione si desea o no solapas en la cubierta +presupuesto.errores.papel-cubierta=Seleccione el tipo de papel para la cubierta +presupuesto.errores.gramaje-cubierta=Seleccione el gramaje del papel para la cubierta \ No newline at end of file diff --git a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-presupuesto.js b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-presupuesto.js index 5bf396f..3c2b962 100644 --- a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-presupuesto.js +++ b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-presupuesto.js @@ -7,14 +7,14 @@ class imagen_presupuesto { this.group = data.group || ""; // Grupo al que pertenece el radio this.texto = data.texto || ""; // Texto de la etiqueta this.selected = data.selected || false; - this.extraClass = data.extraClass + " " || ""; + this.extraClass = (data.extraClass && !(data.extraClass===undefined))? (data.extraClass + ' ') : ''; this.extraData = data.extra_data || {}; // Datos extra opcionales } render() { const contenedor = $('
', { id: this.id, - class: `${this.extraClass}image-container imagen-selector${this.selected ? ' selected' : ''}` + class: `${this.extraClass + ' '}image-container imagen-selector${this.selected ? ' selected' : ''}` }); // Añadir atributos extra al contenedor for (const [key, value] of Object.entries(this.extraData)) { diff --git a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-selector.js b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-selector.js index 05d076a..11bfff5 100644 --- a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-selector.js +++ b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/imagen-selector.js @@ -15,8 +15,6 @@ $('.imagen-container-group').on('click', '.image-container', function () { void img[0].offsetWidth; // Forzar reflow img.addClass('zoom-anim'); - // Guardar selección en hidden - $('#tipoEncuadernacionSeleccionada').val(clicked.attr('id')); clicked.find('input[type="radio"]').prop('checked', true).trigger('change'); }); diff --git a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/presupuestador.js b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/presupuestador.js index 1eb946f..3839fe6 100644 --- a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/presupuestador.js +++ b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/presupuestador.js @@ -21,14 +21,25 @@ class PresupuestoCliente { paginasNegro: '', paginasColor: '', posicionPaginasColor: '', - tipoImpresion: 'fresado', + tipoEncuadernacion: 'fresado', }, interior: { - color: '', - papel: '', - gramaje: '', - },/* - cubierta: {},*/ + tipoImpresion: 'negro', + papelInteriorId: 3, + gramajeInterior: 9, + }, + cubierta: { + tipoCubierta: 'tapaBlanda', + solapasCubierta: 0, + tamanioSolapasCubierta: '80', + cubiertaCaras: 2, + papelGuardasId: 3, + gramajeGuardas: 170, + guardasImpresas: 0, + cabezada: 'WHI', + papelCubiertaId: 3, + gramajeCubierta: 170, + } } // pestaña datos generales @@ -58,16 +69,21 @@ class PresupuestoCliente { this.divContentInterior = $('#content-interior'); this.divOpcionesColor = $('#div-opciones-color'); this.divPapelInterior = $('#div-papel-interior'); + this.divGramajeInterior = $("#div-gramaje-interior"); + this.interior_alert = $('#interior-alert'); // pestaña cubierta + this.divSolapasCubierta = $('#div-solapas-cubierta'); + this.divPapelCubierta = $('#div-papel-cubierta'); + this.divGramajeCubierta = $("#div-gramaje-cubierta"); this.btn_plantilla_cubierta = $('#btn-plantilla-cubierta'); this.btn_impresion_cubierta_help = $('#impresion-cubierta-help'); - } init() { this.#initDatosGenerales(); + this.#initInterior(); this.#initCubierta(); const stored = sessionStorage.getItem("formData"); @@ -89,6 +105,36 @@ class PresupuestoCliente { } } + #getPresupuestoData() { + return { + ...this.#getDatosGeneralesData(), + ...this.#getInteriorData(), + ...this.#getCubiertaData() + }; + } + + #addGramaje(contenedor, gramaje, name) { + const id = `gramaje-${gramaje}`; + + // Crear input + const input = document.createElement('input'); + input.type = 'radio'; + input.className = 'btn-check'; + input.dataset.gramaje = gramaje; + input.id = id; + input.name = name; + + // Crear label + const label = document.createElement('label'); + label.className = 'btn btn-outline-primary material-shadow gramaje-radio'; + label.setAttribute('for', id); + label.textContent = gramaje; + + // Añadir al contenedor + contenedor.append(input); + contenedor.append(label); + } + /****************************** * END OF DATOS GENERALES ******************************/ @@ -109,7 +155,7 @@ class PresupuestoCliente { else { this.divPosicionPaginasColor.removeClass('d-none'); } - this.#updateTipoImpresion(); + this.#updateTipoEncuadernacion(); }); this.formatoPersonalizado.on('change', () => { @@ -130,10 +176,10 @@ class PresupuestoCliente { #nextDatosGenerales() { - const data = this.#getDatosGeneralesData(); + let data = this.#getPresupuestoData(); $.ajax({ - url: '/presupuesto/validar/datos-generales', + url: '/presupuesto/public/validar/datos-generales', type: 'POST', data: data, success: (data) => { @@ -166,6 +212,9 @@ class PresupuestoCliente { this.#loadInteriorData(data); + const interiorData = this.#getInteriorData(); + this.#updateInteriorData(interiorData); + this.#changeTab('pills-inside'); this.divContentInterior.addClass('animate-fadeInUpBounce'); @@ -189,7 +238,7 @@ class PresupuestoCliente { paginasNegro: this.paginasNegro.val(), paginasColor: this.paginasColor.val(), posicionPaginasColor: this.posicionPaginasColor.val(), - tipoImpresion: ($('.tipo-libro.selected').length > 0) ? $('.tipo-libro.selected').attr('id') : 'fresado', + tipoEncuadernacion: ($('.tipo-libro.selected').length > 0) ? $('.tipo-libro.selected').attr('id') : 'fresado', }; } @@ -209,7 +258,7 @@ class PresupuestoCliente { paginasNegro: data.paginasNegro, paginasColor: data.paginasColor, posicionPaginasColor: data.posicionPaginasColor, - tipoImpresion: data.tipoImpresion, + tipoEncuadernacion: data.tipoEncuadernacion, }; } @@ -222,18 +271,18 @@ class PresupuestoCliente { this.tirada2.val(this.formData.datosGenerales.tirada2); this.tirada3.val(this.formData.datosGenerales.tirada3); this.tirada4.val(this.formData.datosGenerales.tirada4); - + this.paginasNegro.val(this.formData.datosGenerales.paginasNegro); this.paginasColor.val(this.formData.datosGenerales.paginasColor); this.posicionPaginasColor.val(this.formData.datosGenerales.posicionPaginasColor); $('.tipo-libro').removeClass('selected'); - $('.image-container#' + this.formData.datosGenerales.tipoImpresion).trigger('click'); - this.#updateTipoImpresion(); + $('.image-container#' + this.formData.datosGenerales.tipoEncuadernacion).trigger('click'); + this.#updateTipoEncuadernacion(); this.formatoPersonalizado.prop('checked', this.formData.datosGenerales.formatoPersonalizado).trigger('change'); - + $('.paginas').trigger('change'); if (this.formatoPersonalizado.is(':checked')) { @@ -270,7 +319,7 @@ class PresupuestoCliente { } } - #updateTipoImpresion() { + #updateTipoEncuadernacion() { const paginas = parseInt(this.paginas.val()); const selectedTipo = $('.tipo-libro.selected').attr('id'); @@ -280,13 +329,24 @@ class PresupuestoCliente { $('.tipo-libro#fresado').addClass('d-none'); $('.tipo-libro#cosido').addClass('d-none'); } + else { + $('.tipo-libro#fresado').removeClass('d-none'); + $('.tipo-libro#cosido').removeClass('d-none'); + } if (paginas < 20) { $('.tipo-libro#espiral').addClass('d-none'); $('.tipo-libro#wireo').addClass('d-none'); } + else { + $('.tipo-libro#espiral').removeClass('d-none'); + $('.tipo-libro#wireo').removeClass('d-none'); + } if (paginas < 12 || paginas > 40) { $('.tipo-libro#grapado').addClass('d-none'); } + else { + $('.tipo-libro#grapado').removeClass('d-none'); + } if (selectedTipo && $('.tipo-libro#' + selectedTipo).length > 0 && !$('.tipo-libro#' + selectedTipo).hasClass('d-none')) { $('.tipo-libro#' + selectedTipo).addClass('selected'); @@ -300,10 +360,10 @@ class PresupuestoCliente { } if ($('.tipo-libro.selected').length > 0) { - this.formData.datosGenerales.tipoImpresion = $('.tipo-libro.selected').attr('id'); + this.formData.datosGenerales.tipoEncuadernacion = $('.tipo-libro.selected').attr('id'); } else { - this.formData.datosGenerales.tipoImpresion = ''; + this.formData.datosGenerales.tipoEncuadernacion = ''; } } /****************************** @@ -314,17 +374,94 @@ class PresupuestoCliente { /****************************** * INTERIOR ******************************/ + + #initInterior() { + + $(document).on('click', '.interior-data', (e) => { + const dataToStore = this.#getInteriorData(); + this.#updateInteriorData(dataToStore); + this.#cacheFormData(); + }); + + $(document).on('click', '.papel-interior', (e) => { + + this.divGramajeInterior.removeClass('animate-fadeInUpBounce'); + + const data = this.#getPresupuestoData(); + $.ajax({ + url: '/presupuesto/public/get-gramaje-interior', + type: 'POST', + data: data, + }).done((data) => { + + this.divGramajeInterior.empty(); + const gramajes = data.opciones_gramaje_interior; + this.#addGramajesInterior(gramajes); + this.divGramajeInterior.addClass('animate-fadeInUpBounce'); + + const dataInterior = this.#getInteriorData(); + this.#updateInteriorData(dataInterior); + this.#cacheFormData(); + + }).fail((xhr, status, error) => { + + }); + }); + + $('.btn-change-tab-interior').on('click', (e) => { + + let data = this.#getPresupuestoData(); + const id = e.currentTarget.id; + + $.ajax({ + url: '/presupuesto/public/validar/interior', + type: 'POST', + data: data, + success: (data) => { + if( id === 'btn-prev-interior') { + + this.#changeTab('pills-general-data'); + } else { + $('.tapa-cubierta.selected').trigger('click'); + this.#changeTab('pills-cover'); + } + }, + error: (xhr, status, error) => { + + this.interior_alert.removeClass('d-none'); + this.interior_alert.find('#inside-alert-list').empty(); + const errors = xhr.responseJSON; + if (errors && typeof errors === 'object') { + if (!this.DEBUG && xhr.responseJSON.error && xhr.responseJSON.error == 'Internal Server Error') { + console.error("Error al validar los datos generales. Internal Server Error"); + return; + } + Object.values(errors).forEach(errorMsg => { + this.interior_alert.find('#inside-alert-list').append(`
  • ${errorMsg}
  • `); + }); + } else { + this.interior_alert.find('#inside-alert-list').append('
  • Error desconocido. Por favor, inténtelo de nuevo más tarde.
  • '); + } + $(window).scrollTop(0); + } + }); + }); + } + #loadInteriorData(data) { - + this.divOpcionesColor.empty(); this.divPapelInterior.empty(); + this.divGramajeInterior.empty(); + const opciones_color = data.opciones_color; for (let i = 0; i < opciones_color.length; i++) { const opcion = opciones_color[i]; const item = new imagen_presupuesto(opcion); + item.extraClass = 'interior-data'; if ((this.formData.interior.color === '' && i === 0) || - this.formData.interior.color === opcion.color) { + this.formData.interior.color === opcion.id) { item.setSelected(true); } this.divOpcionesColor.append(item.render()); @@ -334,12 +471,55 @@ class PresupuestoCliente { for (let i = 0; i < opciones_papel_interior.length; i++) { const opcion = opciones_papel_interior[i]; const item = new imagen_presupuesto(opcion); - if ((this.formData.interior.papel === '' && i === 0) || - this.formData.interior.papel === opcion.papel) { - item.setSelected(true); - } + item.extraClass = 'interior-data papel-interior'; + this.divPapelInterior.append(item.render()); } + + const gramajes = data.opciones_gramaje_interior; + this.#addGramajesInterior(gramajes); + + const dataInterior = this.#getInteriorData(); + this.#updateInteriorData(dataInterior); + this.#cacheFormData(); + } + + #addGramajesInterior(gramajes) { + + for (let i = 0; i < gramajes.length; i++) { + const gramaje = gramajes[i]; + this.#addGramaje(this.divGramajeInterior, gramaje, 'gramaje-interior'); + + // Seleccionar el gramaje por defecto + if (this.formData.interior.gramaje === '' && i === 0) { + $(`#gramaje-${gramaje}`).prop('checked', true); + } else if (this.formData.interior.gramaje === gramaje) { + $(`#gramaje-${gramaje}`).prop('checked', true); + } + } + if (this.divGramajeInterior.find('input[type="radio"]:checked').length === 0) { + // If not, select the first one by default + this.divGramajeInterior.find('input[type="radio"]').first().prop('checked', true); + } + } + + #getInteriorData() { + + const tipoImpresion = $('#div-opciones-color .image-container.selected').attr('id') || 'negro'; + const papelInteriorId = $('#div-papel-interior .image-container.selected').data('sk-id') || 3; + const gramejeInterior = $('input[name="gramaje-interior"]:checked').data('gramaje') || 90; + return { + tipoImpresion: tipoImpresion, + papelInteriorId: papelInteriorId, + gramejeInterior: gramejeInterior + }; + } + + #updateInteriorData(data) { + + this.formData.interior.tipoImpresion = data.tipoImpresion; + this.formData.interior.papelInteriorId = data.papelInteriorId; + this.formData.interior.gramejeInterior = data.gramejeInterior; } @@ -383,6 +563,122 @@ class PresupuestoCliente { showCloseButton: true }); }); + + $(document).on('click', '.tapa-cubierta', (e) => { + + $('.tapa-dura-options').eq(0).removeClass('animate-fadeInUpBounce'); + $('.tapa-blanda-options').eq(0).removeClass('animate-fadeInUpBounce'); + + if(e.currentTarget.id === 'tapaBlanda') { + $('.tapa-dura-options').addClass('d-none'); + $('.tapa-blanda-options').removeClass('d-none'); + $('.tapa-blanda-options').eq(0).addClass('animate-fadeInUpBounce'); + } + else{ + $('.tapa-blanda-options').addClass('d-none'); + $('.tapa-dura-options').removeClass('d-none'); + $('.tapa-dura-options').eq(0).addClass('animate-fadeInUpBounce'); + } + + this.#getPapelesCubierta(e.currentTarget.id); + + const dataToStore = this.#getCubiertaData(); + this.#updateCubiertaData(dataToStore); + this.#cacheFormData(); + }); + + $(document).on('click', '.solapas-cubierta', (e) => { + + if(e.currentTarget.id === 'sin-solapas') { + this.divSolapasCubierta.addClass('d-none'); + } + else{ + this.divSolapasCubierta.removeClass('d-none'); + } + + const dataToStore = this.#getCubiertaData(); + this.#updateCubiertaData(dataToStore); + this.#cacheFormData(); + }); + } + + #getPapelesCubierta(tapa_id) { + + this.divPapelCubierta.removeClass('animate-fadeInUpBounce'); + + return $.ajax({ + url: '/presupuesto/public/get-papel-cubierta', + type: 'POST', + data: { + tipoCubierta: tapa_id, + papelCubiertaId: this.formData.cubierta.papelCubiertaId, + gramajeCubierta: this.formData.cubierta.gramajeCubierta, + }, + success: (data) => { + + this.divPapelCubierta.empty(); + this.divGramajeCubierta.empty(); + + const papelesCubierta = data.opciones_papel_cubierta; + for (let i = 0; i < papelesCubierta.length; i++) { + const papel = papelesCubierta[i]; + const item = new imagen_presupuesto(papel); + item.extraClass = 'cubierta-data papel-cubierta'; + if (papel.id === this.formData.cubierta.papelCubiertaId) { + item.setSelected(true); + } + this.divPapelCubierta.append(item.render()); + } + + this.divPapelCubierta.addClass('animate-fadeInUpBounce'); + }, + error: (xhr, status, error) => { + + console.error("Error al obtener los papeles de cubierta: ", xhr.responseText); + $(window).scrollTop(0); + } + }); + } + + #getCubiertaData() { + + const tipoCubierta = $('.cubierta-data.tapa.selected').attr('id') || 'tapaBlanda'; + const solapas = parseInt($('#div-solapas-cubierta input[type="radio"]:checked').val()) || 0; + const tamanioSolapas = $('#tamanio-solapas-cubierta').val() || '80'; + const cubiertaCaras = parseInt($('#cubierta-caras').val()) || 2; + const guardasPapel = parseInt($('#guardas-papel').val()) || 3; + const guardasGramaje = parseInt($('#guardas-gramaje').val()) || 170; + const guardasImpresas = parseInt($('#guardas-impresas').val()) || 0; + const cabezada = $('#cabezada').val() || 'WHI'; + const papelCubiertaId = $('#papel-cubierta-id').val() || 3; + const gramajeCubierta = $('#gramaje-cubierta').val() || 170; + + return { + tipoCubierta: tipoCubierta, + solapas: solapas, + tamanioSolapas: tamanioSolapas, + cubiertaCaras: cubiertaCaras, + guardasPapel: guardasPapel, + guardasGramaje: guardasGramaje, + guardasImpresas: guardasImpresas, + cabezada: cabezada, + papelCubiertaId: papelCubiertaId, + gramajeCubierta: gramajeCubierta + }; + } + + #updateCubiertaData(data) { + + this.formData.cubierta.tipoCubierta = data.tipoCubierta; + this.formData.cubierta.solapas = data.solapas; + this.formData.cubierta.tamanioSolapas = data.tamanioSolapas; + this.formData.cubierta.cubiertaCaras = data.cubiertaCaras; + this.formData.cubierta.guardasPapel = data.guardasPapel; + this.formData.cubierta.guardasGramaje = data.guardasGramaje; + this.formData.cubierta.guardasImpresas = data.guardasImpresas; + this.formData.cubierta.cabezada = data.cabezada; + this.formData.cubierta.papelCubiertaId = data.papelCubiertaId; + this.formData.cubierta.gramajeCubierta = data.gramajeCubierta; } /****************************** * END CUBIERTA diff --git a/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_cubierta.html b/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_cubierta.html index 1e482f5..8a2f60a 100644 --- a/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_cubierta.html +++ b/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_cubierta.html @@ -1,4 +1,4 @@ -
    +
    -
    -
    +
    +
    -
    +
    -
    +
    -
    + +
    -
    +
    -
    +
    @@ -87,7 +88,8 @@
    -
    +
    +
    @@ -133,22 +135,8 @@
    -
    -
    - - -
    - -
    - - -
    +
    a +
    @@ -165,7 +153,7 @@
    -
    +