feat: create export pdf in rekapitulasi gangguan per jenis gangguan

This commit is contained in:
kur0nek-o
2024-03-22 14:48:50 +07:00
parent fa6e11f25a
commit 0487301697
4 changed files with 498 additions and 33 deletions

View File

@@ -25,7 +25,7 @@ const reportName = 'Rekapitulasi Gangguan All'
const groupingData = (data: any) => {
const groupedData: any = {}
data.value.forEach((item: any) => {
data.forEach((item: any) => {
const { nama_regional, nama_uid } = item
if (!groupedData[nama_regional]) {
@@ -216,7 +216,7 @@ const formatData = (rawData: any) => {
}
formattedData.push([
{ content: 'Total', colSpan: 2, styles: { fontStyle: 'bold' } },
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
formatNumber(total.total),
formatNumber(total.total_selesai),
formatPercentage((total.total_selesai / total.total) * 100),
@@ -259,7 +259,7 @@ const formatData = (rawData: any) => {
}
const formatMetaData = (reportMeta: any) => {
const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : ''
const periode = reportMeta.periode ? reportMeta.periode.split(' s/d ') : ''
let dateFromFormat = ''
let dateToFormat = ''
@@ -283,40 +283,39 @@ const formatMetaData = (reportMeta: any) => {
return { dateFromFormat, dateToFormat, dayTo }
}
const exportToPDF = (reportMeta: any, rawData: any) => {
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
const data = formatData(rawData)
const meta = formatMetaData(reportMeta)
const doc = new jsPDF({
orientation: 'landscape'
})
const fontSize = 5
autoTable(doc, {
head: [
['PT. PLN(Persero)', '', ''],
[
{ content: 'UNIT INDUK', styles: { cellWidth: 25 } },
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
{ content: ':', styles: { cellWidth: 1 } },
reportMeta.value.uid
? reportMeta.value.uid.name.toUpperCase()
reportMeta.uid
? reportMeta.uid.name.toUpperCase()
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
],
[
'UNIT PELAKSANA PELAYANAN PELANGGAN',
':',
reportMeta.value.up3
? reportMeta.value.up3.name.toUpperCase()
reportMeta.up3
? reportMeta.up3.name.toUpperCase()
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
],
[
'POSKO',
':',
reportMeta.value.posko
? reportMeta.value.posko.name.toUpperCase()
: 'Semua Posko'.toUpperCase()
reportMeta.posko ? reportMeta.posko.name.toUpperCase() : 'Semua Posko'.toUpperCase()
]
],
styles: {
fontSize: 3,
fontSize,
cellPadding: 0.1,
textColor: [0, 0, 0],
fontStyle: 'bold'
@@ -331,14 +330,14 @@ const exportToPDF = (reportMeta: any, rawData: any) => {
[`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`]
],
styles: {
fontSize: 3,
fontSize,
cellPadding: 0.1,
textColor: [0, 0, 0],
fontStyle: 'bold',
halign: 'center'
},
theme: 'plain',
startY: 18
startY: 23
})
autoTable(doc, {
@@ -405,7 +404,7 @@ const exportToPDF = (reportMeta: any, rawData: any) => {
],
body: data,
styles: {
fontSize: 3,
fontSize,
cellPadding: 1,
lineColor: [0, 0, 0],
lineWidth: 0.1,
@@ -429,8 +428,15 @@ const exportToPDF = (reportMeta: any, rawData: any) => {
return word.toUpperCase()
})
}
if (data.cell.text[0] === 'TOTAL') {
for (const key in data.row.cells) {
data.row.cells[key].styles.fillColor = [192, 192, 192]
data.row.cells[key].styles.fontStyle = 'bold'
}
}
},
startY: 23
startY: 30
})
autoTable(doc, {
@@ -444,7 +450,7 @@ const exportToPDF = (reportMeta: any, rawData: any) => {
]
],
styles: {
fontSize: 3,
fontSize,
cellPadding: 0.1,
textColor: [0, 0, 0],
fontStyle: 'bold',
@@ -455,9 +461,13 @@ const exportToPDF = (reportMeta: any, rawData: any) => {
margin: { left: 230 }
})
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
console.log('pdf berhasil disimpan')
})
if (preview) {
window.open(doc.output('bloburl'))
} else {
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
console.log('pdf berhasil disimpan')
})
}
}
export { exportToPDF }