From e1b2521368e809d59415eb7be9000966898f9bae Mon Sep 17 00:00:00 2001 From: kur0nek-o Date: Sat, 16 Mar 2024 14:34:46 +0700 Subject: [PATCH] fix: pdf style gangguan melapor lebih dari 1 kali --- .../Pages/Gangguan/Daftar/DGangguan_MLD1K.vue | 142 +++++++++++++++++- 1 file changed, 138 insertions(+), 4 deletions(-) diff --git a/src/components/Pages/Gangguan/Daftar/DGangguan_MLD1K.vue b/src/components/Pages/Gangguan/Daftar/DGangguan_MLD1K.vue index 72702ae..18cc71d 100755 --- a/src/components/Pages/Gangguan/Daftar/DGangguan_MLD1K.vue +++ b/src/components/Pages/Gangguan/Daftar/DGangguan_MLD1K.vue @@ -337,6 +337,14 @@ const data = ref([]) const dataDetail = ref({}) const showDetail = ref(false) const filters = ref() +const reportMeta = ref({ + uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' }, + up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' }, + posko: { id: 0, name: 'Semua Posko' }, + periode: '', + minJmlLapor: 1, + maxJmlLapor: 1 +}) const onSelectionChanged = ({ selectedRowsData }: any) => { const data = selectedRowsData[0] @@ -380,6 +388,8 @@ const filterData = (params: any) => { if (queryResult.data != undefined) { data.value = queryResult.data.daftarGangguanMelaporLebihDariSatuKali } + + reportMeta.value = filters.value console.log(queryResult.data) console.log(queryResult.loading) console.log(queryResult.networkStatus) @@ -390,6 +400,27 @@ const filterData = (params: any) => { } const onExporting = (e: any) => { + const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : '' + + let dateFromFormat = '' + let dateToFormat = '' + let dayTo = '' + + if (periode != '') { + const dateFrom = new Date(periode[0].split('-').reverse().join('-')) + const dateTo = new Date(periode[1].split('-').reverse().join('-')) + + dateFromFormat = `${dateFrom.getDate()}-${dateFrom.toLocaleString('default', { + month: 'long' + })}-${dateFrom.getFullYear()}` + + dateToFormat = `${dateTo.getDate()}-${dateTo.toLocaleString('default', { + month: 'long' + })}-${dateTo.getFullYear()}` + + dayTo = dateTo.toLocaleString('default', { weekday: 'long' }) + } + if (e.format === 'pdf') { const doc = new jsPDF({ orientation: 'landscape' @@ -397,7 +428,60 @@ const onExporting = (e: any) => { autoTable(doc, { head: [ + ['PT. PLN(Persero)', '', ''], [ + { content: 'UNIT INDUK', styles: { cellWidth: 25 } }, + { content: ':', styles: { cellWidth: 1 } }, + reportMeta.value.uid + ? reportMeta.value.uid.name.toUpperCase() + : 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase() + ], + [ + 'UNIT PELAKSANA PELAYANAN PELANGGAN', + ':', + reportMeta.value.up3 + ? reportMeta.value.up3.name.toUpperCase() + : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase() + ], + [ + 'POSKO', + ':', + reportMeta.value.posko + ? reportMeta.value.posko.name.toUpperCase() + : 'Semua Posko'.toUpperCase() + ], + ['LAPOR ULANG', ':', `${reportMeta.value.minJmlLapor} s/d ${reportMeta.value.maxJmlLapor}`] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10 + }) + + autoTable(doc, { + head: [ + ['Daftar Gangguan Melapor Lebih Dari 1 Kali'.toUpperCase()], + [`PERIODE TANGGAL : ${dateFromFormat} SD TGL ${dateToFormat}`] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold', + halign: 'center' + }, + theme: 'plain', + startY: 18 + }) + + autoTable(doc, { + head: [ + [ + 'No', 'No Laporan', 'Tgl Lapor', 'Tgl Response', @@ -415,7 +499,8 @@ const onExporting = (e: any) => { 'Posko' ] ], - body: data.value.map((item) => [ + body: data.value.map((item, i) => [ + { content: ++i, styles: { halign: 'right' } }, item.no_laporan, item.waktu_lapor, item.waktu_response, @@ -433,11 +518,60 @@ const onExporting = (e: any) => { item.nama_posko ]), styles: { - fontSize: 4 - } + fontSize: 3, + cellPadding: 1, + lineColor: [0, 0, 0], + lineWidth: 0.1, + cellWidth: 'auto' + }, + rowPageBreak: 'auto', + headStyles: { + fillColor: [192, 192, 192], + textColor: [0, 0, 0], + fontStyle: 'bold', + cellWidth: 'wrap', + halign: 'center' + }, + bodyStyles: { + textColor: [0, 0, 0] + }, + didParseCell: function (data) { + if (data.row.section === 'head') { + data.cell.text = data.cell.text.map(function (word: any) { + return word.toUpperCase() + }) + } + }, + startY: 23 }) - doc.save('Daftar Gangguan Melapor Lebih Dari 1 Kali.pdf') + autoTable(doc, { + head: [ + [`${dayTo}, ${dateToFormat}`], + [ + { + content: '(.........................................)', + styles: { minCellHeight: 8, valign: 'bottom' } + } + ] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold', + halign: 'center' + }, + theme: 'plain', + tableWidth: 50, + margin: { left: 230 } + }) + + doc + .save('Laporan Daftar Gangguan Melapor Lebih Dari 1 Kali.pdf', { returnPromise: true }) + .then(() => { + console.log('pdf berhasil disimpan') + }) } else { const workbook = new Workbook() const worksheet = workbook.addWorksheet('Daftar Gangguan Melapor Lebih Dari 1 Kali')