corregidos varios fallos de presupuesto

This commit is contained in:
2025-10-15 19:43:00 +02:00
parent 70856edc12
commit f20dd9068a
13 changed files with 130 additions and 76 deletions

View File

@ -2,3 +2,4 @@ cart.title=Cesta de la compra
cart.empty=Tu cesta de la compra está vacía.
cart.item.presupuesto-numero=Presupuesto #
cart.precio=Precio

View File

@ -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.gramaje-cubierta=Seleccione el gramaje del papel para 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.

View File

@ -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() {
var alerts = document.querySelectorAll('.alert.alert-dismissible');

View File

@ -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');
} else {
const $selected = $('#formato option:selected');
@ -21,13 +21,13 @@ export function updateFormato(){
export function updatePaginas() {
const paginas = $('#paginas').val();
$('#summary-paginas').text(paginas );
$('#summary-paginas').text(paginas);
const paginasColor = $('#paginas-color').val();
$('#summary-paginas-color').text(paginasColor );
$('#summary-paginas-color').text(paginasColor);
const paginasNegro = $('#paginas-negro').val();
$('#summary-paginas-negro').text(paginasNegro );
$('#summary-paginas-negro').text(paginasNegro);
}
export function updateTipoImpresion() {
@ -51,34 +51,36 @@ export function updatePapelInterior() {
export function updateGramajeInterior() {
const gramaje = $('input[name="gramaje-interior"]:checked');
if(gramaje.length > 0) {
if (gramaje.length > 0) {
$('#summary-gramaje-interior').text(gramaje.data('gramaje'));
}
}
export function updateTapaCubierta(){
export function updateTapaCubierta() {
const $selected = $('.tapa-cubierta input:checked');
if ($selected.length > 0) {
const resumen = $selected.closest('.tapa-cubierta').data('summary-text') || $selected.closest('.tapa-cubierta').attr('id');
$('#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-dura-row').addClass('d-none');
$('#summary-cubierta-solapas').text($('#sin-solapas').hasClass('selected') ? $('#sin-solapas').data('summary-text') : $('#con-solapas').data('summary-text'));
if($('#con-solapas').hasClass('selected')) {
$('#summary-tamanio-solapa-row').removeClass('d-none');
const $solapasSelected = $('.solapas-cubierta input:checked');
if ($solapasSelected.val() === 'conSolapas') {
$('#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');
} 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-impresion-cubierta-row').removeClass('d-none');
$('#summary-impresion-cubierta').text($('#impresion-cubierta option:selected').text());
}
else{
else {
$('.tapa-blanda-row').addClass('d-none');
$('.tapa-dura-row').removeClass('d-none');
$('#summary-papel-guardas').text($('#papel-guardas option:selected').text());
@ -95,19 +97,24 @@ export function updatePapelCubierta() {
}
}
export function updateGramajeCubierta() {
const gramaje = $('input[name="gramaje-cubierta"]:checked');
if(gramaje.length > 0) {
$('#summary-gramaje-cubierta').text(gramaje.data('gramaje'));
export function updateGramajeCubierta(gramaje) {
if (!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() {
const acabado = $('input[name="acabado-cubierta"]:checked');
if(acabado.length > 0) {
if (acabado.length > 0) {
let labelText = '';
const id = acabado.attr('id');
if (id) {
labelText = $(`label[for="${id}"]`).text().trim();
}
@ -123,20 +130,20 @@ export function updateAcabadoCubierta() {
export function updateSobreCubierta() {
if($('#sobrecubierta').hasClass('active')) {
if ($('#sobrecubierta').hasClass('active')) {
$('#summary-sobrecubierta-papel-gramaje').text($('#papel-sobrecubierta option:selected').text());
$('#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() {
if($('#faja').hasClass('active')) {
if ($('#faja').hasClass('active')) {
$('#summary-faja-papel-gramaje').text($('#papel-faja option:selected').text());
$('#summary-faja-alto-faja').text($('#alto-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();
// Agregar las filas de servicios extras
$('.service-checkbox:checked').each(function() {
$('.service-checkbox:checked').each(function () {
const $servicio = $(this);
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');

View File

@ -37,7 +37,7 @@ export default class PresupuestoWizard {
ivaReducido: true,
},
interior: {
tipoImpresion: 'negro',
tipoImpresion: 'negrohq',
papelInteriorId: 3,
gramajeInterior: 80,
},
@ -135,7 +135,7 @@ export default class PresupuestoWizard {
this.divOpcionesColor = $('#div-opciones-color');
this.divPapelInterior = $('#div-papel-interior');
this.divGramajeInterior = $("#div-gramaje-interior");
this.interior_alert = $('#interior-alert');
this.interior_alert = $('#form-errors');
// pestaña cubierta
this.divSolapasCubierta = $('#div-solapas-cubierta');
@ -777,6 +777,7 @@ export default class PresupuestoWizard {
if (opcion.id === this.formData.interior.papelInteriorId) {
item.setSelected(true);
}
item.group = 'papel-interior';
this.divPapelInterior.append(item.render());
}
@ -808,6 +809,8 @@ export default class PresupuestoWizard {
const data = this.#getPresupuestoData();
this.interior_alert.addClass('d-none').find('#form-errors-alert-list').empty();
Summary.updatePapelInterior();
this.divGramajeInterior.removeClass('animate-fadeInUpBounce');
@ -832,9 +835,16 @@ export default class PresupuestoWizard {
const dataInterior = this.#getInteriorData();
this.#updateInteriorData(dataInterior);
this.#cacheFormData();
Summary.updatePapelInterior();
Summary.updateGramajeInterior();
}).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);
});
});
@ -871,6 +881,7 @@ export default class PresupuestoWizard {
let data = this.#getPresupuestoData();
const id = e.currentTarget.id;
this.interior_alert.addClass('d-none').find('#form-errors-alert-list').empty();
$.ajax({
url: '/presupuesto/public/validar/interior',
@ -928,18 +939,16 @@ export default class PresupuestoWizard {
error: (xhr, status, error) => {
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;
if (errors && typeof errors === 'object') {
if (!this.DEBUG && xhr.responseJSON.error && xhr.responseJSON.error == 'Internal Server Error') {
console.error("Error al validar los datos generales. Internal Server Error");
return;
}
Object.values(errors).forEach(errorMsg => {
this.interior_alert.find('#inside-alert-list').append(`<li>${errorMsg}</li>`);
});
this.interior_alert.find('#form-errors-alert-list').append(`<li>${errors.message}</li>`);
} 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);
}
@ -1144,6 +1153,7 @@ export default class PresupuestoWizard {
}).done((data) => {
const gramajes = data.opciones_gramaje_cubierta;
this.divGramajeCubierta.empty();
this.#addGramajesCubierta(gramajes);
this.divGramajeCubierta.addClass('animate-fadeInUpBounce');
@ -1152,6 +1162,7 @@ export default class PresupuestoWizard {
this.#cacheFormData();
Summary.updatePapelCubierta();
Summary.updateGramajeCubierta();
}).fail((xhr, status, error) => {
@ -1165,7 +1176,7 @@ export default class PresupuestoWizard {
const gramaje = parseInt($('#' + inputId).data('gramaje'));
this.formData.cubierta.gramajeCubierta = gramaje;
this.#cacheFormData();
Summary.updateGramajeCubierta();
Summary.updateGramajeCubierta(gramaje);
});
$(document).on('change', '.datos-cubierta', (e) => {
@ -1701,7 +1712,7 @@ export default class PresupuestoWizard {
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({
id: "ferro-digital",
label: "Ferro Digital",

View File

@ -36,9 +36,9 @@
<!-- Precio o totales (si los tienes) -->
<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">
<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>
</div>
</div>
@ -50,7 +50,8 @@
<div class="d-flex flex-wrap my-n1">
<!-- Botón eliminar -->
<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}" />
<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
@ -59,16 +60,7 @@
</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>

View File

@ -32,6 +32,8 @@
</nav>
</div>
<div class="container-fluid">
<div th:if="${items.isEmpty()}">
<div class="alert alert-info" role="alert" th:text="#{cart.empty}"></div>

View File

@ -95,7 +95,7 @@
</td>
<td id="summary-cubierta-solapas" class="text-end data-summary" data-id-summary="cubierta-solapas"></td>
</tr>
<tr class="tapa-blanda-row d-none">
<tr class="tapa-blanda-row summary-tamanio-solapa-row d-none">
<td class="ps-3">
<span class="ps-3" th:text="#{presupuesto.tamanio-solapa}"></span>
</td>