fix: export pdf in rekapitulasi gangguan all
This commit is contained in:
parent
80a0510f6e
commit
9dfa7d1d92
@ -72,7 +72,6 @@ const groupingData = (data: any, reportMeta: any) => {
|
|||||||
const formatData = (rawData: any, reportMeta: any) => {
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const tempData = groupingData(rawData, reportMeta)
|
const tempData = groupingData(rawData, reportMeta)
|
||||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||||
console.log(tempData.data)
|
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
let parentName = ''
|
let parentName = ''
|
||||||
@ -175,7 +174,7 @@ const formatData = (rawData: any, reportMeta: any) => {
|
|||||||
formatNumber(total.total_dibawah_sla_recovery)
|
formatNumber(total.total_dibawah_sla_recovery)
|
||||||
]
|
]
|
||||||
|
|
||||||
formattedData.push(['1', summaryName, ...result])
|
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||||
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||||
|
|
||||||
return formattedData
|
return formattedData
|
||||||
@ -212,7 +211,6 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
console.log(data)
|
|
||||||
autoTable(doc, {
|
autoTable(doc, {
|
||||||
head: [
|
head: [
|
||||||
['PT. PLN(Persero)', '', ''],
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
@ -25,192 +25,149 @@ const reportName = 'Rekapitulasi Keluhan All'
|
|||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
const detailFontSize = 5
|
const detailFontSize = 5
|
||||||
|
|
||||||
const groupingData = (data: any) => {
|
const getGroupParent = (reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
if (reportMeta.ulp.id != 0) {
|
||||||
|
return {
|
||||||
data.forEach((item: any) => {
|
parent: reportMeta.up3.name,
|
||||||
const { nama_regional, nama_uid } = item
|
summaryName: reportMeta.ulp.name,
|
||||||
|
summaryKey: 'nama_ulp'
|
||||||
if (!groupedData[nama_regional]) {
|
|
||||||
groupedData[nama_regional] = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!groupedData[nama_regional][nama_uid]) {
|
|
||||||
groupedData[nama_regional][nama_uid] = { data: [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
groupedData[nama_regional][nama_uid].data.push(item)
|
|
||||||
})
|
|
||||||
|
|
||||||
for (const regional in groupedData) {
|
|
||||||
for (const uid in groupedData[regional]) {
|
|
||||||
const data = groupedData[regional][uid].data
|
|
||||||
|
|
||||||
data.forEach((item: any) => {
|
|
||||||
if (!groupedData[regional][uid].summary) {
|
|
||||||
groupedData[regional][uid].summary = {
|
|
||||||
total: 0,
|
|
||||||
total_selesai: 0,
|
|
||||||
total_inproses: 0,
|
|
||||||
avg_durasi_response: [],
|
|
||||||
max_durasi_response: 0,
|
|
||||||
min_durasi_response: 0,
|
|
||||||
total_diatas_sla_response: 0,
|
|
||||||
total_dibawah_sla_response: 0,
|
|
||||||
avg_durasi_recovery: [],
|
|
||||||
max_durasi_recovery: 0,
|
|
||||||
min_durasi_recovery: 0,
|
|
||||||
total_diatas_sla_recovery: 0,
|
|
||||||
total_dibawah_sla_recovery: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groupedData[regional][uid].summary.total += item.total
|
|
||||||
groupedData[regional][uid].summary.total_selesai += item.total_selesai
|
|
||||||
groupedData[regional][uid].summary.total_inproses += item.total_inproses
|
|
||||||
groupedData[regional][uid].summary.avg_durasi_response.push(item.avg_durasi_response)
|
|
||||||
groupedData[regional][uid].summary.max_durasi_response =
|
|
||||||
groupedData[regional][uid].summary.max_durasi_response < item.max_durasi_response
|
|
||||||
? item.max_durasi_response
|
|
||||||
: groupedData[regional][uid].summary.max_durasi_response
|
|
||||||
groupedData[regional][uid].summary.min_durasi_response =
|
|
||||||
groupedData[regional][uid].summary.min_durasi_response > item.min_durasi_response
|
|
||||||
? item.min_durasi_response
|
|
||||||
: groupedData[regional][uid].summary.min_durasi_response
|
|
||||||
groupedData[regional][uid].summary.total_diatas_sla_response +=
|
|
||||||
item.total_diatas_sla_response
|
|
||||||
groupedData[regional][uid].summary.total_dibawah_sla_response +=
|
|
||||||
item.total_dibawah_sla_response
|
|
||||||
groupedData[regional][uid].summary.avg_durasi_recovery.push(item.avg_durasi_recovery)
|
|
||||||
groupedData[regional][uid].summary.max_durasi_recovery =
|
|
||||||
groupedData[regional][uid].summary.max_durasi_recovery < item.max_durasi_recovery
|
|
||||||
? item.max_durasi_recovery
|
|
||||||
: groupedData[regional][uid].summary.max_durasi_recovery
|
|
||||||
groupedData[regional][uid].summary.min_durasi_recovery =
|
|
||||||
groupedData[regional][uid].summary.min_durasi_recovery > item.min_durasi_recovery
|
|
||||||
? item.min_durasi_recovery
|
|
||||||
: groupedData[regional][uid].summary.min_durasi_recovery
|
|
||||||
groupedData[regional][uid].summary.total_diatas_sla_recovery +=
|
|
||||||
item.total_diatas_sla_recovery
|
|
||||||
groupedData[regional][uid].summary.total_dibawah_sla_recovery +=
|
|
||||||
item.total_dibawah_sla_recovery
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupedData
|
if (reportMeta.up3.id != 0) {
|
||||||
|
return {
|
||||||
|
parent: reportMeta.uid.name,
|
||||||
|
summaryName: reportMeta.up3.name,
|
||||||
|
summaryKey: 'nama_up3'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reportMeta.uid.id != 0) {
|
||||||
|
return {
|
||||||
|
parent: 'regional',
|
||||||
|
summaryName: reportMeta.uid.name,
|
||||||
|
summaryKey: 'nama_uid'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatData = (rawData: any) => {
|
const groupingData = (data: any, reportMeta: any) => {
|
||||||
const data = groupingData(rawData)
|
const groupedData: any = {}
|
||||||
|
const groupParent = getGroupParent(reportMeta)
|
||||||
|
|
||||||
|
if (groupParent === '') {
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
parent: '',
|
||||||
|
summaryName: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const group = item[groupParent.summaryKey]
|
||||||
|
|
||||||
|
if (!groupedData[group]) {
|
||||||
|
groupedData[group] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedData[group].push(item)
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: groupedData,
|
||||||
|
parent: groupParent.parent,
|
||||||
|
summaryName: groupParent.summaryName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
|
const tempData = groupingData(rawData, reportMeta)
|
||||||
|
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
for (const regional in data) {
|
let parentName = ''
|
||||||
let no = 1
|
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||||
const total: any = {
|
|
||||||
total: 0,
|
|
||||||
total_selesai: 0,
|
|
||||||
total_inproses: 0,
|
|
||||||
avg_durasi_response: [],
|
|
||||||
max_durasi_response: [],
|
|
||||||
min_durasi_response: [],
|
|
||||||
total_diatas_sla_response: 0,
|
|
||||||
total_dibawah_sla_response: 0,
|
|
||||||
avg_durasi_recovery: [],
|
|
||||||
max_durasi_recovery: [],
|
|
||||||
min_durasi_recovery: [],
|
|
||||||
total_diatas_sla_recovery: 0,
|
|
||||||
total_dibawah_sla_recovery: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedData.push([{ content: regional, colSpan: 17, styles: { fontStyle: 'bold' } }])
|
if (tempData.parent === '') {
|
||||||
|
parentName = 'Seluruh Distribusi'
|
||||||
for (const uid in data[regional]) {
|
} else if (tempData.parent === 'regional') {
|
||||||
const summary = data[regional][uid].summary
|
parentName = tempData.data[tempData.summaryName][0].nama_regional
|
||||||
const avgDurasiResponse = summary.avg_durasi_response.length
|
} else {
|
||||||
? summary.avg_durasi_response.reduce((a: any, b: any) => a + b) /
|
parentName = tempData.parent
|
||||||
summary.avg_durasi_response.length
|
|
||||||
: 0
|
|
||||||
const avgDurasiRecovery = summary.avg_durasi_recovery.length
|
|
||||||
? summary.avg_durasi_recovery.reduce((a: any, b: any) => a + b) /
|
|
||||||
summary.avg_durasi_recovery.length
|
|
||||||
: 0
|
|
||||||
|
|
||||||
formattedData.push([
|
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
|
||||||
uid,
|
|
||||||
formatNumber(summary.total),
|
|
||||||
formatNumber(summary.total_selesai),
|
|
||||||
summary.total_selesai != summary.total
|
|
||||||
? formatPercentage((summary.total_selesai / summary.total) * 100)
|
|
||||||
: '100%',
|
|
||||||
formatNumber(summary.total_inproses),
|
|
||||||
formatPercentage(
|
|
||||||
!summary.total_inproses || !summary.total
|
|
||||||
? '0%'
|
|
||||||
: (summary.total_inproses / summary.total) * 100
|
|
||||||
),
|
|
||||||
formatNumber(avgDurasiResponse),
|
|
||||||
formatWaktu(summary.max_durasi_response),
|
|
||||||
formatWaktu(summary.min_durasi_response),
|
|
||||||
formatNumber(summary.total_diatas_sla_response),
|
|
||||||
formatNumber(summary.total_dibawah_sla_response),
|
|
||||||
formatNumber(avgDurasiRecovery),
|
|
||||||
formatWaktu(summary.max_durasi_recovery),
|
|
||||||
formatWaktu(summary.min_durasi_recovery),
|
|
||||||
formatNumber(summary.total_diatas_sla_recovery),
|
|
||||||
formatNumber(summary.total_dibawah_sla_recovery)
|
|
||||||
])
|
|
||||||
|
|
||||||
total.total += summary.total
|
|
||||||
total.total_selesai += summary.total_selesai
|
|
||||||
total.total_inproses += summary.total_inproses
|
|
||||||
total.avg_durasi_response.push(avgDurasiResponse)
|
|
||||||
total.max_durasi_response.push(summary.max_durasi_response)
|
|
||||||
total.min_durasi_response.push(summary.min_durasi_response)
|
|
||||||
total.total_diatas_sla_response += summary.total_diatas_sla_response
|
|
||||||
total.total_dibawah_sla_response += summary.total_dibawah_sla_response
|
|
||||||
total.avg_durasi_recovery.push(avgDurasiRecovery)
|
|
||||||
total.max_durasi_recovery.push(summary.max_durasi_recovery)
|
|
||||||
total.min_durasi_recovery.push(summary.min_durasi_recovery)
|
|
||||||
total.total_diatas_sla_recovery += summary.total_diatas_sla_recovery
|
|
||||||
total.total_dibawah_sla_recovery += summary.total_dibawah_sla_recovery
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedData.push([
|
|
||||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
|
||||||
formatNumber(total.total),
|
|
||||||
formatNumber(total.total_selesai),
|
|
||||||
formatPercentage(
|
|
||||||
!total.total_selesai || !total.total ? '0%' : (total.total_selesai / total.total) * 100
|
|
||||||
),
|
|
||||||
formatNumber(total.total_inproses),
|
|
||||||
formatPercentage(
|
|
||||||
!total.total_inproses || !total.total ? '0%' : (total.total_inproses / total.total) * 100
|
|
||||||
),
|
|
||||||
formatNumber(
|
|
||||||
total.avg_durasi_response.length
|
|
||||||
? total.avg_durasi_response.reduce((a: any, b: any) => a + b) /
|
|
||||||
total.avg_durasi_response.length
|
|
||||||
: 0
|
|
||||||
),
|
|
||||||
formatWaktu(Math.max(...total.max_durasi_response)),
|
|
||||||
formatWaktu(Math.min(...total.min_durasi_response)),
|
|
||||||
formatNumber(total.total_diatas_sla_response),
|
|
||||||
formatNumber(total.total_dibawah_sla_response),
|
|
||||||
formatNumber(
|
|
||||||
total.avg_durasi_recovery.length
|
|
||||||
? total.avg_durasi_recovery.reduce((a: any, b: any) => a + b) /
|
|
||||||
total.avg_durasi_recovery.length
|
|
||||||
: 0
|
|
||||||
),
|
|
||||||
formatWaktu(Math.max(...total.max_durasi_recovery)),
|
|
||||||
formatWaktu(Math.min(...total.min_durasi_recovery)),
|
|
||||||
formatNumber(total.total_diatas_sla_recovery),
|
|
||||||
formatNumber(total.total_dibawah_sla_recovery)
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
total: 0,
|
||||||
|
total_selesai: 0,
|
||||||
|
total_inproses: 0,
|
||||||
|
avg_durasi_response: [],
|
||||||
|
max_durasi_response: [],
|
||||||
|
min_durasi_response: [],
|
||||||
|
total_diatas_sla_response: 0,
|
||||||
|
total_dibawah_sla_response: 0,
|
||||||
|
avg_durasi_recovery: [],
|
||||||
|
max_durasi_recovery: [],
|
||||||
|
min_durasi_recovery: [],
|
||||||
|
total_diatas_sla_recovery: 0,
|
||||||
|
total_dibawah_sla_recovery: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
total.total += item.total
|
||||||
|
total.total_selesai += item.total_selesai
|
||||||
|
total.total_inproses += item.total_inproses
|
||||||
|
total.avg_durasi_response.push(item.avg_durasi_response)
|
||||||
|
total.max_durasi_response.push(item.max_durasi_response)
|
||||||
|
total.min_durasi_response.push(item.min_durasi_response)
|
||||||
|
total.total_diatas_sla_response += item.total_diatas_sla_response
|
||||||
|
total.total_dibawah_sla_response += item.total_dibawah_sla_response
|
||||||
|
total.avg_durasi_recovery.push(item.avg_durasi_recovery)
|
||||||
|
total.max_durasi_recovery.push(item.max_durasi_recovery)
|
||||||
|
total.min_durasi_recovery.push(item.min_durasi_recovery)
|
||||||
|
total.total_diatas_sla_recovery += item.total_diatas_sla_recovery
|
||||||
|
total.total_dibawah_sla_recovery += item.total_dibawah_sla_recovery
|
||||||
|
})
|
||||||
|
|
||||||
|
const persenSelesai =
|
||||||
|
total.total_selesai != total.total ? (total.total_selesai / total.total) * 100 : 100
|
||||||
|
const persenInproses =
|
||||||
|
total.total_inproses != total.total ? (total.total_inproses / total.total) * 100 : 0
|
||||||
|
|
||||||
|
formattedData.push([{ content: parentName, colSpan: 17, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
const result = [
|
||||||
|
formatNumber(total.total),
|
||||||
|
formatNumber(total.total_selesai),
|
||||||
|
formatPercentage(persenSelesai),
|
||||||
|
formatNumber(total.total_inproses),
|
||||||
|
formatPercentage(persenInproses),
|
||||||
|
formatNumber(
|
||||||
|
total.avg_durasi_response.length
|
||||||
|
? total.avg_durasi_response.reduce((a: any, b: any) => a + b) /
|
||||||
|
total.avg_durasi_response.length
|
||||||
|
: 0
|
||||||
|
),
|
||||||
|
formatWaktu(Math.max(...total.max_durasi_response)),
|
||||||
|
formatWaktu(Math.min(...total.min_durasi_response)),
|
||||||
|
formatNumber(total.total_diatas_sla_response),
|
||||||
|
formatNumber(total.total_dibawah_sla_response),
|
||||||
|
formatNumber(
|
||||||
|
total.avg_durasi_recovery.length
|
||||||
|
? total.avg_durasi_recovery.reduce((a: any, b: any) => a + b) /
|
||||||
|
total.avg_durasi_recovery.length
|
||||||
|
: 0
|
||||||
|
),
|
||||||
|
formatWaktu(Math.max(...total.max_durasi_recovery)),
|
||||||
|
formatWaktu(Math.min(...total.min_durasi_recovery)),
|
||||||
|
formatNumber(total.total_diatas_sla_recovery),
|
||||||
|
formatNumber(total.total_dibawah_sla_recovery)
|
||||||
|
]
|
||||||
|
|
||||||
|
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||||
|
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||||
|
|
||||||
return formattedData
|
return formattedData
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,8 +197,7 @@ const formatMetaData = (reportMeta: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
console.log(data)
|
|
||||||
const meta = formatMetaData(reportMeta)
|
const meta = formatMetaData(reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
@ -650,7 +606,7 @@ const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
|||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
const meta = formatMetaData(reportMeta)
|
const meta = formatMetaData(reportMeta)
|
||||||
exportToWord(reportMeta, meta, formatData(rawData), reportName)
|
exportToWord(reportMeta, meta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user