mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
70 lines
2.6 KiB
JavaScript
70 lines
2.6 KiB
JavaScript
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"))
|
|
otDatatable.init()
|
|
otDatatable.initPendientes()
|
|
otDatatable.initFerroPendiente()
|
|
otDatatable.initFerroOk()
|
|
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()
|
|
})
|
|
}
|