diff --git a/src/components/Pages/Gangguan/Rekap/RGangguan_ALL.vue b/src/components/Pages/Gangguan/Rekap/RGangguan_ALL.vue index e69a693..baca03e 100755 --- a/src/components/Pages/Gangguan/Rekap/RGangguan_ALL.vue +++ b/src/components/Pages/Gangguan/Rekap/RGangguan_ALL.vue @@ -588,7 +588,7 @@ :hover-state-enabled="true" @selection-changed="onDataSubSelectionChanged" :column-width="100" - @exporting="onExporting" + @exporting="onExportingDetail" :allow-column-resizing="true" column-resizing-mode="widget" > @@ -1084,7 +1084,12 @@ import DetailDialog from '@/components/Dialogs/DetailDialog.vue' import InputText from '@/components/InputText.vue' import { apolloClient } from '@/utils/api/api.graphql' import { provideApolloClient } from '@vue/apollo-composable' -import { exportToPDF, exportToXLSX } from '@/report/Gangguan/Rekap/RGangguan_ALL' +import { + exportToPDF, + exportToXLSX, + exportDetailToPDF, + exportDetailToXLSX +} from '@/report/Gangguan/Rekap/RGangguan_ALL' const client = apolloClient() provideApolloClient(client) @@ -1340,6 +1345,15 @@ const onExporting = (e: any) => { } } +const onExportingDetail = (e: any) => { + if (e.format === 'pdf') { + exportDetailToPDF(reportMeta.value, dataSub.value) + } else if (e.format === 'xlsx') { + exportDetailToXLSX(reportMeta.value, e) + } else { + } +} + const onDataSelectionChanged = ({ selectedRowsData }: any) => { if (selectedRowsData[0] != undefined) { dataSelected.value = selectedRowsData[0] diff --git a/src/report/Gangguan/Rekap/RGangguan_ALL.ts b/src/report/Gangguan/Rekap/RGangguan_ALL.ts index 99a4438..42c6789 100644 --- a/src/report/Gangguan/Rekap/RGangguan_ALL.ts +++ b/src/report/Gangguan/Rekap/RGangguan_ALL.ts @@ -21,6 +21,8 @@ import { setHeaderStyle } from '@/report/utils/xlsx' import { formatNumber, formatPercentage } from '@/utils/numbers' const reportName = 'Rekapitulasi Gangguan All' +const fontSize = 5 +const detailFontSize = 3 const groupingData = (data: any) => { const groupedData: any = {} @@ -289,7 +291,6 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => const doc = new jsPDF({ orientation: 'landscape' }) - const fontSize = 5 autoTable(doc, { head: [ @@ -470,6 +471,156 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => } } +const exportDetailToPDF = (reportMeta: any, rawData: any) => { + const meta = formatMetaData(reportMeta) + const doc = new jsPDF({ + orientation: 'landscape' + }) + + autoTable(doc, { + head: [['PT. PLN(Persero)']], + styles: { + fontSize: detailFontSize, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10, + margin: 5 + }) + + autoTable(doc, { + head: [ + [`Daftar Detail ${reportName}`.toUpperCase()], + [`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`] + ], + styles: { + fontSize: detailFontSize, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold', + halign: 'center' + }, + theme: 'plain', + startY: 18, + margin: 5 + }) + + autoTable(doc, { + head: [ + [ + 'No', + 'Posko', + 'No Lapor', + 'Tgl/Jam Lapor', + 'Tgl/Jam Datang', + 'Tgl/Jam Nyala', + 'Durasi Response Time', + 'Durasi Recovery Time', + 'Durasi Penugasan Regu', + 'Durasi Perjalanan Regu', + 'Jarak Closing (m)', + 'Dispatch Oleh', + 'IDPEL/NO METER', + 'Nama Pelapor', + 'Alamat Pelapor', + 'No Telp Pelapor', + 'Keterangan Pelapor', + 'Sumber Lapor', + 'Diselesaikan Oleh', + 'Status', + 'Referensi Marking', + 'Kode Gangguan', + 'Jenis Gangguan', + 'Penyebab', + 'Tindakan' + ] + ], + body: rawData.map((item: any, i: any) => [ + { content: i + 1, styles: { halign: 'right' } }, + item.nama_posko, + item.no_laporan, + item.waktu_lapor, + item.waktu_response, + item.waktu_recovery, + item.durasi_response_time, + item.durasi_recovery_time, + '', + '', + item.jarak_closing, + item.dispatch_oleh, + item.idpel_nometer, + item.nama_pelapor, + item.alamat_pelapor, + item.no_telp_pelapor, + item.keterangan_pelapor, + item.pembuat_laporan, + item.diselesaikan_oleh, + item.status_akhir, + item.referensi_marking, + item.kode_gangguan, + item.jenis_gangguan, + item.penyebab, + item.tindakan + ]), + styles: { + fontSize: detailFontSize, + 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', + valign: 'middle' + }, + 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: 24, + margin: 5 + }) + + autoTable(doc, { + head: [ + [`${meta.dayTo}, ${meta.dateToFormat}`], + [ + { + content: '(.........................................)', + styles: { minCellHeight: 8, valign: 'bottom' } + } + ] + ], + styles: { + fontSize: detailFontSize, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold', + halign: 'center' + }, + theme: 'plain', + tableWidth: 50, + margin: { left: 230 } + }) + + doc.save(`Laporan Detail ${reportName}.pdf`, { returnPromise: true }).then(() => { + console.log('pdf berhasil disimpan') + }) +} + const exportToXLSX = (reportMeta: any, e: any) => { const meta = formatMetaData(reportMeta) const workbook = new Workbook() @@ -535,4 +686,39 @@ const exportToXLSX = (reportMeta: any, e: any) => { e.cancel = true } -export { exportToPDF, exportToXLSX } +const exportDetailToXLSX = (reportMeta: any, e: any) => { + const meta = formatMetaData(reportMeta) + const workbook = new Workbook() + const worksheet = workbook.addWorksheet(`${reportName}`) + + setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)') + setHeaderStyle(worksheet, 3, 8, `Daftar Detail ${reportName}`.toUpperCase(), true) + setHeaderStyle( + worksheet, + 4, + 8, + `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + true + ) + + worksheet.mergeCells('H3:J3') + worksheet.mergeCells('H4:J4') + + exportToExcel({ + component: e.component, + worksheet, + autoFilterEnabled: true, + topLeftCell: { row: 6, column: 1 } + }).then(() => { + workbook.xlsx.writeBuffer().then((buffer: any) => { + saveAs( + new Blob([buffer], { type: 'application/octet-stream' }), + `Laporan Detail ${reportName}.xlsx` + ) + }) + }) + + e.cancel = true +} + +export { exportToPDF, exportToXLSX, exportDetailToPDF, exportDetailToXLSX }