feat: create pdf export in rekapitulasi gangguan per jenis gangguan SE004
This commit is contained in:
parent
0487301697
commit
3b6f7efccd
@ -2,7 +2,7 @@ VITE_BASE_URL=http://localhost:5173
|
||||
VITE_BASE_DIRECTORY=/
|
||||
VITE_APP_VERSION=0.0.1
|
||||
VITE_APP_NAME='Executive Information System'
|
||||
VITE_APP_GRAPHQL_ENDPOINT=http://127.0.0.1:32169/graphql
|
||||
# VITE_APP_GRAPHQL_ENDPOINT=http://127.0.0.1:32169/graphql
|
||||
# VITE_APP_REST_ENDPOINT=http://192.168.191.163:32180
|
||||
# VITE_APP_GRAPHQL_ENDPOINT=http://10.1.50.173:32180/graphql
|
||||
VITE_APP_GRAPHQL_ENDPOINT=http://10.1.50.173:32180/graphql
|
||||
VITE_APP_REST_ENDPOINT=http://10.1.50.173:32181
|
@ -4,6 +4,7 @@
|
||||
<Filters
|
||||
@reset-form="data = []"
|
||||
:report-button="true"
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@run-search="() => filterData(filters)"
|
||||
class="mb-4"
|
||||
>
|
||||
@ -788,6 +789,7 @@ import InputText from '@/components/InputText.vue'
|
||||
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import { exportToPDF } from '@/report/Gangguan/Rekap/RGangguan_JenisGangguanSE'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -802,6 +804,12 @@ const dataSubSelected = ref<any>(null)
|
||||
const dialogDetail = ref(false)
|
||||
const loadingData = ref(false)
|
||||
const loadingSubData = ref(false)
|
||||
const reportMeta = ref({
|
||||
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||
posko: { id: 0, name: 'Semua Posko' },
|
||||
periode: ''
|
||||
})
|
||||
|
||||
const closeDialog = () => {
|
||||
dialogDetail.value = false
|
||||
@ -809,15 +817,7 @@ const closeDialog = () => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else {
|
||||
const workbook = new Workbook()
|
||||
const worksheet = workbook.addWorksheet('Employees')
|
||||
@ -860,6 +860,8 @@ const filterData = (params: any) => {
|
||||
data.value = queryResult.data.rekapitulasiJenisGangguanSE004
|
||||
console.log(queryResult.data.rekapitulasiJenisGangguanSE004)
|
||||
}
|
||||
|
||||
reportMeta.value = filters.value
|
||||
})
|
||||
|
||||
onError((queryError) => {
|
||||
|
445
src/report/Gangguan/Rekap/RGangguan_JenisGangguanSE.ts
Normal file
445
src/report/Gangguan/Rekap/RGangguan_JenisGangguanSE.ts
Normal file
@ -0,0 +1,445 @@
|
||||
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 Gangguan/Jenis Gangguan SE 004'
|
||||
|
||||
const groupingData = (data: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const { id_fasilitas } = item
|
||||
|
||||
if (!groupedData[id_fasilitas]) {
|
||||
groupedData[id_fasilitas] = []
|
||||
}
|
||||
|
||||
groupedData[id_fasilitas].push(item)
|
||||
})
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const formatData = (rawData: any) => {
|
||||
const data = groupingData(rawData)
|
||||
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
|
||||
}
|
||||
|
||||
for (const id_fasilitas 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: id_fasilitas, colSpan: 20, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
for (let i = 0; i < data[id_fasilitas].length; i++) {
|
||||
formattedData.push([
|
||||
{ content: i + 1, styles: { halign: 'right' } },
|
||||
data[id_fasilitas][i].kode,
|
||||
data[id_fasilitas][i].sub_kelompok,
|
||||
formatNumber(data[id_fasilitas][i].total),
|
||||
formatNumber(data[id_fasilitas][i].total_selesai),
|
||||
formatPercentage((data[id_fasilitas][i].total_selesai / data[id_fasilitas][i].total) * 100),
|
||||
formatNumber(data[id_fasilitas][i].total_inproses),
|
||||
formatPercentage(
|
||||
data[id_fasilitas][i].total_inproses == null || data[id_fasilitas][i].total == null
|
||||
? '0%'
|
||||
: (data[id_fasilitas][i].total_inproses / data[id_fasilitas][i].total) * 100
|
||||
),
|
||||
formatNumber(data[id_fasilitas][i].total_durasi_response),
|
||||
formatNumber(data[id_fasilitas][i].avg_durasi_response),
|
||||
formatWaktu(data[id_fasilitas][i].max_durasi_response),
|
||||
formatWaktu(data[id_fasilitas][i].min_durasi_response),
|
||||
formatNumber(data[id_fasilitas][i].total_diatas_sla_response),
|
||||
formatNumber(data[id_fasilitas][i].total_dibawah_sla_response),
|
||||
formatNumber(data[id_fasilitas][i].total_durasi_recovery),
|
||||
formatNumber(data[id_fasilitas][i].avg_durasi_recovery),
|
||||
formatWaktu(data[id_fasilitas][i].max_durasi_recovery),
|
||||
formatWaktu(data[id_fasilitas][i].min_durasi_recovery),
|
||||
formatNumber(data[id_fasilitas][i].total_diatas_sla_recovery),
|
||||
formatNumber(data[id_fasilitas][i].total_dibawah_sla_recovery)
|
||||
])
|
||||
|
||||
total.total_laporan += data[id_fasilitas][i].total
|
||||
total.total_laporan_sudah_selesai += data[id_fasilitas][i].total_selesai
|
||||
total.total_laporan_belum_selesai += data[id_fasilitas][i].total_inproses
|
||||
total.total_response_time_total += data[id_fasilitas][i].total_durasi_response
|
||||
total.total_response_time_rata_rata.push(data[id_fasilitas][i].avg_durasi_response)
|
||||
total.total_response_time_max.push(data[id_fasilitas][i].max_durasi_response)
|
||||
total.total_response_time_min.push(data[id_fasilitas][i].min_durasi_response)
|
||||
total.total_response_time_lebih_sla += data[id_fasilitas][i].total_diatas_sla_response
|
||||
total.total_response_time_kurang_sla += data[id_fasilitas][i].total_dibawah_sla_response
|
||||
total.total_recovery_time_total += data[id_fasilitas][i].total_durasi_recovery
|
||||
total.total_recovery_time_rata_rata.push(data[id_fasilitas][i].avg_durasi_recovery)
|
||||
total.total_recovery_time_max.push(data[id_fasilitas][i].max_durasi_recovery)
|
||||
total.total_recovery_time_min.push(data[id_fasilitas][i].min_durasi_recovery)
|
||||
total.total_recovery_time_lebih_sla += data[id_fasilitas][i].total_diatas_sla_recovery
|
||||
total.total_recovery_time_kurang_sla += data[id_fasilitas][i].total_dibawah_sla_recovery
|
||||
|
||||
grandTotal.total_laporan += data[id_fasilitas][i].total
|
||||
grandTotal.total_laporan_sudah_selesai += data[id_fasilitas][i].total_selesai
|
||||
grandTotal.total_laporan_belum_selesai += data[id_fasilitas][i].total_inproses
|
||||
grandTotal.total_response_time_total += data[id_fasilitas][i].total_durasi_response
|
||||
grandTotal.total_response_time_rata_rata.push(data[id_fasilitas][i].avg_durasi_response)
|
||||
grandTotal.total_response_time_max.push(data[id_fasilitas][i].max_durasi_response)
|
||||
grandTotal.total_response_time_min.push(data[id_fasilitas][i].min_durasi_response)
|
||||
grandTotal.total_response_time_lebih_sla += data[id_fasilitas][i].total_diatas_sla_response
|
||||
grandTotal.total_response_time_kurang_sla += data[id_fasilitas][i].total_dibawah_sla_response
|
||||
grandTotal.total_recovery_time_total += data[id_fasilitas][i].total_durasi_recovery
|
||||
grandTotal.total_recovery_time_rata_rata.push(data[id_fasilitas][i].avg_durasi_recovery)
|
||||
grandTotal.total_recovery_time_max.push(data[id_fasilitas][i].max_durasi_recovery)
|
||||
grandTotal.total_recovery_time_min.push(data[id_fasilitas][i].min_durasi_recovery)
|
||||
grandTotal.total_recovery_time_lebih_sla += data[id_fasilitas][i].total_diatas_sla_recovery
|
||||
grandTotal.total_recovery_time_kurang_sla += data[id_fasilitas][i].total_dibawah_sla_recovery
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 3, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.total_laporan),
|
||||
formatNumber(total.total_laporan_sudah_selesai),
|
||||
formatPercentage((total.total_laporan_sudah_selesai / total.total_laporan) * 100),
|
||||
formatNumber(total.total_laporan_belum_selesai),
|
||||
formatPercentage((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)
|
||||
])
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'GRAND TOTAL', colSpan: 3, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(grandTotal.total_laporan),
|
||||
formatNumber(grandTotal.total_laporan_sudah_selesai),
|
||||
formatPercentage((grandTotal.total_laporan_sudah_selesai / grandTotal.total_laporan) * 100),
|
||||
formatNumber(grandTotal.total_laporan_belum_selesai),
|
||||
formatPercentage((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)
|
||||
const meta = formatMetaData(reportMeta)
|
||||
const doc = new jsPDF({
|
||||
orientation: 'landscape'
|
||||
})
|
||||
const fontSize = 5
|
||||
|
||||
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()
|
||||
],
|
||||
[
|
||||
'POSKO',
|
||||
':',
|
||||
reportMeta.posko ? reportMeta.posko.name.toUpperCase() : 'Semua Posko'.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: 'Kode',
|
||||
rowSpan: 3
|
||||
},
|
||||
{
|
||||
content: 'Sub Kelompok (Equipment)',
|
||||
styles: { cellWidth: 25 },
|
||||
rowSpan: 3
|
||||
},
|
||||
{
|
||||
content: 'Laporan',
|
||||
colSpan: 5
|
||||
},
|
||||
{
|
||||
content: 'Response Time',
|
||||
colSpan: 6
|
||||
},
|
||||
{
|
||||
content: 'Recovery Time',
|
||||
colSpan: 6
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
content: 'Total',
|
||||
rowSpan: 2
|
||||
},
|
||||
{
|
||||
content: 'Sudah Selesai',
|
||||
colSpan: 2
|
||||
},
|
||||
{
|
||||
content: 'Belum Selesai',
|
||||
colSpan: 2
|
||||
},
|
||||
{
|
||||
content: 'Menit',
|
||||
colSpan: 4
|
||||
},
|
||||
{
|
||||
content: 'Laporan',
|
||||
colSpan: 2
|
||||
},
|
||||
{
|
||||
content: 'Menit',
|
||||
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) {
|
||||
window.open(doc.output('bloburl'))
|
||||
} else {
|
||||
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||
console.log('pdf berhasil disimpan')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { exportToPDF }
|
Loading…
x
Reference in New Issue
Block a user