mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
terminando pedidos
This commit is contained in:
@ -69,4 +69,18 @@ public class PaisesService {
|
||||
}
|
||||
}
|
||||
|
||||
public String getPaisNombrePorCode3(String code3, Locale locale) {
|
||||
if (code3 == null || code3.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
Optional<Paises> opt = repo.findByCode3(code3);
|
||||
if (opt.isPresent()) {
|
||||
Paises pais = opt.get();
|
||||
String key = pais.getKeyword();
|
||||
return messageSource.getMessage("paises." + key, null, key, locale);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.imprimelibros.erp.pedidos;
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import com.imprimelibros.erp.direcciones.Direccion.TipoIdentificacionFiscal;
|
||||
import com.imprimelibros.erp.paises.Paises;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -50,6 +51,13 @@ public class PedidoDireccion {
|
||||
@Column(name = "pais_code3", nullable = false, length = 3)
|
||||
private String paisCode3 = "esp";
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "pais_code3", referencedColumnName = "code3", insertable = false, updatable = false)
|
||||
private Paises pais;
|
||||
|
||||
@Transient
|
||||
private String paisNombre;
|
||||
|
||||
@Column(name = "telefono", nullable = false, length = 30)
|
||||
private String telefono;
|
||||
|
||||
@ -164,6 +172,14 @@ public class PedidoDireccion {
|
||||
this.paisCode3 = paisCode3;
|
||||
}
|
||||
|
||||
public Paises getPais() {
|
||||
return pais;
|
||||
}
|
||||
|
||||
public void setPais(Paises pais) {
|
||||
this.pais = pais;
|
||||
}
|
||||
|
||||
public String getTelefono() {
|
||||
return telefono;
|
||||
}
|
||||
@ -207,5 +223,12 @@ public class PedidoDireccion {
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPaisNombre() {
|
||||
return paisNombre;
|
||||
}
|
||||
|
||||
public void setPaisNombre(String paisNombre) {
|
||||
this.paisNombre = paisNombre;
|
||||
}
|
||||
}
|
||||
@ -11,5 +11,7 @@ public interface PedidoDireccionRepository extends JpaRepository<PedidoDireccion
|
||||
|
||||
// Si en tu código sueles trabajar con el objeto:
|
||||
List<PedidoDireccion> findByPedidoLinea(PedidoLinea pedidoLinea);
|
||||
|
||||
PedidoDireccion findByPedidoIdAndFacturacionTrue(Long pedidoId);
|
||||
}
|
||||
|
||||
|
||||
@ -152,6 +152,14 @@ public class PedidoService {
|
||||
return resultados;
|
||||
}
|
||||
|
||||
public PedidoDireccion getDireccionFacturacionPedido(Long pedidoId) {
|
||||
return pedidoDireccionRepository.findByPedidoIdAndFacturacionTrue(pedidoId);
|
||||
}
|
||||
|
||||
public List<PedidoDireccion> getDireccionesEntregaPedidoLinea(Long pedidoLineaId) {
|
||||
return pedidoDireccionRepository.findByPedidoLinea_Id(pedidoLineaId);
|
||||
}
|
||||
|
||||
/***************************
|
||||
* MÉTODOS PRIVADOS
|
||||
***************************/
|
||||
@ -239,9 +247,9 @@ public class PedidoService {
|
||||
direccion.setUnidades((Integer) dir.getOrDefault("cantidad", 1));
|
||||
direccion.setEjemplarPrueba(false);
|
||||
}
|
||||
direccion.setFacturacion(false);
|
||||
}
|
||||
|
||||
direccion.setFacturacion(false);
|
||||
direccion.setAtt((String) dir.getOrDefault("att", ""));
|
||||
direccion.setDireccion((String) dir.getOrDefault("direccion", ""));
|
||||
direccion.setCp((Integer) dir.getOrDefault("cp", 0));
|
||||
|
||||
@ -20,6 +20,7 @@ import com.imprimelibros.erp.datatables.DataTable;
|
||||
import com.imprimelibros.erp.datatables.DataTablesParser;
|
||||
import com.imprimelibros.erp.datatables.DataTablesRequest;
|
||||
import com.imprimelibros.erp.datatables.DataTablesResponse;
|
||||
import com.imprimelibros.erp.paises.PaisesService;
|
||||
import com.imprimelibros.erp.users.UserDao;
|
||||
|
||||
import jakarta.persistence.criteria.Join;
|
||||
@ -37,14 +38,16 @@ public class PedidosController {
|
||||
private final UserDao repoUser;
|
||||
private final MessageSource messageSource;
|
||||
private final PedidoLineaRepository repoPedidoLinea;
|
||||
private final PaisesService paisesService;
|
||||
|
||||
public PedidosController(PedidoRepository repoPedido, PedidoService pedidoService, UserDao repoUser, MessageSource messageSource,
|
||||
PedidoLineaRepository repoPedidoLinea) {
|
||||
PedidoLineaRepository repoPedidoLinea, PaisesService paisesService) {
|
||||
this.repoPedido = repoPedido;
|
||||
this.pedidoService = pedidoService;
|
||||
this.repoUser = repoUser;
|
||||
this.messageSource = messageSource;
|
||||
this.repoPedidoLinea = repoPedidoLinea;
|
||||
this.paisesService = paisesService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ -177,7 +180,30 @@ public class PedidosController {
|
||||
} else {
|
||||
model.addAttribute("isAdmin", false);
|
||||
}
|
||||
|
||||
PedidoDireccion direccionFacturacion = pedidoService.getDireccionFacturacionPedido(id);
|
||||
if(direccionFacturacion != null){
|
||||
String paisNombre = paisesService.getPaisNombrePorCode3(direccionFacturacion.getPaisCode3(), locale);
|
||||
direccionFacturacion.setPaisNombre(paisNombre);
|
||||
}
|
||||
|
||||
model.addAttribute("direccionFacturacion", direccionFacturacion);
|
||||
|
||||
List<Map<String, Object>> lineas = pedidoService.getLineas(id, locale);
|
||||
for (Map<String, Object> linea : lineas) {
|
||||
List<PedidoDireccion> dirEntrega = pedidoService.getDireccionesEntregaPedidoLinea(
|
||||
((Number) linea.get("lineaId")).longValue()
|
||||
);
|
||||
|
||||
if (dirEntrega != null && !dirEntrega.isEmpty()) {
|
||||
for (PedidoDireccion direccion : dirEntrega) {
|
||||
String paisNombre = paisesService.getPaisNombrePorCode3(direccion.getPaisCode3(), locale);
|
||||
direccion.setPaisNombre(paisNombre);
|
||||
}
|
||||
}
|
||||
linea.put("direccionesEntrega", dirEntrega);
|
||||
|
||||
}
|
||||
model.addAttribute("lineas", lineas);
|
||||
model.addAttribute("id", id);
|
||||
return "imprimelibros/pedidos/pedidos-view";
|
||||
|
||||
Reference in New Issue
Block a user