mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-08 11:59:13 +00:00
153 lines
4.5 KiB
Java
153 lines
4.5 KiB
Java
package com.imprimelibros.erp.cart;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.context.MessageSource;
|
|
import com.imprimelibros.erp.cart.dto.DireccionCardDTO;
|
|
import com.imprimelibros.erp.direcciones.Direccion;
|
|
import com.imprimelibros.erp.presupuesto.dto.Presupuesto;
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
@Entity
|
|
@Table(name = "cart_direcciones")
|
|
public class CartDireccion {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "cart_id", nullable = false)
|
|
private Cart cart;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "direccion_id", nullable = false)
|
|
private Direccion direccion;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "presupuesto_id")
|
|
private Presupuesto presupuesto;
|
|
|
|
@Column(name = "unidades")
|
|
private Integer unidades;
|
|
|
|
@Column(name = "isPalets", nullable = false)
|
|
private Boolean isPalets;
|
|
|
|
// --- Getters & Setters ---
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public Cart getCart() {
|
|
return cart;
|
|
}
|
|
|
|
public void setCart(Cart cart) {
|
|
this.cart = cart;
|
|
}
|
|
|
|
public Direccion getDireccion() {
|
|
return direccion;
|
|
}
|
|
|
|
public void setDireccion(Direccion direccion) {
|
|
this.direccion = direccion;
|
|
}
|
|
|
|
public Presupuesto getPresupuesto() {
|
|
return presupuesto;
|
|
}
|
|
|
|
public void setPresupuesto(Presupuesto presupuesto) {
|
|
this.presupuesto = presupuesto;
|
|
}
|
|
|
|
public Integer getUnidades() {
|
|
return unidades;
|
|
}
|
|
|
|
public void setUnidades(Integer unidades) {
|
|
this.unidades = unidades;
|
|
}
|
|
|
|
public Boolean getIsPalets() {
|
|
return isPalets;
|
|
}
|
|
|
|
public void setIsPalets(Boolean isPalets) {
|
|
this.isPalets = isPalets;
|
|
}
|
|
|
|
public DireccionCardDTO toDireccionCard(MessageSource messageSource, Locale locale) {
|
|
|
|
String pais = messageSource.getMessage("paises." + this.direccion.getPais().getKeyword(), null,
|
|
this.direccion.getPais().getKeyword(), locale);
|
|
|
|
return new DireccionCardDTO(
|
|
this.direccion,
|
|
this.presupuesto != null ? this.presupuesto.getId() : null,
|
|
this.unidades,
|
|
this.isPalets,
|
|
pais
|
|
);
|
|
}
|
|
|
|
public Map<String, Object> toSkMap(Integer numeroUnidades, Double pesoKg, Boolean palets, Boolean ejemplarPrueba) {
|
|
|
|
Map<String, Object> direccion = new HashMap<>();
|
|
direccion.put("cantidad", numeroUnidades);
|
|
direccion.put("peso", pesoKg);
|
|
direccion.put("att", this.getDireccion().getAtt());
|
|
direccion.put("email", this.getDireccion().getUser().getUserName());
|
|
direccion.put("direccion", this.getDireccion().getDireccion());
|
|
direccion.put("pais_code3", this.getDireccion().getPaisCode3());
|
|
direccion.put("cp", this.getDireccion().getCp());
|
|
direccion.put("municipio", this.getDireccion().getCiudad());
|
|
direccion.put("provincia", this.getDireccion().getProvincia());
|
|
direccion.put("telefono", this.getDireccion().getTelefono());
|
|
direccion.put("entregaPieCalle", palets ? 1 : 0);
|
|
direccion.put("is_ferro_prototipo", ejemplarPrueba ? 1 : 0);
|
|
direccion.put("num_ferro_prototipo", ejemplarPrueba ? 1 : 0);
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("direccion", direccion);
|
|
map.put("unidades", numeroUnidades);
|
|
map.put("entregaPalets", palets ? 1 : 0);
|
|
|
|
return map;
|
|
}
|
|
|
|
public Map<String, Object> toSkMapDepositoLegal() {
|
|
Map<String, Object> direccion = new HashMap<>();
|
|
direccion.put("cantidad", 4);
|
|
direccion.put("peso", 0);
|
|
direccion.put("att", "Unidades para Depósito Legal (sin envío)");
|
|
direccion.put("email", "");
|
|
direccion.put("direccion", "");
|
|
direccion.put("pais_code3", "esp");
|
|
direccion.put("cp", "");
|
|
direccion.put("municipio", "");
|
|
direccion.put("provincia", "");
|
|
direccion.put("telefono", "");
|
|
direccion.put("entregaPieCalle", 0);
|
|
direccion.put("is_ferro_prototipo", 0);
|
|
direccion.put("num_ferro_prototipo", 0);
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("direccion", direccion);
|
|
map.put("unidades", 4);
|
|
map.put("entregaPalets", 0);
|
|
|
|
return map;
|
|
}
|
|
|
|
}
|