mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
terminado a falta de pruebas en servidor
This commit is contained in:
@ -445,6 +445,7 @@ public class CartService {
|
||||
cartDireccionRepo.deleteByDireccionIdAndCartStatus(direccionId, Cart.Status.ACTIVE);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public Long crearPedido(Long cartId, Locale locale) {
|
||||
|
||||
@ -456,21 +457,25 @@ public class CartService {
|
||||
|
||||
for (Integer i = 0; i < items.size(); i++) {
|
||||
CartItem item = items.get(i);
|
||||
Presupuesto p = item.getPresupuesto();
|
||||
Presupuesto pCart = item.getPresupuesto();
|
||||
|
||||
// Asegurarnos de trabajar con la entidad gestionada por JPA
|
||||
Presupuesto p = presupuestoRepo.findById(pCart.getId())
|
||||
.orElseThrow(() -> new IllegalStateException("Presupuesto no encontrado: " + pCart.getId()));
|
||||
|
||||
Map<String, Object> data_to_send = presupuestoService.toSkApiRequest(p, true);
|
||||
data_to_send.put("createPedido", 0);
|
||||
if (items.size() > 1) {
|
||||
// Recuperar el mapa anidado datosCabecera
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> datosCabecera = (Map<String, Object>) data_to_send.get("datosCabecera");
|
||||
if (datosCabecera != null) {
|
||||
Object tituloOriginal = datosCabecera.get("titulo");
|
||||
datosCabecera.put(
|
||||
"titulo",
|
||||
"[" + (i + 1) + "/" + items.size() + "] " + (tituloOriginal != null ? tituloOriginal : ""));
|
||||
}
|
||||
|
||||
// Recuperar el mapa anidado datosCabecera
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> datosCabecera = (Map<String, Object>) data_to_send.get("datosCabecera");
|
||||
if (datosCabecera != null) {
|
||||
Object tituloOriginal = datosCabecera.get("titulo");
|
||||
datosCabecera.put(
|
||||
"titulo",
|
||||
"[" + (i + 1) + "/" + items.size() + "] " + (tituloOriginal != null ? tituloOriginal : ""));
|
||||
}
|
||||
|
||||
Map<String, Object> direcciones_presupuesto = this.getDireccionesPresupuesto(cart, p);
|
||||
data_to_send.put("direcciones", direcciones_presupuesto.get("direcciones"));
|
||||
data_to_send.put("direccionesFP1", direcciones_presupuesto.get("direccionesFP1"));
|
||||
@ -530,11 +535,8 @@ public class CartService {
|
||||
|
||||
List<Map<String, Object>> direccionesPresupuesto = new ArrayList<>();
|
||||
List<Map<String, Object>> direccionesPrueba = new ArrayList<>();
|
||||
List<CartDireccion> direcciones = cart.getDirecciones().stream()
|
||||
.filter(d -> d.getPresupuesto() != null && d.getPresupuesto().getId().equals(presupuesto.getId()))
|
||||
.toList();
|
||||
if (cart.getOnlyOneShipment()) {
|
||||
direcciones = direcciones.stream().limit(1).toList();
|
||||
List<CartDireccion> direcciones = cart.getDirecciones().stream().limit(1).toList();
|
||||
if (!direcciones.isEmpty()) {
|
||||
direccionesPresupuesto.add(direcciones.get(0).toSkMap(
|
||||
presupuesto.getSelectedTirada(),
|
||||
@ -555,11 +557,19 @@ public class CartService {
|
||||
}
|
||||
Map<String, Object> direccionesRet = new HashMap<>();
|
||||
direccionesRet.put("direcciones", direccionesPresupuesto);
|
||||
direccionesRet.put("direccionesFP1", direccionesPrueba.get(0));
|
||||
if (!direccionesPrueba.isEmpty())
|
||||
direccionesRet.put("direccionesFP1", direccionesPrueba.get(0));
|
||||
else {
|
||||
direccionesRet.put("direccionesFP1", new ArrayList<>());
|
||||
}
|
||||
return direccionesRet;
|
||||
}
|
||||
} else {
|
||||
for (CartDireccion cd : cart.getDirecciones()) {
|
||||
List<CartDireccion> direcciones = cart.getDirecciones().stream()
|
||||
.filter(d -> d.getPresupuesto() != null && d.getPresupuesto().getId().equals(presupuesto.getId()))
|
||||
.toList();
|
||||
|
||||
for (CartDireccion cd : direcciones) {
|
||||
|
||||
// direccion de ejemplar de prueba
|
||||
if (cd.getPresupuesto() == null || !cd.getPresupuesto().getId().equals(presupuesto.getId())) {
|
||||
|
||||
@ -457,6 +457,7 @@ public class PaymentService {
|
||||
* - crea el pedido a partir del carrito
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
private Boolean processOrder(Long cartId, Locale locale) {
|
||||
|
||||
Cart cart = this.cartService.findById(cartId);
|
||||
|
||||
@ -315,16 +315,28 @@ public class PresupuestoService {
|
||||
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("tipo_impresion_id", this.getTipoImpresionId(presupuesto));
|
||||
if (toSave) {
|
||||
Boolean hasDepositoLegal = false;
|
||||
if (presupuesto.getServiciosJson() != null
|
||||
&& presupuesto.getServiciosJson().contains("deposito-legal")) {
|
||||
hasDepositoLegal = true;
|
||||
}
|
||||
|
||||
if (toSave && hasDepositoLegal) {
|
||||
body.put("tirada", Arrays.stream(presupuesto.getTiradas())
|
||||
.filter(Objects::nonNull)
|
||||
.map(tirada -> tirada + 4)
|
||||
.collect(Collectors.toList()));
|
||||
if(presupuesto.getSelectedTirada() != null) {
|
||||
presupuesto.setSelectedTirada(presupuesto.getSelectedTirada());
|
||||
}
|
||||
} else {
|
||||
body.put("tirada", Arrays.stream(presupuesto.getTiradas())
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
body.put("selectedTirada",
|
||||
presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : presupuesto.getTirada1());
|
||||
body.put("tamanio", tamanio);
|
||||
body.put("tipo", presupuesto.getTipoEncuadernacion());
|
||||
body.put("clienteId", SK_CLIENTE_ID);
|
||||
@ -356,6 +368,7 @@ public class PresupuestoService {
|
||||
}
|
||||
|
||||
if (toSave) {
|
||||
Map<String, Object> servicios = new HashMap<>();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("input_data", body);
|
||||
data.put("ferroDigital", 1);
|
||||
@ -365,11 +378,13 @@ public class PresupuestoService {
|
||||
if (presupuesto.getServiciosJson() != null
|
||||
&& presupuesto.getServiciosJson().indexOf("ejemplar-prueba") > 0) {
|
||||
data.put("prototipo", 1);
|
||||
servicios.put("prototipo", "1");
|
||||
} else {
|
||||
data.put("prototipo", 0);
|
||||
}
|
||||
if (presupuesto.getServiciosJson() != null && presupuesto.getServiciosJson().indexOf("retractilado") > 0) {
|
||||
data.put("retractilado", 1);
|
||||
servicios.put("retractilado", "1");
|
||||
} else {
|
||||
data.put("retractilado", 0);
|
||||
}
|
||||
@ -382,6 +397,7 @@ public class PresupuestoService {
|
||||
datosCabecera.put("coleccion", "");
|
||||
datosCabecera.put("referenciaCliente", presupuesto.getId());
|
||||
data.put("datosCabecera", datosCabecera);
|
||||
body.put("servicios", servicios);
|
||||
return data;
|
||||
|
||||
}
|
||||
@ -1099,10 +1115,14 @@ public class PresupuestoService {
|
||||
try {
|
||||
// retractilado: recalcular precio
|
||||
if (s.get("id").equals("retractilado")) {
|
||||
double precio_retractilado = obtenerPrecioRetractilado(cantidad) != null
|
||||
? Double.parseDouble(obtenerPrecioRetractilado(cantidad))
|
||||
: 0.0;
|
||||
s.put("price", precio_retractilado);
|
||||
|
||||
String p = obtenerPrecioRetractilado(cantidad);
|
||||
if(p != null){
|
||||
double precio_retractilado = Double.parseDouble(p);
|
||||
s.put("price", precio_retractilado);
|
||||
} else {
|
||||
s.put("price", 0.0);
|
||||
}
|
||||
}
|
||||
// si tiene protitipo, guardamos el valor para el IVA al 4%
|
||||
else if (s.get("id").equals("ejemplar-prueba")) {
|
||||
@ -1120,7 +1140,8 @@ public class PresupuestoService {
|
||||
}
|
||||
}
|
||||
try {
|
||||
presupuesto.setServiciosJson(new ObjectMapper().writeValueAsString(servicios));
|
||||
if(presupuesto.getSelectedTirada() != null && presupuesto.getSelectedTirada().equals(tirada))
|
||||
presupuesto.setServiciosJson(new ObjectMapper().writeValueAsString(servicios));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user