fix: report in monalisa rekapitulasi gangguan
This commit is contained in:
parent
b5926326d3
commit
4341defad8
@ -13,108 +13,80 @@ const reportName = 'Dispacthing Time (DT) Gangguan'
|
||||
const fontSize = 5
|
||||
const detailFontSize = 3
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
data.forEach((item: any) => {
|
||||
const { nama_regional } = item
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
if (!groupedData[nama_regional]) {
|
||||
groupedData[nama_regional] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[nama_regional].data.push(item)
|
||||
})
|
||||
|
||||
for (const regional in groupedData) {
|
||||
const data = groupedData[regional].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[regional].summary) {
|
||||
groupedData[regional].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[regional].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[regional].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[regional].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[regional].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[regional].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
} else {
|
||||
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
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[key].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[key].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[key].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[key].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[key].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -127,126 +99,70 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
yoy_tahun_ini: []
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const formattedData: any = []
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
formattedData.push([{ content: title, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
let no = 1
|
||||
for (const regional in data) {
|
||||
const summary = data[regional].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
regional,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) *
|
||||
100
|
||||
),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) *
|
||||
100
|
||||
)
|
||||
])
|
||||
|
||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||
}
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
key,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.mom_bulan_kemarin.push(item.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(item.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(item.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(item.yoy_tahun_ini)
|
||||
})
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
)
|
||||
]
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
...result
|
||||
])
|
||||
|
||||
return formattedData
|
||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||
}
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
@ -11,108 +11,80 @@ import { exportToWord } from './doc/MonalisaGR_ENSGangguan_DOC'
|
||||
const reportName = 'Rekapitulasi ENS Gangguan'
|
||||
const fontSize = 5
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
data.forEach((item: any) => {
|
||||
const { nama_regional } = item
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
if (!groupedData[nama_regional]) {
|
||||
groupedData[nama_regional] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[nama_regional].data.push(item)
|
||||
})
|
||||
|
||||
for (const regional in groupedData) {
|
||||
const data = groupedData[regional].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[regional].summary) {
|
||||
groupedData[regional].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[regional].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[regional].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[regional].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[regional].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[regional].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
} else {
|
||||
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
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[key].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[key].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[key].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[key].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[key].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -125,100 +97,59 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
yoy_tahun_ini: 0
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
formattedData.push([{ content: title, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
let no = 1
|
||||
for (const regional in data) {
|
||||
const summary = data[regional].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
regional,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) *
|
||||
100
|
||||
),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) *
|
||||
100
|
||||
)
|
||||
])
|
||||
|
||||
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||
total.mom_bulan_ini += summary.mom_bulan_ini
|
||||
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||
}
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.mom_bulan_kemarin),
|
||||
formatNumber(total.mom_bulan_ini),
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
key,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(total.yoy_tahun_kemarin),
|
||||
formatNumber(total.yoy_tahun_ini),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
total.mom_bulan_ini += item.mom_bulan_ini
|
||||
total.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
total.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
})
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(total.mom_bulan_kemarin),
|
||||
formatNumber(total.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(total.yoy_tahun_kemarin),
|
||||
formatNumber(total.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
]
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||
|
||||
return formattedData
|
||||
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||
total.mom_bulan_ini += summary.mom_bulan_ini
|
||||
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.mom_bulan_kemarin),
|
||||
formatNumber(total.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(total.yoy_tahun_kemarin),
|
||||
formatNumber(total.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
@ -12,102 +12,74 @@ const reportName = 'Rekapitulasi Gangguan Belum Selesai'
|
||||
const fontSize = 5
|
||||
const detailFontSize = 3
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
data.forEach((item: any) => {
|
||||
const { nama_regional } = item
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
if (!groupedData[nama_regional]) {
|
||||
groupedData[nama_regional] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[nama_regional].data.push(item)
|
||||
})
|
||||
|
||||
for (const regional in groupedData) {
|
||||
const data = groupedData[regional].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[regional].summary) {
|
||||
groupedData[regional].summary = {
|
||||
jumlah_gangguan: 0,
|
||||
jumlah_informasi: 0,
|
||||
total: 0
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.jumlah_gangguan += item.jumlah_gangguan
|
||||
groupedData[regional].summary.jumlah_informasi += item.jumlah_informasi
|
||||
groupedData[regional].summary.total += item.total
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
} else {
|
||||
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
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
jumlah_gangguan: 0,
|
||||
jumlah_informasi: 0,
|
||||
total: 0
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.jumlah_gangguan += item.jumlah_gangguan
|
||||
groupedData[key].summary.jumlah_informasi += item.jumlah_informasi
|
||||
groupedData[key].summary.total += item.total
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -119,69 +91,36 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
total: 0
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
const total: any = {
|
||||
jumlah_gangguan: 0,
|
||||
jumlah_informasi: 0,
|
||||
total: 0
|
||||
}
|
||||
formattedData.push([{ content: title, colSpan: 5, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 5, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
let no = 1
|
||||
for (const regional in data) {
|
||||
const summary = data[regional].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
regional,
|
||||
formatNumber(summary.jumlah_gangguan),
|
||||
formatNumber(summary.jumlah_informasi),
|
||||
formatNumber(summary.total)
|
||||
])
|
||||
|
||||
total.jumlah_gangguan += summary.jumlah_gangguan
|
||||
total.jumlah_informasi += summary.jumlah_informasi
|
||||
total.total += summary.total
|
||||
}
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.jumlah_gangguan),
|
||||
formatNumber(total.jumlah_informasi),
|
||||
formatNumber(total.total)
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
key,
|
||||
formatNumber(summary.jumlah_gangguan),
|
||||
formatNumber(summary.jumlah_informasi),
|
||||
formatNumber(summary.total)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.jumlah_gangguan += item.jumlah_gangguan
|
||||
total.jumlah_informasi += item.jumlah_informasi
|
||||
total.total += item.total
|
||||
})
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 5, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(total.jumlah_gangguan),
|
||||
formatNumber(total.jumlah_informasi),
|
||||
formatNumber(total.total)
|
||||
]
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||
|
||||
return formattedData
|
||||
total.jumlah_gangguan += summary.jumlah_gangguan
|
||||
total.jumlah_informasi += summary.jumlah_informasi
|
||||
total.total += summary.total
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.jumlah_gangguan),
|
||||
formatNumber(total.jumlah_informasi),
|
||||
formatNumber(total.total)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
@ -11,59 +11,92 @@ import { exportToWord } from './doc/MonalisaGR_JumlahDDRPTRCTGangguan_DOC'
|
||||
const reportName = 'Jumlah dan Durasi RPT RCT Gangguan'
|
||||
const fontSize = 5
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
total_durasi_response_time_bulan_ini: 0,
|
||||
count_durasi_response_time_bulan_ini: 0,
|
||||
total_durasi_recovery_time_bulan_ini: 0,
|
||||
count_durasi_recovery_time_bulan_ini: 0,
|
||||
total_durasi_response_time_tahun_ini: 0,
|
||||
count_durasi_response_time_tahun_ini: 0,
|
||||
total_durasi_recovery_time_tahun_ini: 0,
|
||||
count_durasi_recovery_time_tahun_ini: 0
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.total_durasi_response_time_bulan_ini +=
|
||||
item.total_durasi_response_time_bulan_ini
|
||||
groupedData[key].summary.count_durasi_response_time_bulan_ini +=
|
||||
item.count_durasi_response_time_bulan_ini
|
||||
groupedData[key].summary.total_durasi_recovery_time_bulan_ini +=
|
||||
item.total_durasi_recovery_time_bulan_ini
|
||||
groupedData[key].summary.count_durasi_recovery_time_bulan_ini +=
|
||||
item.count_durasi_recovery_time_bulan_ini
|
||||
groupedData[key].summary.total_durasi_response_time_tahun_ini +=
|
||||
item.total_durasi_response_time_tahun_ini
|
||||
groupedData[key].summary.count_durasi_response_time_tahun_ini +=
|
||||
item.count_durasi_response_time_tahun_ini
|
||||
groupedData[key].summary.total_durasi_recovery_time_tahun_ini +=
|
||||
item.total_durasi_recovery_time_tahun_ini
|
||||
groupedData[key].summary.count_durasi_recovery_time_tahun_ini +=
|
||||
item.count_durasi_recovery_time_tahun_ini
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
const groupParent = getGroupParent(reportMeta)
|
||||
|
||||
if (groupParent === '') {
|
||||
return {
|
||||
data,
|
||||
parent: '',
|
||||
summaryName: ''
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
data: data,
|
||||
parent: groupParent.parent,
|
||||
summaryName: groupParent.summaryName
|
||||
}
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -80,88 +113,72 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
count_durasi_recovery_time_tahun_ini: 0
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
rawData.forEach((data: any) => {
|
||||
total.total_durasi_response_time_bulan_ini += data.total_durasi_response_time_bulan_ini
|
||||
total.count_durasi_response_time_bulan_ini += data.count_durasi_response_time_bulan_ini
|
||||
total.total_durasi_recovery_time_bulan_ini += data.total_durasi_recovery_time_bulan_ini
|
||||
total.count_durasi_recovery_time_bulan_ini += data.count_durasi_recovery_time_bulan_ini
|
||||
total.total_durasi_response_time_tahun_ini += data.total_durasi_response_time_tahun_ini
|
||||
total.count_durasi_response_time_tahun_ini += data.count_durasi_response_time_tahun_ini
|
||||
total.total_durasi_recovery_time_tahun_ini += data.total_durasi_recovery_time_tahun_ini
|
||||
total.count_durasi_recovery_time_tahun_ini += data.count_durasi_recovery_time_tahun_ini
|
||||
})
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
'NASIONAL',
|
||||
formatNumber(total.total_durasi_response_time_bulan_ini),
|
||||
formatNumber(total.count_durasi_response_time_bulan_ini),
|
||||
key,
|
||||
formatNumber(summary.total_durasi_response_time_bulan_ini),
|
||||
formatNumber(summary.count_durasi_response_time_bulan_ini),
|
||||
formatNumber(
|
||||
total.total_durasi_response_time_bulan_ini / total.count_durasi_response_time_bulan_ini
|
||||
summary.total_durasi_response_time_bulan_ini / summary.count_durasi_response_time_bulan_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_recovery_time_bulan_ini),
|
||||
formatNumber(total.count_durasi_recovery_time_bulan_ini),
|
||||
formatNumber(summary.total_durasi_recovery_time_bulan_ini),
|
||||
formatNumber(summary.count_durasi_recovery_time_bulan_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_recovery_time_bulan_ini / total.count_durasi_recovery_time_bulan_ini
|
||||
summary.total_durasi_recovery_time_bulan_ini / summary.count_durasi_recovery_time_bulan_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_response_time_tahun_ini),
|
||||
formatNumber(total.count_durasi_response_time_tahun_ini),
|
||||
formatNumber(summary.total_durasi_response_time_tahun_ini),
|
||||
formatNumber(summary.count_durasi_response_time_tahun_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_response_time_tahun_ini / total.count_durasi_response_time_tahun_ini
|
||||
summary.total_durasi_response_time_tahun_ini / summary.count_durasi_response_time_tahun_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_recovery_time_tahun_ini),
|
||||
formatNumber(total.count_durasi_recovery_time_tahun_ini),
|
||||
formatNumber(summary.total_durasi_recovery_time_tahun_ini),
|
||||
formatNumber(summary.count_durasi_recovery_time_tahun_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_recovery_time_tahun_ini / total.count_durasi_recovery_time_tahun_ini
|
||||
summary.total_durasi_recovery_time_tahun_ini / summary.count_durasi_recovery_time_tahun_ini
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.total_durasi_response_time_bulan_ini += item.total_durasi_response_time_bulan_ini
|
||||
total.count_durasi_response_time_bulan_ini += item.count_durasi_response_time_bulan_ini
|
||||
total.total_durasi_recovery_time_bulan_ini += item.total_durasi_recovery_time_bulan_ini
|
||||
total.count_durasi_recovery_time_bulan_ini += item.count_durasi_recovery_time_bulan_ini
|
||||
total.total_durasi_response_time_tahun_ini += item.total_durasi_response_time_tahun_ini
|
||||
total.count_durasi_response_time_tahun_ini += item.count_durasi_response_time_tahun_ini
|
||||
total.total_durasi_recovery_time_tahun_ini += item.total_durasi_recovery_time_tahun_ini
|
||||
total.count_durasi_recovery_time_tahun_ini += item.count_durasi_recovery_time_tahun_ini
|
||||
})
|
||||
|
||||
formattedData.push([
|
||||
summaryName,
|
||||
formatNumber(total.total_durasi_response_time_bulan_ini),
|
||||
formatNumber(total.count_durasi_response_time_bulan_ini),
|
||||
formatNumber(
|
||||
total.total_durasi_response_time_bulan_ini / total.count_durasi_response_time_bulan_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_recovery_time_bulan_ini),
|
||||
formatNumber(total.count_durasi_recovery_time_bulan_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_recovery_time_bulan_ini / total.count_durasi_recovery_time_bulan_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_response_time_tahun_ini),
|
||||
formatNumber(total.count_durasi_response_time_tahun_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_response_time_tahun_ini / total.count_durasi_response_time_tahun_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_recovery_time_tahun_ini),
|
||||
formatNumber(total.count_durasi_recovery_time_tahun_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_recovery_time_tahun_ini / total.count_durasi_recovery_time_tahun_ini
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
total.total_durasi_response_time_bulan_ini += summary.total_durasi_response_time_bulan_ini
|
||||
total.count_durasi_response_time_bulan_ini += summary.count_durasi_response_time_bulan_ini
|
||||
total.total_durasi_recovery_time_bulan_ini += summary.total_durasi_recovery_time_bulan_ini
|
||||
total.count_durasi_recovery_time_bulan_ini += summary.count_durasi_recovery_time_bulan_ini
|
||||
total.total_durasi_response_time_tahun_ini += summary.total_durasi_response_time_tahun_ini
|
||||
total.count_durasi_response_time_tahun_ini += summary.count_durasi_response_time_tahun_ini
|
||||
total.total_durasi_recovery_time_tahun_ini += summary.total_durasi_recovery_time_tahun_ini
|
||||
total.count_durasi_recovery_time_tahun_ini += summary.count_durasi_recovery_time_tahun_ini
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
title,
|
||||
formatNumber(total.total_durasi_response_time_bulan_ini),
|
||||
formatNumber(total.count_durasi_response_time_bulan_ini),
|
||||
formatNumber(
|
||||
total.total_durasi_response_time_bulan_ini / total.count_durasi_response_time_bulan_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_recovery_time_bulan_ini),
|
||||
formatNumber(total.count_durasi_recovery_time_bulan_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_recovery_time_bulan_ini / total.count_durasi_recovery_time_bulan_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_response_time_tahun_ini),
|
||||
formatNumber(total.count_durasi_response_time_tahun_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_response_time_tahun_ini / total.count_durasi_response_time_tahun_ini
|
||||
),
|
||||
formatNumber(total.total_durasi_recovery_time_tahun_ini),
|
||||
formatNumber(total.count_durasi_recovery_time_tahun_ini),
|
||||
formatPercentage(
|
||||
total.total_durasi_recovery_time_tahun_ini / total.count_durasi_recovery_time_tahun_ini
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
@ -22,7 +22,7 @@ const groupingData = (data: any, reportMeta: any) => {
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
let key = 'default'
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
@ -152,113 +152,6 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
return formattedData
|
||||
}
|
||||
|
||||
// const formatData = (rawData: any, reportMeta: any) => {
|
||||
// const formattedData: any = []
|
||||
|
||||
// const total: any = {
|
||||
// mom_bulan_kemarin: 0,
|
||||
// mom_bulan_ini: 0,
|
||||
// yoy_tahun_kemarin: 0,
|
||||
// yoy_tahun_ini: 0
|
||||
// }
|
||||
|
||||
// if (reportMeta.regional.id == 0 || reportMeta.uid.id == 0) {
|
||||
// const data = groupingData(rawData, reportMeta)
|
||||
// const title = reportMeta.regional.id != 0 ? reportMeta.regional.name : 'NASIONAL'
|
||||
|
||||
// formattedData.push([{ content: title, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
// let no = 1
|
||||
// for (const key in data) {
|
||||
// const summary = data[key].summary
|
||||
|
||||
// formattedData.push([
|
||||
// { content: no++, styles: { halign: 'right' } },
|
||||
// key,
|
||||
// formatNumber(summary.mom_bulan_kemarin),
|
||||
// formatNumber(summary.mom_bulan_ini),
|
||||
// formatPercentage(
|
||||
// !summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
// ? '0%'
|
||||
// : ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) *
|
||||
// 100
|
||||
// ),
|
||||
// formatNumber(summary.yoy_tahun_kemarin),
|
||||
// formatNumber(summary.yoy_tahun_ini),
|
||||
// formatPercentage(
|
||||
// !summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
// ? '0%'
|
||||
// : ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) *
|
||||
// 100
|
||||
// )
|
||||
// ])
|
||||
|
||||
// total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||
// total.mom_bulan_ini += summary.mom_bulan_ini
|
||||
// total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||
// total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||
// }
|
||||
|
||||
// formattedData.push([
|
||||
// { content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
// formatNumber(total.mom_bulan_kemarin),
|
||||
// formatNumber(total.mom_bulan_ini),
|
||||
// formatPercentage(
|
||||
// !total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
// ? '0%'
|
||||
// : ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
// ),
|
||||
// formatNumber(total.yoy_tahun_kemarin),
|
||||
// formatNumber(total.yoy_tahun_ini),
|
||||
// formatPercentage(
|
||||
// !total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
// ? '0%'
|
||||
// : ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
// )
|
||||
// ])
|
||||
|
||||
// return formattedData
|
||||
// } else {
|
||||
// const tempData = groupingData(rawData, reportMeta)
|
||||
// const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
// const formattedData: any = []
|
||||
|
||||
// let parentName = tempData.parent
|
||||
// let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
// data.forEach((item: any) => {
|
||||
// total.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
// total.mom_bulan_ini += item.mom_bulan_ini
|
||||
// total.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
// total.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
// })
|
||||
|
||||
// formattedData.push([{ content: parentName, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
// const result = [
|
||||
// formatNumber(total.mom_bulan_kemarin),
|
||||
// formatNumber(total.mom_bulan_ini),
|
||||
// formatPercentage(
|
||||
// !total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
// ? '0%'
|
||||
// : ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
// ),
|
||||
// formatNumber(total.yoy_tahun_kemarin),
|
||||
// formatNumber(total.yoy_tahun_ini),
|
||||
// formatPercentage(
|
||||
// !total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
// ? '0%'
|
||||
// : ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
// )
|
||||
// ]
|
||||
|
||||
// formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
// formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||
|
||||
// return formattedData
|
||||
// }
|
||||
// }
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
const day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||
const date = new Date().getDate()
|
||||
|
@ -11,108 +11,80 @@ import { exportToWord } from './doc/MonalisaGR_LaporUlang_DOC'
|
||||
const reportName = 'Rekapitulasi Lapor Ulang Gangguan'
|
||||
const fontSize = 5
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
data.forEach((item: any) => {
|
||||
const { nama_regional } = item
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
if (!groupedData[nama_regional]) {
|
||||
groupedData[nama_regional] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[nama_regional].data.push(item)
|
||||
})
|
||||
|
||||
for (const regional in groupedData) {
|
||||
const data = groupedData[regional].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[regional].summary) {
|
||||
groupedData[regional].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[regional].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[regional].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[regional].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[regional].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[regional].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
} else {
|
||||
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
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[key].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[key].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[key].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[key].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[key].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -125,100 +97,59 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
yoy_tahun_ini: 0
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
formattedData.push([{ content: title, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
let no = 1
|
||||
for (const regional in data) {
|
||||
const summary = data[regional].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
regional,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) *
|
||||
100
|
||||
),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) *
|
||||
100
|
||||
)
|
||||
])
|
||||
|
||||
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||
total.mom_bulan_ini += summary.mom_bulan_ini
|
||||
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||
}
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.mom_bulan_kemarin),
|
||||
formatNumber(total.mom_bulan_ini),
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
key,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(total.yoy_tahun_kemarin),
|
||||
formatNumber(total.yoy_tahun_ini),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
total.mom_bulan_ini += item.mom_bulan_ini
|
||||
total.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
total.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
})
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(total.mom_bulan_kemarin),
|
||||
formatNumber(total.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(total.yoy_tahun_kemarin),
|
||||
formatNumber(total.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
]
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } }, ...result])
|
||||
|
||||
return formattedData
|
||||
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||
total.mom_bulan_ini += summary.mom_bulan_ini
|
||||
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.mom_bulan_kemarin),
|
||||
formatNumber(total.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(total.yoy_tahun_kemarin),
|
||||
formatNumber(total.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
@ -11,108 +11,80 @@ import { exportToWord } from './doc/MonalisaGR_RecoveryTimeGangguan_DOC'
|
||||
const reportName = 'Recovery Time (RCT) Gangguan'
|
||||
const fontSize = 5
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
data.forEach((item: any) => {
|
||||
const { nama_regional } = item
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
if (!groupedData[nama_regional]) {
|
||||
groupedData[nama_regional] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[nama_regional].data.push(item)
|
||||
})
|
||||
|
||||
for (const regional in groupedData) {
|
||||
const data = groupedData[regional].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[regional].summary) {
|
||||
groupedData[regional].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[regional].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[regional].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[regional].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[regional].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[regional].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
} else {
|
||||
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
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[key].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[key].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[key].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[key].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[key].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -125,125 +97,70 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
yoy_tahun_ini: []
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
formattedData.push([{ content: title, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
let no = 1
|
||||
for (const regional in data) {
|
||||
const summary = data[regional].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
regional,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) *
|
||||
100
|
||||
),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) *
|
||||
100
|
||||
)
|
||||
])
|
||||
|
||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||
}
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
key,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.mom_bulan_kemarin.push(item.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(item.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(item.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(item.yoy_tahun_ini)
|
||||
})
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
)
|
||||
]
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([
|
||||
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
...result
|
||||
])
|
||||
|
||||
return formattedData
|
||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||
}
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
@ -11,108 +11,80 @@ import { exportToWord } from './doc/MonalisaGR_ResponseTimeGangguan_DOC'
|
||||
const reportName = 'Response Time (RPT) Gangguan'
|
||||
const fontSize = 5
|
||||
|
||||
const getGroupParent = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.ulp.name,
|
||||
summaryName: reportMeta.ulp.name,
|
||||
summaryKey: 'nama_ulp'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.up3.name,
|
||||
summaryName: reportMeta.up3.name,
|
||||
summaryKey: 'nama_up3'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.uid.name,
|
||||
summaryName: reportMeta.uid.name,
|
||||
summaryKey: 'nama_uid'
|
||||
}
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return {
|
||||
parent: reportMeta.regional.name,
|
||||
summaryName: reportMeta.regional.name,
|
||||
summaryKey: 'nama_regional'
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const groupingData = (data: any, reportMeta: any) => {
|
||||
const groupedData: any = {}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
data.forEach((item: any) => {
|
||||
const { nama_regional } = item
|
||||
const reportMetaMapping: any = {
|
||||
ulp: 'nama_ulp',
|
||||
up3: 'nama_ulp',
|
||||
uid: 'nama_up3',
|
||||
regional: 'nama_uid',
|
||||
default: 'nama_regional'
|
||||
}
|
||||
|
||||
if (!groupedData[nama_regional]) {
|
||||
groupedData[nama_regional] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[nama_regional].data.push(item)
|
||||
})
|
||||
|
||||
for (const regional in groupedData) {
|
||||
const data = groupedData[regional].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[regional].summary) {
|
||||
groupedData[regional].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[regional].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[regional].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[regional].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[regional].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[regional].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
} else {
|
||||
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
|
||||
let key = 'nama_regional'
|
||||
for (const prop in reportMetaMapping) {
|
||||
if (reportMeta[prop] && reportMeta[prop].id != 0) {
|
||||
key = reportMetaMapping[prop]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
data.forEach((item: any) => {
|
||||
const groupKey = item[key]
|
||||
|
||||
if (!groupedData[groupKey]) {
|
||||
groupedData[groupKey] = { data: [] }
|
||||
}
|
||||
|
||||
groupedData[groupKey].data.push(item)
|
||||
})
|
||||
|
||||
for (const key in groupedData) {
|
||||
const data = groupedData[key].data
|
||||
|
||||
data.forEach((item: any) => {
|
||||
if (!groupedData[key].summary) {
|
||||
groupedData[key].summary = {
|
||||
mom_bulan_kemarin: 0,
|
||||
mom_bulan_ini: 0,
|
||||
persen_mom: [],
|
||||
yoy_tahun_kemarin: 0,
|
||||
yoy_tahun_ini: 0,
|
||||
persen_yoy: []
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[key].summary.mom_bulan_kemarin += item.mom_bulan_kemarin
|
||||
groupedData[key].summary.mom_bulan_ini += item.mom_bulan_ini
|
||||
groupedData[key].summary.persen_mom.push(item.persen_mom)
|
||||
groupedData[key].summary.yoy_tahun_kemarin += item.yoy_tahun_kemarin
|
||||
groupedData[key].summary.yoy_tahun_ini += item.yoy_tahun_ini
|
||||
groupedData[key].summary.persen_yoy.push(item.persen_yoy)
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const getTitle = (reportMeta: any) => {
|
||||
if (reportMeta.ulp.id != 0) {
|
||||
return reportMeta.ulp.name
|
||||
}
|
||||
|
||||
if (reportMeta.up3.id != 0) {
|
||||
return reportMeta.up3.name
|
||||
}
|
||||
|
||||
if (reportMeta.uid.id != 0) {
|
||||
return reportMeta.uid.name
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id != 0) {
|
||||
return reportMeta.regional.name
|
||||
}
|
||||
|
||||
return 'NASIONAL'
|
||||
}
|
||||
|
||||
const formatData = (rawData: any, reportMeta: any) => {
|
||||
@ -125,125 +97,70 @@ const formatData = (rawData: any, reportMeta: any) => {
|
||||
yoy_tahun_ini: []
|
||||
}
|
||||
|
||||
if (reportMeta.regional.id == 0) {
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const data = groupingData(rawData, reportMeta)
|
||||
const title = getTitle(reportMeta)
|
||||
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
formattedData.push([{ content: title, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
let no = 1
|
||||
for (const regional in data) {
|
||||
const summary = data[regional].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
regional,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) *
|
||||
100
|
||||
),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) *
|
||||
100
|
||||
)
|
||||
])
|
||||
|
||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||
}
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
let no = 1
|
||||
for (const key in data) {
|
||||
const summary = data[key].summary
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
{ content: no++, styles: { halign: 'right' } },
|
||||
key,
|
||||
formatNumber(summary.mom_bulan_kemarin),
|
||||
formatNumber(summary.mom_bulan_ini),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatNumber(summary.yoy_tahun_kemarin),
|
||||
formatNumber(summary.yoy_tahun_ini),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
const formattedData: any = []
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName ? tempData.summaryName : 'Seluruh Unit'
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.mom_bulan_kemarin.push(item.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(item.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(item.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(item.yoy_tahun_ini)
|
||||
})
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
)
|
||||
]
|
||||
|
||||
formattedData.push([{ content: '1', styles: { halign: 'right' } }, summaryName, ...result])
|
||||
formattedData.push([
|
||||
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
...result
|
||||
])
|
||||
|
||||
return formattedData
|
||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||
}
|
||||
|
||||
const totalMoMBulanKemarin =
|
||||
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.mom_bulan_kemarin.length
|
||||
const totalMoMBulanIni =
|
||||
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||
const totalYoYTahunKemarin =
|
||||
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||
total.yoy_tahun_kemarin.length
|
||||
const totalYoYTahunIni =
|
||||
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(totalMoMBulanKemarin),
|
||||
formatNumber(totalMoMBulanIni),
|
||||
formatPercentage(
|
||||
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||
? '0%'
|
||||
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||
),
|
||||
formatNumber(totalYoYTahunKemarin),
|
||||
formatNumber(totalYoYTahunIni),
|
||||
formatPercentage(
|
||||
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||
? '0%'
|
||||
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||
)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user