Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function generate() {
- const httpGet = (url, callback) => {
- const http = new XMLHttpRequest();
- http.open('GET', url, true);
- http.onload = () => {
- if (http.status >= 200 && http.status < 400) {
- // Success!
- callback(http.responseText);
- }
- };
- http.send();
- };
- httpGet('/get_vistorias', (res) => {
- let vistorias = JSON.parse(res);
- console.log(vistorias)
- document.querySelector('body').innerHTML += `<table id="vist-table"><tr>
- <th>Número</th>
- <th>Data de Vistoria</th>
- <th>Grupo</th>
- <th>Concessionária</th>
- <th>Placa</th>
- <th>Setor</th>
- <th>Vendedor</th>
- <th>Modo de Pagamento</th>
- <th>Valor</th>
- </tr></table>`;
- vistorias.forEach((vist) => {
- document.querySelector('#vist-table').innerHTML += `<tr>
- <td>${vist.pk}</td>
- <td>${vist.fields.Data_de_Registro.split('-').reverse().join('/')}
- </td>
- <td>${vist.fields.Grupo_da_concessionaria[0].toUpperCase() + vist.fields.Grupo_da_concessionaria.slice(1)}</td>
- <td>${vist.fields.Concessionaria[0].toUpperCase() + vist.fields.Concessionaria.slice(1)}</td>
- <td>${vist.fields.Placa.toUpperCase()}</td>
- <td>${vist.fields.Setor[0].toUpperCase() + vist.fields.Setor.slice(1)}</td>
- <td>${vist.fields.Vendedor[0].toUpperCase() + vist.fields.Vendedor.slice(1)}</td>
- <td>${vist.fields.Modos_de_pagamento[0].toUpperCase() + vist.fields.Modos_de_pagamento.slice(1)}</td>
- <td>${vist.fields.Valor_pago}</td>
- </tr>`;
- });
- var page = new URL(window.location.href).searchParams.get("page");
- var doc = new jsPDF('landscape', 'pt');
- var res = doc.autoTableHtmlToJson(document.getElementById("vist-table"));
- doc.autoTable(res.columns, res.data, { margin: { top: 80 } });
- var header = function (data) {
- doc.setFontSize(18);
- doc.setTextColor(40);
- doc.setFontStyle('normal');
- //doc.addImage(headerImgData, 'JPEG', data.settings.margin.left, 20, 50, 50);
- // doc.text("Relatorio das Vistorias", data.settings.margin.left, 50);
- };
- var options = {
- beforePageContent: header,
- margin: {
- top: 80
- },
- startY: doc.autoTableEndPosY() + 20
- };
- const putZero = (num) => {
- return num >= 10 ? num : `0${num}`
- }
- // doc.autoTable(res.columns, res.data, options);
- // console.log(date)
- doc.text(`Relatório de Vistorias - ${putZero(new Date().getDate())}/${putZero(new Date().getMonth()+1)}/${putZero(new Date().getFullYear())}`, 50, 49)
- doc.save(`Relatório-${putZero(new Date().getDate())}-${putZero(new Date().getMonth()+1)}-${putZero(new Date().getFullYear())}.pdf`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement