mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
terminado
This commit is contained in:
@ -16,6 +16,7 @@ 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.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
@ -27,6 +28,8 @@ import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestoMaquetacion;
|
||||
import com.imprimelibros.erp.presupuesto.validation.PresupuestoValidationGroups;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/presupuesto")
|
||||
public class PresupuestoController {
|
||||
@ -93,7 +96,7 @@ public class PresupuestoController {
|
||||
@PostMapping("/public/validar/cubierta")
|
||||
public ResponseEntity<?> validarCubierta(
|
||||
@Validated(PresupuestoValidationGroups.Cubierta.class) Presupuesto presupuesto,
|
||||
BindingResult result,
|
||||
BindingResult result,
|
||||
@RequestParam(name = "calcular", defaultValue = "true") boolean calcular,
|
||||
Locale locale) {
|
||||
|
||||
@ -150,6 +153,9 @@ public class PresupuestoController {
|
||||
Map<String, Object> resultado = new HashMap<>();
|
||||
// servicios extra
|
||||
resultado.putAll(presupuestoService.obtenerServiciosExtras(presupuesto, locale, apiClient));
|
||||
Map<String, String> language = new HashMap<>();
|
||||
language.put("calcular", messageSource.getMessage("presupuesto.calcular", null, locale));
|
||||
resultado.put("language", language);
|
||||
|
||||
return ResponseEntity.ok(resultado);
|
||||
}
|
||||
@ -307,23 +313,35 @@ public class PresupuestoController {
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value="/public/maquetacion/form", produces = MediaType.TEXT_HTML_VALUE)
|
||||
@GetMapping(value = "/public/maquetacion/form", produces = MediaType.TEXT_HTML_VALUE)
|
||||
public String getMaquetacionForm(Model model) {
|
||||
model.addAttribute("presupuestoMaquetacion", new PresupuestoMaquetacion());
|
||||
return "imprimelibros/presupuestos/presupuesto-maquetacion-form :: maquetacionForm";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/public/maquetacion")
|
||||
public ResponseEntity<?> getPresupuestoMaquetacion(
|
||||
PresupuestoMaquetacion presupuestoMaquetacion,
|
||||
Model model, Locale locale) {
|
||||
Map<String, Object> resultado = presupuestoService.getPrecioMaquetacion(presupuestoMaquetacion);
|
||||
if((Double)resultado.get("precio") == 0.0 && (Integer)resultado.get("numPaginasEstimadas") == 0
|
||||
&& (Double)resultado.get("precioPaginaEstimado") == 0.0){
|
||||
return ResponseEntity.badRequest().body(messageSource.getMessage("presupuesto.errores.presupuesto-maquetacion", null, locale));
|
||||
}
|
||||
return ResponseEntity.ok(resultado);
|
||||
@Valid @ModelAttribute PresupuestoMaquetacion presupuestoMaquetacion,
|
||||
BindingResult result,
|
||||
Locale locale) {
|
||||
|
||||
if (result.hasErrors()) {
|
||||
// Construimos un mapa field -> mensaje para tu AJAX
|
||||
Map<String, String> errores = result.getFieldErrors().stream()
|
||||
.collect(java.util.stream.Collectors.toMap(
|
||||
fe -> fe.getField(),
|
||||
fe -> fe.getDefaultMessage(),
|
||||
(a, b) -> a));
|
||||
return ResponseEntity.badRequest().body(errores);
|
||||
}
|
||||
|
||||
Map<String, Object> resultado = presupuestoService.getPrecioMaquetacion(presupuestoMaquetacion, locale);
|
||||
if ((Double) resultado.get("precio") == 0.0 && (Integer) resultado.get("numPaginasEstimadas") == 0
|
||||
&& (Double) resultado.get("precioPaginaEstimado") == 0.0) {
|
||||
return ResponseEntity.badRequest()
|
||||
.body(messageSource.getMessage("presupuesto.errores.presupuesto-maquetacion", null, locale));
|
||||
}
|
||||
return ResponseEntity.ok(resultado);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user