mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-23 17:20:21 +00:00
preparando el imprimir
This commit is contained in:
225
src/main/resources/static/assets/css/presupuestopdf.css
Normal file
225
src/main/resources/static/assets/css/presupuestopdf.css
Normal file
@ -0,0 +1,225 @@
|
||||
/* === Fuentes ===
|
||||
* Para HTML→PDF con OpenHTMLtoPDF, es preferible registrar las TTF en el renderer.
|
||||
* Aun así, incluimos @font-face por si renderizas en navegador.
|
||||
* Coloca los TTF en /static/fonts/ y ajusta los nombres si procede.
|
||||
*/
|
||||
@font-face {
|
||||
font-family: "Open Sans";
|
||||
src: url("/assets/fonts/OpenSans-Regular.ttf") format("truetype");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Open Sans";
|
||||
src: url("/assets/fonts/OpenSans-SemiBold.ttf") format("truetype");
|
||||
font-weight: 600;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Open Sans";
|
||||
src: url("/assets/fonts/OpenSans-Bold.ttf") format("truetype");
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
:root {
|
||||
--text: #1f2937;
|
||||
--muted: #6b7280;
|
||||
--border: #e5e7eb;
|
||||
--brand: #0ea5e9; /* azul suave */
|
||||
--bg-light: #f8fafc; /* gris muy claro */
|
||||
}
|
||||
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 18mm 15mm 22mm 15mm;
|
||||
@bottom-right {
|
||||
content: "Página " counter(page) " / " counter(pages);
|
||||
}
|
||||
}
|
||||
html, body {
|
||||
font-family: "Open Sans", Arial, sans-serif;
|
||||
color: var(--text);
|
||||
font-size: 11pt;
|
||||
line-height: 1.35;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
.doc-header {
|
||||
display: table;
|
||||
width: 100%;
|
||||
margin-bottom: 10mm;
|
||||
border-bottom: 2px solid var(--brand);
|
||||
padding-bottom: 6mm;
|
||||
}
|
||||
.brand {
|
||||
display: table-cell;
|
||||
vertical-align: top;
|
||||
width: 60%;
|
||||
}
|
||||
.logo {
|
||||
height: 34px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.brand-meta { margin-top: 4px; }
|
||||
.company-name {
|
||||
font-weight: 700;
|
||||
font-size: 12pt;
|
||||
}
|
||||
.company-meta {
|
||||
color: var(--muted);
|
||||
font-size: 9.5pt;
|
||||
}
|
||||
|
||||
.doc-title {
|
||||
display: table-cell;
|
||||
vertical-align: top;
|
||||
width: 40%;
|
||||
text-align: right;
|
||||
}
|
||||
.title-main {
|
||||
font-size: 18pt;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.doc-info {
|
||||
margin-top: 6px;
|
||||
margin-left: auto;
|
||||
font-size: 10pt;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.doc-info td {
|
||||
padding: 3px 0 3px 12px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.doc-info td:first-child {
|
||||
color: var(--muted);
|
||||
padding-left: 0;
|
||||
}
|
||||
.right { text-align: right; }
|
||||
|
||||
.blocks {
|
||||
display: table;
|
||||
width: 100%;
|
||||
table-layout: fixed;
|
||||
margin-bottom: 8mm;
|
||||
}
|
||||
.block {
|
||||
display: table-cell;
|
||||
width: 50%;
|
||||
padding-right: 6mm;
|
||||
vertical-align: top;
|
||||
}
|
||||
.block:last-child { padding-right: 0; }
|
||||
.block-title {
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
font-size: 10pt;
|
||||
color: var(--brand);
|
||||
margin-bottom: 2mm;
|
||||
}
|
||||
.block-body {
|
||||
border: 1px solid var(--border);
|
||||
padding: 4mm;
|
||||
background: var(--bg-light);
|
||||
}
|
||||
.row {
|
||||
margin-bottom: 2mm;
|
||||
display: block;
|
||||
}
|
||||
.row .label {
|
||||
display: inline-block;
|
||||
width: 27%;
|
||||
color: var(--muted);
|
||||
}
|
||||
.row .value {
|
||||
display: inline-block;
|
||||
width: 70%;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.table-section .section-title,
|
||||
.notes .section-title {
|
||||
font-weight: 600;
|
||||
font-size: 10.5pt;
|
||||
margin: 6mm 0 2mm 0;
|
||||
}
|
||||
|
||||
.items {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 10.5pt;
|
||||
}
|
||||
.items thead th {
|
||||
text-align: left;
|
||||
border-bottom: 2px solid var(--brand);
|
||||
padding: 6px 6px;
|
||||
background: #eef8fe;
|
||||
font-weight: 600;
|
||||
}
|
||||
.items tbody td {
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 6px 6px;
|
||||
vertical-align: top;
|
||||
}
|
||||
.items .col-right { text-align: right; }
|
||||
.items .col-center { text-align: center; }
|
||||
.items .col-desc .desc { font-weight: 600; }
|
||||
.items .col-desc .meta { color: var(--muted); font-size: 9.5pt; margin-top: 2px; }
|
||||
.items .group-header td {
|
||||
background: var(--bg-light);
|
||||
color: var(--brand);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.totals {
|
||||
margin-top: 6mm;
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
.totals-table {
|
||||
margin-left: auto;
|
||||
border-collapse: collapse;
|
||||
min-width: 70mm;
|
||||
}
|
||||
.totals-table td {
|
||||
padding: 4px 0 4px 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.totals-table td:first-child {
|
||||
color: var(--muted);
|
||||
padding-left: 0;
|
||||
}
|
||||
.totals-table .total-row td {
|
||||
border-bottom: 2px solid var(--brand);
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
.totals-table .right { text-align: right; }
|
||||
|
||||
.notes .note-text {
|
||||
border: 1px solid var(--border);
|
||||
padding: 4mm;
|
||||
background: #fff;
|
||||
font-size: 10pt;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.doc-footer {
|
||||
margin-top: 8mm;
|
||||
padding-top: 4mm;
|
||||
border-top: 1px solid var(--border);
|
||||
display: table;
|
||||
width: 100%;
|
||||
color: var(--muted);
|
||||
font-size: 9pt;
|
||||
}
|
||||
.footer-left { display: table-cell; }
|
||||
.footer-right {
|
||||
display: table-cell;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Compatibilidad PDF (OpenHTMLtoPDF) */
|
||||
.page-number::after { content: counter(page); }
|
||||
.page-count::after { content: counter(pages); }
|
||||
BIN
src/main/resources/static/assets/fonts/OpenSans-Bold.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-Bold.ttf
Normal file
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-BoldItalic.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-BoldItalic.ttf
Normal file
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-ExtraBold.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-ExtraBold.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-Italic.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-Italic.ttf
Normal file
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-Light.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-Light.ttf
Normal file
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-LightItalic.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-LightItalic.ttf
Normal file
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-Regular.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-Regular.ttf
Normal file
Binary file not shown.
BIN
src/main/resources/static/assets/fonts/OpenSans-Semibold.ttf
Normal file
BIN
src/main/resources/static/assets/fonts/OpenSans-Semibold.ttf
Normal file
Binary file not shown.
Binary file not shown.
@ -1,9 +1,14 @@
|
||||
import PresupuestoWizard from './wizard.js';
|
||||
|
||||
if($('#presupuesto_id').val() == null || $('#presupuesto_id').val() === '') {
|
||||
sessionStorage.removeItem('formData');
|
||||
}
|
||||
|
||||
const app = new PresupuestoWizard({
|
||||
mode: 'private',
|
||||
readonly: false,
|
||||
presupuestoId: $('#presupuesto_id').val(),
|
||||
canSave: true,
|
||||
useSessionCache: false,
|
||||
useSessionCache: true,
|
||||
});
|
||||
app.init();
|
||||
@ -1,5 +1,8 @@
|
||||
import PresupuestoWizard from './wizard.js';
|
||||
|
||||
// remove formData from sessionStorage to avoid conflicts
|
||||
sessionStorage.removeItem('formData');
|
||||
|
||||
const app = new PresupuestoWizard({
|
||||
mode: 'public',
|
||||
readonly: false,
|
||||
|
||||
@ -4,6 +4,6 @@ const app = new PresupuestoWizard({
|
||||
mode: 'public',
|
||||
readonly: true,
|
||||
canSave: false,
|
||||
useSessionCache: false,
|
||||
useSessionCache: true,
|
||||
});
|
||||
app.init();
|
||||
@ -180,6 +180,8 @@ export default class PresupuestoWizard {
|
||||
|
||||
async init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
$.ajaxSetup({
|
||||
beforeSend: function (xhr) {
|
||||
const token = document.querySelector('meta[name="_csrf"]')?.content;
|
||||
@ -190,7 +192,7 @@ export default class PresupuestoWizard {
|
||||
|
||||
const root = document.getElementById('presupuesto-app');
|
||||
const mode = root?.dataset.mode || 'public';
|
||||
const presupuestoId = root?.dataset.id || null;
|
||||
const presupuestoId = this.opts.presupuestoId || null;
|
||||
|
||||
let stored = null;
|
||||
if (this.opts.useSessionCache) {
|
||||
@ -249,26 +251,19 @@ export default class PresupuestoWizard {
|
||||
|
||||
const alert = $('#form-errors');
|
||||
const servicios = [];
|
||||
$('.service-checkbox:checked').each(function () {
|
||||
const $servicio = $(this);
|
||||
servicios.push({
|
||||
id: $servicio.attr('id') ?? $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim(),
|
||||
label: $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim(),
|
||||
units: $servicio.attr('id') === 'marcapaginas' ? self.formData.servicios.datosMarcapaginas.marcapaginas_tirada : 1,
|
||||
price: $servicio.data('price') ?? $(`label[for="${$servicio.attr('id')}"] .service-price`).text().trim().replace(" " + self.divExtras.data('currency'), ''),
|
||||
});
|
||||
});
|
||||
const payload = {
|
||||
id: this.opts.presupuestoId,
|
||||
mode: this.opts.mode,
|
||||
presupuesto: this.#getPresupuestoData(),
|
||||
servicios: servicios,
|
||||
servicios: this.formData.servicios.servicios,
|
||||
datosMaquetacion: this.formData.servicios.datosMaquetacion,
|
||||
datosMarcapaginas: this.formData.servicios.datosMarcapaginas,
|
||||
cliente_id: $('#cliente_id').val() || null,
|
||||
};
|
||||
try {
|
||||
alert.addClass('d-none').find('ul').empty();
|
||||
$.ajax({
|
||||
url: '/presupuesto/save',
|
||||
url: '/presupuesto/api/save',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(payload)
|
||||
@ -341,7 +336,7 @@ export default class PresupuestoWizard {
|
||||
...this.#getInteriorData(),
|
||||
...this.#getCubiertaData(),
|
||||
selectedTirada: this.formData.selectedTirada
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -501,6 +496,18 @@ export default class PresupuestoWizard {
|
||||
|
||||
$('.alto-faja-max').text(`max: ${this.formData.datosGenerales.alto} mm`);
|
||||
|
||||
// check if selected tirada is still valid
|
||||
const tiradas = [
|
||||
parseInt(this.formData.datosGenerales.tirada1),
|
||||
parseInt(this.formData.datosGenerales.tirada2) || 0,
|
||||
parseInt(this.formData.datosGenerales.tirada3) || 0,
|
||||
parseInt(this.formData.datosGenerales.tirada4) || 0,
|
||||
].filter(t => t > 0).sort((a, b) => a - b);
|
||||
|
||||
if (!tiradas.includes(this.formData.selectedTirada)) {
|
||||
this.formData.selectedTirada = tiradas[0];
|
||||
}
|
||||
|
||||
this.#loadInteriorData(data);
|
||||
|
||||
const interiorData = this.#getInteriorData();
|
||||
@ -1592,7 +1599,14 @@ export default class PresupuestoWizard {
|
||||
const $target = $(e.currentTarget);
|
||||
|
||||
if ($target.prop('checked')) {
|
||||
this.formData.servicios.servicios.push($target.val());
|
||||
this.formData.servicios.servicios.push(
|
||||
$target.val(),
|
||||
{
|
||||
id: $target.attr('id') ?? $(`label[for="${$target.attr('id')}"] .service-title`).text().trim(),
|
||||
label: $(`label[for="${$target.attr('id')}"] .service-title`).text().trim(),
|
||||
units: $target.attr('id') === 'marcapaginas' ? self.formData.servicios.datosMarcapaginas.marcapaginas_tirada : 1,
|
||||
price: $target.data('price') ?? $(`label[for="${$target.attr('id')}"] .service-price`).text().trim().replace(" " + self.divExtras.data('currency'), ''),
|
||||
});
|
||||
} else {
|
||||
const index = this.formData.servicios.servicios.indexOf($target.val());
|
||||
if (index > -1) {
|
||||
@ -1615,7 +1629,7 @@ export default class PresupuestoWizard {
|
||||
|
||||
this.divExtras.addClass('animate-fadeInUpBounce');
|
||||
for (const extra of servicios) {
|
||||
if (this.formData.servicios.servicios.includes(extra.id) && !extra.checked) {
|
||||
if (this.formData.servicios.servicios.some(s => s.id === extra.id) && !extra.checked) {
|
||||
extra.checked = true;
|
||||
if (extra.id === "marcapaginas" || extra.id === "maquetacion") {
|
||||
extra.price = extra.id === "marcapaginas" ?
|
||||
@ -1626,11 +1640,6 @@ export default class PresupuestoWizard {
|
||||
}
|
||||
const item = new ServiceOptionCard(extra);
|
||||
this.divExtras.append(item.render());
|
||||
if (item.checked) {
|
||||
if (!this.formData.servicios.servicios.includes(extra.id)) {
|
||||
this.formData.servicios.servicios.push(extra.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.#cacheFormData();
|
||||
|
||||
@ -0,0 +1,151 @@
|
||||
(() => {
|
||||
// si jQuery está cargado, añade CSRF a AJAX
|
||||
const csrfToken = document.querySelector('meta[name="_csrf"]')?.getAttribute('content');
|
||||
const csrfHeader = document.querySelector('meta[name="_csrf_header"]')?.getAttribute('content');
|
||||
if (window.$ && csrfToken && csrfHeader) {
|
||||
$.ajaxSetup({
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader(csrfHeader, csrfToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const language = document.documentElement.lang || 'es-ES';
|
||||
|
||||
// Comprueba dependencias antes de iniciar
|
||||
if (!window.DataTable) {
|
||||
console.error('DataTables no está cargado aún');
|
||||
return;
|
||||
}
|
||||
|
||||
const table = new DataTable('#presupuestos-clientes-user-datatable', {
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
orderCellsTop: true,
|
||||
pageLength: 50,
|
||||
lengthMenu: [10, 25, 50, 100, 500],
|
||||
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
|
||||
responsive: true,
|
||||
dom: 'lBrtip',
|
||||
buttons: {
|
||||
dom: {
|
||||
button: {
|
||||
className: 'btn btn-sm btn-outline-primary me-1'
|
||||
},
|
||||
buttons: [
|
||||
{ extend: 'copy' },
|
||||
{ extend: 'csv' },
|
||||
{ extend: 'excel' },
|
||||
{ extend: 'pdf' },
|
||||
{ extend: 'print' },
|
||||
{ extend: 'colvis' }
|
||||
],
|
||||
}
|
||||
},
|
||||
ajax: {
|
||||
url: '/presupuesto/datatable/clientes',
|
||||
method: 'GET',
|
||||
},
|
||||
order: [[0, 'asc']],
|
||||
columns: [
|
||||
{ data: 'id', name: 'id', orderable: true },
|
||||
{ data: 'titulo', name: 'titulo', orderable: true },
|
||||
{ data: 'tipoEncuadernacion', name: 'tipoEncuadernacion', orderable: true },
|
||||
{ data: 'tipoCubierta', name: 'tipoCubierta', orderable: true },
|
||||
{ data: 'tipoImpresion', name: 'tipoImpresion', orderable: true },
|
||||
{ data: 'selectedTirada', name: 'selectedTirada', orderable: true },
|
||||
{ data: 'paginas', name: 'paginas', orderable: true },
|
||||
{ data: 'estado', name: 'estado', orderable: true },
|
||||
{ data: 'totalConIva', name: 'totalConIva', orderable: true },
|
||||
{ data: 'updatedAt', name: 'updatedAt', orderable: true },
|
||||
{ data: 'actions', orderable: false, searchable: false }
|
||||
],
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-user-datatable').on('click', '.btn-edit-privado', function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
const id = $(this).data('id');
|
||||
if (id) {
|
||||
window.location.href = '/presupuesto/edit/' + id;
|
||||
}
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-user-datatable').on('click', '.btn-delete-privado', function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
const id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: window.languageBundle.get(['presupuesto.delete.title']) || 'Eliminar presupuesto',
|
||||
html: window.languageBundle.get(['presupuesto.delete.text']) || 'Esta acción no se puede deshacer.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger w-xs mt-2',
|
||||
cancelButton: 'btn btn-light w-xs mt-2'
|
||||
},
|
||||
confirmButtonText: window.languageBundle.get(['presupuesto.delete.button']) || 'Eliminar',
|
||||
cancelButtonText: window.languageBundle.get(['app.cancelar']) || 'Cancelar',
|
||||
}).then((result) => {
|
||||
if (!result.isConfirmed) return;
|
||||
|
||||
$.ajax({
|
||||
url: '/presupuesto/' + id,
|
||||
type: 'DELETE',
|
||||
success: function () {
|
||||
Swal.fire({
|
||||
icon: 'success', title: window.languageBundle.get(['presupuesto.delete.ok.title']) || 'Eliminado',
|
||||
text: window.languageBundle.get(['presupuesto.delete.ok.text']) || 'El presupuesto ha sido eliminado con éxito.',
|
||||
showConfirmButton: true,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary w-xs mt-2',
|
||||
},
|
||||
});
|
||||
$('#presupuestos-anonimos-datatable').DataTable().ajax.reload(null, false);
|
||||
},
|
||||
error: function (xhr) {
|
||||
// usa el mensaje del backend; fallback genérico por si no llega JSON
|
||||
const msg = (xhr.responseJSON && xhr.responseJSON.message)
|
||||
|| 'Error al eliminar el presupuesto.';
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'No se pudo eliminar',
|
||||
text: msg,
|
||||
buttonsStyling: false,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary me-2', // clases para el botón confirmar
|
||||
cancelButton: 'btn btn-light' // clases para cancelar
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-user-datatable').on('keyup', '.presupuesto-filter', function (e) {
|
||||
const colName = $(this).data('col');
|
||||
const colIndex = table.column(colName + ':name').index();
|
||||
|
||||
if (table.column(colIndex).search() !== this.value) {
|
||||
table.column(colIndex).search(this.value).draw();
|
||||
}
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-user-datatable').on('change', '.presupuesto-select-filter', function (e) {
|
||||
const name = $(this).data('col');
|
||||
const colIndex = table.column(name + ':name').index();
|
||||
|
||||
if (table.column(colIndex).search() !== this.value) {
|
||||
table.column(colIndex).search(this.value).draw();
|
||||
}
|
||||
});
|
||||
|
||||
$('#addPresupuestoButton').on('click', async function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
window.location.href = '/presupuesto/add/private/' + $('#cliente_id').val();
|
||||
});
|
||||
|
||||
})();
|
||||
@ -24,12 +24,11 @@ import { preguntarTipoPresupuesto } from './presupuesto-utils.js';
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
orderCellsTop: true,
|
||||
stateSave: true,
|
||||
pageLength: 50,
|
||||
lengthMenu: [10, 25, 50, 100, 500],
|
||||
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
|
||||
responsive: true,
|
||||
dom: 'Bflrtip',
|
||||
dom: 'lBrtip',
|
||||
buttons: {
|
||||
dom: {
|
||||
button: {
|
||||
@ -51,20 +50,20 @@ import { preguntarTipoPresupuesto } from './presupuesto-utils.js';
|
||||
},
|
||||
order: [[0, 'asc']],
|
||||
columns: [
|
||||
{ data: 'id', name: 'id', title: 'ID', orderable: true },
|
||||
{ data: 'titulo', name: 'titulo', title: 'Título', orderable: true },
|
||||
{ data: 'tipoEncuadernacion', name: 'tipoEncuadernacion', title: 'Encuadernación', orderable: true },
|
||||
{ data: 'tipoCubierta', name: 'tipoCubierta', title: 'Cubierta', orderable: true },
|
||||
{ data: 'tipoImpresion', name: 'tipoImpresion', title: 'Tipo de impresión', orderable: true },
|
||||
{ data: 'tirada', name: 'selectedTirada', title: 'Tirada', orderable: true },
|
||||
{ data: 'paginas', name: 'paginas', title: 'Páginas', orderable: true },
|
||||
{ data: 'estado', name: 'estado', title: 'Estado', orderable: true },
|
||||
{ data: 'totalConIva', name: 'totalConIva', title: 'Total con IVA', orderable: true },
|
||||
{ data: 'pais', name: 'pais', title: 'País', orderable: true },
|
||||
{ data: 'region', name: 'region', title: 'Región', orderable: true },
|
||||
{ data: 'ciudad', name: 'ciudad', title: 'Ciudad', orderable: true },
|
||||
{ data: 'updatedAt', name: 'updatedAt', title: 'Actualizado el', orderable: true },
|
||||
{ data: 'actions', title: 'Acciones', orderable: false, searchable: false }
|
||||
{ data: 'id', name: 'id', orderable: true },
|
||||
{ data: 'titulo', name: 'titulo', orderable: true },
|
||||
{ data: 'tipoEncuadernacion', name: 'tipoEncuadernacion', orderable: true },
|
||||
{ data: 'tipoCubierta', name: 'tipoCubierta', orderable: true },
|
||||
{ data: 'tipoImpresion', name: 'tipoImpresion', orderable: true },
|
||||
{ data: 'selectedTirada', name: 'selectedTirada', orderable: true },
|
||||
{ data: 'paginas', name: 'paginas', orderable: true },
|
||||
{ data: 'estado', name: 'estado', orderable: true },
|
||||
{ data: 'totalConIva', name: 'totalConIva', orderable: true },
|
||||
{ data: 'pais', name: 'pais', orderable: true },
|
||||
{ data: 'region', name: 'region', orderable: true },
|
||||
{ data: 'ciudad', name: 'ciudad', orderable: true },
|
||||
{ data: 'updatedAt', name: 'updatedAt', orderable: true },
|
||||
{ data: 'actions', orderable: false, searchable: false }
|
||||
],
|
||||
});
|
||||
|
||||
@ -130,6 +129,148 @@ import { preguntarTipoPresupuesto } from './presupuesto-utils.js';
|
||||
});
|
||||
});
|
||||
|
||||
$('#presupuestos-anonimos-datatable').on('keyup', '.presupuesto-filter', function (e) {
|
||||
const colName = $(this).data('col');
|
||||
const colIndex = table_anonimos.column(colName + ':name').index();
|
||||
|
||||
if (table_anonimos.column(colIndex).search() !== this.value) {
|
||||
table_anonimos.column(colIndex).search(this.value).draw();
|
||||
}
|
||||
});
|
||||
|
||||
$('#presupuestos-anonimos-datatable').on('change', '.presupuesto-select-filter', function (e) {
|
||||
const colName = $(this).data('col');
|
||||
const colIndex = table_anonimos.column(colName + ':name').index();
|
||||
const value = $(this).val();
|
||||
table_anonimos.column(colIndex).search(value).draw();
|
||||
});
|
||||
|
||||
|
||||
const table_clientes = new DataTable('#presupuestos-clientes-datatable', {
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
orderCellsTop: true,
|
||||
pageLength: 50,
|
||||
lengthMenu: [10, 25, 50, 100, 500],
|
||||
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
|
||||
responsive: true,
|
||||
dom: 'lBrtip',
|
||||
buttons: {
|
||||
dom: {
|
||||
button: {
|
||||
className: 'btn btn-sm btn-outline-primary me-1'
|
||||
},
|
||||
buttons: [
|
||||
{ extend: 'copy' },
|
||||
{ extend: 'csv' },
|
||||
{ extend: 'excel' },
|
||||
{ extend: 'pdf' },
|
||||
{ extend: 'print' },
|
||||
{ extend: 'colvis' }
|
||||
],
|
||||
}
|
||||
},
|
||||
ajax: {
|
||||
url: '/presupuesto/datatable/clientes',
|
||||
method: 'GET',
|
||||
},
|
||||
order: [[0, 'asc']],
|
||||
columns: [
|
||||
{ data: 'id', name: 'id', orderable: true },
|
||||
{ data: 'user', name: 'user.fullName', orderable: true },
|
||||
{ data: 'titulo', name: 'titulo', orderable: true },
|
||||
{ data: 'tipoEncuadernacion', name: 'tipoEncuadernacion', orderable: true },
|
||||
{ data: 'tipoCubierta', name: 'tipoCubierta', orderable: true },
|
||||
{ data: 'tipoImpresion', name: 'tipoImpresion', orderable: true },
|
||||
{ data: 'selectedTirada', name: 'selectedTirada', orderable: true },
|
||||
{ data: 'paginas', name: 'paginas', orderable: true },
|
||||
{ data: 'estado', name: 'estado', orderable: true },
|
||||
{ data: 'totalConIva', name: 'totalConIva', orderable: true },
|
||||
{ data: 'updatedAt', name: 'updatedAt', orderable: true },
|
||||
{ data: 'actions', orderable: false, searchable: false }
|
||||
],
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-datatable').on('click', '.btn-edit-privado', function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
const id = $(this).data('id');
|
||||
if (id) {
|
||||
window.location.href = '/presupuesto/edit/' + id;
|
||||
}
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-datatable').on('click', '.btn-delete-privado', function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
const id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: window.languageBundle.get(['presupuesto.delete.title']) || 'Eliminar presupuesto',
|
||||
html: window.languageBundle.get(['presupuesto.delete.text']) || 'Esta acción no se puede deshacer.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger w-xs mt-2',
|
||||
cancelButton: 'btn btn-light w-xs mt-2'
|
||||
},
|
||||
confirmButtonText: window.languageBundle.get(['presupuesto.delete.button']) || 'Eliminar',
|
||||
cancelButtonText: window.languageBundle.get(['app.cancelar']) || 'Cancelar',
|
||||
}).then((result) => {
|
||||
if (!result.isConfirmed) return;
|
||||
|
||||
$.ajax({
|
||||
url: '/presupuesto/' + id,
|
||||
type: 'DELETE',
|
||||
success: function () {
|
||||
Swal.fire({
|
||||
icon: 'success', title: window.languageBundle.get(['presupuesto.delete.ok.title']) || 'Eliminado',
|
||||
text: window.languageBundle.get(['presupuesto.delete.ok.text']) || 'El presupuesto ha sido eliminado con éxito.',
|
||||
showConfirmButton: true,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary w-xs mt-2',
|
||||
},
|
||||
});
|
||||
$('#presupuestos-clientes-datatable').DataTable().ajax.reload(null, false);
|
||||
},
|
||||
error: function (xhr) {
|
||||
// usa el mensaje del backend; fallback genérico por si no llega JSON
|
||||
const msg = (xhr.responseJSON && xhr.responseJSON.message)
|
||||
|| 'Error al eliminar el presupuesto.';
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'No se pudo eliminar',
|
||||
text: msg,
|
||||
buttonsStyling: false,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary me-2', // clases para el botón confirmar
|
||||
cancelButton: 'btn btn-light' // clases para cancelar
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('#presupuestos-clientes-datatable').on('keyup', '.presupuesto-filter', function (e) {
|
||||
const colName = $(this).data('col');
|
||||
const colIndex = table_clientes.column(colName + ':name').index();
|
||||
|
||||
if (table_clientes.column(colIndex).search() !== this.value) {
|
||||
table_clientes.column(colIndex).search(this.value).draw();
|
||||
}
|
||||
});
|
||||
|
||||
$('#presupuestos-clientes-datatable').on('change', '.presupuesto-select-filter', function (e) {
|
||||
const colName = $(this).data('col');
|
||||
const colIndex = table_clientes.column(colName + ':name').index();
|
||||
const value = $(this).val();
|
||||
table_clientes.column(colIndex).search(value).draw();
|
||||
});
|
||||
|
||||
|
||||
$('#addPresupuestoButton').on('click', async function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user