fix: report rekapitulasi keluhan all
This commit is contained in:
parent
dba22ec07d
commit
05d5da7dd5
@ -12,80 +12,125 @@ const reportName = 'Rekapitulasi Keluhan All'
|
||||
const fontSize = 5
|
||||
const detailFontSize = 5
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
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 groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
const groupParent = getGroupParent(reportMeta)
|
||||
|
||||
if (groupParent === '') {
|
||||
return {
|
||||
data,
|
||||
parent: '',
|
||||
summaryName: ''
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
default: 'nama_uid'
|
||||
}
|
||||
|
||||
let key = 'nama_uid'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const group = item[groupParent.summaryKey]
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[group]) {
|
||||
groupedData[group] = []
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[group].push(item)
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
return {
|
||||
data: groupedData,
|
||||
parent: groupParent.parent,
|
||||
summaryName: groupParent.summaryName
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.total += item.total
|
||||
groupedData[key].summary.total_selesai += item.total_selesai
|
||||
groupedData[key].summary.total_inproses += item.total_inproses
|
||||
groupedData[key].summary.avg_durasi_response.push(item.avg_durasi_response)
|
||||
groupedData[key].summary.max_durasi_response.push(item.max_durasi_response)
|
||||
groupedData[key].summary.min_durasi_response.push(item.min_durasi_response)
|
||||
groupedData[key].summary.total_diatas_sla_response += item.total_diatas_sla_response
|
||||
groupedData[key].summary.total_dibawah_sla_response += item.total_dibawah_sla_response
|
||||
groupedData[key].summary.avg_durasi_recovery.push(item.avg_durasi_recovery)
|
||||
groupedData[key].summary.max_durasi_recovery.push(item.max_durasi_recovery)
|
||||
groupedData[key].summary.min_durasi_recovery.push(item.min_durasi_recovery)
|
||||
groupedData[key].summary.total_diatas_sla_recovery += item.total_diatas_sla_recovery
|
||||
groupedData[key].summary.total_dibawah_sla_recovery += item.total_dibawah_sla_recovery
|
||||
})
|
||||
|
||||
groupedData[key].summary.persen_selesai =
|
||||
groupedData[key].summary.total_selesai != groupedData[key].summary.total
|
||||
? (groupedData[key].summary.total_selesai / groupedData[key].summary.total) * 100
|
||||
: 100
|
||||
|
||||
groupedData[key].summary.persen_inproses =
|
||||
groupedData[key].summary.total_inproses != groupedData[key].summary.total
|
||||
? (groupedData[key].summary.total_inproses / groupedData[key].summary.total) * 100
|
||||
: 0
|
||||
|
||||
groupedData[key].summary.avg_durasi_response = groupedData[key].summary.avg_durasi_response
|
||||
.length
|
||||
? groupedData[key].summary.avg_durasi_response.reduce((a: any, b: any) => a + b) /
|
||||
groupedData[key].summary.avg_durasi_response.length
|
||||
: 0
|
||||
|
||||
groupedData[key].summary.max_durasi_response = Math.max(
|
||||
...groupedData[key].summary.max_durasi_response
|
||||
)
|
||||
groupedData[key].summary.min_durasi_response = Math.min(
|
||||
...groupedData[key].summary.min_durasi_response
|
||||
)
|
||||
|
||||
groupedData[key].summary.avg_durasi_recovery = groupedData[key].summary.avg_durasi_recovery
|
||||
.length
|
||||
? groupedData[key].summary.avg_durasi_recovery.reduce((a: any, b: any) => a + b) /
|
||||
groupedData[key].summary.avg_durasi_recovery.length
|
||||
: 0
|
||||
|
||||
groupedData[key].summary.max_durasi_recovery = Math.max(
|
||||
...groupedData[key].summary.max_durasi_recovery
|
||||
)
|
||||
groupedData[key].summary.min_durasi_recovery = Math.min(
|
||||
...groupedData[key].summary.min_durasi_recovery
|
||||
)
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return 'nama_ulp'
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return 'nama_uid'
|
||||
}
|
||||
|
||||
return 'nama_regional'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
// const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const data = tempData.data[tempData.summaryName]
|
||||
const formattedData: any = []
|
||||
console.table('data', data)
|
||||
|
||||
let parentName = ''
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
if (tempData.parent === '') {
|
||||
parentName = 'Seluruh Distribusi'
|
||||
} else if (tempData.parent === 'regional') {
|
||||
parentName = tempData.data[tempData.summaryName][0].nama_regional
|
||||
} else {
|
||||
parentName = tempData.summaryName
|
||||
}
|
||||
const groupedData: any = {}
|
||||
|
||||
const total: any = {
|
||||
total: 0,
|
||||
@ -103,59 +148,97 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
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 data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
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
|
||||
for (const key in data) {
|
||||
const groupKey = data[key].data[0][title]
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 17, styles: { fontStyle: 'bold' } }])
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
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)
|
||||
]
|
||||
groupedData[groupKey].data.push({
|
||||
key: key,
|
||||
value: data[key]
|
||||
})
|
||||
}
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||
for (const key in groupedData) {
|
||||
formattedData.push([{ content: key, colSpan: 17, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
groupedData[key].data.forEach((item: any, index: any) => {
|
||||
const summary = item.value.summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: index + 1, styles: { halign: 'right' } },
|
||||
item.key,
|
||||
formatNumber(summary.total),
|
||||
formatNumber(summary.total_selesai),
|
||||
formatPercentage(summary.persen_selesai),
|
||||
formatNumber(summary.total_inproses),
|
||||
formatPercentage(summary.persen_inproses),
|
||||
formatNumber(summary.avg_durasi_response),
|
||||
formatWaktu(summary.max_durasi_response),
|
||||
formatWaktu(summary.min_durasi_response),
|
||||
formatNumber(summary.total_diatas_sla_response),
|
||||
formatNumber(summary.total_dibawah_sla_response),
|
||||
formatNumber(summary.avg_durasi_recovery),
|
||||
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(summary.avg_durasi_response)
|
||||
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(summary.avg_durasi_recovery)
|
||||
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
|
||||
})
|
||||
|
||||
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: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
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)
|
||||
])
|
||||
}
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user