mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-24 09:40:21 +00:00
falta el selector de acabados
This commit is contained in:
@ -1,10 +1,21 @@
|
||||
import * as Summary from "./summary.js";
|
||||
import { formateaMoneda } from "../utils.js";
|
||||
|
||||
|
||||
let valoresAcabados = [];
|
||||
|
||||
$(document).on('change', '#maquetacion', function (e) {
|
||||
e.preventDefault();
|
||||
if ($('#maquetacion').is(':checked')) {
|
||||
$.get("/presupuesto/public/maquetacion/form", function (data) {
|
||||
$("#maquetacionModalBody").html(data);
|
||||
valoresAcabados = $("#acabado-marcapaginas").html();
|
||||
if($('#caras-impresion').val() === 'una_cara') {
|
||||
$("#acabado-marcapaginas").html($(valoresAcabados).filter('.marcapaginas-1cara'));
|
||||
}
|
||||
else {
|
||||
$("#acabado-marcapaginas").html($(valoresAcabados).filter('.marcapaginas-2caras'));
|
||||
}
|
||||
$("#maquetacionModal").modal("show");
|
||||
});
|
||||
} else {
|
||||
@ -35,8 +46,8 @@ $(document).on("submit", "#maquetacionForm", function (e) {
|
||||
|
||||
const resumenHtml = `
|
||||
<div class="text-start">
|
||||
<p>Páginas calculadas: ${json.numPaginasEstimadas ?? "-"}</p>
|
||||
<p>Precio por página estimado: ${formateaMoneda(json.precioPaginaEstimado) || "-"}</p>
|
||||
<p>${json.language.num_paginas_estimadas || 'Páginas calculadas'}: ${json.numPaginasEstimadas ?? "-"}</p>
|
||||
<p>${json.language.precio_por_pagina_estimado || 'Precio por página estimado'}: ${formateaMoneda(json.precioPaginaEstimado) || "-"}</p>
|
||||
<hr class="my-2">
|
||||
${json.precio ?
|
||||
`<h3 class="mb-0"><strong>Precio:</strong> ${formateaMoneda(json.precio)}</h3>` : ""}
|
||||
@ -97,6 +108,15 @@ $(document).on("submit", "#maquetacionForm", function (e) {
|
||||
});
|
||||
});
|
||||
|
||||
$document).on('change', '#caras-impresion', function (e) {
|
||||
e.preventDefault();
|
||||
if($('#caras-impresion').val() === 'una_cara') {
|
||||
$("#acabado-marcapaginas").html($(valoresAcabados).filter('.marcapaginas-1cara'));
|
||||
} else {
|
||||
$("#acabado-marcapaginas").html($(valoresAcabados).filter('.marcapaginas-2caras'));
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('hidden.bs.modal', '#maquetacionModal', function () {
|
||||
|
||||
const calcularStr = $('#div-extras').data('language-calcular');
|
||||
@ -105,11 +125,3 @@ $(document).on('hidden.bs.modal', '#maquetacionModal', function () {
|
||||
$('label[for="maquetacion"] .service-price').text(calcularStr);
|
||||
});
|
||||
|
||||
function formateaMoneda(valor) {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR' }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,107 @@
|
||||
import * as Summary from "./summary.js";
|
||||
import { formateaMoneda, formateaMoneda6Decimales } from "../utils.js";
|
||||
|
||||
$(document).on('change', '#marcapaginas', function (e) {
|
||||
e.preventDefault();
|
||||
if ($('#marcapaginas').is(':checked')) {
|
||||
$.get("/presupuesto/public/marcapaginas/form", function (data) {
|
||||
$("#marcapaginasModalBody").html(data);
|
||||
$("#marcapaginasModal").modal("show");
|
||||
});
|
||||
} else {
|
||||
const calcularStr = $('#div-extras').data('language-calcular');
|
||||
$('#marcapaginas').data('price', calcularStr);
|
||||
$('label[for="marcapaginas"] .service-price')
|
||||
.text(calcularStr);
|
||||
$('#marcapaginas').prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("submit", "#marcapaginasForm", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const $form = $(this);
|
||||
|
||||
$.ajax({
|
||||
url: $form.attr("action"),
|
||||
type: $form.attr("method"),
|
||||
data: $form.serialize(),
|
||||
dataType: "json",
|
||||
success: function (json) {
|
||||
|
||||
const modalEl = document.getElementById("marcapaginasModal");
|
||||
const modal = bootstrap.Modal.getInstance(modalEl) || new bootstrap.Modal(modalEl);
|
||||
modal.hide();
|
||||
|
||||
|
||||
const resumenHtml = `
|
||||
<div class="text-start">
|
||||
<p>${json.language.precio_unidad || 'Precio por unidad'}: ${formateaMoneda6Decimales(json.precio_unitario) || "-"}</p>
|
||||
<h3 class="mb-0">${json.language.precio_total || 'Precio total'}: ${formateaMoneda(json.precio_total) || "-"}</h3>
|
||||
</div>
|
||||
`;
|
||||
|
||||
Swal.fire({
|
||||
title: json.language.presupuesto_marcapaginas || 'Presupuesto Marcapáginas',
|
||||
html: resumenHtml,
|
||||
icon: 'info',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: json.language.add_to_presupuesto || 'Añadir al presupuesto',
|
||||
cancelButtonText: json.language.cancel || 'Cancelar',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary me-2', // clases para el botón confirmar
|
||||
cancelButton: 'btn btn-light' // clases para cancelar
|
||||
},
|
||||
buttonsStyling: false,
|
||||
reverseButtons: false,
|
||||
allowOutsideClick: false
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$('#marcapaginas').prop('checked', true);
|
||||
$('#marcapaginas').data('price', json.precio_total);
|
||||
$('label[for="marcapaginas"] .service-price')
|
||||
.text(formateaMoneda(json.precio_total));
|
||||
Summary.updateExtras();
|
||||
}
|
||||
else {
|
||||
const calcularStr = $('#div-extras').data('language-calcular');
|
||||
$('#marcapaginas').prop('checked', false);
|
||||
$('#marcapaginas').data('price', calcularStr);
|
||||
$('label[for="marcapaginas"] .service-price').text(calcularStr);
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
try {
|
||||
const errs = JSON.parse(xhr.responseText); // { numCaracteres: "…" , … }
|
||||
// limpia errores previos
|
||||
$form.find(".is-invalid").removeClass("is-invalid");
|
||||
$form.find(".invalid-feedback").text("");
|
||||
|
||||
// recorre los errores y los muestra
|
||||
Object.entries(errs).forEach(([field, msg]) => {
|
||||
const $input = $form.find(`[name="${field}"]`);
|
||||
if ($input.length) {
|
||||
$input.addClass("is-invalid");
|
||||
$input.siblings(".invalid-feedback").text(msg);
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
$("#marcapaginasModalBody").html(
|
||||
"<div class='alert alert-danger'>" + xhr.responseText + "</div>"
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('hidden.bs.modal', '#marcapaginasModal', function () {
|
||||
|
||||
const calcularStr = $('#div-extras').data('language-calcular');
|
||||
$('#marcapaginas').prop('checked', false);
|
||||
$('#marcapaginas').data('price', calcularStr);
|
||||
$('label[for="marcapaginas"] .service-price').text(calcularStr);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
function formateaMoneda(valor) {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR' }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
export { formateaMoneda };
|
||||
|
||||
function formateaMoneda4Decimales(valor) {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR', minimumFractionDigits: 4 }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
export { formateaMoneda4Decimales };
|
||||
|
||||
function formateaMoneda6Decimales(valor) {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR', minimumFractionDigits: 6 }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
export { formateaMoneda6Decimales };
|
||||
Reference in New Issue
Block a user