mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
trabajando en el wizard del presupuesto
This commit is contained in:
@ -5,6 +5,7 @@ import org.springframework.ui.Model;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -16,15 +17,17 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import com.imprimelibros.erp.configurationERP.VariableService;
|
||||
import com.imprimelibros.erp.datatables.*;
|
||||
import com.imprimelibros.erp.externalApi.skApiClient;
|
||||
import com.imprimelibros.erp.i18n.TranslationService;
|
||||
@ -41,6 +44,8 @@ import jakarta.validation.Valid;
|
||||
@RequestMapping("/presupuesto")
|
||||
public class PresupuestoController {
|
||||
|
||||
private final PresupuestoRepository presupuestoRepository;
|
||||
|
||||
@Autowired
|
||||
protected PresupuestoService presupuestoService;
|
||||
|
||||
@ -53,12 +58,16 @@ public class PresupuestoController {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final TranslationService translationService;
|
||||
private final PresupuestoDatatableService dtService;
|
||||
private final VariableService variableService;
|
||||
|
||||
public PresupuestoController(ObjectMapper objectMapper, TranslationService translationService,
|
||||
PresupuestoDatatableService dtService) {
|
||||
PresupuestoDatatableService dtService, PresupuestoRepository presupuestoRepository,
|
||||
VariableService variableService) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.translationService = translationService;
|
||||
this.dtService = dtService;
|
||||
this.presupuestoRepository = presupuestoRepository;
|
||||
this.variableService = variableService;
|
||||
}
|
||||
|
||||
@PostMapping("/public/validar/datos-generales")
|
||||
@ -421,7 +430,7 @@ public class PresupuestoController {
|
||||
// MÉTODOS PARA USUARIOS AUTENTICADOS
|
||||
// =============================================
|
||||
@GetMapping
|
||||
public String getPresupuestoView(Model model, Authentication authentication, Locale locale) {
|
||||
public String getPresupuestoList(Model model, Authentication authentication, Locale locale) {
|
||||
|
||||
List<String> keys = List.of();
|
||||
|
||||
@ -431,9 +440,55 @@ public class PresupuestoController {
|
||||
return "imprimelibros/presupuestos/presupuesto-list";
|
||||
}
|
||||
|
||||
@GetMapping(value = { "/edit/{id}", "/view/{id}" })
|
||||
public String getPresupuestoEditForm(
|
||||
@PathVariable(name = "id", required = true) Long id,
|
||||
RedirectAttributes redirectAttributes,
|
||||
Model model,
|
||||
Authentication authentication,
|
||||
Locale locale) {
|
||||
|
||||
List<String> keys = List.of(
|
||||
"presupuesto.plantilla-cubierta",
|
||||
"presupuesto.plantilla-cubierta-text",
|
||||
"presupuesto.impresion-cubierta",
|
||||
"presupuesto.impresion-cubierta-help");
|
||||
|
||||
Map<String, String> translations = translationService.getTranslations(locale, keys);
|
||||
model.addAttribute("languageBundle", translations);
|
||||
model.addAttribute("pod", variableService.getValorEntero("POD"));
|
||||
model.addAttribute("ancho_alto_min", variableService.getValorEntero("ancho_alto_min"));
|
||||
model.addAttribute("ancho_alto_max", variableService.getValorEntero("ancho_alto_max"));
|
||||
|
||||
// Buscar el presupuesto
|
||||
Optional<Presupuesto> presupuestoOpt = presupuestoRepository.findById(id);
|
||||
boolean isUser = authentication.getAuthorities().stream()
|
||||
.anyMatch(a -> a.getAuthority().equals("ROLE_USER"));
|
||||
|
||||
if (isUser) {
|
||||
// Si es usuario, solo puede ver sus propios presupuestos
|
||||
String username = authentication.getName();
|
||||
if (!presupuestoOpt.get().getUser().getUserName().equals(username)) {
|
||||
presupuestoOpt = Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
if (presupuestoOpt.isEmpty()) {
|
||||
// Añadir mensaje flash para mostrar alerta
|
||||
redirectAttributes.addFlashAttribute("errorMessage",
|
||||
messageSource.getMessage("presupuesto.errores.presupuesto-no-existe", new Object[] { id }, locale));
|
||||
// Redirigir a la vista de lista
|
||||
return "redirect:/presupuesto";
|
||||
}
|
||||
|
||||
// Si existe, lo añadimos al modelo
|
||||
model.addAttribute("presupuesto", presupuestoOpt.get());
|
||||
return "imprimelibros/presupuestos/presupuesto-form";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/datatable/anonimos", produces = "application/json")
|
||||
@ResponseBody
|
||||
public DataTablesResponse<Map<String,Object>> datatableAnonimos(
|
||||
public DataTablesResponse<Map<String, Object>> datatableAnonimos(
|
||||
HttpServletRequest request, Authentication auth, Locale locale) {
|
||||
|
||||
DataTablesRequest dt = DataTablesParser.from(request);
|
||||
|
||||
@ -177,7 +177,7 @@ public class PresupuestoDatatableService {
|
||||
m.put("actions",
|
||||
"<div class=\"hstack gap-3 flex-wrap\">" +
|
||||
"<a href=\"javascript:void(0);\" data-id=\"" + p.getId()
|
||||
+ "\" class=\"link-success btn-edit-anonimo fs-15\"><i class=\"ri-edit-2-line\"></i></a>" +
|
||||
+ "\" class=\"link-success btn-edit-anonimo fs-15\"><i class=\"ri-eye-line\"></i></a>" +
|
||||
"<a href=\"javascript:void(0);\" data-id=\"" + p.getId()
|
||||
+ "\" class=\"link-danger btn-delete-anonimo fs-15\"><i class=\"ri-delete-bin-5-line\"></i></a>"
|
||||
+
|
||||
|
||||
Reference in New Issue
Block a user