mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-28 14:48:50 +00:00
corregidos varios fallos de presupuesto
This commit is contained in:
@ -5,10 +5,11 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import com.imprimelibros.erp.users.UserDetailsImpl;
|
import com.imprimelibros.erp.users.UserDetailsImpl;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.imprimelibros.erp.users.User;
|
import com.imprimelibros.erp.users.User;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
|
||||||
|
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -27,24 +28,23 @@ public class CartController {
|
|||||||
* Adáptalo a tu UserDetails (e.g., SecurityContext con getId())
|
* Adáptalo a tu UserDetails (e.g., SecurityContext con getId())
|
||||||
*/
|
*/
|
||||||
private Long currentUserId(Principal principal) {
|
private Long currentUserId(Principal principal) {
|
||||||
if (principal == null) {
|
if (principal == null) {
|
||||||
throw new IllegalStateException("Usuario no autenticado");
|
throw new IllegalStateException("Usuario no autenticado");
|
||||||
}
|
|
||||||
|
|
||||||
if (principal instanceof Authentication auth) {
|
|
||||||
Object principalObj = auth.getPrincipal();
|
|
||||||
|
|
||||||
if (principalObj instanceof UserDetailsImpl udi) {
|
|
||||||
return udi.getId();
|
|
||||||
} else if (principalObj instanceof User u && u.getId() != null) {
|
|
||||||
return u.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (principal instanceof Authentication auth) {
|
||||||
|
Object principalObj = auth.getPrincipal();
|
||||||
|
|
||||||
|
if (principalObj instanceof UserDetailsImpl udi) {
|
||||||
|
return udi.getId();
|
||||||
|
} else if (principalObj instanceof User u && u.getId() != null) {
|
||||||
|
return u.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException("No se pudo obtener el ID del usuario actual");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException("No se pudo obtener el ID del usuario actual");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Vista del carrito */
|
/** Vista del carrito */
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String viewCart(Model model, Principal principal, Locale locale) {
|
public String viewCart(Model model, Principal principal, Locale locale) {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -65,8 +66,8 @@ public class CartService {
|
|||||||
Presupuesto p = presupuestoRepo.findById(item.getPresupuestoId())
|
Presupuesto p = presupuestoRepo.findById(item.getPresupuestoId())
|
||||||
.orElseThrow(() -> new IllegalStateException("Presupuesto no encontrado: " + item.getPresupuestoId()));
|
.orElseThrow(() -> new IllegalStateException("Presupuesto no encontrado: " + item.getPresupuestoId()));
|
||||||
|
|
||||||
this.getElementoCart(p, locale);
|
|
||||||
Map<String, Object> elemento = getElementoCart(p, locale);
|
Map<String, Object> elemento = getElementoCart(p, locale);
|
||||||
|
elemento.put("cartItemId", item.getId());
|
||||||
resultados.add(elemento);
|
resultados.add(elemento);
|
||||||
}
|
}
|
||||||
System.out.println("Cart items: " + resultados);
|
System.out.println("Cart items: " + resultados);
|
||||||
@ -157,12 +158,14 @@ public class CartService {
|
|||||||
HashMap<String, Object> linea = new HashMap<>();
|
HashMap<String, Object> linea = new HashMap<>();
|
||||||
Double precio_unitario = 0.0;
|
Double precio_unitario = 0.0;
|
||||||
Double precio_total = 0.0;
|
Double precio_total = 0.0;
|
||||||
|
BigDecimal total = BigDecimal.ZERO;
|
||||||
linea.put("descripcion", presupuestoFormatter.resumen(presupuesto, servicios, locale));
|
linea.put("descripcion", presupuestoFormatter.resumen(presupuesto, servicios, locale));
|
||||||
linea.put("cantidad", presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : 0);
|
linea.put("cantidad", presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : 0);
|
||||||
precio_unitario = (presupuesto.getPrecioUnitario() != null ? presupuesto.getPrecioUnitario().doubleValue() : 0.0);
|
precio_unitario = (presupuesto.getPrecioUnitario() != null ? presupuesto.getPrecioUnitario().doubleValue() : 0.0);
|
||||||
precio_total = (presupuesto.getPrecioTotalTirada() != null ? presupuesto.getPrecioTotalTirada().doubleValue() : 0.0);
|
precio_total = (presupuesto.getPrecioTotalTirada() != null ? presupuesto.getPrecioTotalTirada().doubleValue() : 0.0);
|
||||||
linea.put("precio_unitario", precio_unitario);
|
linea.put("precio_unitario", precio_unitario);
|
||||||
linea.put("precio_total", BigDecimal.valueOf(precio_total).setScale(2, RoundingMode.HALF_UP));
|
linea.put("precio_total", BigDecimal.valueOf(precio_total).setScale(2, RoundingMode.HALF_UP));
|
||||||
|
total = total.add(BigDecimal.valueOf(precio_total));
|
||||||
lineas.add(linea);
|
lineas.add(linea);
|
||||||
|
|
||||||
if (hayDepositoLegal) {
|
if (hayDepositoLegal) {
|
||||||
@ -171,6 +174,7 @@ public class CartService {
|
|||||||
linea.put("cantidad", 4);
|
linea.put("cantidad", 4);
|
||||||
linea.put("precio_unitario", precio_unitario);
|
linea.put("precio_unitario", precio_unitario);
|
||||||
linea.put("precio_total", BigDecimal.valueOf(precio_unitario * 4).setScale(2, RoundingMode.HALF_UP));
|
linea.put("precio_total", BigDecimal.valueOf(precio_unitario * 4).setScale(2, RoundingMode.HALF_UP));
|
||||||
|
total = total.add(BigDecimal.valueOf(precio_unitario * 4));
|
||||||
lineas.add(linea);
|
lineas.add(linea);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,10 +188,14 @@ public class CartService {
|
|||||||
? Double.parseDouble(servicio.get("price").toString())
|
? Double.parseDouble(servicio.get("price").toString())
|
||||||
/ Double.parseDouble(servicio.get("units").toString())
|
/ Double.parseDouble(servicio.get("units").toString())
|
||||||
: servicio.get("price"));
|
: servicio.get("price"));
|
||||||
|
total = total.add(BigDecimal.valueOf(Double.parseDouble(servicioData.get("precio").toString())));
|
||||||
servicioData.put("unidades", servicio.get("units"));
|
servicioData.put("unidades", servicio.get("units"));
|
||||||
serviciosExtras.add(servicioData);
|
serviciosExtras.add(servicioData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);
|
||||||
|
String formattedString = currencyFormat.format(total.setScale(2, RoundingMode.HALF_UP).doubleValue());
|
||||||
|
resumen.put("total", formattedString);
|
||||||
resumen.put("lineas", lineas);
|
resumen.put("lineas", lineas);
|
||||||
resumen.put("servicios", serviciosExtras);
|
resumen.put("servicios", serviciosExtras);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.imprimelibros.erp.externalApi;
|
package com.imprimelibros.erp.externalApi;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
@ -20,6 +21,7 @@ import java.util.Map;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class skApiClient {
|
public class skApiClient {
|
||||||
@ -30,11 +32,13 @@ public class skApiClient {
|
|||||||
private final AuthService authService;
|
private final AuthService authService;
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
private final MargenPresupuestoDao margenPresupuestoDao;
|
private final MargenPresupuestoDao margenPresupuestoDao;
|
||||||
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
public skApiClient(AuthService authService, MargenPresupuestoDao margenPresupuestoDao) {
|
public skApiClient(AuthService authService, MargenPresupuestoDao margenPresupuestoDao, MessageSource messageSource) {
|
||||||
this.authService = authService;
|
this.authService = authService;
|
||||||
this.restTemplate = new RestTemplate();
|
this.restTemplate = new RestTemplate();
|
||||||
this.margenPresupuestoDao = margenPresupuestoDao;
|
this.margenPresupuestoDao = margenPresupuestoDao;
|
||||||
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrice(Map<String, Object> requestBody, TipoEncuadernacion tipoEncuadernacion,
|
public String getPrice(Map<String, Object> requestBody, TipoEncuadernacion tipoEncuadernacion,
|
||||||
@ -113,7 +117,7 @@ public class skApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getMaxSolapas(Map<String, Object> requestBody) {
|
public Integer getMaxSolapas(Map<String, Object> requestBody, Locale locale) {
|
||||||
try {
|
try {
|
||||||
String jsonResponse = performWithRetry(() -> {
|
String jsonResponse = performWithRetry(() -> {
|
||||||
String url = this.skApiUrl + "api/calcular-solapas";
|
String url = this.skApiUrl + "api/calcular-solapas";
|
||||||
@ -150,7 +154,7 @@ public class skApiClient {
|
|||||||
JsonNode root = mapper.readTree(jsonResponse);
|
JsonNode root = mapper.readTree(jsonResponse);
|
||||||
|
|
||||||
if (root.get("data") == null || !root.get("data").isInt()) {
|
if (root.get("data") == null || !root.get("data").isInt()) {
|
||||||
throw new RuntimeException("Respuesta inesperada de calcular-solapas: " + jsonResponse);
|
throw new RuntimeException(messageSource.getMessage("presupuesto.errores.error-interior", new Object[]{1} , locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
return root.get("data").asInt();
|
return root.get("data").asInt();
|
||||||
|
|||||||
@ -145,7 +145,7 @@ public class PresupuestoController {
|
|||||||
return ResponseEntity.badRequest().body(errores);
|
return ResponseEntity.badRequest().body(errores);
|
||||||
}
|
}
|
||||||
Map<String, Object> resultado = new HashMap<>();
|
Map<String, Object> resultado = new HashMap<>();
|
||||||
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto)));
|
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto), locale));
|
||||||
resultado.putAll(presupuestoService.obtenerOpcionesAcabadosCubierta(presupuesto, locale));
|
resultado.putAll(presupuestoService.obtenerOpcionesAcabadosCubierta(presupuesto, locale));
|
||||||
return ResponseEntity.ok(resultado);
|
return ResponseEntity.ok(resultado);
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ public class PresupuestoController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto)));
|
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto), locale));
|
||||||
return ResponseEntity.ok(resultado);
|
return ResponseEntity.ok(resultado);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ public class PresupuestoController {
|
|||||||
presupuesto.setGramajeInterior(Integer.parseInt(opciones.get(0))); // Asignar primera opción
|
presupuesto.setGramajeInterior(Integer.parseInt(opciones.get(0))); // Asignar primera opción
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto)));
|
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto), locale));
|
||||||
return ResponseEntity.ok(resultado);
|
return ResponseEntity.ok(resultado);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ public class PresupuestoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> resultado = new HashMap<>();
|
Map<String, Object> resultado = new HashMap<>();
|
||||||
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto)));
|
resultado.put("solapas", apiClient.getMaxSolapas(presupuestoService.toSkApiRequest(presupuesto), locale));
|
||||||
return ResponseEntity.ok(resultado);
|
return ResponseEntity.ok(resultado);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -109,17 +109,23 @@ public class PresupuestoService {
|
|||||||
// POD solo color foto
|
// POD solo color foto
|
||||||
ImagenPresupuesto opcionColor = this.presupuestadorItems.getImpresionColor(locale);
|
ImagenPresupuesto opcionColor = this.presupuestadorItems.getImpresionColor(locale);
|
||||||
opcionColor.setSelected(Presupuesto.TipoImpresion.color.equals(presupuesto.getTipoImpresion()));
|
opcionColor.setSelected(Presupuesto.TipoImpresion.color.equals(presupuesto.getTipoImpresion()));
|
||||||
|
if (Presupuesto.TipoImpresion.color.equals(presupuesto.getTipoImpresion()))
|
||||||
|
opcionColor.setSelected(true);
|
||||||
opciones.add(opcionColor);
|
opciones.add(opcionColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
ImagenPresupuesto opcionColorHq = this.presupuestadorItems.getImpresionColorPremium(locale);
|
ImagenPresupuesto opcionColorHq = this.presupuestadorItems.getImpresionColorPremium(locale);
|
||||||
if (Presupuesto.TipoImpresion.colorhq.equals(presupuesto.getTipoImpresion()))
|
if (Presupuesto.TipoImpresion.colorhq.equals(presupuesto.getTipoImpresion()))
|
||||||
opcionColorHq.setSelected(true);
|
opcionColorHq.setSelected(true);
|
||||||
opciones.add(opcionColorHq);
|
opciones.add(opcionColorHq);
|
||||||
} else {
|
} else {
|
||||||
ImagenPresupuesto opcionNegro = this.presupuestadorItems.getImpresionNegro(locale);
|
if (!this.isPOD(presupuesto)) {
|
||||||
if (Presupuesto.TipoImpresion.negro.equals(presupuesto.getTipoImpresion()))
|
// POD solo negro premium
|
||||||
opcionNegro.setSelected(true);
|
ImagenPresupuesto opcionNegro = this.presupuestadorItems.getImpresionNegro(locale);
|
||||||
opciones.add(opcionNegro);
|
if (Presupuesto.TipoImpresion.negro.equals(presupuesto.getTipoImpresion()))
|
||||||
|
opcionNegro.setSelected(true);
|
||||||
|
opciones.add(opcionNegro);
|
||||||
|
}
|
||||||
ImagenPresupuesto opcionNegroHq = this.presupuestadorItems.getImpresionNegroPremium(locale);
|
ImagenPresupuesto opcionNegroHq = this.presupuestadorItems.getImpresionNegroPremium(locale);
|
||||||
if (Presupuesto.TipoImpresion.negrohq.equals(presupuesto.getTipoImpresion()))
|
if (Presupuesto.TipoImpresion.negrohq.equals(presupuesto.getTipoImpresion()))
|
||||||
opcionNegroHq.setSelected(true);
|
opcionNegroHq.setSelected(true);
|
||||||
@ -1183,7 +1189,6 @@ public class PresupuestoService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// Métodos privados
|
// Métodos privados
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
|||||||
@ -2,3 +2,4 @@ cart.title=Cesta de la compra
|
|||||||
cart.empty=Tu cesta de la compra está vacía.
|
cart.empty=Tu cesta de la compra está vacía.
|
||||||
|
|
||||||
cart.item.presupuesto-numero=Presupuesto #
|
cart.item.presupuesto-numero=Presupuesto #
|
||||||
|
cart.precio=Precio
|
||||||
|
|||||||
@ -328,6 +328,7 @@ presupuesto.errores.solapas-cubierta=Seleccione si desea o no solapas en la cubi
|
|||||||
presupuesto.errores.papel-cubierta=Seleccione el tipo de papel para la cubierta
|
presupuesto.errores.papel-cubierta=Seleccione el tipo de papel para la cubierta
|
||||||
presupuesto.errores.gramaje-cubierta=Seleccione el gramaje del papel para la cubierta
|
presupuesto.errores.gramaje-cubierta=Seleccione el gramaje del papel para la cubierta
|
||||||
presupuesto.errores.acabado-cubierta=Seleccione el acabado de la cubierta
|
presupuesto.errores.acabado-cubierta=Seleccione el acabado de la cubierta
|
||||||
|
presupuesto.errores.error-interior=Se ha producido un error al procesar el interior. Error {0}. Por favor, contacte con soporte.
|
||||||
|
|
||||||
presupuesto.errores.presupuesto-no-existe=El presupuesto con ID {0} no existe.
|
presupuesto.errores.presupuesto-no-existe=El presupuesto con ID {0} no existe.
|
||||||
|
|
||||||
|
|||||||
@ -160,6 +160,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function elementInViewport(el) {
|
||||||
|
if (el) {
|
||||||
|
var top = el.offsetTop;
|
||||||
|
var left = el.offsetLeft;
|
||||||
|
var width = el.offsetWidth;
|
||||||
|
var height = el.offsetHeight;
|
||||||
|
|
||||||
|
if (el.offsetParent) {
|
||||||
|
while (el.offsetParent) {
|
||||||
|
el = el.offsetParent;
|
||||||
|
top += el.offsetTop;
|
||||||
|
left += el.offsetLeft;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
top >= window.pageYOffset &&
|
||||||
|
left >= window.pageXOffset &&
|
||||||
|
top + height <= window.pageYOffset + window.innerHeight &&
|
||||||
|
left + width <= window.pageXOffset + window.innerWidth
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function initsAlert() {
|
function initsAlert() {
|
||||||
var alerts = document.querySelectorAll('.alert.alert-dismissible');
|
var alerts = document.querySelectorAll('.alert.alert-dismissible');
|
||||||
|
|||||||
@ -7,9 +7,9 @@ export function updateEncuadernacion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFormato(){
|
export function updateFormato() {
|
||||||
|
|
||||||
if($('#formato-personalizado').is(':checked')) {
|
if ($('#formato-personalizado').is(':checked')) {
|
||||||
$('#summary-formato').text($('#ancho').val() + 'x' + $('#alto').val() + ' mm');
|
$('#summary-formato').text($('#ancho').val() + 'x' + $('#alto').val() + ' mm');
|
||||||
} else {
|
} else {
|
||||||
const $selected = $('#formato option:selected');
|
const $selected = $('#formato option:selected');
|
||||||
@ -21,13 +21,13 @@ export function updateFormato(){
|
|||||||
export function updatePaginas() {
|
export function updatePaginas() {
|
||||||
|
|
||||||
const paginas = $('#paginas').val();
|
const paginas = $('#paginas').val();
|
||||||
$('#summary-paginas').text(paginas );
|
$('#summary-paginas').text(paginas);
|
||||||
|
|
||||||
const paginasColor = $('#paginas-color').val();
|
const paginasColor = $('#paginas-color').val();
|
||||||
$('#summary-paginas-color').text(paginasColor );
|
$('#summary-paginas-color').text(paginasColor);
|
||||||
|
|
||||||
const paginasNegro = $('#paginas-negro').val();
|
const paginasNegro = $('#paginas-negro').val();
|
||||||
$('#summary-paginas-negro').text(paginasNegro );
|
$('#summary-paginas-negro').text(paginasNegro);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateTipoImpresion() {
|
export function updateTipoImpresion() {
|
||||||
@ -51,34 +51,36 @@ export function updatePapelInterior() {
|
|||||||
export function updateGramajeInterior() {
|
export function updateGramajeInterior() {
|
||||||
|
|
||||||
const gramaje = $('input[name="gramaje-interior"]:checked');
|
const gramaje = $('input[name="gramaje-interior"]:checked');
|
||||||
if(gramaje.length > 0) {
|
if (gramaje.length > 0) {
|
||||||
$('#summary-gramaje-interior').text(gramaje.data('gramaje'));
|
$('#summary-gramaje-interior').text(gramaje.data('gramaje'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateTapaCubierta(){
|
export function updateTapaCubierta() {
|
||||||
|
|
||||||
const $selected = $('.tapa-cubierta input:checked');
|
const $selected = $('.tapa-cubierta input:checked');
|
||||||
if ($selected.length > 0) {
|
if ($selected.length > 0) {
|
||||||
const resumen = $selected.closest('.tapa-cubierta').data('summary-text') || $selected.closest('.tapa-cubierta').attr('id');
|
const resumen = $selected.closest('.tapa-cubierta').data('summary-text') || $selected.closest('.tapa-cubierta').attr('id');
|
||||||
$('#summary-tapa-cubierta').text(resumen);
|
$('#summary-tapa-cubierta').text(resumen);
|
||||||
}
|
}
|
||||||
if($selected.closest('.tapa-cubierta').attr('id') === 'tapaBlanda') {
|
if ($selected.closest('.tapa-cubierta').attr('id') === 'tapaBlanda') {
|
||||||
|
|
||||||
$('.tapa-blanda-row').removeClass('d-none');
|
$('.tapa-blanda-row').removeClass('d-none');
|
||||||
$('.tapa-dura-row').addClass('d-none');
|
$('.tapa-dura-row').addClass('d-none');
|
||||||
$('#summary-cubierta-solapas').text($('#sin-solapas').hasClass('selected') ? $('#sin-solapas').data('summary-text') : $('#con-solapas').data('summary-text'));
|
const $solapasSelected = $('.solapas-cubierta input:checked');
|
||||||
if($('#con-solapas').hasClass('selected')) {
|
if ($solapasSelected.val() === 'conSolapas') {
|
||||||
$('#summary-tamanio-solapa-row').removeClass('d-none');
|
$('#summary-cubierta-solapas').text($('#con-solapas').data('summary-text'));
|
||||||
|
$('.summary-tamanio-solapa-row').removeClass('d-none');
|
||||||
$('#summary-tamanio-solapa').text($('#tamanio-solapas-cubierta').val() + ' mm');
|
$('#summary-tamanio-solapa').text($('#tamanio-solapas-cubierta').val() + ' mm');
|
||||||
} else {
|
} else {
|
||||||
$('#summary-tamanio-solapa-row').addClass('d-none');
|
$('#summary-cubierta-solapas').text($('#sin-solapas').data('summary-text'));
|
||||||
|
$('.summary-tamanio-solapa-row').addClass('d-none');
|
||||||
$('#summary-tamanio-solapa').text('');
|
$('#summary-tamanio-solapa').text('');
|
||||||
}
|
}
|
||||||
$('#summary-impresion-cubierta-row').removeClass('d-none');
|
$('#summary-impresion-cubierta-row').removeClass('d-none');
|
||||||
$('#summary-impresion-cubierta').text($('#impresion-cubierta option:selected').text());
|
$('#summary-impresion-cubierta').text($('#impresion-cubierta option:selected').text());
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
$('.tapa-blanda-row').addClass('d-none');
|
$('.tapa-blanda-row').addClass('d-none');
|
||||||
$('.tapa-dura-row').removeClass('d-none');
|
$('.tapa-dura-row').removeClass('d-none');
|
||||||
$('#summary-papel-guardas').text($('#papel-guardas option:selected').text());
|
$('#summary-papel-guardas').text($('#papel-guardas option:selected').text());
|
||||||
@ -95,19 +97,24 @@ export function updatePapelCubierta() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateGramajeCubierta() {
|
export function updateGramajeCubierta(gramaje) {
|
||||||
const gramaje = $('input[name="gramaje-cubierta"]:checked');
|
|
||||||
if(gramaje.length > 0) {
|
if (!gramaje) {
|
||||||
$('#summary-gramaje-cubierta').text(gramaje.data('gramaje'));
|
const gramaje = $('input[name="gramaje-cubierta"]:checked');
|
||||||
|
if (gramaje.length > 0) {
|
||||||
|
$('#summary-gramaje-cubierta').text(gramaje.data('gramaje'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$('#summary-gramaje-cubierta').text(gramaje);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateAcabadoCubierta() {
|
export function updateAcabadoCubierta() {
|
||||||
const acabado = $('input[name="acabado-cubierta"]:checked');
|
const acabado = $('input[name="acabado-cubierta"]:checked');
|
||||||
if(acabado.length > 0) {
|
if (acabado.length > 0) {
|
||||||
let labelText = '';
|
let labelText = '';
|
||||||
const id = acabado.attr('id');
|
const id = acabado.attr('id');
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
labelText = $(`label[for="${id}"]`).text().trim();
|
labelText = $(`label[for="${id}"]`).text().trim();
|
||||||
}
|
}
|
||||||
@ -123,20 +130,20 @@ export function updateAcabadoCubierta() {
|
|||||||
|
|
||||||
export function updateSobreCubierta() {
|
export function updateSobreCubierta() {
|
||||||
|
|
||||||
if($('#sobrecubierta').hasClass('active')) {
|
if ($('#sobrecubierta').hasClass('active')) {
|
||||||
$('#summary-sobrecubierta-papel-gramaje').text($('#papel-sobrecubierta option:selected').text());
|
$('#summary-sobrecubierta-papel-gramaje').text($('#papel-sobrecubierta option:selected').text());
|
||||||
$('#summary-sobrecubierta-tamanio-solapa').text($('#tamanio-solapas-sobrecubierta').val() + ' mm');
|
$('#summary-sobrecubierta-tamanio-solapa').text($('#tamanio-solapas-sobrecubierta').val() + ' mm');
|
||||||
$('#summary-sobrecubierta-acabado').text($('#sobrecubierta-acabado option:selected').text());
|
$('#summary-sobrecubierta-acabado').text($('#sobrecubierta-acabado option:selected').text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFaja() {
|
export function updateFaja() {
|
||||||
|
|
||||||
if($('#faja').hasClass('active')) {
|
if ($('#faja').hasClass('active')) {
|
||||||
$('#summary-faja-papel-gramaje').text($('#papel-faja option:selected').text());
|
$('#summary-faja-papel-gramaje').text($('#papel-faja option:selected').text());
|
||||||
$('#summary-faja-alto-faja').text($('#alto-faja').val() + ' mm');
|
$('#summary-faja-alto-faja').text($('#alto-faja').val() + ' mm');
|
||||||
$('#summary-faja-tamanio-solapa').text($('#tamanio-solapas-faja').val() + ' mm');
|
$('#summary-faja-tamanio-solapa').text($('#tamanio-solapas-faja').val() + ' mm');
|
||||||
$('#summary-faja-acabado').text($('#faja-acabado option:selected').text());
|
$('#summary-faja-acabado').text($('#faja-acabado option:selected').text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +153,7 @@ export function updateExtras() {
|
|||||||
$tbody.empty();
|
$tbody.empty();
|
||||||
|
|
||||||
// Agregar las filas de servicios extras
|
// Agregar las filas de servicios extras
|
||||||
$('.service-checkbox:checked').each(function() {
|
$('.service-checkbox:checked').each(function () {
|
||||||
const $servicio = $(this);
|
const $servicio = $(this);
|
||||||
const resumen = $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim() || $servicio.attr('id');
|
const resumen = $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim() || $servicio.attr('id');
|
||||||
const price = $(`label[for="${$servicio.attr('id')}"] .service-price`).text().trim() || $servicio.attr('price');
|
const price = $(`label[for="${$servicio.attr('id')}"] .service-price`).text().trim() || $servicio.attr('price');
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export default class PresupuestoWizard {
|
|||||||
ivaReducido: true,
|
ivaReducido: true,
|
||||||
},
|
},
|
||||||
interior: {
|
interior: {
|
||||||
tipoImpresion: 'negro',
|
tipoImpresion: 'negrohq',
|
||||||
papelInteriorId: 3,
|
papelInteriorId: 3,
|
||||||
gramajeInterior: 80,
|
gramajeInterior: 80,
|
||||||
},
|
},
|
||||||
@ -135,7 +135,7 @@ export default class PresupuestoWizard {
|
|||||||
this.divOpcionesColor = $('#div-opciones-color');
|
this.divOpcionesColor = $('#div-opciones-color');
|
||||||
this.divPapelInterior = $('#div-papel-interior');
|
this.divPapelInterior = $('#div-papel-interior');
|
||||||
this.divGramajeInterior = $("#div-gramaje-interior");
|
this.divGramajeInterior = $("#div-gramaje-interior");
|
||||||
this.interior_alert = $('#interior-alert');
|
this.interior_alert = $('#form-errors');
|
||||||
|
|
||||||
// pestaña cubierta
|
// pestaña cubierta
|
||||||
this.divSolapasCubierta = $('#div-solapas-cubierta');
|
this.divSolapasCubierta = $('#div-solapas-cubierta');
|
||||||
@ -777,6 +777,7 @@ export default class PresupuestoWizard {
|
|||||||
if (opcion.id === this.formData.interior.papelInteriorId) {
|
if (opcion.id === this.formData.interior.papelInteriorId) {
|
||||||
item.setSelected(true);
|
item.setSelected(true);
|
||||||
}
|
}
|
||||||
|
item.group = 'papel-interior';
|
||||||
this.divPapelInterior.append(item.render());
|
this.divPapelInterior.append(item.render());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,6 +809,8 @@ export default class PresupuestoWizard {
|
|||||||
|
|
||||||
const data = this.#getPresupuestoData();
|
const data = this.#getPresupuestoData();
|
||||||
|
|
||||||
|
this.interior_alert.addClass('d-none').find('#form-errors-alert-list').empty();
|
||||||
|
|
||||||
Summary.updatePapelInterior();
|
Summary.updatePapelInterior();
|
||||||
|
|
||||||
this.divGramajeInterior.removeClass('animate-fadeInUpBounce');
|
this.divGramajeInterior.removeClass('animate-fadeInUpBounce');
|
||||||
@ -832,9 +835,16 @@ export default class PresupuestoWizard {
|
|||||||
const dataInterior = this.#getInteriorData();
|
const dataInterior = this.#getInteriorData();
|
||||||
this.#updateInteriorData(dataInterior);
|
this.#updateInteriorData(dataInterior);
|
||||||
this.#cacheFormData();
|
this.#cacheFormData();
|
||||||
|
Summary.updatePapelInterior();
|
||||||
Summary.updateGramajeInterior();
|
Summary.updateGramajeInterior();
|
||||||
|
|
||||||
}).fail((xhr, status, error) => {
|
}).fail((xhr, status, error) => {
|
||||||
|
this.interior_alert.removeClass('d-none');
|
||||||
|
const errors = xhr.responseJSON;
|
||||||
|
if (errors && typeof errors === 'object') {
|
||||||
|
this.interior_alert.find('#form-errors-alert-list').append(`<li>${errors.message}</li>`);
|
||||||
|
|
||||||
|
}
|
||||||
console.error("Error al obtener los gramajes de interior: ", xhr.responseText);
|
console.error("Error al obtener los gramajes de interior: ", xhr.responseText);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -871,6 +881,7 @@ export default class PresupuestoWizard {
|
|||||||
|
|
||||||
let data = this.#getPresupuestoData();
|
let data = this.#getPresupuestoData();
|
||||||
const id = e.currentTarget.id;
|
const id = e.currentTarget.id;
|
||||||
|
this.interior_alert.addClass('d-none').find('#form-errors-alert-list').empty();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/presupuesto/public/validar/interior',
|
url: '/presupuesto/public/validar/interior',
|
||||||
@ -928,18 +939,16 @@ export default class PresupuestoWizard {
|
|||||||
error: (xhr, status, error) => {
|
error: (xhr, status, error) => {
|
||||||
|
|
||||||
this.interior_alert.removeClass('d-none');
|
this.interior_alert.removeClass('d-none');
|
||||||
this.interior_alert.find('#inside-alert-list').empty();
|
this.interior_alert.find('#form-errors-alert-list').empty();
|
||||||
const errors = xhr.responseJSON;
|
const errors = xhr.responseJSON;
|
||||||
if (errors && typeof errors === 'object') {
|
if (errors && typeof errors === 'object') {
|
||||||
if (!this.DEBUG && xhr.responseJSON.error && xhr.responseJSON.error == 'Internal Server Error') {
|
if (!this.DEBUG && xhr.responseJSON.error && xhr.responseJSON.error == 'Internal Server Error') {
|
||||||
console.error("Error al validar los datos generales. Internal Server Error");
|
console.error("Error al validar los datos generales. Internal Server Error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object.values(errors).forEach(errorMsg => {
|
this.interior_alert.find('#form-errors-alert-list').append(`<li>${errors.message}</li>`);
|
||||||
this.interior_alert.find('#inside-alert-list').append(`<li>${errorMsg}</li>`);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this.interior_alert.find('#inside-alert-list').append('<li>Error desconocido. Por favor, inténtelo de nuevo más tarde.</li>');
|
this.interior_alert.find('#form-errors-alert-list').append('<li>Error desconocido. Por favor, inténtelo de nuevo más tarde.</li>');
|
||||||
}
|
}
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
@ -1144,6 +1153,7 @@ export default class PresupuestoWizard {
|
|||||||
}).done((data) => {
|
}).done((data) => {
|
||||||
|
|
||||||
const gramajes = data.opciones_gramaje_cubierta;
|
const gramajes = data.opciones_gramaje_cubierta;
|
||||||
|
this.divGramajeCubierta.empty();
|
||||||
this.#addGramajesCubierta(gramajes);
|
this.#addGramajesCubierta(gramajes);
|
||||||
this.divGramajeCubierta.addClass('animate-fadeInUpBounce');
|
this.divGramajeCubierta.addClass('animate-fadeInUpBounce');
|
||||||
|
|
||||||
@ -1152,6 +1162,7 @@ export default class PresupuestoWizard {
|
|||||||
this.#cacheFormData();
|
this.#cacheFormData();
|
||||||
|
|
||||||
Summary.updatePapelCubierta();
|
Summary.updatePapelCubierta();
|
||||||
|
|
||||||
Summary.updateGramajeCubierta();
|
Summary.updateGramajeCubierta();
|
||||||
|
|
||||||
}).fail((xhr, status, error) => {
|
}).fail((xhr, status, error) => {
|
||||||
@ -1165,7 +1176,7 @@ export default class PresupuestoWizard {
|
|||||||
const gramaje = parseInt($('#' + inputId).data('gramaje'));
|
const gramaje = parseInt($('#' + inputId).data('gramaje'));
|
||||||
this.formData.cubierta.gramajeCubierta = gramaje;
|
this.formData.cubierta.gramajeCubierta = gramaje;
|
||||||
this.#cacheFormData();
|
this.#cacheFormData();
|
||||||
Summary.updateGramajeCubierta();
|
Summary.updateGramajeCubierta(gramaje);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('change', '.datos-cubierta', (e) => {
|
$(document).on('change', '.datos-cubierta', (e) => {
|
||||||
@ -1701,7 +1712,7 @@ export default class PresupuestoWizard {
|
|||||||
this.divExtras.append(item.render());
|
this.divExtras.append(item.render());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.formData.servicios.servicios.includes(s => s.id === "ferro-digital")) {
|
if (!this.formData.servicios.servicios.includes(s => s.id === "ferro-digital")) {
|
||||||
this.formData.servicios.servicios.push({
|
this.formData.servicios.servicios.push({
|
||||||
id: "ferro-digital",
|
id: "ferro-digital",
|
||||||
label: "Ferro Digital",
|
label: "Ferro Digital",
|
||||||
|
|||||||
@ -36,9 +36,9 @@
|
|||||||
|
|
||||||
<!-- Precio o totales (si los tienes) -->
|
<!-- Precio o totales (si los tienes) -->
|
||||||
<div class="col-sm-auto text-end">
|
<div class="col-sm-auto text-end">
|
||||||
<p class="text-muted mb-1">Precio estimado</p>
|
<p class="text-muted mb-1" th:text="#{cart.precio}">Precio</p>
|
||||||
<h5 class="fs-14 mb-0">
|
<h5 class="fs-14 mb-0">
|
||||||
<span th:text="${item.price != null ? #numbers.formatDecimal(item.price, 1, 2) : '-'}">0,00</span> €
|
<span th:text="${item.total != null ? item.total : '-'}">0,00</span>
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -50,7 +50,8 @@
|
|||||||
<div class="d-flex flex-wrap my-n1">
|
<div class="d-flex flex-wrap my-n1">
|
||||||
<!-- Botón eliminar -->
|
<!-- Botón eliminar -->
|
||||||
<div>
|
<div>
|
||||||
<form th:action="@{|/cart/${item.id}/remove|}" method="post" class="d-inline">
|
<form th:action="@{|/cart/${item.cartItemId}/remove|}" method="post" class="d-inline">
|
||||||
|
<input type="hidden" name="_method" value="delete" />
|
||||||
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
|
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
|
||||||
<button type="submit" class="btn btn-sm btn-link text-body p-1 px-2">
|
<button type="submit" class="btn btn-sm btn-link text-body p-1 px-2">
|
||||||
<i class="ri-delete-bin-fill text-muted align-bottom me-1"></i> Eliminar
|
<i class="ri-delete-bin-fill text-muted align-bottom me-1"></i> Eliminar
|
||||||
@ -59,16 +60,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-auto text-end">
|
|
||||||
<div class="d-flex align-items-center gap-2 text-muted">
|
|
||||||
<div>Total:</div>
|
|
||||||
<h5 class="fs-14 mb-0">
|
|
||||||
<span
|
|
||||||
th:text="${item.price != null ? #numbers.formatDecimal(item.price, 1, 2) : '-'}">0,00</span>
|
|
||||||
€
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -32,6 +32,8 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div th:if="${items.isEmpty()}">
|
<div th:if="${items.isEmpty()}">
|
||||||
<div class="alert alert-info" role="alert" th:text="#{cart.empty}"></div>
|
<div class="alert alert-info" role="alert" th:text="#{cart.empty}"></div>
|
||||||
|
|||||||
@ -95,7 +95,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td id="summary-cubierta-solapas" class="text-end data-summary" data-id-summary="cubierta-solapas"></td>
|
<td id="summary-cubierta-solapas" class="text-end data-summary" data-id-summary="cubierta-solapas"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="tapa-blanda-row d-none">
|
<tr class="tapa-blanda-row summary-tamanio-solapa-row d-none">
|
||||||
<td class="ps-3">
|
<td class="ps-3">
|
||||||
<span class="ps-3" th:text="#{presupuesto.tamanio-solapa}"></span>
|
<span class="ps-3" th:text="#{presupuesto.tamanio-solapa}"></span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user