diff --git a/src/components/Pages/Gangguan/Daftar/DGangguan_BM.vue b/src/components/Pages/Gangguan/Daftar/DGangguan_BM.vue index bb25347..1970a02 100755 --- a/src/components/Pages/Gangguan/Daftar/DGangguan_BM.vue +++ b/src/components/Pages/Gangguan/Daftar/DGangguan_BM.vue @@ -311,11 +311,7 @@ import { import { useQuery } from '@vue/apollo-composable' import { dummyData } from '@/utils/dummy' import { queries } from '@/utils/api/api.graphql' -import { jsPDF } from 'jspdf' -import autoTable from 'jspdf-autotable' -import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' -import { saveAs } from 'file-saver' -import { Workbook } from 'exceljs' +import { exportToPDF, exportToDOCX, exportToXLSX } from '@/report/Gangguan/Daftar/DGangguan_BM' const position = { of: '#data' } const showIndicator = ref(true) @@ -377,198 +373,12 @@ 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' - }) - - 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() - ], - [ - 'MEDIA', - ':', - reportMeta.value.media - ? reportMeta.value.media.name.toUpperCase() - : 'Semua Media'.toUpperCase() - ] - ], - styles: { - fontSize: 3, - cellPadding: 0.1, - textColor: [0, 0, 0], - fontStyle: 'bold' - }, - theme: 'plain', - startY: 10 - }) - - autoTable(doc, { - head: [ - ['Daftar Gangguan Berdasarkan Media'.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', - 'Nama Pelapor', - 'Alamat Pelapor', - 'No Telp Pelapor', - 'Keterangan Pelapor', - 'Status', - 'Tgl Lapor', - 'Tgl Response', - 'Tgl Recovery', - 'Durasi Response Time', - 'Durasi Recovery Time', - 'Sumber Lapor', - 'Tgl Media', - 'Keterangan Media' - ] - ], - body: data.value.map((item, i) => [ - { content: ++i, styles: { halign: 'right' } }, - item.no_laporan, - item.nama_pelapor, - item.alamat_pelapor, - item.no_telp_pelapor, - item.keterangan_pelapor, - item.status_akhir, - item.waktu_lapor, - item.waktu_response, - item.waktu_recovery, - parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', - parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', - item.nama_posko, - item.waktu_media, - item.keterangan_media - ]), - styles: { - 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 - }) - - 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 Berdasarkan Media.pdf', { returnPromise: true }).then(() => { - console.log('pdf berhasil disimpan') - }) + exportToPDF(reportMeta, data) + } else if (e.format === 'xlsx') { + exportToXLSX(reportMeta, data, e) } else { - const workbook = new Workbook() - const worksheet = workbook.addWorksheet('Daftar Gangguan Berdasarkan Media') - - exportToExcel({ - component: e.component, - worksheet, - autoFilterEnabled: true - }).then(() => { - workbook.xlsx.writeBuffer().then((buffer: any) => { - saveAs( - new Blob([buffer], { type: 'application/octet-stream' }), - 'Daftar Gangguan Berdasarkan Media.xlsx' - ) - }) - }) - - e.cancel = true + exportToDOCX(reportMeta, data) } } diff --git a/src/components/Pages/Gangguan/Daftar/DGangguan_DMAPKT.vue b/src/components/Pages/Gangguan/Daftar/DGangguan_DMAPKT.vue index f5a0deb..904002a 100755 --- a/src/components/Pages/Gangguan/Daftar/DGangguan_DMAPKT.vue +++ b/src/components/Pages/Gangguan/Daftar/DGangguan_DMAPKT.vue @@ -321,11 +321,7 @@ import { import { useQuery } from '@vue/apollo-composable' import { dummyData } from '@/utils/dummy' import { queries } from '@/utils/api/api.graphql' -import { jsPDF } from 'jspdf' -import autoTable from 'jspdf-autotable' -import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' -import { saveAs } from 'file-saver' -import { Workbook } from 'exceljs' +import { exportToPDF, exportToXLSX, exportToDOCX } from '@/report/Gangguan/Daftar/DGangguan_DMAPKT' const position = { of: '#data' } const showIndicator = ref(true) @@ -388,193 +384,12 @@ 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' - }) - - 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() - ] - ], - styles: { - fontSize: 3, - cellPadding: 0.1, - textColor: [0, 0, 0], - fontStyle: 'bold' - }, - theme: 'plain', - startY: 10 - }) - - autoTable(doc, { - head: [ - ['Daftar Gangguan Diselesaikan Mobile APKT'.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', - 'Tgl Recovery', - 'Durasi Response Time', - 'Durasi Recovery Time', - 'Status', - 'IDPEL/NO METER', - 'Nama Pelapor', - 'Alamat Pelapor', - 'No Telp Pelapor', - 'Keterangan Pelapor', - 'Sumber Lapor', - 'Posko' - ] - ], - body: data.value.map((item, i) => [ - { content: ++i, styles: { halign: 'right' } }, - item.no_laporan, - item.waktu_lapor, - item.waktu_response, - item.waktu_recovery, - parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', - parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', - item.status_akhir, - item.idpel_nometer, - item.nama_pelapor, - item.alamat_pelapor, - item.no_telp_pelapor, - item.keterangan_pelapor, - item.media, - item.nama_posko - ]), - styles: { - 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 - }) - - 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 Diselesaikan Mobile APKT.pdf', { returnPromise: true }) - .then(() => { - console.log('pdf berhasil disimpan') - }) + exportToPDF(reportMeta, data) + } else if (e.format === 'xlsx') { + exportToXLSX(reportMeta, data, e) } else { - const workbook = new Workbook() - const worksheet = workbook.addWorksheet('Daftar Gangguan Diselesaikan Mobile APKT') - - exportToExcel({ - component: e.component, - worksheet, - autoFilterEnabled: true - }).then(() => { - workbook.xlsx.writeBuffer().then((buffer: any) => { - saveAs( - new Blob([buffer], { type: 'application/octet-stream' }), - 'Daftar Gangguan Diselesaikan Mobile APKT.xlsx' - ) - }) - }) - - e.cancel = true + exportToDOCX(reportMeta, data) } } diff --git a/src/components/Pages/Gangguan/Daftar/DGangguan_RecoveryTime.vue b/src/components/Pages/Gangguan/Daftar/DGangguan_RecoveryTime.vue index 40d331d..2e1d7b1 100755 --- a/src/components/Pages/Gangguan/Daftar/DGangguan_RecoveryTime.vue +++ b/src/components/Pages/Gangguan/Daftar/DGangguan_RecoveryTime.vue @@ -347,11 +347,11 @@ import { import { useQuery } from '@vue/apollo-composable' import { queries } from '@/utils/api/api.graphql' import { dummyData } from '@/utils/dummy' -import { jsPDF } from 'jspdf' -import autoTable from 'jspdf-autotable' -import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' -import { saveAs } from 'file-saver' -import { Workbook } from 'exceljs' +import { + exportToPDF, + exportToXLSX, + exportToDOCX +} from '@/report/Gangguan/Daftar/DGangguan_RecoveryTime' const position = { of: '#data' } const showIndicator = ref(true) @@ -404,203 +404,12 @@ const filterData = (params: any) => { } const onExporting = (e: any) => { - const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : '' - const minTime = reportMeta.value.minTime ? reportMeta.value.minTime : '' - const maxTime = reportMeta.value.maxTime ? reportMeta.value.maxTime : '' - - let dateFromFormat = '' - let dateToFormat = '' - let dayTo = '' - let durasi = '' - - if (minTime == '46' && maxTime != '143998560') { - durasi = 'Melebihi SLA (>45 Menit)' - } else if (minTime == '1' && maxTime == '45') { - durasi = 'Dibawah / Sesuai SLA (<=45 Menit)' - } else { - durasi = 'Durasi Menit' - } - - 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' - }) - - 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() - ], - ['Durasi', ':', `${durasi} ${durasi == 'Durasi Menit' ? minTime + ' - ' + maxTime : ''}`] - ], - styles: { - fontSize: 3, - cellPadding: 0.1, - textColor: [0, 0, 0], - fontStyle: 'bold' - }, - theme: 'plain', - startY: 10 - }) - - autoTable(doc, { - head: [ - ['Daftar Gangguan Recovery Time'.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', - 'Tgl Recovery', - 'Durasi Response Time', - 'Durasi Recovery Time', - 'Status', - 'Referensi Marking', - 'IDPEL/NO METER', - 'Nama Pelapor', - 'Alamat Pelapor', - 'No Telp Pelapor', - 'Keterangan Pelapor', - 'Posko' - ] - ], - body: data.value.map((item, i) => [ - { content: ++i, styles: { halign: 'right' } }, - item.no_laporan, - item.waktu_lapor, - item.waktu_response, - item.waktu_recovery, - parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', - parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', - item.status_akhir, - item.referensi_marking, - item.idpel_nometer, - item.nama_pelapor, - item.alamat_pelapor, - item.no_telp_pelapor, - item.keterangan_pelapor, - item.nama_posko - ]), - styles: { - 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 - }) - - 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 Recovery Time.pdf', { returnPromise: true }).then(() => { - console.log('pdf berhasil disimpan') - }) + exportToPDF(reportMeta, data) + } else if (e.format === 'xlsx') { + exportToXLSX(reportMeta, data, e) } else { - const workbook = new Workbook() - const worksheet = workbook.addWorksheet('Daftar Gangguan Recovery Time') - - exportToExcel({ - component: e.component, - worksheet, - autoFilterEnabled: true - }).then(() => { - workbook.xlsx.writeBuffer().then((buffer: any) => { - saveAs( - new Blob([buffer], { type: 'application/octet-stream' }), - 'Daftar Gangguan Recovery Time.xlsx' - ) - }) - }) - - e.cancel = true + exportToDOCX(reportMeta, data) } } diff --git a/src/components/Pages/Gangguan/Daftar/DGangguan_ResponseTime.vue b/src/components/Pages/Gangguan/Daftar/DGangguan_ResponseTime.vue index 638bfb6..8da8dcf 100755 --- a/src/components/Pages/Gangguan/Daftar/DGangguan_ResponseTime.vue +++ b/src/components/Pages/Gangguan/Daftar/DGangguan_ResponseTime.vue @@ -324,11 +324,11 @@ import InputText from '@/components/InputText.vue' import { useQuery } from '@vue/apollo-composable' import { queries } from '@/utils/api/api.graphql' import { dummyData } from '@/utils/dummy' -import { jsPDF } from 'jspdf' -import autoTable from 'jspdf-autotable' -import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' -import { saveAs } from 'file-saver' -import { Workbook } from 'exceljs' +import { + exportToPDF, + exportToXLSX, + exportToDOCX +} from '@/report/Gangguan/Daftar/DGangguan_ResponseTime' const position = { of: '#data' } const showIndicator = ref(true) @@ -391,203 +391,12 @@ const { onResult, onError, loading, refetch } = useQuery(queries.gangguan.daftar }) const onExporting = (e: any) => { - const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : '' - const minTime = reportMeta.value.minTime ? reportMeta.value.minTime : '' - const maxTime = reportMeta.value.maxTime ? reportMeta.value.maxTime : '' - - let dateFromFormat = '' - let dateToFormat = '' - let dayTo = '' - let durasi = '' - - if (minTime == '46' && maxTime != '143998560') { - durasi = 'Melebihi SLA (>45 Menit)' - } else if (minTime == '1' && maxTime == '45') { - durasi = 'Dibawah / Sesuai SLA (<=45 Menit)' - } else { - durasi = 'Durasi Menit' - } - - 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' - }) - - 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() - ], - ['Durasi', ':', `${durasi} ${durasi == 'Durasi Menit' ? minTime + ' - ' + maxTime : ''}`] - ], - styles: { - fontSize: 3, - cellPadding: 0.1, - textColor: [0, 0, 0], - fontStyle: 'bold' - }, - theme: 'plain', - startY: 10 - }) - - autoTable(doc, { - head: [ - ['Daftar Gangguan Response Time'.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', - 'Tgl Recovery', - 'Durasi Response Time', - 'Durasi Recovery Time', - 'Status', - 'Referensi Marking', - 'IDPEL/NO METER', - 'Nama Pelapor', - 'Alamat Pelapor', - 'No Telp Pelapor', - 'Keterangan Pelapor', - 'Posko' - ] - ], - body: data.value.map((item, i) => [ - { content: ++i, styles: { halign: 'right' } }, - item.no_laporan, - item.waktu_lapor, - item.waktu_response, - item.waktu_recovery, - parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', - parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', - item.status_akhir, - item.referensi_marking, - item.idpel_nometer, - item.nama_pelapor, - item.alamat_pelapor, - item.no_telp_pelapor, - item.keterangan_pelapor, - item.nama_posko - ]), - styles: { - 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 - }) - - 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 Response Time.pdf', { returnPromise: true }).then(() => { - console.log('pdf berhasil disimpan') - }) + exportToPDF(reportMeta, data) + } else if (e.format === 'xlsx') { + exportToXLSX(reportMeta, data, e) } else { - const workbook = new Workbook() - const worksheet = workbook.addWorksheet('Daftar Gangguan Response Time') - - exportToExcel({ - component: e.component, - worksheet, - autoFilterEnabled: true - }).then(() => { - workbook.xlsx.writeBuffer().then((buffer: any) => { - saveAs( - new Blob([buffer], { type: 'application/octet-stream' }), - 'Daftar Gangguan Response Time.xlsx' - ) - }) - }) - - e.cancel = true + exportToDOCX(reportMeta, data) } } diff --git a/src/components/Pages/Gangguan/Daftar/DGangguan_STIDP.vue b/src/components/Pages/Gangguan/Daftar/DGangguan_STIDP.vue index 9aeced9..db4a1b8 100755 --- a/src/components/Pages/Gangguan/Daftar/DGangguan_STIDP.vue +++ b/src/components/Pages/Gangguan/Daftar/DGangguan_STIDP.vue @@ -321,11 +321,7 @@ import { import { useQuery } from '@vue/apollo-composable' import { queries } from '@/utils/api/api.graphql' import { dummyData } from '@/utils/dummy' -import { jsPDF } from 'jspdf' -import autoTable from 'jspdf-autotable' -import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' -import { saveAs } from 'file-saver' -import { Workbook } from 'exceljs' +import { exportToPDF, exportToDOCX, exportToXLSX } from '@/report/Gangguan/Daftar/DGangguan_STIDP' const position = { of: '#data' } const showIndicator = ref(true) @@ -388,193 +384,12 @@ 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' - }) - - 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() - ] - ], - styles: { - fontSize: 3, - cellPadding: 0.1, - textColor: [0, 0, 0], - fontStyle: 'bold' - }, - theme: 'plain', - startY: 10 - }) - - autoTable(doc, { - head: [ - ['Daftar Gangguan Selesai Tanpa ID Pelanggan'.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', - 'Tgl Recovery', - 'Durasi Response Time', - 'Durasi Recovery Time', - 'Status', - 'IDPEL/NO METER', - 'Nama Pelapor', - 'Alamat Pelapor', - 'No Telp Pelapor', - 'Keterangan Pelapor', - 'Sumber Lapor', - 'Posko' - ] - ], - body: data.value.map((item, i) => [ - { content: ++i, styles: { halign: 'right' } }, - item.no_laporan, - item.waktu_lapor, - item.waktu_response, - item.waktu_recovery, - parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', - parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', - item.status_akhir, - item.idpel_nometer, - item.nama_pelapor, - item.alamat_pelapor, - item.no_telp_pelapor, - item.keterangan_pelapor, - item.media, - item.nama_posko - ]), - styles: { - 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 - }) - - 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 Selesai Tanpa ID Pelanggan.pdf', { returnPromise: true }) - .then(() => { - console.log('pdf berhasil disimpan') - }) + exportToPDF(reportMeta, data) + } else if (e.format === 'xlsx') { + exportToXLSX(reportMeta, data, e) } else { - const workbook = new Workbook() - const worksheet = workbook.addWorksheet('Daftar Gangguan Selesai Tanpa ID Pelanggan') - - exportToExcel({ - component: e.component, - worksheet, - autoFilterEnabled: true - }).then(() => { - workbook.xlsx.writeBuffer().then((buffer: any) => { - saveAs( - new Blob([buffer], { type: 'application/octet-stream' }), - 'Daftar Gangguan Selesai Tanpa ID Pelanggan.xlsx' - ) - }) - }) - - e.cancel = true + exportToDOCX(reportMeta, data) } } diff --git a/src/report/Gangguan/Daftar/DGangguan_BM.ts b/src/report/Gangguan/Daftar/DGangguan_BM.ts new file mode 100644 index 0000000..8ed3e69 --- /dev/null +++ b/src/report/Gangguan/Daftar/DGangguan_BM.ts @@ -0,0 +1,539 @@ +import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' +import { + Document, + AlignmentType, + Packer, + Paragraph, + Table, + TableCell, + TableRow, + VerticalAlign, + TextRun, + WidthType, + PageOrientation +} from 'docx' +import { saveAs } from 'file-saver' +import { jsPDF } from 'jspdf' +import autoTable from 'jspdf-autotable' +import { Workbook } from 'exceljs' +import { formatWaktu } from '@/components/Form/FiltersType/reference' +import { setHeaderStyle } from '@/report/utils/xlsx' + +const reportName = 'Daftar Gangguan Berdasarkan Media' + +const formatMetaData = (reportMeta: 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' }) + } + + return { dateFromFormat, dateToFormat, dayTo } +} + +const exportToPDF = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + const doc = new jsPDF({ + orientation: 'landscape' + }) + + 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() + ], + [ + 'MEDIA', + ':', + reportMeta.value.media + ? reportMeta.value.media.name.toUpperCase() + : 'Semua Media'.toUpperCase() + ] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10 + }) + + autoTable(doc, { + head: [ + [`${reportName}`.toUpperCase()], + [`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.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', + 'Nama Pelapor', + 'Alamat Pelapor', + 'No Telp Pelapor', + 'Keterangan Pelapor', + 'Status', + 'Tgl Lapor', + 'Tgl Response', + 'Tgl Recovery', + 'Durasi Response Time', + 'Durasi Recovery Time', + 'Sumber Lapor', + 'Tgl Media', + 'Keterangan Media' + ] + ], + body: data.value.map((item: any, i: any) => [ + { content: ++i, styles: { halign: 'right' } }, + item.no_laporan, + item.nama_pelapor, + item.alamat_pelapor, + item.no_telp_pelapor, + item.keterangan_pelapor, + item.status_akhir, + item.waktu_lapor, + item.waktu_response, + item.waktu_recovery, + parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', + parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', + item.nama_posko, + item.waktu_media, + item.keterangan_media + ]), + styles: { + 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 + }) + + autoTable(doc, { + head: [ + [`${meta.dayTo}, ${meta.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 ${reportName}.pdf`, { returnPromise: true }).then(() => { + console.log('pdf berhasil disimpan') + }) +} + +const exportToXLSX = (reportMeta: any, data: 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, + 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, + 5, + 1, + `MEDIA : ${ + reportMeta.value.media + ? reportMeta.value.media.name.toUpperCase() + : 'Semua Media'.toUpperCase() + }` + ) + + setHeaderStyle(worksheet, 7, 8, `${reportName}`.toUpperCase(), true) + setHeaderStyle( + worksheet, + 8, + 8, + `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + true + ) + + worksheet.mergeCells('A1:F1') + worksheet.mergeCells('A2:F2') + worksheet.mergeCells('A3:F3') + worksheet.mergeCells('A4:F4') + worksheet.mergeCells('H7:J7') + worksheet.mergeCells('H8:J8') + + exportToExcel({ + component: e.component, + worksheet, + autoFilterEnabled: true, + topLeftCell: { row: 10, column: 1 } + }).then(() => { + workbook.xlsx.writeBuffer().then((buffer: any) => { + saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`) + }) + }) + + e.cancel = true +} + +const exportToDOCX = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + + const generateRows = () => { + return data.value.map((item: any, i: any) => { + return new TableRow({ + children: [ + { text: `${++i}`, field: 'no' }, + { text: item.no_laporan, field: 'no_laporan' }, + { text: item.nama_pelapor, field: 'nama_pelapor' }, + { text: item.alamat_pelapor, field: 'alamat_pelapor' }, + { text: item.no_telp_pelapor, field: 'no_telp_pelapor' }, + { text: item.keterangan_pelapor, field: 'keterangan_pelapor' }, + { text: item.status_akhir, field: 'status_akhir' }, + { text: item.waktu_lapor, field: 'waktu_lapor' }, + { text: item.waktu_response, field: 'waktu_response' }, + { text: item.waktu_recovery, field: 'waktu_recovery' }, + { + text: parseInt(item.durasi_response_time) + ? formatWaktu(item.durasi_response_time) + : '-', + field: 'durasi_response_time' + }, + { + text: parseInt(item.durasi_recovery_time) + ? formatWaktu(item.durasi_recovery_time) + : '-', + field: 'durasi_recovery_time' + }, + { text: item.nama_posko, field: 'posko' }, + { text: item.waktu_media, field: 'waktu_media' }, + { text: item.keterangan_media, field: 'keterangan_media' } + ].map( + (cell) => + new TableCell({ + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: cell.text, + size: 4 + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }) + }) + } + + const doc = new Document({ + sections: [ + { + properties: { + page: { + size: { + orientation: PageOrientation.LANDSCAPE + } + } + }, + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: 'PT. PLN(Persero)', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT INDUK : ${ + reportMeta.value.uid + ? reportMeta.value.uid.name.toUpperCase() + : 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT PELAKSANA PELAYANAN PELANGGAN : ${ + reportMeta.value.up3 + ? reportMeta.value.up3.name.toUpperCase() + : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `POSKO : ${ + reportMeta.value.posko + ? reportMeta.value.posko.name.toUpperCase() + : 'Semua Posko'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `MEDIA : ${ + reportMeta.value.media + ? reportMeta.value.media.name.toUpperCase() + : 'Semua Media'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `${reportName}`.toUpperCase(), + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Table({ + width: { + size: 13950, + type: WidthType.DXA + }, + rows: [ + new TableRow({ + children: [ + { text: 'No', field: 'no' }, + { text: 'No Laporan', field: 'no_laporan' }, + { text: 'Nama Pelapor', field: 'nama_pelapor' }, + { text: 'Alamat Pelapor', field: 'alamat_pelapor' }, + { text: 'No Telp Pelapor', field: 'no_telp_pelapor' }, + { text: 'Keterangan Pelapor', field: 'keterangan_pelapor' }, + { text: 'Status', field: 'status_akhir' }, + { text: 'Tgl Lapor', field: 'waktu_lapor' }, + { text: 'Tgl Response', field: 'waktu_response' }, + { text: 'Tgl Recovery', field: 'waktu_recovery' }, + { text: 'Durasi Response Time', field: 'durasi_response_time' }, + { text: 'Durasi Recovery Time', field: 'durasi_recovery_time' }, + { text: 'Sumber Lapor', field: 'posko' }, + { text: 'Tgl Media', field: 'waktu_media' }, + { text: 'Keterangan Media', field: 'keterangan_media' } + ].map( + (header) => + new TableCell({ + children: [ + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: header.text, + bold: true, + size: 4, + allCaps: true + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }), + ...generateRows() + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: `${meta.dayTo}, ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: '(.........................................)', + bold: true, + size: 4 + }) + ] + }) + ] + } + ] + }) + + Packer.toBlob(doc).then((blob) => { + saveAs(blob, `Laporan ${reportName}.docx`) + console.log('Document created successfully') + }) +} + +export { exportToPDF, exportToXLSX, exportToDOCX } diff --git a/src/report/Gangguan/Daftar/DGangguan_DKPL.ts b/src/report/Gangguan/Daftar/DGangguan_DKPL.ts index c9e3545..5f47a7c 100644 --- a/src/report/Gangguan/Daftar/DGangguan_DKPL.ts +++ b/src/report/Gangguan/Daftar/DGangguan_DKPL.ts @@ -517,6 +517,7 @@ const exportToDOCX = (reportMeta: any, data: any) => { }) Packer.toBlob(doc).then((blob) => { + console.log(blob) saveAs(blob, `Laporan ${reportName}.docx`) console.log('Document created successfully') }) diff --git a/src/report/Gangguan/Daftar/DGangguan_DMAPKT.ts b/src/report/Gangguan/Daftar/DGangguan_DMAPKT.ts new file mode 100644 index 0000000..bea5799 --- /dev/null +++ b/src/report/Gangguan/Daftar/DGangguan_DMAPKT.ts @@ -0,0 +1,509 @@ +import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' +import { + Document, + AlignmentType, + Packer, + Paragraph, + Table, + TableCell, + TableRow, + VerticalAlign, + TextRun, + WidthType, + PageOrientation +} from 'docx' +import { saveAs } from 'file-saver' +import { jsPDF } from 'jspdf' +import autoTable from 'jspdf-autotable' +import { Workbook } from 'exceljs' +import { formatWaktu } from '@/components/Form/FiltersType/reference' +import { setHeaderStyle } from '@/report/utils/xlsx' + +const reportName = 'Daftar Gangguan Diselesaikan Mobile APKT' + +const formatMetaData = (reportMeta: 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' }) + } + + return { dateFromFormat, dateToFormat, dayTo } +} + +const exportToPDF = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + const doc = new jsPDF({ + orientation: 'landscape' + }) + + 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() + ] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10 + }) + + autoTable(doc, { + head: [ + [`${reportName}`.toUpperCase()], + [`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.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', + 'Tgl Recovery', + 'Durasi Response Time', + 'Durasi Recovery Time', + 'Status', + 'IDPEL/NO METER', + 'Nama Pelapor', + 'Alamat Pelapor', + 'No Telp Pelapor', + 'Keterangan Pelapor', + 'Sumber Lapor', + 'Posko' + ] + ], + body: data.value.map((item: any, i: any) => [ + { content: ++i, styles: { halign: 'right' } }, + item.no_laporan, + item.waktu_lapor, + item.waktu_response, + item.waktu_recovery, + parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', + parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', + item.status_akhir, + item.idpel_nometer, + item.nama_pelapor, + item.alamat_pelapor, + item.no_telp_pelapor, + item.keterangan_pelapor, + item.media, + item.nama_posko + ]), + styles: { + 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 + }) + + autoTable(doc, { + head: [ + [`${meta.dayTo}, ${meta.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 ${reportName}.pdf`, { returnPromise: true }).then(() => { + console.log('pdf berhasil disimpan') + }) +} + +const exportToXLSX = (reportMeta: any, data: 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, + 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, `${reportName}`.toUpperCase(), true) + setHeaderStyle( + worksheet, + 8, + 8, + `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + true + ) + + worksheet.mergeCells('A1:F1') + worksheet.mergeCells('A2:F2') + worksheet.mergeCells('A3:F3') + worksheet.mergeCells('A4:F4') + worksheet.mergeCells('H7:J7') + worksheet.mergeCells('H8:J8') + + exportToExcel({ + component: e.component, + worksheet, + autoFilterEnabled: true, + topLeftCell: { row: 10, column: 1 } + }).then(() => { + workbook.xlsx.writeBuffer().then((buffer: any) => { + saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`) + }) + }) + + e.cancel = true +} + +const exportToDOCX = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + + const generateRows = () => { + return data.value.map((item: any, i: any) => { + return new TableRow({ + children: [ + { text: `${++i}`, field: 'no' }, + { text: item.no_laporan, field: 'no_laporan' }, + { text: item.waktu_lapor, field: 'waktu_lapor' }, + { text: item.waktu_response, field: 'waktu_response' }, + { text: item.waktu_recovery, field: 'waktu_recovery' }, + { + text: parseInt(item.durasi_response_time) + ? formatWaktu(item.durasi_response_time) + : '-', + field: 'durasi_response_time' + }, + { + text: parseInt(item.durasi_recovery_time) + ? formatWaktu(item.durasi_recovery_time) + : '-', + field: 'durasi_recovery_time' + }, + { text: item.status_akhir, field: 'status_akhir' }, + { text: item.idpel_nometer, field: 'idpel_nometer' }, + { text: item.nama_pelapor, field: 'nama_pelapor' }, + { text: item.alamat_pelapor, field: 'alamat_pelapor' }, + { text: item.no_telp_pelapor, field: 'no_telp_pelapor' }, + { text: item.keterangan_pelapor, field: 'keterangan_pelapor' }, + { text: item.media, field: 'media' }, + { text: item.nama_posko, field: 'posko' } + ].map( + (cell) => + new TableCell({ + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: cell.text, + size: 4 + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }) + }) + } + + const doc = new Document({ + sections: [ + { + properties: { + page: { + size: { + orientation: PageOrientation.LANDSCAPE + } + } + }, + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: 'PT. PLN(Persero)', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT INDUK : ${ + reportMeta.value.uid + ? reportMeta.value.uid.name.toUpperCase() + : 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT PELAKSANA PELAYANAN PELANGGAN : ${ + reportMeta.value.up3 + ? reportMeta.value.up3.name.toUpperCase() + : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `POSKO : ${ + reportMeta.value.posko + ? reportMeta.value.posko.name.toUpperCase() + : 'Semua Posko'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `${reportName}`.toUpperCase(), + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Table({ + width: { + size: 13950, + type: WidthType.DXA + }, + rows: [ + new TableRow({ + children: [ + { text: 'No', field: 'no' }, + { text: 'No Laporan', field: 'no_laporan' }, + { text: 'Tgl Lapor', field: 'waktu_lapor' }, + { text: 'Tgl Response', field: 'waktu_response' }, + { text: 'Tgl Recovery', field: 'waktu_recovery' }, + { text: 'Durasi Response Time', field: 'durasi_response_time' }, + { text: 'Durasi Recovery Time', field: 'durasi_recovery_time' }, + { text: 'Status', field: 'status_akhir' }, + { text: 'IDPEL/NO METER', field: 'idpel_nometer' }, + { text: 'Nama Pelapor', field: 'nama_pelapor' }, + { text: 'Alamat Pelapor', field: 'alamat_pelapor' }, + { text: 'No Telp Pelapor', field: 'no_telp_pelapor' }, + { text: 'Keterangan Pelapor', field: 'keterangan_pelapor' }, + { text: 'Sumber Lapor', field: 'media' }, + { text: 'Posko', field: 'posko' } + ].map( + (header) => + new TableCell({ + children: [ + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: header.text, + bold: true, + size: 4, + allCaps: true + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }), + ...generateRows() + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: `${meta.dayTo}, ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: '(.........................................)', + bold: true, + size: 4 + }) + ] + }) + ] + } + ] + }) + + Packer.toBlob(doc).then((blob) => { + saveAs(blob, `Laporan ${reportName}.docx`) + console.log('Document created successfully') + }) +} + +export { exportToPDF, exportToXLSX, exportToDOCX } diff --git a/src/report/Gangguan/Daftar/DGangguan_RecoveryTime.ts b/src/report/Gangguan/Daftar/DGangguan_RecoveryTime.ts new file mode 100644 index 0000000..e312f75 --- /dev/null +++ b/src/report/Gangguan/Daftar/DGangguan_RecoveryTime.ts @@ -0,0 +1,550 @@ +import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' +import { + Document, + AlignmentType, + Packer, + Paragraph, + Table, + TableCell, + TableRow, + VerticalAlign, + TextRun, + WidthType, + PageOrientation +} from 'docx' +import { saveAs } from 'file-saver' +import { jsPDF } from 'jspdf' +import autoTable from 'jspdf-autotable' +import { Workbook } from 'exceljs' +import { formatWaktu } from '@/components/Form/FiltersType/reference' +import { setHeaderStyle } from '@/report/utils/xlsx' + +const reportName = 'Daftar Gangguan Recovery Time' + +const formatMetaData = (reportMeta: any) => { + const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : '' + const minTime = reportMeta.value.minTime ? reportMeta.value.minTime : '' + const maxTime = reportMeta.value.maxTime ? reportMeta.value.maxTime : '' + + let dateFromFormat = '' + let dateToFormat = '' + let dayTo = '' + let durasi = '' + + if (minTime == '46' && maxTime != '143998560') { + durasi = 'Melebihi SLA (>45 Menit)' + } else if (minTime == '1' && maxTime == '45') { + durasi = 'Dibawah / Sesuai SLA (<=45 Menit)' + } else { + durasi = 'Durasi Menit' + } + + 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' }) + } + + return { + dateFromFormat, + dateToFormat, + dayTo, + durasi, + minTime, + maxTime + } +} + +const exportToPDF = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + const doc = new jsPDF({ + orientation: 'landscape' + }) + + 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() + ], + [ + 'Durasi', + ':', + `${meta.durasi} ${meta.durasi == 'Durasi Menit' ? meta.minTime + ' - ' + meta.maxTime : ''}` + ] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10 + }) + + autoTable(doc, { + head: [ + [`${reportName}`.toUpperCase()], + [`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.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', + 'Tgl Recovery', + 'Durasi Response Time', + 'Durasi Recovery Time', + 'Status', + 'Referensi Marking', + 'IDPEL/NO METER', + 'Nama Pelapor', + 'Alamat Pelapor', + 'No Telp Pelapor', + 'Keterangan Pelapor', + 'Posko' + ] + ], + body: data.value.map((item: any, i: any) => [ + { content: ++i, styles: { halign: 'right' } }, + item.no_laporan, + item.waktu_lapor, + item.waktu_response, + item.waktu_recovery, + parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', + parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', + item.status_akhir, + item.referensi_marking, + item.idpel_nometer, + item.nama_pelapor, + item.alamat_pelapor, + item.no_telp_pelapor, + item.keterangan_pelapor, + item.nama_posko + ]), + styles: { + 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 + }) + + autoTable(doc, { + head: [ + [`${meta.dayTo}, ${meta.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 ${reportName}.pdf`, { returnPromise: true }).then(() => { + console.log('pdf berhasil disimpan') + }) +} + +const exportToXLSX = (reportMeta: any, data: 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, + 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, + 5, + 1, + `DURASI : ${meta.durasi} ${meta.durasi == 'Durasi Menit' ? meta.minTime + ' - ' + meta.maxTime : ''}` + ) + + setHeaderStyle(worksheet, 7, 8, `${reportName}`.toUpperCase(), true) + setHeaderStyle( + worksheet, + 8, + 8, + `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + true + ) + + worksheet.mergeCells('A1:F1') + worksheet.mergeCells('A2:F2') + worksheet.mergeCells('A3:F3') + worksheet.mergeCells('A4:F4') + worksheet.mergeCells('H7:J7') + worksheet.mergeCells('H8:J8') + + exportToExcel({ + component: e.component, + worksheet, + autoFilterEnabled: true, + topLeftCell: { row: 11, column: 1 } + }).then(() => { + workbook.xlsx.writeBuffer().then((buffer: any) => { + saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`) + }) + }) + + e.cancel = true +} + +const exportToDOCX = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + + const generateRows = () => { + return data.value.map((item: any, i: any) => { + return new TableRow({ + children: [ + { text: `${++i}`, field: 'no' }, + { text: item.no_laporan, field: 'no_laporan' }, + { text: item.waktu_lapor, field: 'waktu_lapor' }, + { text: item.waktu_response, field: 'waktu_response' }, + { text: item.waktu_recovery, field: 'waktu_recovery' }, + { + text: parseInt(item.durasi_response_time) + ? formatWaktu(item.durasi_response_time) + : '-', + field: 'durasi_response_time' + }, + { + text: parseInt(item.durasi_recovery_time) + ? formatWaktu(item.durasi_recovery_time) + : '-', + field: 'durasi_recovery_time' + }, + { text: item.status_akhir, field: 'status_akhir' }, + { text: item.referensi_marking, field: 'referensi_marking' }, + { text: item.idpel_nometer, field: 'idpel_nometer' }, + { text: item.nama_pelapor, field: 'nama_pelapor' }, + { text: item.alamat_pelapor, field: 'alamat_pelapor' }, + { text: item.no_telp_pelapor, field: 'no_telp_pelapor' }, + { text: item.keterangan_pelapor, field: 'keterangan_pelapor' }, + { text: item.nama_posko, field: 'nama_posko' } + ].map( + (cell) => + new TableCell({ + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: cell.text, + size: 4 + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }) + }) + } + + const doc = new Document({ + sections: [ + { + properties: { + page: { + size: { + orientation: PageOrientation.LANDSCAPE + } + } + }, + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: 'PT. PLN(Persero)', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT INDUK : ${ + reportMeta.value.uid + ? reportMeta.value.uid.name.toUpperCase() + : 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT PELAKSANA PELAYANAN PELANGGAN : ${ + reportMeta.value.up3 + ? reportMeta.value.up3.name.toUpperCase() + : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `POSKO : ${ + reportMeta.value.posko + ? reportMeta.value.posko.name.toUpperCase() + : 'Semua Posko'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `DURASI : ${meta.durasi} ${ + meta.durasi == 'Durasi Menit' ? meta.minTime + ' - ' + meta.maxTime : '' + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `${reportName}`.toUpperCase(), + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Table({ + width: { + size: 13950, + type: WidthType.DXA + }, + rows: [ + new TableRow({ + children: [ + { text: 'No', field: 'no' }, + { text: 'No Laporan', field: 'no_laporan' }, + { text: 'Tgl Lapor', field: 'waktu_lapor' }, + { text: 'Tgl Response', field: 'waktu_response' }, + { text: 'Tgl Recovery', field: 'waktu_recovery' }, + { text: 'Durasi Response Time', field: 'durasi_response_time' }, + { text: 'Durasi Recovery Time', field: 'durasi_recovery_time' }, + { text: 'Status', field: 'status_akhir' }, + { text: 'Referensi Marking', field: 'referensi_marking' }, + { text: 'IDPEL/NO METER', field: 'idpel_nometer' }, + { text: 'Nama Pelapor', field: 'nama_pelapor' }, + { text: 'Alamat Pelapor', field: 'alamat_pelapor' }, + { text: 'No Telp Pelapor', field: 'no_telp_pelapor' }, + { text: 'Keterangan Pelapor', field: 'keterangan_pelapor' }, + { text: 'Posko', field: 'nama_posko' } + ].map( + (header) => + new TableCell({ + children: [ + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: header.text, + bold: true, + size: 4, + allCaps: true + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }), + ...generateRows() + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: `${meta.dayTo}, ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: '(.........................................)', + bold: true, + size: 4 + }) + ] + }) + ] + } + ] + }) + + Packer.toBlob(doc).then((blob) => { + saveAs(blob, `Laporan ${reportName}.docx`) + console.log('Document created successfully') + }) +} + +export { exportToPDF, exportToXLSX, exportToDOCX } diff --git a/src/report/Gangguan/Daftar/DGangguan_ResponseTime.ts b/src/report/Gangguan/Daftar/DGangguan_ResponseTime.ts new file mode 100644 index 0000000..8315e7d --- /dev/null +++ b/src/report/Gangguan/Daftar/DGangguan_ResponseTime.ts @@ -0,0 +1,550 @@ +import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' +import { + Document, + AlignmentType, + Packer, + Paragraph, + Table, + TableCell, + TableRow, + VerticalAlign, + TextRun, + WidthType, + PageOrientation +} from 'docx' +import { saveAs } from 'file-saver' +import { jsPDF } from 'jspdf' +import autoTable from 'jspdf-autotable' +import { Workbook } from 'exceljs' +import { formatWaktu } from '@/components/Form/FiltersType/reference' +import { setHeaderStyle } from '@/report/utils/xlsx' + +const reportName = 'Daftar Gangguan Response Time' + +const formatMetaData = (reportMeta: any) => { + const periode = reportMeta.value.periode ? reportMeta.value.periode.split(' s/d ') : '' + const minTime = reportMeta.value.minTime ? reportMeta.value.minTime : '' + const maxTime = reportMeta.value.maxTime ? reportMeta.value.maxTime : '' + + let dateFromFormat = '' + let dateToFormat = '' + let dayTo = '' + let durasi = '' + + if (minTime == '46' && maxTime != '143998560') { + durasi = 'Melebihi SLA (>45 Menit)' + } else if (minTime == '1' && maxTime == '45') { + durasi = 'Dibawah / Sesuai SLA (<=45 Menit)' + } else { + durasi = 'Durasi Menit' + } + + 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' }) + } + + return { + dateFromFormat, + dateToFormat, + dayTo, + durasi, + minTime, + maxTime + } +} + +const exportToPDF = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + const doc = new jsPDF({ + orientation: 'landscape' + }) + + 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() + ], + [ + 'Durasi', + ':', + `${meta.durasi} ${meta.durasi == 'Durasi Menit' ? meta.minTime + ' - ' + meta.maxTime : ''}` + ] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10 + }) + + autoTable(doc, { + head: [ + [`${reportName}`.toUpperCase()], + [`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.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', + 'Tgl Recovery', + 'Durasi Response Time', + 'Durasi Recovery Time', + 'Status', + 'Referensi Marking', + 'IDPEL/NO METER', + 'Nama Pelapor', + 'Alamat Pelapor', + 'No Telp Pelapor', + 'Keterangan Pelapor', + 'Posko' + ] + ], + body: data.value.map((item: any, i: any) => [ + { content: ++i, styles: { halign: 'right' } }, + item.no_laporan, + item.waktu_lapor, + item.waktu_response, + item.waktu_recovery, + parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', + parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', + item.status_akhir, + item.referensi_marking, + item.idpel_nometer, + item.nama_pelapor, + item.alamat_pelapor, + item.no_telp_pelapor, + item.keterangan_pelapor, + item.nama_posko + ]), + styles: { + 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 + }) + + autoTable(doc, { + head: [ + [`${meta.dayTo}, ${meta.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 ${reportName}.pdf`, { returnPromise: true }).then(() => { + console.log('pdf berhasil disimpan') + }) +} + +const exportToXLSX = (reportMeta: any, data: 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, + 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, + 5, + 1, + `DURASI : ${meta.durasi} ${meta.durasi == 'Durasi Menit' ? meta.minTime + ' - ' + meta.maxTime : ''}` + ) + + setHeaderStyle(worksheet, 7, 8, `${reportName}`.toUpperCase(), true) + setHeaderStyle( + worksheet, + 8, + 8, + `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + true + ) + + worksheet.mergeCells('A1:F1') + worksheet.mergeCells('A2:F2') + worksheet.mergeCells('A3:F3') + worksheet.mergeCells('A4:F4') + worksheet.mergeCells('H7:J7') + worksheet.mergeCells('H8:J8') + + exportToExcel({ + component: e.component, + worksheet, + autoFilterEnabled: true, + topLeftCell: { row: 11, column: 1 } + }).then(() => { + workbook.xlsx.writeBuffer().then((buffer: any) => { + saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`) + }) + }) + + e.cancel = true +} + +const exportToDOCX = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + + const generateRows = () => { + return data.value.map((item: any, i: any) => { + return new TableRow({ + children: [ + { text: `${++i}`, field: 'no' }, + { text: item.no_laporan, field: 'no_laporan' }, + { text: item.waktu_lapor, field: 'waktu_lapor' }, + { text: item.waktu_response, field: 'waktu_response' }, + { text: item.waktu_recovery, field: 'waktu_recovery' }, + { + text: parseInt(item.durasi_response_time) + ? formatWaktu(item.durasi_response_time) + : '-', + field: 'durasi_response_time' + }, + { + text: parseInt(item.durasi_recovery_time) + ? formatWaktu(item.durasi_recovery_time) + : '-', + field: 'durasi_recovery_time' + }, + { text: item.status_akhir, field: 'status_akhir' }, + { text: item.referensi_marking, field: 'referensi_marking' }, + { text: item.idpel_nometer, field: 'idpel_nometer' }, + { text: item.nama_pelapor, field: 'nama_pelapor' }, + { text: item.alamat_pelapor, field: 'alamat_pelapor' }, + { text: item.no_telp_pelapor, field: 'no_telp_pelapor' }, + { text: item.keterangan_pelapor, field: 'keterangan_pelapor' }, + { text: item.nama_posko, field: 'nama_posko' } + ].map( + (cell) => + new TableCell({ + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: cell.text, + size: 4 + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }) + }) + } + + const doc = new Document({ + sections: [ + { + properties: { + page: { + size: { + orientation: PageOrientation.LANDSCAPE + } + } + }, + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: 'PT. PLN(Persero)', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT INDUK : ${ + reportMeta.value.uid + ? reportMeta.value.uid.name.toUpperCase() + : 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT PELAKSANA PELAYANAN PELANGGAN : ${ + reportMeta.value.up3 + ? reportMeta.value.up3.name.toUpperCase() + : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `POSKO : ${ + reportMeta.value.posko + ? reportMeta.value.posko.name.toUpperCase() + : 'Semua Posko'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `DURASI : ${meta.durasi} ${ + meta.durasi == 'Durasi Menit' ? meta.minTime + ' - ' + meta.maxTime : '' + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `${reportName}`.toUpperCase(), + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Table({ + width: { + size: 13950, + type: WidthType.DXA + }, + rows: [ + new TableRow({ + children: [ + { text: 'No', field: 'no' }, + { text: 'No Laporan', field: 'no_laporan' }, + { text: 'Tgl Lapor', field: 'waktu_lapor' }, + { text: 'Tgl Response', field: 'waktu_response' }, + { text: 'Tgl Recovery', field: 'waktu_recovery' }, + { text: 'Durasi Response Time', field: 'durasi_response_time' }, + { text: 'Durasi Recovery Time', field: 'durasi_recovery_time' }, + { text: 'Status', field: 'status_akhir' }, + { text: 'Referensi Marking', field: 'referensi_marking' }, + { text: 'IDPEL/NO METER', field: 'idpel_nometer' }, + { text: 'Nama Pelapor', field: 'nama_pelapor' }, + { text: 'Alamat Pelapor', field: 'alamat_pelapor' }, + { text: 'No Telp Pelapor', field: 'no_telp_pelapor' }, + { text: 'Keterangan Pelapor', field: 'keterangan_pelapor' }, + { text: 'Posko', field: 'nama_posko' } + ].map( + (header) => + new TableCell({ + children: [ + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: header.text, + bold: true, + size: 4, + allCaps: true + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }), + ...generateRows() + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: `${meta.dayTo}, ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: '(.........................................)', + bold: true, + size: 4 + }) + ] + }) + ] + } + ] + }) + + Packer.toBlob(doc).then((blob) => { + saveAs(blob, `Laporan ${reportName}.docx`) + console.log('Document created successfully') + }) +} + +export { exportToPDF, exportToXLSX, exportToDOCX } diff --git a/src/report/Gangguan/Daftar/DGangguan_STIDP.ts b/src/report/Gangguan/Daftar/DGangguan_STIDP.ts new file mode 100644 index 0000000..32caaf2 --- /dev/null +++ b/src/report/Gangguan/Daftar/DGangguan_STIDP.ts @@ -0,0 +1,509 @@ +import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter' +import { + Document, + AlignmentType, + Packer, + Paragraph, + Table, + TableCell, + TableRow, + VerticalAlign, + TextRun, + WidthType, + PageOrientation +} from 'docx' +import { saveAs } from 'file-saver' +import { jsPDF } from 'jspdf' +import autoTable from 'jspdf-autotable' +import { Workbook } from 'exceljs' +import { formatWaktu } from '@/components/Form/FiltersType/reference' +import { setHeaderStyle } from '@/report/utils/xlsx' + +const reportName = 'Daftar Gangguan Selesai Tanpa ID Pelanggan' + +const formatMetaData = (reportMeta: 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' }) + } + + return { dateFromFormat, dateToFormat, dayTo } +} + +const exportToPDF = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + const doc = new jsPDF({ + orientation: 'landscape' + }) + + 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() + ] + ], + styles: { + fontSize: 3, + cellPadding: 0.1, + textColor: [0, 0, 0], + fontStyle: 'bold' + }, + theme: 'plain', + startY: 10 + }) + + autoTable(doc, { + head: [ + [`${reportName}`.toUpperCase()], + [`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.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', + 'Tgl Recovery', + 'Durasi Response Time', + 'Durasi Recovery Time', + 'Status', + 'IDPEL/NO METER', + 'Nama Pelapor', + 'Alamat Pelapor', + 'No Telp Pelapor', + 'Keterangan Pelapor', + 'Sumber Lapor', + 'Posko' + ] + ], + body: data.value.map((item: any, i: any) => [ + { content: ++i, styles: { halign: 'right' } }, + item.no_laporan, + item.waktu_lapor, + item.waktu_response, + item.waktu_recovery, + parseInt(item.durasi_response_time) ? formatWaktu(item.durasi_response_time) : '-', + parseInt(item.durasi_recovery_time) ? formatWaktu(item.durasi_recovery_time) : '-', + item.status_akhir, + item.idpel_nometer, + item.nama_pelapor, + item.alamat_pelapor, + item.no_telp_pelapor, + item.keterangan_pelapor, + item.media, + item.nama_posko + ]), + styles: { + 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 + }) + + autoTable(doc, { + head: [ + [`${meta.dayTo}, ${meta.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 ${reportName}.pdf`, { returnPromise: true }).then(() => { + console.log('pdf berhasil disimpan') + }) +} + +const exportToXLSX = (reportMeta: any, data: 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, + 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, `${reportName}`.toUpperCase(), true) + setHeaderStyle( + worksheet, + 8, + 8, + `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + true + ) + + worksheet.mergeCells('A1:F1') + worksheet.mergeCells('A2:F2') + worksheet.mergeCells('A3:F3') + worksheet.mergeCells('A4:F4') + worksheet.mergeCells('H7:J7') + worksheet.mergeCells('H8:J8') + + exportToExcel({ + component: e.component, + worksheet, + autoFilterEnabled: true, + topLeftCell: { row: 10, column: 1 } + }).then(() => { + workbook.xlsx.writeBuffer().then((buffer: any) => { + saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`) + }) + }) + + e.cancel = true +} + +const exportToDOCX = (reportMeta: any, data: any) => { + const meta = formatMetaData(reportMeta) + + const generateRows = () => { + return data.value.map((item: any, i: any) => { + return new TableRow({ + children: [ + { text: `${++i}`, field: 'no' }, + { text: item.no_laporan, field: 'no_laporan' }, + { text: item.waktu_lapor, field: 'waktu_lapor' }, + { text: item.waktu_response, field: 'waktu_response' }, + { text: item.waktu_recovery, field: 'waktu_recovery' }, + { + text: parseInt(item.durasi_response_time) + ? formatWaktu(item.durasi_response_time) + : '-', + field: 'durasi_response_time' + }, + { + text: parseInt(item.durasi_recovery_time) + ? formatWaktu(item.durasi_recovery_time) + : '-', + field: 'durasi_recovery_time' + }, + { text: item.status_akhir, field: 'status_akhir' }, + { text: item.idpel_nometer, field: 'idpel_nometer' }, + { text: item.nama_pelapor, field: 'nama_pelapor' }, + { text: item.alamat_pelapor, field: 'alamat_pelapor' }, + { text: item.no_telp_pelapor, field: 'no_telp_pelapor' }, + { text: item.keterangan_pelapor, field: 'keterangan_pelapor' }, + { text: item.media, field: 'media' }, + { text: item.nama_posko, field: 'posko' } + ].map( + (cell) => + new TableCell({ + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: cell.text, + size: 4 + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }) + }) + } + + const doc = new Document({ + sections: [ + { + properties: { + page: { + size: { + orientation: PageOrientation.LANDSCAPE + } + } + }, + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: 'PT. PLN(Persero)', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT INDUK : ${ + reportMeta.value.uid + ? reportMeta.value.uid.name.toUpperCase() + : 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `UNIT PELAKSANA PELAYANAN PELANGGAN : ${ + reportMeta.value.up3 + ? reportMeta.value.up3.name.toUpperCase() + : 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: `POSKO : ${ + reportMeta.value.posko + ? reportMeta.value.posko.name.toUpperCase() + : 'Semua Posko'.toUpperCase() + }`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `${reportName}`.toUpperCase(), + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: `PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Table({ + width: { + size: 13950, + type: WidthType.DXA + }, + rows: [ + new TableRow({ + children: [ + { text: 'No', field: 'no' }, + { text: 'No Laporan', field: 'no_laporan' }, + { text: 'Tgl Lapor', field: 'waktu_lapor' }, + { text: 'Tgl Response', field: 'waktu_response' }, + { text: 'Tgl Recovery', field: 'waktu_recovery' }, + { text: 'Durasi Response Time', field: 'durasi_response_time' }, + { text: 'Durasi Recovery Time', field: 'durasi_recovery_time' }, + { text: 'Status', field: 'status_akhir' }, + { text: 'IDPEL/NO METER', field: 'idpel_nometer' }, + { text: 'Nama Pelapor', field: 'nama_pelapor' }, + { text: 'Alamat Pelapor', field: 'alamat_pelapor' }, + { text: 'No Telp Pelapor', field: 'no_telp_pelapor' }, + { text: 'Keterangan Pelapor', field: 'keterangan_pelapor' }, + { text: 'Sumber Lapor', field: 'media' }, + { text: 'Posko', field: 'posko' } + ].map( + (header) => + new TableCell({ + children: [ + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun({ + text: header.text, + bold: true, + size: 4, + allCaps: true + }) + ] + }) + ], + verticalAlign: VerticalAlign.CENTER + }) + ) + }), + ...generateRows() + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: `${meta.dayTo}, ${meta.dateToFormat}`, + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + children: [ + new TextRun({ + text: '', + bold: true, + size: 4 + }) + ] + }), + new Paragraph({ + alignment: AlignmentType.RIGHT, + children: [ + new TextRun({ + text: '(.........................................)', + bold: true, + size: 4 + }) + ] + }) + ] + } + ] + }) + + Packer.toBlob(doc).then((blob) => { + saveAs(blob, `Laporan ${reportName}.docx`) + console.log('Document created successfully') + }) +} + +export { exportToPDF, exportToXLSX, exportToDOCX }