trabajando en añadir

This commit is contained in:
2025-10-24 16:15:05 +02:00
parent 3517918afe
commit 2ed032d7c6
18 changed files with 1412 additions and 47 deletions

View File

@ -0,0 +1,225 @@
package com.imprimelibros.erp.direcciones;
import jakarta.persistence.*;
import java.io.Serializable;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import com.imprimelibros.erp.common.jpa.AbstractAuditedEntity;
import com.imprimelibros.erp.paises.Paises;
import com.imprimelibros.erp.users.User;
@Entity
@Table(name = "direcciones", indexes = {
@Index(name = "idx_direcciones_user", columnList = "user_id"),
@Index(name = "idx_direcciones_pais_code3", columnList = "pais_code3")
})
@SQLDelete(sql = "UPDATE direcciones SET deleted = 1, deleted_at = NOW(3) WHERE id = ?")
@SQLRestriction("deleted = 0")
public class Direccion extends AbstractAuditedEntity implements Serializable {
public enum TipoIdentificacionFiscal {
DNI("direcciones.dni"),
NIE("direcciones.nie"),
CIF("direcciones.cif"),
Pasaporte("direcciones.pasaporte"),
VAT_ID("direcciones.vat_id");
private String key;
TipoIdentificacionFiscal(String key) {
this.key = key;
}
public String getKey() {
return key;
}
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// --- FK a users(id)
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Column(name = "alias", length = 100, nullable = false)
private String alias;
@Column(name = "att", length = 150, nullable = false)
private String att;
@Column(name = "direccion", length = 255, nullable = false)
private String direccion;
@Column(name = "cp", length = 20, nullable = false)
private Integer cp;
@Column(name = "ciudad", length = 100, nullable = false)
private String ciudad;
@Column(name = "provincia", length = 100, nullable = false)
private String provincia;
// Usamos el code3 del país como FK lógica (String)
@Column(name = "pais_code3", length = 3, nullable = false)
private String paisCode3 = "esp";
@Column(name = "telefono", length = 30, nullable = false)
private String telefono;
@Column(name = "instrucciones", length = 255)
private String instrucciones;
@Column(name = "is_facturacion", nullable = false)
private boolean direccionFacturacion = false;
@Column(name = "razon_social", length = 150)
private String razonSocial;
@Enumerated(EnumType.STRING)
@Column(name = "tipo_identificacion_fiscal", length = 20, nullable = false)
private TipoIdentificacionFiscal tipoIdentificacionFiscal = TipoIdentificacionFiscal.DNI;
@Column(name = "identificacion_fiscal", length = 50)
private String identificacionFiscal;
// --- Asociación opcional (read-only) a Pais por code3, si tienes la entidad
// Pais
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pais_code3", referencedColumnName = "code3", insertable = false, updatable = false)
private Paises pais;
// --- Getters & Setters ---
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getAtt() {
return att;
}
public void setAtt(String att) {
this.att = att;
}
public String getDireccion() {
return direccion;
}
public void setDireccion(String direccion) {
this.direccion = direccion;
}
public Integer getCp() {
return cp;
}
public void setCp(Integer cp) {
this.cp = cp;
}
public String getCiudad() {
return ciudad;
}
public void setCiudad(String ciudad) {
this.ciudad = ciudad;
}
public String getProvincia() {
return provincia;
}
public void setProvincia(String provincia) {
this.provincia = provincia;
}
public String getPaisCode3() {
return paisCode3;
}
public void setPaisCode3(String paisCode3) {
this.paisCode3 = paisCode3;
}
public String getTelefono() {
return telefono;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
public String getInstrucciones() {
return instrucciones;
}
public void setInstrucciones(String instrucciones) {
this.instrucciones = instrucciones;
}
public boolean isDireccionFacturacion() {
return direccionFacturacion;
}
public void setDireccionFacturacion(boolean direccionFacturacion) {
this.direccionFacturacion = direccionFacturacion;
}
public String getRazonSocial() {
return razonSocial;
}
public void setRazonSocial(String razonSocial) {
this.razonSocial = razonSocial;
}
public TipoIdentificacionFiscal getTipoIdentificacionFiscal() {
return tipoIdentificacionFiscal;
}
public void setTipoIdentificacionFiscal(TipoIdentificacionFiscal tipo) {
this.tipoIdentificacionFiscal = tipo;
}
public String getIdentificacionFiscal() {
return identificacionFiscal;
}
public void setIdentificacionFiscal(String identificacionFiscal) {
this.identificacionFiscal = identificacionFiscal;
}
public Paises getPais() {
return pais;
}
public void setPais(Paises pais) {
this.pais = pais;
}
}