From d0ccfb56261165ef11954534d4b6102931a43974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sun, 8 Feb 2026 12:44:17 +0100 Subject: [PATCH] hehco --- .gitignore | 2 +- logs/erp.log | 29 ++++++ .../presupuesto/PresupuestoController.java | 96 +++++++++++++++++++ .../imprimelibros/presupuestador/wizard.js | 44 +++++++++ 4 files changed, 170 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 39e8316..27ce526 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,4 @@ build/ .vscode/ ### Logs ### -erp-*.log +erp*.log diff --git a/logs/erp.log b/logs/erp.log index 8a19c3f..d845ddb 100644 --- a/logs/erp.log +++ b/logs/erp.log @@ -404,3 +404,32 @@ java.net.ConnectException: Connection refused: connect at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:491) ~[tomcat-embed-core-10.1.50.jar:10.1.50] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) ~[tomcat-embed-core-10.1.50.jar:10.1.50] at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na] +2026-02-08 12:42:18 INFO [restartedMain] c.imprimelibros.erp.ErpApplication - Starting ErpApplication using Java 21.0.10 with PID 27948 (C:\Users\jjime\Documents\00_DESIGN_NOTEBOOK\PROGRAMMING\erp-imprimelibros\target\classes started by jjime in C:\Users\jjime\Documents\00_DESIGN_NOTEBOOK\PROGRAMMING\erp-imprimelibros) +2026-02-08 12:42:18 INFO [restartedMain] c.imprimelibros.erp.ErpApplication - The following 1 profile is active: "dev" +2026-02-08 12:42:22 INFO [restartedMain] com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting... +2026-02-08 12:42:23 INFO [restartedMain] com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@46a18c93 +2026-02-08 12:42:23 INFO [restartedMain] com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed. +2026-02-08 12:42:23 INFO [restartedMain] liquibase.changelog - Reading from imprimelibros.DATABASECHANGELOG +2026-02-08 12:42:24 INFO [restartedMain] liquibase.ui - Database is up to date, no changesets to execute +2026-02-08 12:42:24 INFO [restartedMain] liquibase.changelog - Reading from imprimelibros.DATABASECHANGELOG +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - UPDATE SUMMARY +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - Run: 0 +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - Previously run: 69 +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - Filtered out: 0 +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - ------------------------------- +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - Total change sets: 69 +2026-02-08 12:42:24 INFO [restartedMain] liquibase.util - Update summary generated +2026-02-08 12:42:24 INFO [restartedMain] liquibase.command - Command execution complete +2026-02-08 12:42:24 INFO [restartedMain] o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [name: default] +2026-02-08 12:42:24 INFO [restartedMain] org.hibernate.Version - HHH000412: Hibernate ORM core version 6.6.39.Final +2026-02-08 12:42:24 INFO [restartedMain] o.h.c.i.RegionFactoryInitiator - HHH000026: Second-level cache disabled +2026-02-08 12:42:24 INFO [restartedMain] o.hibernate.orm.connections.pooling - HHH10001005: Database info: + Database JDBC URL [Connecting through datasource 'HikariDataSource (HikariPool-1)'] + Database driver: undefined/unknown + Database version: 8.0.45 + Autocommit mode: undefined/unknown + Isolation level: undefined/unknown + Minimum pool size: undefined/unknown + Maximum pool size: undefined/unknown +2026-02-08 12:42:25 INFO [restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator - HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration) +2026-02-08 12:42:30 INFO [restartedMain] c.imprimelibros.erp.ErpApplication - Started ErpApplication in 11.753 seconds (process running for 12.682) diff --git a/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java b/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java index 66cd41b..2dfaefc 100644 --- a/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java +++ b/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java @@ -513,6 +513,102 @@ public class PresupuestoController { return ResponseEntity.ok(resumen); } + @PostMapping("/public/prepare-claim") + public ResponseEntity prepareClaim( + @RequestBody Map body, + HttpServletRequest request) { + + Long presupuestoId = objectMapper.convertValue(body.get("presupuestoId"), Long.class); + if (presupuestoId == null) { + return ResponseEntity.badRequest().body(Map.of("message", "missing presupuestoId")); + } + + Presupuesto p = presupuestoRepository.findById(presupuestoId).orElse(null); + if (p == null) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Map.of("message", "presupuesto not found")); + } + + if (p.getOrigen() != Presupuesto.Origen.publico) { + return ResponseEntity.badRequest().body(Map.of("message", "presupuesto not public")); + } + + request.getSession(true).setAttribute("presupuesto_claim_id", presupuestoId); + return ResponseEntity.ok(Map.of("success", true)); + } + + @GetMapping("/claim") + @Transactional + public String claimPresupuesto( + HttpServletRequest request, + Authentication authentication, + RedirectAttributes redirectAttributes, + Locale locale) { + + Object attr = request.getSession(false) != null + ? request.getSession(false).getAttribute("presupuesto_claim_id") + : null; + + Long presupuestoId = null; + if (attr instanceof Long) { + presupuestoId = (Long) attr; + } else if (attr != null) { + try { + presupuestoId = Long.valueOf(attr.toString()); + } catch (NumberFormatException ignore) { + } + } + + if (presupuestoId == null) { + redirectAttributes.addFlashAttribute("errorMessage", + messageSource.getMessage("presupuesto.errores.presupuesto-no-existe", new Object[] { 0 }, locale)); + return "redirect:/presupuesto"; + } + + Presupuesto p = presupuestoRepository.findById(presupuestoId).orElse(null); + if (p == null) { + redirectAttributes.addFlashAttribute("errorMessage", + messageSource.getMessage("presupuesto.errores.presupuesto-no-existe", + new Object[] { presupuestoId }, locale)); + return "redirect:/presupuesto"; + } + + if (p.getUser() != null && authentication != null) { + Long currentUserId = null; + if (authentication.getPrincipal() instanceof UserDetailsImpl udi) { + currentUserId = udi.getId(); + } else { + currentUserId = userRepo.findIdByUserNameIgnoreCase(authentication.getName()).orElse(null); + } + if (currentUserId != null && p.getUser().getId().equals(currentUserId)) { + request.getSession().removeAttribute("presupuesto_claim_id"); + return "redirect:/presupuesto/edit/" + p.getId(); + } + } + + if (p.getOrigen() != Presupuesto.Origen.publico) { + redirectAttributes.addFlashAttribute("errorMessage", + messageSource.getMessage("presupuesto.errores.presupuesto-no-existe", + new Object[] { presupuestoId }, locale)); + return "redirect:/presupuesto"; + } + + if (authentication != null) { + if (authentication.getPrincipal() instanceof UserDetailsImpl udi) { + p.setUser(userRepo.getReferenceById(udi.getId())); + } else { + userRepo.findByUserNameIgnoreCase(authentication.getName()).ifPresent(p::setUser); + } + } + + p.setOrigen(Presupuesto.Origen.privado); + p.setEstado(Presupuesto.Estado.borrador); + presupuestoRepository.saveAndFlush(p); + + request.getSession().removeAttribute("presupuesto_claim_id"); + return "redirect:/presupuesto/edit/" + p.getId(); + } + // ============================================= // MÉTODOS PARA USUARIOS AUTENTICADOS // ============================================= diff --git a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/wizard.js b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/wizard.js index 46dca29..026f2eb 100644 --- a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/wizard.js +++ b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestador/wizard.js @@ -318,6 +318,50 @@ export default class PresupuestoWizard { document.body.removeChild(a); }); + $(document) + .off('click.login-required', '.btn-login-required') + .on('click.login-required', '.btn-login-required', async (e) => { + e.preventDefault(); + + const rawId = this.opts.presupuestoId || window.PRESUPUESTO_ID || $('#presupuesto_id').val(); + const presupuestoId = rawId ? parseInt(rawId, 10) : null; + + if (!presupuestoId || Number.isNaN(presupuestoId)) { + Swal.fire({ + icon: 'error', + title: 'No se encontró el presupuesto', + text: 'Vuelve a generar el resumen e inténtalo de nuevo.', + buttonsStyling: false, + customClass: { + confirmButton: 'btn btn-secondary me-2', + cancelButton: 'btn btn-light' + }, + }); + return; + } + + try { + await $.ajax({ + url: '/presupuesto/public/prepare-claim', + type: 'POST', + contentType: 'application/json', + data: JSON.stringify({ presupuestoId }) + }); + window.location.assign('/presupuesto/claim'); + } catch (err) { + Swal.fire({ + icon: 'error', + title: 'No se pudo continuar', + text: 'Inténtalo de nuevo en unos segundos.', + buttonsStyling: false, + customClass: { + confirmButton: 'btn btn-secondary me-2', + cancelButton: 'btn btn-light' + }, + }); + } + }); + }