feat: create xls export in daftar gangguan dialihkan ke posko lain

This commit is contained in:
kur0nek-o
2024-03-20 10:24:31 +07:00
parent 39c75a6af8
commit ae5bd2366e
2 changed files with 181 additions and 14 deletions

View File

@ -375,6 +375,24 @@ const dataDetail = ref<any>()
const showDetail = ref(false)
const closeDetail = () => (showDetail.value = false)
const setHeaderStyle = (
worksheet: any,
row: number,
column: number,
value: string,
horizontalAlignment: boolean = false
) => {
const cell = worksheet.getRow(row).getCell(column)
cell.value = value
cell.alignment = { vertical: 'middle' }
cell.font = { bold: true }
if (horizontalAlignment) {
cell.alignment.horizontal = 'center'
}
}
const onExporting = (e: any) => {
const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : ''
@ -401,7 +419,6 @@ const onExporting = (e: any) => {
const doc = new jsPDF({
orientation: 'landscape'
})
autoTable(doc, {
head: [
['PT. PLN(Persero)', '', ''],
@ -436,7 +453,6 @@ const onExporting = (e: any) => {
theme: 'plain',
startY: 10
})
autoTable(doc, {
head: [
['DAFTAR GANGGUAN DIALIHKAN KE POSKO LAIN'],
@ -452,7 +468,6 @@ const onExporting = (e: any) => {
theme: 'plain',
startY: 18
})
autoTable(doc, {
head: [
[
@ -525,7 +540,6 @@ const onExporting = (e: any) => {
},
startY: 23
})
autoTable(doc, {
head: [
[`${dayTo}, ${dateToFormat}`],
@ -547,7 +561,6 @@ const onExporting = (e: any) => {
tableWidth: 50,
margin: { left: 230 }
})
doc
.save('Laporan Daftar Gangguan Dialihkan Ke Posko Lain.pdf', { returnPromise: true })
.then(() => {
@ -557,15 +570,64 @@ const onExporting = (e: any) => {
const workbook = new Workbook()
const worksheet = workbook.addWorksheet('Daftar Gangguan Dialihkan Ke Posko Lain')
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
setHeaderStyle(
worksheet,
2,
1,
`UNIT INDUK : ${
reportMeta.value.uid
? reportMeta.value.uid.name.toUpperCase()
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
}`
)
setHeaderStyle(
worksheet,
3,
1,
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
reportMeta.value.up3
? reportMeta.value.up3.name.toUpperCase()
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
}`
)
setHeaderStyle(
worksheet,
4,
1,
`POSKO : ${
reportMeta.value.posko
? reportMeta.value.posko.name.toUpperCase()
: 'Semua Posko'.toUpperCase()
}`
)
setHeaderStyle(worksheet, 7, 8, `DAFTAR GANGGUAN DIALIHKAN KE POSKO LAIN`, true)
setHeaderStyle(
worksheet,
8,
8,
`PERIODE TANGGAL : ${dateFromFormat} SD TGL ${dateToFormat}`,
true
)
worksheet.mergeCells('A1:F1')
worksheet.mergeCells('A2:F2')
worksheet.mergeCells('A3:F3')
worksheet.mergeCells('A4:F4')
worksheet.mergeCells('H7:I7')
worksheet.mergeCells('H8:I8')
exportToExcel({
component: e.component,
worksheet,
autoFilterEnabled: true
autoFilterEnabled: true,
topLeftCell: { row: 10, column: 1 }
}).then(() => {
workbook.xlsx.writeBuffer().then((buffer: any) => {
saveAs(
new Blob([buffer], { type: 'application/octet-stream' }),
'Daftar Gangguan Dialihkan Ke Posko Lain.xlsx'
'Laporan Daftar Gangguan Dialihkan Ke Posko Lain.xlsx'
)
})
})