mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-28 13:49:12 +00:00
quitado tipo de entrega de todos sitios. Trabajando en el iva dependiendo de la dirección de facturación
This commit is contained in:
@ -80,7 +80,7 @@ public class CartController {
|
||||
else if (direcciones != null && direcciones.containsKey("direcciones"))
|
||||
model.addAttribute("direcciones", direcciones.get("direcciones"));
|
||||
|
||||
var summary = service.getCartSummary(cart, locale);
|
||||
var summary = service.getCartSummary(cart, locale, true);
|
||||
model.addAttribute("cartSummary", summary);
|
||||
if (summary.get("errorShipmentCost") != null && (Boolean) summary.get("errorShipmentCost"))
|
||||
model.addAttribute("errorEnvio", true);
|
||||
@ -165,7 +165,7 @@ public class CartController {
|
||||
|
||||
try {
|
||||
service.updateCart(id, updateRequest);
|
||||
var cartSummary = service.getCartSummary(service.getCartById(id), locale);
|
||||
var cartSummary = service.getCartSummary(service.getCartById(id), locale, true);
|
||||
model.addAttribute("cartSummary", cartSummary);
|
||||
|
||||
return "imprimelibros/cart/_cartSummary :: cartSummary(summary=${cartSummary})";
|
||||
|
||||
@ -163,7 +163,7 @@ public class CartService {
|
||||
return itemRepo.findByCartId(cart.getId()).size();
|
||||
}
|
||||
|
||||
public Map<String, Object> getCartSummaryRaw(Cart cart, Locale locale) {
|
||||
public Map<String, Object> getCartSummaryRaw(Cart cart, Locale locale, Boolean hasTaxes) {
|
||||
|
||||
double base = 0.0;
|
||||
double iva4 = 0.0;
|
||||
@ -269,6 +269,11 @@ public class CartService {
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasTaxes) {
|
||||
iva4 = 0.0;
|
||||
iva21 = 0.0;
|
||||
}
|
||||
|
||||
double totalBeforeDiscount = base + iva4 + iva21 + shipment;
|
||||
int fidelizacion = this.getDescuentoFidelizacion(cart.getUserId());
|
||||
double descuento = totalBeforeDiscount * fidelizacion / 100.0;
|
||||
@ -318,8 +323,8 @@ public class CartService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Map<String, Object> getCartSummary(Cart cart, Locale locale) {
|
||||
Map<String, Object> raw = getCartSummaryRaw(cart, locale);
|
||||
public Map<String, Object> getCartSummary(Cart cart, Locale locale, Boolean hasTaxes) {
|
||||
Map<String, Object> raw = getCartSummaryRaw(cart, locale, hasTaxes);
|
||||
|
||||
double base = (Double) raw.get("base");
|
||||
double iva4 = (Double) raw.get("iva4");
|
||||
|
||||
@ -22,6 +22,7 @@ import com.imprimelibros.erp.direcciones.DireccionService;
|
||||
import com.imprimelibros.erp.cart.Cart;
|
||||
import com.imprimelibros.erp.cart.CartService;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/checkout")
|
||||
public class CheckoutController {
|
||||
@ -58,10 +59,25 @@ public class CheckoutController {
|
||||
|
||||
Long userId = Utils.currentUserId(principal);
|
||||
Cart cart = cartService.getOrCreateActiveCart(userId);
|
||||
model.addAttribute("summary", cartService.getCartSummary(cart, locale));
|
||||
model.addAttribute("summary", cartService.getCartSummary(cart, locale, true));
|
||||
return "imprimelibros/checkout/checkout"; // crea esta vista si quieres (tabla simple)
|
||||
}
|
||||
|
||||
@GetMapping({"/get-summary", "/get-summary/{direccionId}"})
|
||||
public String getCheckoutSummary(@PathVariable(required = false) Long direccionId, Principal principal, Model model, Locale locale) {
|
||||
Long userId = Utils.currentUserId(principal);
|
||||
Cart cart = cartService.getOrCreateActiveCart(userId);
|
||||
Boolean hasTaxes = true;
|
||||
if(direccionId != null) {
|
||||
hasTaxes = direccionService.hasTaxes(direccionId);
|
||||
}
|
||||
Map<String, Object> summary = cartService.getCartSummary(cart, locale, hasTaxes);
|
||||
model.addAttribute("summary", summary);
|
||||
|
||||
return "imprimelibros/checkout/_summary :: checkoutSummary(summary=${summary})";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/get-address/{id}")
|
||||
public String getDireccionCard(@PathVariable Long id, Model model, Locale locale) {
|
||||
Direccion dir = direccionService.findById(id)
|
||||
|
||||
@ -153,4 +153,26 @@ public class DireccionService {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean hasTaxes(Long direccionId) {
|
||||
if(direccionId == null) {
|
||||
return true; // Si no hay dirección, asumimos que sí tiene impuestos
|
||||
}
|
||||
Optional<Direccion> dir = repo.findById(direccionId);
|
||||
if (dir == null || dir.isEmpty()) {
|
||||
throw new RuntimeException("Dirección no encontrada");
|
||||
}
|
||||
if(dir.get().getPaisCode3().toLowerCase().equals("esp")) {
|
||||
int provincia = dir.get().getCp() / 1000;
|
||||
|
||||
if (provincia == 35 || provincia == 38 ) {
|
||||
return false; // Canarias (sin IVA)lñ.
|
||||
}
|
||||
return true; // España (todas las provincias)
|
||||
}
|
||||
else{
|
||||
// Fuera de España, asumimos que no tiene impuestos (puedes ajustar esto según tus necesidades)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -81,7 +81,8 @@ public class PedidoService {
|
||||
Pedido pedido = new Pedido();
|
||||
|
||||
Cart cart = cartService.getCartById(cartId);
|
||||
Map<String, Object> cartSummaryRaw = cartService.getCartSummaryRaw(cart, Locale.getDefault());
|
||||
Boolean hasTaxes = direccionService.hasTaxes(direccionFacturacionId);
|
||||
Map<String, Object> cartSummaryRaw = cartService.getCartSummaryRaw(cart, Locale.getDefault(), hasTaxes);
|
||||
|
||||
// Datos económicos (ojo con las claves, son las del summaryRaw)
|
||||
pedido.setBase((Double) cartSummaryRaw.getOrDefault("base", 0.0d));
|
||||
|
||||
@ -109,21 +109,6 @@ public class Presupuesto extends AbstractAuditedEntity implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Entrega {
|
||||
peninsula("presupuesto.entrega.peninsula"),
|
||||
canarias("presupuesto.entrega.canarias"),
|
||||
paises_ue("presupuesto.entrega.paises-ue");
|
||||
|
||||
private final String messageKey;
|
||||
|
||||
Entrega(String messageKey) {
|
||||
this.messageKey = messageKey;
|
||||
}
|
||||
|
||||
public String getMessageKey() {
|
||||
return messageKey;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Presupuesto clone() {
|
||||
@ -188,10 +173,6 @@ public class Presupuesto extends AbstractAuditedEntity implements Cloneable {
|
||||
@Column(name = "iva_reducido")
|
||||
private Boolean ivaReducido;
|
||||
|
||||
@Column(name = "entrega_tipo")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Entrega entregaTipo;
|
||||
|
||||
@Column(name = "iva_importe_4", precision = 12, scale = 2)
|
||||
private BigDecimal ivaImporte4;
|
||||
|
||||
@ -531,14 +512,6 @@ public class Presupuesto extends AbstractAuditedEntity implements Cloneable {
|
||||
this.ivaReducido = ivaReducido;
|
||||
}
|
||||
|
||||
public Entrega getEntregaTipo() {
|
||||
return entregaTipo;
|
||||
}
|
||||
|
||||
public void setEntregaTipo(Entrega entregaTipo) {
|
||||
this.entregaTipo = entregaTipo;
|
||||
}
|
||||
|
||||
public BigDecimal getIvaImporte4() {
|
||||
return ivaImporte4;
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ public class PresupuestoFormDataMapper {
|
||||
public String paginasColor = "";
|
||||
public String posicionPaginasColor = "";
|
||||
public String tipoEncuadernacion = "fresado"; // enum name
|
||||
public String entregaTipo = "peninsula"; // enum name
|
||||
public boolean ivaReducido = true;
|
||||
}
|
||||
|
||||
@ -157,7 +156,6 @@ public class PresupuestoFormDataMapper {
|
||||
|
||||
vm.datosGenerales.tipoEncuadernacion = enumName(p.getTipoEncuadernacion(), "fresado");
|
||||
|
||||
vm.datosGenerales.entregaTipo = enumName(p.getEntregaTipo(), "peninsula");
|
||||
vm.datosGenerales.ivaReducido = Boolean.TRUE.equals(p.getIvaReducido());
|
||||
|
||||
// ===== Interior
|
||||
|
||||
@ -329,7 +329,7 @@ public class PresupuestoService {
|
||||
.filter(Objects::nonNull)
|
||||
.map(tirada -> tirada + 4)
|
||||
.collect(Collectors.toList()));
|
||||
if(presupuesto.getSelectedTirada() != null) {
|
||||
if (presupuesto.getSelectedTirada() != null) {
|
||||
presupuesto.setSelectedTirada(presupuesto.getSelectedTirada());
|
||||
}
|
||||
} else {
|
||||
@ -337,7 +337,7 @@ public class PresupuestoService {
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
body.put("selectedTirada",
|
||||
presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : presupuesto.getTirada1());
|
||||
body.put("tamanio", tamanio);
|
||||
@ -352,7 +352,7 @@ public class PresupuestoService {
|
||||
body.put("cubierta", cubierta);
|
||||
body.put("guardas", null);
|
||||
// Para las reimpresiones
|
||||
if(presupuesto.getIsReimpresion() != null && presupuesto.getIsReimpresion()) {
|
||||
if (presupuesto.getIsReimpresion() != null && presupuesto.getIsReimpresion()) {
|
||||
body.put("reimpresion", 1);
|
||||
body.put("iskn", presupuesto.getProveedorRef1());
|
||||
}
|
||||
@ -1124,9 +1124,9 @@ public class PresupuestoService {
|
||||
try {
|
||||
// retractilado: recalcular precio
|
||||
if (s.get("id").equals("retractilado")) {
|
||||
|
||||
|
||||
String p = obtenerPrecioRetractilado(cantidad);
|
||||
if(p != null){
|
||||
if (p != null) {
|
||||
double precio_retractilado = Double.parseDouble(p);
|
||||
s.put("price", precio_retractilado);
|
||||
} else {
|
||||
@ -1149,7 +1149,7 @@ public class PresupuestoService {
|
||||
}
|
||||
}
|
||||
try {
|
||||
if(presupuesto.getSelectedTirada() != null && presupuesto.getSelectedTirada().equals(tirada))
|
||||
if (presupuesto.getSelectedTirada() != null && presupuesto.getSelectedTirada().equals(tirada))
|
||||
presupuesto.setServiciosJson(new ObjectMapper().writeValueAsString(servicios));
|
||||
} catch (Exception ignore) {
|
||||
System.out.println("Error guardando servicios JSON: " + ignore.getMessage());
|
||||
@ -1162,21 +1162,19 @@ public class PresupuestoService {
|
||||
|
||||
// Si la entrega es en peninsula, se mira el valor del iva
|
||||
// Canarias y paises UE no llevan IVA
|
||||
if (presupuesto.getEntregaTipo() == Presupuesto.Entrega.peninsula) {
|
||||
// Si el iva es reducido, el precio de la tirada y el del prototipo llevan IVA
|
||||
// 4%
|
||||
if (presupuesto.getIvaReducido()) {
|
||||
ivaImporte4 = baseImponible.add(serviciosIva4).multiply(BigDecimal.valueOf(4)).divide(
|
||||
BigDecimal.valueOf(100), 2,
|
||||
RoundingMode.HALF_UP);
|
||||
ivaImporte21 = serviciosTotal.subtract(serviciosIva4).multiply(BigDecimal.valueOf(21)).divide(
|
||||
BigDecimal.valueOf(100), 2,
|
||||
RoundingMode.HALF_UP);
|
||||
} else {
|
||||
ivaImporte21 = baseImponible.add(serviciosTotal).multiply(BigDecimal.valueOf(21)).divide(
|
||||
BigDecimal.valueOf(100), 2,
|
||||
RoundingMode.HALF_UP);
|
||||
}
|
||||
// Si el iva es reducido, el precio de la tirada y el del prototipo llevan IVA
|
||||
// 4%
|
||||
if (presupuesto.getIvaReducido()) {
|
||||
ivaImporte4 = baseImponible.add(serviciosIva4).multiply(BigDecimal.valueOf(4)).divide(
|
||||
BigDecimal.valueOf(100), 2,
|
||||
RoundingMode.HALF_UP);
|
||||
ivaImporte21 = serviciosTotal.subtract(serviciosIva4).multiply(BigDecimal.valueOf(21)).divide(
|
||||
BigDecimal.valueOf(100), 2,
|
||||
RoundingMode.HALF_UP);
|
||||
} else {
|
||||
ivaImporte21 = baseImponible.add(serviciosTotal).multiply(BigDecimal.valueOf(21)).divide(
|
||||
BigDecimal.valueOf(100), 2,
|
||||
RoundingMode.HALF_UP);
|
||||
}
|
||||
baseImponible = baseImponible.add(serviciosTotal);
|
||||
BigDecimal totalConIva = baseImponible.add(ivaImporte21).add(ivaImporte4);
|
||||
@ -1332,10 +1330,10 @@ public class PresupuestoService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Boolean hasMaquetacion(Presupuesto presupuesto) {
|
||||
if (presupuesto.getServiciosJson() != null && !presupuesto.getServiciosJson().isEmpty()) {
|
||||
if(presupuesto.getServiciosJson().contains("maquetacion")) {
|
||||
if (presupuesto.getServiciosJson().contains("maquetacion")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1474,7 +1472,6 @@ public class PresupuestoService {
|
||||
target.setServiciosTotal(src.getServiciosTotal());
|
||||
target.setBaseImponible(src.getBaseImponible());
|
||||
target.setIvaReducido(src.getIvaReducido());
|
||||
target.setEntregaTipo(src.getEntregaTipo());
|
||||
target.setIvaImporte4(src.getIvaImporte4());
|
||||
target.setIvaImporte21(src.getIvaImporte21());
|
||||
target.setTotalConIva(src.getTotalConIva());
|
||||
|
||||
Reference in New Issue
Block a user