feat: create export pdf and xlsx in rekapitulasi keluhan per tanggal
This commit is contained in:
parent
a260bc6cbb
commit
dc91eb9322
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -459,7 +460,7 @@
|
|||||||
:hover-state-enabled="true"
|
:hover-state-enabled="true"
|
||||||
@selection-changed="onDataSubSelectionChanged"
|
@selection-changed="onDataSubSelectionChanged"
|
||||||
:column-width="100"
|
:column-width="100"
|
||||||
@exporting="onExporting"
|
@exporting="onExportingDetail"
|
||||||
:allow-column-resizing="true"
|
:allow-column-resizing="true"
|
||||||
column-resizing-mode="widget"
|
column-resizing-mode="widget"
|
||||||
>
|
>
|
||||||
@ -780,7 +781,7 @@ import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
|
|||||||
import InputText from '@/components/InputText.vue'
|
import InputText from '@/components/InputText.vue'
|
||||||
import Filters from '@/components/Form/Filters.vue'
|
import Filters from '@/components/Form/Filters.vue'
|
||||||
import Type13 from '@/components/Form/FiltersType/Type13.vue'
|
import Type13 from '@/components/Form/FiltersType/Type13.vue'
|
||||||
import { ref, onMounted, watch } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { DxDataGrid } from 'devextreme-vue'
|
import { DxDataGrid } from 'devextreme-vue'
|
||||||
import {
|
import {
|
||||||
DxColumn,
|
DxColumn,
|
||||||
@ -796,12 +797,6 @@ import {
|
|||||||
DxSelection,
|
DxSelection,
|
||||||
DxGrouping
|
DxGrouping
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||||
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
@ -809,6 +804,12 @@ import { apolloClient } from '@/utils/api/api.graphql'
|
|||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import { reformatDate } from '@/utils/texts'
|
import { reformatDate } from '@/utils/texts'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX,
|
||||||
|
exportDetailToPDF,
|
||||||
|
exportDetailToXLSX
|
||||||
|
} from '@/report/Keluhan/Rekap/RKeluhan_PerTanggal'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -827,6 +828,13 @@ const loadingSubData = ref(false)
|
|||||||
const agreeToShowDialog = ref(false)
|
const agreeToShowDialog = ref(false)
|
||||||
const progressSelected = ref(0)
|
const progressSelected = ref(0)
|
||||||
const isGroupBy = ref(false)
|
const isGroupBy = ref(false)
|
||||||
|
const reportMeta = ref({
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
periode: '',
|
||||||
|
groupBy: false
|
||||||
|
})
|
||||||
|
|
||||||
const setAgreementDialog = (status: boolean, progress: number) => {
|
const setAgreementDialog = (status: boolean, progress: number) => {
|
||||||
agreeToShowDialog.value = status
|
agreeToShowDialog.value = status
|
||||||
@ -864,6 +872,14 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
uid: uid ? uid : { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: up3 ? up3 : { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: ulp ? ulp : { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
periode: params.periode,
|
||||||
|
groupBy: params.groupBy
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
@ -930,30 +946,19 @@ const showDetail = () => {
|
|||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
}
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
}
|
||||||
|
|
||||||
exportToExcel({
|
const onExportingDetail = (e: any) => {
|
||||||
component: e.component,
|
if (e.format === 'pdf') {
|
||||||
worksheet,
|
exportDetailToPDF(reportMeta.value, dataSub.value)
|
||||||
autoFilterEnabled: true
|
} else if (e.format === 'xlsx') {
|
||||||
}).then(() => {
|
exportDetailToXLSX(reportMeta.value, e)
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
} else {
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
757
src/report/Keluhan/Rekap/RKeluhan_PerTanggal.ts
Normal file
757
src/report/Keluhan/Rekap/RKeluhan_PerTanggal.ts
Normal file
@ -0,0 +1,757 @@
|
|||||||
|
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'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
|
||||||
|
const reportName = 'Rekapitulasi Keluhan Per Tanggal'
|
||||||
|
const fontSize = 5
|
||||||
|
const detailFontSize = 3
|
||||||
|
|
||||||
|
const groupingData = (data: any) => {
|
||||||
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_uid } = item
|
||||||
|
|
||||||
|
if (!groupedData[nama_uid]) {
|
||||||
|
groupedData[nama_uid] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedData[nama_uid].push(item)
|
||||||
|
})
|
||||||
|
|
||||||
|
return groupedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, groupBy: boolean) => {
|
||||||
|
const formattedData: any = []
|
||||||
|
const grandTotal: any = {
|
||||||
|
total_laporan: 0,
|
||||||
|
total_laporan_sudah_selesai: 0,
|
||||||
|
total_laporan_belum_selesai: 0,
|
||||||
|
total_response_time_total: 0,
|
||||||
|
total_response_time_rata_rata: [],
|
||||||
|
total_response_time_max: [],
|
||||||
|
total_response_time_min: [],
|
||||||
|
total_response_time_lebih_sla: 0,
|
||||||
|
total_response_time_kurang_sla: 0,
|
||||||
|
total_recovery_time_total: 0,
|
||||||
|
total_recovery_time_rata_rata: [],
|
||||||
|
total_recovery_time_max: [],
|
||||||
|
total_recovery_time_min: [],
|
||||||
|
total_recovery_time_lebih_sla: 0,
|
||||||
|
total_recovery_time_kurang_sla: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupBy) {
|
||||||
|
const data = groupingData(rawData)
|
||||||
|
|
||||||
|
for (const nama_uid in data) {
|
||||||
|
const total: any = {
|
||||||
|
total_laporan: 0,
|
||||||
|
total_laporan_sudah_selesai: 0,
|
||||||
|
total_laporan_belum_selesai: 0,
|
||||||
|
total_response_time_total: 0,
|
||||||
|
total_response_time_rata_rata: [],
|
||||||
|
total_response_time_max: [],
|
||||||
|
total_response_time_min: [],
|
||||||
|
total_response_time_lebih_sla: 0,
|
||||||
|
total_response_time_kurang_sla: 0,
|
||||||
|
total_recovery_time_total: 0,
|
||||||
|
total_recovery_time_rata_rata: [],
|
||||||
|
total_recovery_time_max: [],
|
||||||
|
total_recovery_time_min: [],
|
||||||
|
total_recovery_time_lebih_sla: 0,
|
||||||
|
total_recovery_time_kurang_sla: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([{ content: nama_uid, colSpan: 19, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
for (let i = 0; i < data[nama_uid].length; i++) {
|
||||||
|
formattedData.push([
|
||||||
|
{ content: i + 1, styles: { halign: 'right' } },
|
||||||
|
data[nama_uid][i].tanggal_lapor,
|
||||||
|
formatNumber(data[nama_uid][i].total),
|
||||||
|
formatNumber(data[nama_uid][i].total_selesai),
|
||||||
|
formatPercentage(
|
||||||
|
!data[nama_uid][i].total || !data[nama_uid][i].total_selesai
|
||||||
|
? '0%'
|
||||||
|
: (data[nama_uid][i].total_selesai / data[nama_uid][i].total) * 100
|
||||||
|
),
|
||||||
|
formatNumber(data[nama_uid][i].total_inproses),
|
||||||
|
formatPercentage(
|
||||||
|
!data[nama_uid][i].total_inproses || !data[nama_uid][i].total
|
||||||
|
? '0%'
|
||||||
|
: (data[nama_uid][i].total_inproses / data[nama_uid][i].total) * 100
|
||||||
|
),
|
||||||
|
formatNumber(data[nama_uid][i].total_durasi_response),
|
||||||
|
formatNumber(data[nama_uid][i].avg_durasi_response),
|
||||||
|
formatWaktu(data[nama_uid][i].max_durasi_response),
|
||||||
|
formatWaktu(data[nama_uid][i].min_durasi_response),
|
||||||
|
formatNumber(data[nama_uid][i].total_diatas_sla_response),
|
||||||
|
formatNumber(data[nama_uid][i].total_dibawah_sla_response),
|
||||||
|
formatNumber(data[nama_uid][i].total_durasi_recovery),
|
||||||
|
formatNumber(data[nama_uid][i].avg_durasi_recovery),
|
||||||
|
formatWaktu(data[nama_uid][i].max_durasi_recovery),
|
||||||
|
formatWaktu(data[nama_uid][i].min_durasi_recovery),
|
||||||
|
formatNumber(data[nama_uid][i].total_diatas_sla_recovery),
|
||||||
|
formatNumber(data[nama_uid][i].total_dibawah_sla_recovery)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.total_laporan += data[nama_uid][i].total
|
||||||
|
total.total_laporan_sudah_selesai += data[nama_uid][i].total_selesai
|
||||||
|
total.total_laporan_belum_selesai += data[nama_uid][i].total_inproses
|
||||||
|
total.total_response_time_total += data[nama_uid][i].total_durasi_response
|
||||||
|
total.total_response_time_rata_rata.push(data[nama_uid][i].avg_durasi_response)
|
||||||
|
total.total_response_time_max.push(data[nama_uid][i].max_durasi_response)
|
||||||
|
total.total_response_time_min.push(data[nama_uid][i].min_durasi_response)
|
||||||
|
total.total_response_time_lebih_sla += data[nama_uid][i].total_diatas_sla_response
|
||||||
|
total.total_response_time_kurang_sla += data[nama_uid][i].total_dibawah_sla_response
|
||||||
|
total.total_recovery_time_total += data[nama_uid][i].total_durasi_recovery
|
||||||
|
total.total_recovery_time_rata_rata.push(data[nama_uid][i].avg_durasi_recovery)
|
||||||
|
total.total_recovery_time_max.push(data[nama_uid][i].max_durasi_recovery)
|
||||||
|
total.total_recovery_time_min.push(data[nama_uid][i].min_durasi_recovery)
|
||||||
|
total.total_recovery_time_lebih_sla += data[nama_uid][i].total_diatas_sla_recovery
|
||||||
|
total.total_recovery_time_kurang_sla += data[nama_uid][i].total_dibawah_sla_recovery
|
||||||
|
|
||||||
|
grandTotal.total_laporan += data[nama_uid][i].total
|
||||||
|
grandTotal.total_laporan_sudah_selesai += data[nama_uid][i].total_selesai
|
||||||
|
grandTotal.total_laporan_belum_selesai += data[nama_uid][i].total_inproses
|
||||||
|
grandTotal.total_response_time_total += data[nama_uid][i].total_durasi_response
|
||||||
|
grandTotal.total_response_time_rata_rata.push(data[nama_uid][i].avg_durasi_response)
|
||||||
|
grandTotal.total_response_time_max.push(data[nama_uid][i].max_durasi_response)
|
||||||
|
grandTotal.total_response_time_min.push(data[nama_uid][i].min_durasi_response)
|
||||||
|
grandTotal.total_response_time_lebih_sla += data[nama_uid][i].total_diatas_sla_response
|
||||||
|
grandTotal.total_response_time_kurang_sla += data[nama_uid][i].total_dibawah_sla_response
|
||||||
|
grandTotal.total_recovery_time_total += data[nama_uid][i].total_durasi_recovery
|
||||||
|
grandTotal.total_recovery_time_rata_rata.push(data[nama_uid][i].avg_durasi_recovery)
|
||||||
|
grandTotal.total_recovery_time_max.push(data[nama_uid][i].max_durasi_recovery)
|
||||||
|
grandTotal.total_recovery_time_min.push(data[nama_uid][i].min_durasi_recovery)
|
||||||
|
grandTotal.total_recovery_time_lebih_sla += data[nama_uid][i].total_diatas_sla_recovery
|
||||||
|
grandTotal.total_recovery_time_kurang_sla += data[nama_uid][i].total_dibawah_sla_recovery
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
|
formatNumber(total.total_laporan),
|
||||||
|
formatNumber(total.total_laporan_sudah_selesai),
|
||||||
|
formatPercentage(
|
||||||
|
!total.total_laporan || !total.total_laporan_sudah_selesai
|
||||||
|
? '0%'
|
||||||
|
: (total.total_laporan_sudah_selesai / total.total_laporan) * 100
|
||||||
|
),
|
||||||
|
formatNumber(total.total_laporan_belum_selesai),
|
||||||
|
formatPercentage(
|
||||||
|
!total.total_laporan || !total.total_laporan_belum_selesai
|
||||||
|
? '0%'
|
||||||
|
: (total.total_laporan_belum_selesai / total.total_laporan) * 100
|
||||||
|
),
|
||||||
|
formatNumber(total.total_response_time_total),
|
||||||
|
formatNumber(
|
||||||
|
total.total_response_time_rata_rata.length
|
||||||
|
? total.total_response_time_rata_rata.reduce((a: any, b: any) => a + b) /
|
||||||
|
total.total_response_time_rata_rata.length
|
||||||
|
: 0
|
||||||
|
),
|
||||||
|
formatWaktu(Math.max(...total.total_response_time_max)),
|
||||||
|
formatWaktu(Math.min(...total.total_response_time_min)),
|
||||||
|
formatNumber(total.total_response_time_lebih_sla),
|
||||||
|
formatNumber(total.total_response_time_kurang_sla),
|
||||||
|
formatNumber(total.total_recovery_time_total),
|
||||||
|
formatNumber(
|
||||||
|
total.total_recovery_time_rata_rata.length
|
||||||
|
? total.total_recovery_time_rata_rata.reduce((a: any, b: any) => a + b) /
|
||||||
|
total.total_recovery_time_rata_rata.length
|
||||||
|
: 0
|
||||||
|
),
|
||||||
|
formatWaktu(Math.max(...total.total_recovery_time_max)),
|
||||||
|
formatWaktu(Math.min(...total.total_recovery_time_min)),
|
||||||
|
formatNumber(total.total_recovery_time_lebih_sla),
|
||||||
|
formatNumber(total.total_recovery_time_kurang_sla)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < rawData.length; i++) {
|
||||||
|
formattedData.push([
|
||||||
|
{ content: i + 1, styles: { halign: 'right' } },
|
||||||
|
rawData[i].tanggal_lapor,
|
||||||
|
formatNumber(rawData[i].total),
|
||||||
|
formatNumber(rawData[i].total_selesai),
|
||||||
|
formatPercentage(
|
||||||
|
!rawData[i].total || !rawData[i].total_selesai
|
||||||
|
? '0%'
|
||||||
|
: (rawData[i].total_selesai / rawData[i].total) * 100
|
||||||
|
),
|
||||||
|
formatNumber(rawData[i].total_inproses),
|
||||||
|
formatPercentage(
|
||||||
|
!rawData[i].total_inproses || !rawData[i].total
|
||||||
|
? '0%'
|
||||||
|
: (rawData[i].total_inproses / rawData[i].total) * 100
|
||||||
|
),
|
||||||
|
formatNumber(rawData[i].total_durasi_response),
|
||||||
|
formatNumber(rawData[i].avg_durasi_response),
|
||||||
|
formatWaktu(rawData[i].max_durasi_response),
|
||||||
|
formatWaktu(rawData[i].min_durasi_response),
|
||||||
|
formatNumber(rawData[i].total_diatas_sla_response),
|
||||||
|
formatNumber(rawData[i].total_dibawah_sla_response),
|
||||||
|
formatNumber(rawData[i].total_durasi_recovery),
|
||||||
|
formatNumber(rawData[i].avg_durasi_recovery),
|
||||||
|
formatWaktu(rawData[i].max_durasi_recovery),
|
||||||
|
formatWaktu(rawData[i].min_durasi_recovery),
|
||||||
|
formatNumber(rawData[i].total_diatas_sla_recovery),
|
||||||
|
formatNumber(rawData[i].total_dibawah_sla_recovery)
|
||||||
|
])
|
||||||
|
|
||||||
|
grandTotal.total_laporan += rawData[i].total
|
||||||
|
grandTotal.total_laporan_sudah_selesai += rawData[i].total_selesai
|
||||||
|
grandTotal.total_laporan_belum_selesai += rawData[i].total_inproses
|
||||||
|
grandTotal.total_response_time_total += rawData[i].total_durasi_response
|
||||||
|
grandTotal.total_response_time_rata_rata.push(rawData[i].avg_durasi_response)
|
||||||
|
grandTotal.total_response_time_max.push(rawData[i].max_durasi_response)
|
||||||
|
grandTotal.total_response_time_min.push(rawData[i].min_durasi_response)
|
||||||
|
grandTotal.total_response_time_lebih_sla += rawData[i].total_diatas_sla_response
|
||||||
|
grandTotal.total_response_time_kurang_sla += rawData[i].total_dibawah_sla_response
|
||||||
|
grandTotal.total_recovery_time_total += rawData[i].total
|
||||||
|
grandTotal.total_recovery_time_rata_rata.push(rawData[i].avg_durasi_recovery)
|
||||||
|
grandTotal.total_recovery_time_max.push(rawData[i].max_durasi_recovery)
|
||||||
|
grandTotal.total_recovery_time_min.push(rawData[i].min_durasi_recovery)
|
||||||
|
grandTotal.total_recovery_time_lebih_sla += rawData[i].total_diatas_sla_recovery
|
||||||
|
grandTotal.total_recovery_time_kurang_sla += rawData[i].total_dibawah_sla_recovery
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: 'GRAND TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
|
formatNumber(grandTotal.total_laporan),
|
||||||
|
formatNumber(grandTotal.total_laporan_sudah_selesai),
|
||||||
|
formatPercentage(
|
||||||
|
!grandTotal.total_laporan || !grandTotal.total_laporan_sudah_selesai
|
||||||
|
? '0%'
|
||||||
|
: (grandTotal.total_laporan_sudah_selesai / grandTotal.total_laporan) * 100
|
||||||
|
),
|
||||||
|
formatNumber(grandTotal.total_laporan_belum_selesai),
|
||||||
|
formatPercentage(
|
||||||
|
!grandTotal.total_laporan || !grandTotal.total_laporan_belum_selesai
|
||||||
|
? '0%'
|
||||||
|
: (grandTotal.total_laporan_belum_selesai / grandTotal.total_laporan) * 100
|
||||||
|
),
|
||||||
|
formatNumber(grandTotal.total_response_time_total),
|
||||||
|
formatNumber(
|
||||||
|
grandTotal.total_response_time_rata_rata.length
|
||||||
|
? grandTotal.total_response_time_rata_rata.reduce((a: any, b: any) => a + b) /
|
||||||
|
grandTotal.total_response_time_rata_rata.length
|
||||||
|
: 0
|
||||||
|
),
|
||||||
|
formatWaktu(Math.max(...grandTotal.total_response_time_max)),
|
||||||
|
formatWaktu(Math.min(...grandTotal.total_response_time_min)),
|
||||||
|
formatNumber(grandTotal.total_response_time_lebih_sla),
|
||||||
|
formatNumber(grandTotal.total_response_time_kurang_sla),
|
||||||
|
formatNumber(grandTotal.total_recovery_time_total),
|
||||||
|
formatNumber(
|
||||||
|
grandTotal.total_recovery_time_rata_rata.length
|
||||||
|
? grandTotal.total_recovery_time_rata_rata.reduce((a: any, b: any) => a + b) /
|
||||||
|
grandTotal.total_recovery_time_rata_rata.length
|
||||||
|
: 0
|
||||||
|
),
|
||||||
|
formatWaktu(Math.max(...grandTotal.total_recovery_time_max)),
|
||||||
|
formatWaktu(Math.min(...grandTotal.total_recovery_time_min)),
|
||||||
|
formatNumber(grandTotal.total_recovery_time_lebih_sla),
|
||||||
|
formatNumber(grandTotal.total_recovery_time_kurang_sla)
|
||||||
|
])
|
||||||
|
|
||||||
|
return formattedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatMetaData = (reportMeta: any) => {
|
||||||
|
const periode = reportMeta.periode ? reportMeta.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, rawData: any, preview: boolean = false) => {
|
||||||
|
const data = formatData(rawData, reportMeta.groupBy)
|
||||||
|
const meta = formatMetaData(reportMeta)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
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,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'No',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Tanggal Lapor',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Laporan',
|
||||||
|
colSpan: 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Response Time',
|
||||||
|
colSpan: 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Penyelesaian',
|
||||||
|
colSpan: 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'Total',
|
||||||
|
rowSpan: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Sudah Selesai',
|
||||||
|
colSpan: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Belum Selesai',
|
||||||
|
colSpan: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Hari',
|
||||||
|
colSpan: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Laporan',
|
||||||
|
colSpan: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Hari',
|
||||||
|
colSpan: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Laporan',
|
||||||
|
colSpan: 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Jml',
|
||||||
|
'%',
|
||||||
|
'Jml',
|
||||||
|
'%',
|
||||||
|
'Total',
|
||||||
|
'Rata-Rata',
|
||||||
|
'Max',
|
||||||
|
'Min',
|
||||||
|
'>Sla',
|
||||||
|
'<Sla',
|
||||||
|
'Total',
|
||||||
|
'Rata-Rata',
|
||||||
|
'Max',
|
||||||
|
'Min',
|
||||||
|
'>Sla',
|
||||||
|
'<Sla'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
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()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'TOTAL') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'GRAND TOTAL') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${meta.dayTo}, ${meta.dateToFormat}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
'No Laporan',
|
||||||
|
'Tgl Lapor',
|
||||||
|
'Dalam Proses Bidang',
|
||||||
|
'Selesai Bidang Unit',
|
||||||
|
'Durasi Response Time',
|
||||||
|
'Durasi Recovery Time',
|
||||||
|
'Status',
|
||||||
|
'IDPEL/NO METER',
|
||||||
|
'Nama Pelapor',
|
||||||
|
'Alamat Pelapor',
|
||||||
|
'No Telp Pelapor',
|
||||||
|
'Keterangan Pelapor',
|
||||||
|
'Rayon',
|
||||||
|
'Uraian',
|
||||||
|
'Response Pelanggan'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: rawData.map((item: any, i: any) => [
|
||||||
|
{ content: i + 1, styles: { halign: 'right' } },
|
||||||
|
item.no_laporan,
|
||||||
|
item.waktu_lapor,
|
||||||
|
item.waktu_response,
|
||||||
|
item.waktu_recovery,
|
||||||
|
item.durasi_response_time,
|
||||||
|
item.durasi_recovery_time,
|
||||||
|
item.status_akhir,
|
||||||
|
item.idpel_nometer,
|
||||||
|
item.nama_pelapor,
|
||||||
|
item.alamat_pelapor,
|
||||||
|
item.no_telp_pelapor,
|
||||||
|
item.keterangan_pelapor,
|
||||||
|
item.nama_ulp,
|
||||||
|
item.uraian,
|
||||||
|
item.respon_pelanggan
|
||||||
|
]),
|
||||||
|
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()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 6, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
7,
|
||||||
|
1,
|
||||||
|
`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:S1')
|
||||||
|
worksheet.mergeCells('A2:S2')
|
||||||
|
worksheet.mergeCells('A3:S3')
|
||||||
|
worksheet.mergeCells('A4:S4')
|
||||||
|
worksheet.mergeCells('A6:S6')
|
||||||
|
worksheet.mergeCells('A7:S7')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 9, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const meta = formatMetaData(reportMeta)
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`Detail ${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(worksheet, 3, 1, `Daftar Detail ${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:P1')
|
||||||
|
worksheet.mergeCells('A3:P3')
|
||||||
|
worksheet.mergeCells('A4:P4')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 6, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(
|
||||||
|
new Blob([buffer], { type: 'application/octet-stream' }),
|
||||||
|
`Laporan Detail ${reportName}.xlsx`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportDetailToPDF, exportToXLSX, exportDetailToXLSX }
|
Loading…
x
Reference in New Issue
Block a user