diff --git a/docker-compose.yml b/docker-compose.yml index 751abe9..c54c8b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: MYSQL_USER: imprimelibros_user MYSQL_PASSWORD: om91irrDctd ports: - - "3306:3306" + - "3309:3306" volumes: - db_data:/var/lib/mysql networks: diff --git a/pom.xml b/pom.xml index 9e40c4e..5f641c6 100644 --- a/pom.xml +++ b/pom.xml @@ -85,11 +85,13 @@ spring-boot-starter-test test + org.springframework.security spring-security-test test + 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 1a09795..a4af0ee 100644 --- a/src/main/java/com/imprimelibros/erp/config/Presupuestador/PresupuestadorItems.java +++ b/src/main/java/com/imprimelibros/erp/config/Presupuestador/PresupuestadorItems.java @@ -33,9 +33,6 @@ public class PresupuestadorItems { public ImagenPresupuesto getImpresionColor(Locale locale) { - String clave = "presupuesto.color"; // ✅ - String texto = messageSource.getMessage(clave, null, locale); - System.out.println("Clave: " + clave + " => Texto: " + texto); return new ImagenPresupuesto( "color", "/assets/images/imprimelibros/presupuestador/color.png", @@ -64,6 +61,17 @@ public class PresupuestadorItems { false); } + public ImagenPresupuesto getPapelOffsetBlancoVolumen(Locale locale) { + + return new ImagenPresupuesto( + "offset-blanco-volumen", + "/assets/images/imprimelibros/presupuestador/offset-blanco.png", + "", + messageSource.getMessage("presupuesto.offset-blanco-volumen", null, locale), + Map.of("sk-id", "7"), + false); + } + public ImagenPresupuesto getPapelOffsetAhuesado(Locale locale) { return new ImagenPresupuesto( diff --git a/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java b/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java index 1f7122c..321cde8 100644 --- a/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java +++ b/src/main/java/com/imprimelibros/erp/controller/PresupuestoController.java @@ -7,6 +7,7 @@ import com.imprimelibros.erp.service.PresupuestoService; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.List; import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; @@ -17,10 +18,10 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.PostMapping; - - +import com.imprimelibros.erp.config.Presupuestador.ImagenPresupuesto; import com.imprimelibros.erp.config.validation.PresupuestoValidationGroups; import com.imprimelibros.erp.entity.Presupuesto; +import com.imprimelibros.erp.externalApi.skApiClient; @RestController @RequestMapping("/presupuesto") @@ -29,6 +30,9 @@ public class PresupuestoController { @Autowired protected PresupuestoService presupuestoService; + @Autowired + protected skApiClient apiClient; + @PostMapping("/public/validar/datos-generales") public ResponseEntity validarDatosGenerales( @Validated(PresupuestoValidationGroups.DatosGenerales.class) Presupuesto presupuesto, @@ -48,7 +52,20 @@ public class PresupuestoController { // opciones color Map resultado = presupuestoService.obtenerOpcionesColor(presupuesto, locale); - + List opcionesColor = (List) resultado.get("opciones_color"); + if (opcionesColor != null && !opcionesColor.isEmpty()) { + Presupuesto.TipoImpresion colorActual = presupuesto.getTipoImpresion(); + if (!opcionesColor.stream().anyMatch(opcion -> opcion.getId().equals(colorActual.name()))) { + String idSeleccionado = opcionesColor.get(0).getId(); + try { + Presupuesto.TipoImpresion tipo = Presupuesto.TipoImpresion.valueOf(idSeleccionado); + presupuesto.setTipoImpresion(tipo); + } catch (IllegalArgumentException e) { + System.err.println("Tipo de impresión no válido: " + idSeleccionado); + } + } + } + // opciones papel interior resultado.putAll(presupuestoService.obtenerOpcionesPapelInterior(presupuesto, locale)); @@ -57,7 +74,6 @@ public class PresupuestoController { return ResponseEntity.ok(resultado); } - @PostMapping("/public/validar/interior") public ResponseEntity validarInterior( @Validated(PresupuestoValidationGroups.Interior.class) Presupuesto presupuesto, @@ -74,9 +90,42 @@ public class PresupuestoController { if (!errores.isEmpty()) { return ResponseEntity.badRequest().body(errores); } - return ResponseEntity.ok(Collections.singletonMap("success", true)); + Map resultado = new HashMap<>(); + resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto))); + return ResponseEntity.ok(resultado); } + @PostMapping("/public/get-papel-interior") + public ResponseEntity getPapelInterior( + @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())); + + if (!errores.isEmpty()) { + return ResponseEntity.badRequest().body(errores); + } + + // opciones color + Map resultado = presupuestoService.obtenerOpcionesPapelInterior(presupuesto, locale); + + // opciones gramaje interior + resultado.putAll(presupuestoService.obtenerOpcionesGramajeInterior(presupuesto)); + List opciones = (List) resultado.get("opciones_gramaje_interior"); + + if (opciones != null && !opciones.isEmpty()) { + String gramajeActual = presupuesto.getGramajeInterior().toString(); + if (!opciones.contains(gramajeActual)) { + presupuesto.setGramajeInterior(Integer.parseInt(opciones.get(0))); // Asignar primera opción + } + } + + resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto))); + return ResponseEntity.ok(resultado); + } @PostMapping("/public/get-gramaje-interior") public ResponseEntity getGramajeInterior( @@ -93,6 +142,34 @@ public class PresupuestoController { } Map resultado = presupuestoService.obtenerOpcionesGramajeInterior(presupuesto); + List opciones = (List) resultado.get("opciones_gramaje_interior"); + + if (opciones != null && !opciones.isEmpty()) { + String gramajeActual = presupuesto.getGramajeInterior().toString(); + if (!opciones.contains(gramajeActual)) { + presupuesto.setGramajeInterior(Integer.parseInt(opciones.get(0))); // Asignar primera opción + } + } + resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto))); + return ResponseEntity.ok(resultado); + } + + @PostMapping("/public/get-max-solapas") + public ResponseEntity getMaxSolapas( + @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 = new HashMap<>(); + resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto))); return ResponseEntity.ok(resultado); } @@ -101,7 +178,42 @@ public class PresupuestoController { Presupuesto presupuesto, BindingResult result, Locale locale) { - Map resultado = presupuestoService.obtenerOpcionesPapelCubierta(presupuesto, locale); + Map resultado = new HashMap<>(); + Map papelesCubierta = presupuestoService.obtenerOpcionesPapelCubierta(presupuesto, locale); + List opciones = (List) presupuestoService + .obtenerOpcionesPapelCubierta(presupuesto, locale) + .get("opciones_papel_cubierta"); + + if (opciones != null && opciones.stream().noneMatch( + o -> o.getExtra_data().get("sk-id").equals(String.valueOf(presupuesto.getPapelCubiertaId())))) { + presupuesto.setPapelCubiertaId(Integer.valueOf(opciones.get(0).getExtra_data().get("sk-id"))); + } + resultado.putAll(papelesCubierta); + + resultado.putAll(presupuestoService.obtenerOpcionesGramajeCubierta(presupuesto)); + List gramajesCubierta = (List) resultado.get("opciones_gramaje_cubierta"); + if (gramajesCubierta != null && !gramajesCubierta.isEmpty()) { + String gramajeActual = presupuesto.getGramajeCubierta().toString(); + if (!gramajesCubierta.contains(gramajeActual)) { + presupuesto.setGramajeCubierta(Integer.parseInt(gramajesCubierta.get(0))); // Asignar primera opción + } + } + return ResponseEntity.ok(resultado); + } + + @PostMapping("/public/get-gramaje-cubierta") + public ResponseEntity getGramajeCubierta( + Presupuesto presupuesto, + BindingResult result) { + + Map resultado = presupuestoService.obtenerOpcionesGramajeCubierta(presupuesto); + List gramajesCubierta = (List) resultado.get("opciones_gramaje_cubierta"); + if (gramajesCubierta != null && !gramajesCubierta.isEmpty()) { + String gramajeActual = presupuesto.getGramajeCubierta().toString(); + if (!gramajesCubierta.contains(gramajeActual)) { + presupuesto.setGramajeCubierta(Integer.parseInt(gramajesCubierta.get(0))); // Asignar primera opción + } + } 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 1dfda69..53b3c17 100644 --- a/src/main/java/com/imprimelibros/erp/entity/Presupuesto.java +++ b/src/main/java/com/imprimelibros/erp/entity/Presupuesto.java @@ -7,10 +7,15 @@ import jakarta.persistence.*; import com.imprimelibros.erp.config.validation.PresupuestoValidationGroups; import com.imprimelibros.erp.config.validation.Tamanio; +import java.util.HashMap; +import java.util.Arrays; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.Map; + import com.imprimelibros.erp.config.validation.ConsistentTiradas; import com.imprimelibros.erp.config.validation.Par; - @ConsistentTiradas(groups = PresupuestoValidationGroups.DatosGenerales.class) @Tamanio(groups = PresupuestoValidationGroups.DatosGenerales.class) @Entity @@ -25,8 +30,8 @@ public class Presupuesto { negro, negrohq, color, colorhq } - public enum TipoCubierta{ - tapaBlanda, tapaDuraLomoRecto, tapaDuraLomoRedondo + public enum TipoCubierta { + tapaBlanda, tapaDura, tapaDuraLomoRedondo } @Id @@ -56,7 +61,7 @@ public class Presupuesto { @Column(name = "tirada3") private Integer tirada3; - + @Column(name = "tirada4") private Integer tirada4; @@ -67,7 +72,7 @@ public class Presupuesto { @NotNull(message = "{presupuesto.errores.alto}", groups = PresupuestoValidationGroups.DatosGenerales.class) @Column(name = "alto") private Integer alto; - + @Column(name = "formatoPersonalizado") private Boolean formatoPersonalizado; @@ -97,7 +102,7 @@ public class Presupuesto { @NotNull(message = "{presupuesto.errores.gramaje-interior}", groups = PresupuestoValidationGroups.Interior.class) @Column(name = "gramaje_interior") - private Integer gramejeInterior; + private Integer gramajeInterior; @NotNull(message = "{presupuesto.errores.tipo-cubierta}", groups = PresupuestoValidationGroups.Cubierta.class) @Column(name = "tipo_cubierta") @@ -126,10 +131,10 @@ public class Presupuesto { @NotNull(message = "{presupuesto.errores.papel-cubierta}", groups = PresupuestoValidationGroups.Cubierta.class) @Column(name = "papel_cubierta_id") - private Integer papelCubiertaId = 2; + private Integer papelCubiertaId = 2; @NotNull(message = "{presupuesto.errores.gramaje-cubierta}", groups = PresupuestoValidationGroups.Cubierta.class) - @Column(name = "gramaje_cubierta") + @Column(name = "gramaje_cubierta") private Integer gramajeCubierta = 240; // Getters y Setters @@ -179,7 +184,7 @@ public class Presupuesto { } public Integer[] getTiradas() { - return new Integer[]{tirada1, tirada2, tirada3, tirada4}; + return new Integer[] { tirada1, tirada2, tirada3, tirada4 }; } public void setTirada4(Integer tirada4) { @@ -282,12 +287,12 @@ public class Presupuesto { this.papelInteriorId = papelInteriorId; } - public Integer getGramejeInterior() { - return gramejeInterior; + public Integer getGramajeInterior() { + return gramajeInterior; } - public void setGramejeInterior(Integer gramejeInterior) { - this.gramejeInterior = gramejeInterior; + public void setGramajeInterior(Integer gramajeInterior) { + this.gramajeInterior = gramajeInterior; } public TipoCubierta getTipoCubierta() { @@ -370,6 +375,4 @@ public class Presupuesto { 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 1e40d69..a8f1243 100644 --- a/src/main/java/com/imprimelibros/erp/service/PresupuestoService.java +++ b/src/main/java/com/imprimelibros/erp/service/PresupuestoService.java @@ -1,9 +1,12 @@ package com.imprimelibros.erp.service; 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; @@ -12,6 +15,7 @@ import org.springframework.stereotype.Service; import com.imprimelibros.erp.config.Presupuestador.ImagenPresupuesto; import com.imprimelibros.erp.config.Presupuestador.PresupuestadorItems; import com.imprimelibros.erp.entity.Presupuesto; +import com.imprimelibros.erp.entity.Presupuesto.TipoCubierta; @Service public class PresupuestoService { @@ -92,8 +96,15 @@ public class PresupuestoService { List 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)); - opciones.add(this.presupuestadorItems.getPapelOffsetAhuesadoVolumen(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) { @@ -126,25 +137,38 @@ public class PresupuestoService { List 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) { - if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro || - presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) { - gramajes.add("80"); - } + gramajes.add("80"); gramajes.add("90"); - } else if (presupuesto.getPapelInteriorId() != null && presupuesto.getPapelInteriorId() == AHUESADO_OFFSET_ID) { + 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"); } - gramajes.add("150"); - gramajes.add("170"); + + } 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) { @@ -152,21 +176,31 @@ public class PresupuestoService { if (presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.negro || presupuesto.getTipoImpresion() == Presupuesto.TipoImpresion.color) { gramajes.add("70"); + gramajes.add("80"); } - 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) { + 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"); } - gramajes.add("135"); + 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 response = new HashMap<>(); @@ -190,21 +224,136 @@ public class PresupuestoService { 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; } + public Map obtenerOpcionesGramajeCubierta(Presupuesto presupuesto) { + + List 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 response = new HashMap<>(); + response.put("opciones_gramaje_cubierta", gramajes); + return response; + } + + + public Map toSkApiRequest(Presupuesto presupuesto) { + + final int SK_CLIENTE_ID = 1284; + final int SK_PAGINAS_CUADERNILLO = 32; + + Map tamanio = Map.of( + "ancho", presupuesto.getAncho(), + "alto", presupuesto.getAlto()); + Map interior = Map.of( + "papelInterior", presupuesto.getPapelInteriorId(), + "gramajeInterior", presupuesto.getGramajeInterior()); + Map 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 sobrecubierta = new HashMap<>(); + * sobrecubierta.put("papel", "2"); + * sobrecubierta.put("gramaje", 170); + * sobrecubierta.put("solapas", 80); + * sobrecubierta.put("acabado", null); + * + * Map servicios = Map.of( + * "retractilado", 0, + * "retractilado5", 0, + * "ferro", 0, + * "ferroDigital", 0, + * "marcapaginas", 0, + * "prototipo", 0); + */ + Map 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 + } + + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4addc83..dbf5c9a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,10 +4,14 @@ logging.level.org.springframework.security=DEBUG logging.level.root=WARN logging.level.org.springframework=ERROR -spring.datasource.url=jdbc:mysql://localhost:3306/imprimelibros +spring.datasource.url=jdbc:mysql://localhost:3309/imprimelibros spring.datasource.username=imprimelibros_user spring.datasource.password=om91irrDctd spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +safekat.api.url=http://localhost:8000/ +safekat.api.email=imnavajas@coit.es +safekat.api.password"=Safekat2024 + spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true \ No newline at end of file diff --git a/src/main/resources/i18n/presupuesto_es.properties b/src/main/resources/i18n/presupuesto_es.properties index fdfebfd..da4852a 100644 --- a/src/main/resources/i18n/presupuesto_es.properties +++ b/src/main/resources/i18n/presupuesto_es.properties @@ -48,6 +48,7 @@ presupuesto.blanco-negro-premium= Blanco y negro Premium presupuesto.color=Color presupuesto.color-premium=Color Premium presupuesto.offset-blanco=Offset Blanco +presupuesto.offset-blanco-volumen=Offset Blanco Volumen presupuesto.offset-ahuesado=Offset Ahuesado presupuesto.offset-ahuesado-volumen=Offset Ahuesado Volumen presupuesto.estucado-mate=Estucado Mate @@ -85,7 +86,8 @@ presupuesto.gramaje-cubierta=Gramaje cubierta presupuesto.gramaje-cubierta-descripcion=Seleccione el gramaje para la cubierta presupuesto.volver-interior=Volver a diseño interior presupuesto.continuar-extras-libro=Continuar a extras del libro - +presupuesto.offset=Offset +presupuesto.estucado=Estucado # Errores presupuesto.errores-title=Corrija los siguientes errores: diff --git a/src/main/resources/static/assets/css/presupuestador.css b/src/main/resources/static/assets/css/presupuestador.css index b9d3574..3db239a 100644 --- a/src/main/resources/static/assets/css/presupuestador.css +++ b/src/main/resources/static/assets/css/presupuestador.css @@ -92,4 +92,5 @@ .animate-fadeInUpBounce { animation: fadeInUpBounce 0.6s ease-out both; animation-delay: 0.1s; + will-change: transform; } \ No newline at end of file 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 3839fe6..09192ef 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 @@ -26,7 +26,7 @@ class PresupuestoCliente { interior: { tipoImpresion: 'negro', papelInteriorId: 3, - gramajeInterior: 9, + gramajeInterior: 80, }, cubierta: { tipoCubierta: 'tapaBlanda', @@ -86,6 +86,21 @@ class PresupuestoCliente { this.#initInterior(); this.#initCubierta(); + $(document).on('change', 'input[min][max]', function () { + const $input = $(this); + let valor = parseFloat($input.val()); + const min = parseFloat($input.attr('min')); + const max = parseFloat($input.attr('max')); + + if (isNaN(valor)) return; + + if (valor < min) { + $input.val(min); + } else if (valor > max) { + $input.val(max); + } + }); + const stored = sessionStorage.getItem("formData"); if (stored) { this.formData = JSON.parse(stored); @@ -114,6 +129,7 @@ class PresupuestoCliente { } #addGramaje(contenedor, gramaje, name) { + const id = `gramaje-${gramaje}`; // Crear input @@ -126,7 +142,7 @@ class PresupuestoCliente { // Crear label const label = document.createElement('label'); - label.className = 'btn btn-outline-primary material-shadow gramaje-radio'; + label.className = 'btn btn-outline-primary material-shadow gramaje-radio gramaje-interior'; label.setAttribute('for', id); label.textContent = gramaje; @@ -383,28 +399,109 @@ class PresupuestoCliente { this.#cacheFormData(); }); + + $(document).on('click', '.opcion-color', (e) => { + + const data = this.#getPresupuestoData(); + + this.divPapelInterior.empty(); + this.divGramajeInterior.empty(); + + this.divPapelInterior.removeClass('animate-fadeInUpBounce'); + this.divGramajeInterior.removeClass('animate-fadeInUpBounce'); + + $.ajax({ + url: '/presupuesto/public/get-papel-interior', + type: 'POST', + data: data, + success: (data) => { + + this.divPapelInterior.addClass('animate-fadeInUpBounce'); + this.divGramajeInterior.addClass('animate-fadeInUpBounce'); + + const opciones_papel_interior = data.opciones_papel_interior; + for (let i = 0; i < opciones_papel_interior.length; i++) { + const opcion = opciones_papel_interior[i]; + const item = new imagen_presupuesto(opcion); + item.extraClass = 'interior-data papel-interior'; + if (opcion.id === this.formData.interior.papelInteriorId) { + item.setSelected(true); + } + this.divPapelInterior.append(item.render()); + } + + const gramajes = data.opciones_gramaje_interior; + + const maxSolapas = data.solapas ?? 120; + $('.solapas-presupuesto').attr('max', maxSolapas); + $('.max-solapa-text').text(function (_, textoActual) { + return textoActual.replace(/\d+/, maxSolapas); + }); + + this.#addGramajesInterior(gramajes); + }, + error: (xhr, status, error) => { + + console.error("Error al obtener los papeles de interior: ", xhr.responseText); + } + }); + }); + $(document).on('click', '.papel-interior', (e) => { - this.divGramajeInterior.removeClass('animate-fadeInUpBounce'); - const data = this.#getPresupuestoData(); + + this.divGramajeInterior.removeClass('animate-fadeInUpBounce'); + this.divGramajeInterior.empty(); + $.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 maxSolapas = data.solapas ?? 120; + $('.solapas-presupuesto').attr('max', maxSolapas); + $('.max-solapa-text').text(function (_, textoActual) { + return textoActual.replace(/\d+/, maxSolapas); + }); + const dataInterior = this.#getInteriorData(); this.#updateInteriorData(dataInterior); this.#cacheFormData(); }).fail((xhr, status, error) => { + console.error("Error al obtener los gramajes de interior: ", xhr.responseText); + }); + }); + $(document).on('click', '.gramaje-interior', (e) => { + + const inputId = $(e.currentTarget).attr('for'); + const gramaje = parseInt($('#' + inputId).data('gramaje')); + this.formData.interior.gramajeInterior = gramaje; + this.#cacheFormData(); + + const data = this.#getPresupuestoData(); + + $.ajax({ + url: '/presupuesto/public/get-max-solapas', + type: 'POST', + data: data, + }).done((data) => { + + const maxSolapas = data.solapas ?? 120; + $('.solapas-presupuesto').attr('max', maxSolapas); + $('.max-solapa-text').text(function (_, textoActual) { + return textoActual.replace(/\d+/, maxSolapas); + }); + + }).fail((xhr, status, error) => { + console.error("Error al obtener los gramajes de interior: ", xhr.responseText); }); }); @@ -418,10 +515,15 @@ class PresupuestoCliente { type: 'POST', data: data, success: (data) => { - if( id === 'btn-prev-interior') { - + if (id === 'btn-prev-interior') { + this.#changeTab('pills-general-data'); } else { + const maxSolapas = data.solapas ?? 120; + $('.solapas-presupuesto').attr('max', maxSolapas); + $('.max-solapa-text').text(function (_, textoActual) { + return textoActual.replace(/\d+/, maxSolapas); + }); $('.tapa-cubierta.selected').trigger('click'); this.#changeTab('pills-cover'); } @@ -459,7 +561,7 @@ class PresupuestoCliente { for (let i = 0; i < opciones_color.length; i++) { const opcion = opciones_color[i]; const item = new imagen_presupuesto(opcion); - item.extraClass = 'interior-data'; + item.extraClass = 'interior-data opcion-color'; if ((this.formData.interior.color === '' && i === 0) || this.formData.interior.color === opcion.id) { item.setSelected(true); @@ -491,9 +593,9 @@ class PresupuestoCliente { this.#addGramaje(this.divGramajeInterior, gramaje, 'gramaje-interior'); // Seleccionar el gramaje por defecto - if (this.formData.interior.gramaje === '' && i === 0) { + if (this.formData.interior.gramajeInterior === '' && i === 0) { $(`#gramaje-${gramaje}`).prop('checked', true); - } else if (this.formData.interior.gramaje === gramaje) { + } else if (this.formData.interior.gramajeInterior == gramaje) { $(`#gramaje-${gramaje}`).prop('checked', true); } } @@ -507,11 +609,11 @@ class PresupuestoCliente { 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; + const gramajeInterior = $('input[name="gramaje-interior"]:checked').data('gramaje') || 90; return { tipoImpresion: tipoImpresion, papelInteriorId: papelInteriorId, - gramejeInterior: gramejeInterior + gramajeInterior: gramajeInterior }; } @@ -519,7 +621,7 @@ class PresupuestoCliente { this.formData.interior.tipoImpresion = data.tipoImpresion; this.formData.interior.papelInteriorId = data.papelInteriorId; - this.formData.interior.gramejeInterior = data.gramejeInterior; + this.formData.interior.gramajeInterior = data.gramajeInterior; } @@ -566,92 +668,147 @@ class PresupuestoCliente { $(document).on('click', '.tapa-cubierta', (e) => { + const prevTargetisTapaDura = !$('.tapa-dura-options').hasClass('d-none'); + $('.tapa-dura-options').eq(0).removeClass('animate-fadeInUpBounce'); $('.tapa-blanda-options').eq(0).removeClass('animate-fadeInUpBounce'); - - if(e.currentTarget.id === 'tapaBlanda') { + + if (e.currentTarget.id === 'tapaBlanda') { + $('.tapa-blanda-options').eq(0).addClass('animate-fadeInUpBounce'); $('.tapa-dura-options').addClass('d-none'); $('.tapa-blanda-options').removeClass('d-none'); - $('.tapa-blanda-options').eq(0).addClass('animate-fadeInUpBounce'); } - else{ + else { + $('.tapa-dura-options').eq(0).addClass('animate-fadeInUpBounce'); $('.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); - + if (!(e.currentTarget.id !== 'tapaBlanda' && prevTargetisTapaDura)) { + + this.#getPapelesCubierta(e.currentTarget.id); + } + }); + + $(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(); }); - $(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(); + $(document).on('click', '.papel-cubierta', (e) => { + + const data = this.#getPresupuestoData(); + + this.divGramajeCubierta.removeClass('animate-fadeInUpBounce'); + this.divGramajeCubierta.empty(); + + $.ajax({ + url: '/presupuesto/public/get-gramaje-cubierta', + type: 'POST', + data: data, + }).done((data) => { + + const gramajes = data.opciones_gramaje_cubierta; + this.#addGramajesCubierta(gramajes); + this.divGramajeCubierta.addClass('animate-fadeInUpBounce'); + + const dataCubierta = this.#getCubiertaData(); + this.#updateCubiertaData(dataCubierta); + this.#cacheFormData(); + + }).fail((xhr, status, error) => { + console.error("Error al obtener los gramajes de interior: ", xhr.responseText); + }); }); } #getPapelesCubierta(tapa_id) { - this.divPapelCubierta.removeClass('animate-fadeInUpBounce'); + new Promise((resolve) => { + this.divPapelCubierta.empty(); + this.divGramajeCubierta.empty(); + setTimeout(resolve, 250); + }).then(() => { + this.divPapelCubierta.removeClass('animate-fadeInUpBounce'); + this.divGramajeCubierta.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) => { + $.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.addClass('animate-fadeInUpBounce'); + this.divGramajeCubierta.addClass('animate-fadeInUpBounce'); - 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); + 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 (item.extraData["sk-id"] == this.formData.cubierta.papelCubiertaId) { + item.setSelected(true); + } + this.divPapelCubierta.append(item.render()); } - this.divPapelCubierta.append(item.render()); + + if (this.divPapelCubierta.find('.image-container.selected').length === 0) { + this.divPapelCubierta.find('.image-container').first().addClass('selected'); + this.formData.cubierta.papelCubiertaId = + this.divPapelCubierta.find('.image-container').first().data('sk-id') || 3; + } + + const gramajesCubierta = data.opciones_gramaje_cubierta; + for (let i = 0; i < gramajesCubierta.length; i++) { + const gramaje = gramajesCubierta[i]; + this.#addGramaje(this.divGramajeCubierta, gramaje, 'gramaje-cubierta'); + + if (this.formData.cubierta.gramajeCubierta === '' && i === 0) { + $(`#gramaje-${gramaje}`).prop('checked', true); + } else if (this.formData.cubierta.gramajeCubierta == gramaje) { + $(`#gramaje-${gramaje}`).prop('checked', true); + } + } + if (this.divGramajeCubierta.find('input[type="radio"]:checked').length === 0) { + this.divGramajeCubierta.find('input[type="radio"]').first().prop('checked', true); + } + + const dataToStore = this.#getCubiertaData(); + this.#updateCubiertaData(dataToStore); + this.#cacheFormData(); + }, + error: (xhr, status, error) => { + console.error("Error al obtener los papeles de cubierta: ", xhr.responseText); + $(window).scrollTop(0); } - - 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 tipoCubierta = $('.tapa-cubierta.selected').attr('id') || 'tapaBlanda'; + const solapas = $('.solapas-cubierta.selected').id == 'sin-solapas' ? 0 : 1 || 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; + const papelCubiertaId = $('#div-papel-cubierta .image-container.selected').data('sk-id') || 3; + const gramajeCubierta = $('input[name="gramaje-cubierta"]:checked').data('gramaje') || 240; return { tipoCubierta: tipoCubierta, @@ -680,6 +837,25 @@ class PresupuestoCliente { this.formData.cubierta.papelCubiertaId = data.papelCubiertaId; this.formData.cubierta.gramajeCubierta = data.gramajeCubierta; } + + #addGramajesCubierta(gramajes) { + + for (let i = 0; i < gramajes.length; i++) { + const gramaje = gramajes[i]; + this.#addGramaje(this.divGramajeCubierta, gramaje, 'gramaje-cubierta'); + + // Seleccionar el gramaje por defecto + if (this.formData.interior.gramajeCubierta === '' && i === 0) { + $(`#gramaje-${gramaje}`).prop('checked', true); + } else if (this.formData.interior.gramajeCubierta == gramaje) { + $(`#gramaje-${gramaje}`).prop('checked', true); + } + } + if (this.divGramajeCubierta.find('input[type="radio"]:checked').length === 0) { + // If not, select the first one by default + this.divGramajeCubierta.find('input[type="radio"]').first().prop('checked', true); + } + } /****************************** * 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 8a2f60a..02da709 100644 --- a/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_cubierta.html +++ b/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_cubierta.html @@ -29,7 +29,7 @@ -
+
-
+ +
+
+
-
- - -
+ +
+
+ + +
-
- - -
+
+ + +
+
+ +
+ +
+ +
+ + +
+
+ + +
+ + +
+

min: 60 mm

+

max: 120 mm

+
+
+
-
- -
- -
- -
- - - -
-
+ +
@@ -135,8 +160,8 @@
-
a - +
+
diff --git a/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_interior.html b/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_interior.html index 2fa0c72..0927bec 100644 --- a/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_interior.html +++ b/src/main/resources/templates/imprimelibros/presupuestos/presupuestador-items/_interior.html @@ -36,37 +36,6 @@
-
- - -
- -
- - -
- -
- - -
- -
- - -
@@ -83,32 +52,7 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - +
diff --git a/src/test/java/com/imprimelibros/erp/ErpApplicationTests.java b/src/test/java/com/imprimelibros/erp/ErpApplicationTests.java deleted file mode 100644 index d8a60bb..0000000 --- a/src/test/java/com/imprimelibros/erp/ErpApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.imprimelibros.erp; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ErpApplicationTests { - - @Test - void contextLoads() { - } - -}