mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
terminado
This commit is contained in:
@ -576,6 +576,42 @@ public class skApiClient {
|
||||
return Boolean.parseBoolean(result);
|
||||
}
|
||||
|
||||
|
||||
public Boolean cancelarPedido(Long pedidoId) {
|
||||
|
||||
String result = performWithRetry(() -> {
|
||||
String url = this.skApiUrl + "api/cancelar-pedido/" + pedidoId;
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(authService.getToken());
|
||||
|
||||
HttpEntity<Void> entity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
url,
|
||||
HttpMethod.POST,
|
||||
entity,
|
||||
String.class);
|
||||
|
||||
try {
|
||||
Map<String, Object> responseBody = new ObjectMapper().readValue(
|
||||
response.getBody(),
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
Boolean success = (Boolean) (responseBody.get("success") != null ? responseBody.get("success") : false);
|
||||
|
||||
return success.toString();
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return "false"; // Fallback en caso de error
|
||||
}
|
||||
});
|
||||
return Boolean.parseBoolean(result);
|
||||
}
|
||||
|
||||
/******************
|
||||
* PRIVATE METHODS
|
||||
******************/
|
||||
|
||||
@ -355,9 +355,35 @@ public class PedidoService {
|
||||
pedidoLineaRepository.save(pedidoLinea);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Boolean cancelarPedido(Long pedidoId) {
|
||||
|
||||
Pedido pedido = pedidoRepository.findById(pedidoId).orElse(null);
|
||||
if (pedido == null) {
|
||||
return false;
|
||||
}
|
||||
Boolean result = skApiClient.cancelarPedido(Long.valueOf(pedido.getProveedorRef()));
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
List<PedidoLinea> lineas = pedidoLineaRepository.findByPedidoId(pedidoId);
|
||||
for (PedidoLinea linea : lineas) {
|
||||
if (linea.getEstado() != PedidoLinea.Estado.terminado) {
|
||||
linea.setEstado(PedidoLinea.Estado.cancelado);
|
||||
pedidoLineaRepository.save(linea);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************
|
||||
* MÉTODOS PRIVADOS
|
||||
***************************/
|
||||
|
||||
private byte[] downloadFile(Long pedidoLineaId, String fileType, Locale locale) {
|
||||
PedidoLinea pedidoLinea = pedidoLineaRepository.findById(pedidoLineaId).orElse(null);
|
||||
if (pedidoLinea == null) {
|
||||
|
||||
@ -211,6 +211,15 @@ public class PedidosController {
|
||||
@PathVariable(name = "id", required = true) Long id,
|
||||
Model model, Locale locale) {
|
||||
|
||||
List<String> keys = List.of(
|
||||
"app.cancelar",
|
||||
"app.yes",
|
||||
"pedido.view.cancel-title",
|
||||
"pedido.view.cancel-text");
|
||||
|
||||
Map<String, String> translations = translationService.getTranslations(locale, keys);
|
||||
model.addAttribute("languageBundle", translations);
|
||||
|
||||
Boolean isAdmin = Utils.isCurrentUserAdmin();
|
||||
if (isAdmin) {
|
||||
model.addAttribute("isAdmin", true);
|
||||
@ -226,6 +235,7 @@ public class PedidosController {
|
||||
|
||||
model.addAttribute("direccionFacturacion", direccionFacturacion);
|
||||
|
||||
Boolean showCancel = false;
|
||||
List<Map<String, Object>> lineas = pedidoService.getLineas(id, locale);
|
||||
for (Map<String, Object> linea : lineas) {
|
||||
|
||||
@ -252,6 +262,10 @@ public class PedidosController {
|
||||
}
|
||||
linea.put("buttons", buttons);
|
||||
}
|
||||
|
||||
if(pedidoLinea.getEstado() != PedidoLinea.Estado.cancelado && pedidoLinea.getEstado() != PedidoLinea.Estado.terminado) {
|
||||
showCancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
List<PedidoDireccion> dirEntrega = pedidoService.getDireccionesEntregaPedidoLinea(
|
||||
@ -267,10 +281,30 @@ public class PedidosController {
|
||||
|
||||
}
|
||||
model.addAttribute("lineas", lineas);
|
||||
model.addAttribute("showCancel", showCancel);
|
||||
model.addAttribute("id", id);
|
||||
return "imprimelibros/pedidos/pedidos-view";
|
||||
}
|
||||
|
||||
@PostMapping("/cancel/{id}")
|
||||
@ResponseBody
|
||||
public Map<String, Object> cancelPedido(
|
||||
@PathVariable(name = "id", required = true) Long id,
|
||||
Locale locale) {
|
||||
Boolean result = pedidoService.cancelarPedido(id);
|
||||
if (result) {
|
||||
String successMsg = messageSource.getMessage("pedido.success.pedido-cancelado", null, locale);
|
||||
return Map.of(
|
||||
"success", true,
|
||||
"message", successMsg);
|
||||
} else {
|
||||
String errorMsg = messageSource.getMessage("pedido.errors.cancel-pedido", null, locale);
|
||||
return Map.of(
|
||||
"success", false,
|
||||
"message", errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Acciones sobre las lineas de pedido
|
||||
// -------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user