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 fontSize = 5
|
||||||
const detailFontSize = 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 groupingData = (data: any, reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
const groupedData: any = {}
|
||||||
const groupParent = getGroupParent(reportMeta)
|
|
||||||
|
|
||||||
if (groupParent === '') {
|
const reportMetaMapping: any = {
|
||||||
return {
|
ulp: 'nama_ulp',
|
||||||
data,
|
uid: 'nama_up3',
|
||||||
parent: '',
|
default: 'nama_uid'
|
||||||
summaryName: ''
|
}
|
||||||
|
|
||||||
|
let key = 'nama_uid'
|
||||||
|
for (const prop in reportMetaMapping) {
|
||||||
|
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||||
|
key = reportMetaMapping[prop]
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.forEach((item: any) => {
|
data.forEach((item: any) => {
|
||||||
const group = item[groupParent.summaryKey]
|
const groupKey = item[key]
|
||||||
|
|
||||||
if (!groupedData[group]) {
|
if (!groupedData[groupKey]) {
|
||||||
groupedData[group] = []
|
groupedData[groupKey] = { data: [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
groupedData[group].push(item)
|
groupedData[groupKey].data.push(item)
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
for (const key in groupedData) {
|
||||||
data: groupedData,
|
const data = groupedData[key].data
|
||||||
parent: groupParent.parent,
|
|
||||||
summaryName: groupParent.summaryName
|
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 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 = []
|
const formattedData: any = []
|
||||||
console.table('data', data)
|
const groupedData: any = {}
|
||||||
|
|
||||||
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 total: any = {
|
const total: any = {
|
||||||
total: 0,
|
total: 0,
|
||||||
@ -103,20 +148,61 @@ const formatData = (rawData: any, reportMeta: any) => {
|
|||||||
total_dibawah_sla_recovery: 0
|
total_dibawah_sla_recovery: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
data.forEach((item: any) => {
|
const data = groupingData(rawData, reportMeta)
|
||||||
total.total += item.total
|
const title = getTitle(reportMeta)
|
||||||
total.total_selesai += item.total_selesai
|
|
||||||
total.total_inproses += item.total_inproses
|
for (const key in data) {
|
||||||
total.avg_durasi_response.push(item.avg_durasi_response)
|
const groupKey = data[key].data[0][title]
|
||||||
total.max_durasi_response.push(item.max_durasi_response)
|
|
||||||
total.min_durasi_response.push(item.min_durasi_response)
|
if (!groupedData[groupKey]) {
|
||||||
total.total_diatas_sla_response += item.total_diatas_sla_response
|
groupedData[groupKey] = { data: [] }
|
||||||
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)
|
groupedData[groupKey].data.push({
|
||||||
total.min_durasi_recovery.push(item.min_durasi_recovery)
|
key: key,
|
||||||
total.total_diatas_sla_recovery += item.total_diatas_sla_recovery
|
value: data[key]
|
||||||
total.total_dibawah_sla_recovery += item.total_dibawah_sla_recovery
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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 =
|
const persenSelesai =
|
||||||
@ -124,9 +210,8 @@ const formatData = (rawData: any, reportMeta: any) => {
|
|||||||
const persenInproses =
|
const persenInproses =
|
||||||
total.total_inproses != total.total ? (total.total_inproses / total.total) * 100 : 0
|
total.total_inproses != total.total ? (total.total_inproses / total.total) * 100 : 0
|
||||||
|
|
||||||
formattedData.push([{ content: parentName, colSpan: 17, styles: { fontStyle: 'bold' } }])
|
formattedData.push([
|
||||||
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
const result = [
|
|
||||||
formatNumber(total.total),
|
formatNumber(total.total),
|
||||||
formatNumber(total.total_selesai),
|
formatNumber(total.total_selesai),
|
||||||
formatPercentage(persenSelesai),
|
formatPercentage(persenSelesai),
|
||||||
@ -152,10 +237,8 @@ const formatData = (rawData: any, reportMeta: any) => {
|
|||||||
formatWaktu(Math.min(...total.min_durasi_recovery)),
|
formatWaktu(Math.min(...total.min_durasi_recovery)),
|
||||||
formatNumber(total.total_diatas_sla_recovery),
|
formatNumber(total.total_diatas_sla_recovery),
|
||||||
formatNumber(total.total_dibawah_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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user