mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
zip pdf download
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import OrdenTrabajoDatatable from '../../components/datatables/otDatatable.js'
|
||||
import Ajax from '../../components/ajax.js'
|
||||
import { alertError, alertSuccessMessage } from '../../components/alerts/sweetAlert.js'
|
||||
|
||||
$(function () {
|
||||
const otDatatable = new OrdenTrabajoDatatable($("#ots-datatables-container"))
|
||||
@ -9,5 +11,59 @@ $(function () {
|
||||
otDatatable.initNews()
|
||||
otDatatable.initProd()
|
||||
otDatatable.initWaiting()
|
||||
otDatatable.events()
|
||||
// otDatatable.initRevisionComercial()
|
||||
})
|
||||
$("#btn-download-pdf-zip").on('click', async () => {
|
||||
let zip = new JSZip()
|
||||
let ordenesTrabajo = otDatatable.getSelectIDs()
|
||||
for (let element of ordenesTrabajo) {
|
||||
try {
|
||||
|
||||
// Create hidden iframe
|
||||
Notiflix.Block.circle('.section-block',{opacity : 1});
|
||||
const response = await getPdf(element);
|
||||
var opt = {
|
||||
margin: 2,
|
||||
filename: $(response).find(".pdf-wrapper").data("id") + ".pdf",
|
||||
image: { type: 'jpeg', quality: 1 },
|
||||
html2canvas: { scale: 4, logging: false },
|
||||
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
|
||||
};
|
||||
let pdf = await html2pdf().set(opt).from(response).outputPdf('blob');
|
||||
zip.file(opt.filename, pdf);
|
||||
} catch (error) {
|
||||
}
|
||||
};
|
||||
if (ordenesTrabajo.length > 0) {
|
||||
|
||||
Notiflix.Block.remove('.section-block');
|
||||
zip.generateAsync({ type: "blob" }).then(function (blob) {
|
||||
const now = new Date();
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
const timestamp = `${now.getFullYear()}_${pad(now.getMonth() + 1)}_${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
||||
const filename = `ordenes_trabajo_${timestamp}.zip`;
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
});
|
||||
}else{
|
||||
alertError('Seleccione una OT para descargar').fire()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
const getPdf = (otId) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
new Ajax('/produccion/ordentrabajo/pdf/content/' + otId, null, null, resolve, reject).get()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user