package com.imprimelibros.erp.facturacion.dto; import java.time.Instant; import com.imprimelibros.erp.facturacion.FacturaDireccion; import com.imprimelibros.erp.pedidos.PedidoDireccion; public class DireccionFacturacionDto { private String razonSocial; private String identificacionFiscal; private String direccion; private String cp; private String ciudad; private String provincia; private String paisKeyword; private String telefono; public String getRazonSocial() { return razonSocial; } public void setRazonSocial(String razonSocial) { this.razonSocial = razonSocial; } public String getIdentificacionFiscal() { return identificacionFiscal; } public void setIdentificacionFiscal(String identificacionFiscal) { this.identificacionFiscal = identificacionFiscal; } public String getDireccion() { return direccion; } public void setDireccion(String direccion) { this.direccion = direccion; } public String getCp() { return cp; } public void setCp(String 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 getPaisKeyword() { return paisKeyword; } public void setPaisKeyword(String paisKeyword) { this.paisKeyword = paisKeyword; } public String getTelefono() { return telefono; } public void setTelefono(String telefono) { this.telefono = telefono; } public FacturaDireccion toFacturaDireccion() { FacturaDireccion fd = new FacturaDireccion(); applyTo(fd); return fd; } public PedidoDireccion toPedidoDireccion() { PedidoDireccion pd = new PedidoDireccion(); applyTo(pd); pd.setFacturacion(true); return pd; } public void applyTo(PedidoDireccion pd) { pd.setAtt(""); pd.setRazonSocial(this.razonSocial); pd.setIdentificacionFiscal(this.identificacionFiscal); pd.setDireccion(this.direccion); // CP robusto Integer cpInt = null; if (this.cp != null && !this.cp.isBlank()) { try { cpInt = Integer.valueOf(this.cp.trim()); } catch (NumberFormatException ignored) { // si quieres, lanza IllegalArgumentException para validarlo } } pd.setCp(cpInt); pd.setCiudad(this.ciudad); pd.setProvincia(this.provincia); pd.setPaisCode3(this.paisKeyword); pd.setTelefono(this.telefono); } public void applyTo(FacturaDireccion fd ) { fd.setAtt(""); fd.setRazonSocial(this.razonSocial); fd.setIdentificacionFiscal(this.identificacionFiscal); fd.setDireccion(this.direccion); // CP robusto Integer cpInt = null; if (this.cp != null && !this.cp.isBlank()) { try { cpInt = Integer.valueOf(this.cp.trim()); } catch (NumberFormatException ignored) { // si quieres, lanza IllegalArgumentException para validarlo } } fd.setCp(cpInt); fd.setCiudad(this.ciudad); fd.setProvincia(this.provincia); fd.setPaisCode3(this.paisKeyword); fd.setTelefono(this.telefono); fd.setCreatedAt(Instant.now()); } }