fix: report in rekapitulasi keluhan
This commit is contained in:
@ -59,18 +59,8 @@ const groupingData = (data: any, reportMeta: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.forEach((item: any) => {
|
|
||||||
const group = item[groupParent.summaryKey]
|
|
||||||
|
|
||||||
if (!groupedData[group]) {
|
|
||||||
groupedData[group] = []
|
|
||||||
}
|
|
||||||
|
|
||||||
groupedData[group].push(item)
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: groupedData,
|
data: data,
|
||||||
parent: groupParent.parent,
|
parent: groupParent.parent,
|
||||||
summaryName: groupParent.summaryName
|
summaryName: groupParent.summaryName
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,62 @@ import { exportToWord } from './doc/MonalisaKR_JumlahDDRPTRCTKeluhan'
|
|||||||
const reportName = 'Jumlah dan Durasi RPT RCT Keluhan'
|
const reportName = 'Jumlah dan Durasi RPT RCT Keluhan'
|
||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
|
|
||||||
const formatData = (rawData: any) => {
|
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 = {}
|
||||||
|
const groupParent = getGroupParent(reportMeta)
|
||||||
|
|
||||||
|
if (groupParent === '') {
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
parent: '',
|
||||||
|
summaryName: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: data,
|
||||||
|
parent: groupParent.parent,
|
||||||
|
summaryName: groupParent.summaryName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -25,42 +80,88 @@ const formatData = (rawData: any) => {
|
|||||||
count_durasi_recovery_time_tahun_ini: 0
|
count_durasi_recovery_time_tahun_ini: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
rawData.forEach((data: any) => {
|
if (reportMeta.regional.id == 0) {
|
||||||
total.total_durasi_response_time_bulan_ini += data.total_durasi_response_time_bulan_ini
|
rawData.forEach((data: any) => {
|
||||||
total.count_durasi_response_time_bulan_ini += data.count_durasi_response_time_bulan_ini
|
total.total_durasi_response_time_bulan_ini += data.total_durasi_response_time_bulan_ini
|
||||||
total.total_durasi_recovery_time_bulan_ini += data.total_durasi_recovery_time_bulan_ini
|
total.count_durasi_response_time_bulan_ini += data.count_durasi_response_time_bulan_ini
|
||||||
total.count_durasi_recovery_time_bulan_ini += data.count_durasi_recovery_time_bulan_ini
|
total.total_durasi_recovery_time_bulan_ini += data.total_durasi_recovery_time_bulan_ini
|
||||||
total.total_durasi_response_time_tahun_ini += data.total_durasi_response_time_tahun_ini
|
total.count_durasi_recovery_time_bulan_ini += data.count_durasi_recovery_time_bulan_ini
|
||||||
total.count_durasi_response_time_tahun_ini += data.count_durasi_response_time_tahun_ini
|
total.total_durasi_response_time_tahun_ini += data.total_durasi_response_time_tahun_ini
|
||||||
total.total_durasi_recovery_time_tahun_ini += data.total_durasi_recovery_time_tahun_ini
|
total.count_durasi_response_time_tahun_ini += data.count_durasi_response_time_tahun_ini
|
||||||
total.count_durasi_recovery_time_tahun_ini += data.count_durasi_recovery_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
|
||||||
|
})
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
'NASIONAL',
|
'NASIONAL',
|
||||||
formatNumber(total.total_durasi_response_time_bulan_ini),
|
formatNumber(total.total_durasi_response_time_bulan_ini),
|
||||||
formatNumber(total.count_durasi_response_time_bulan_ini),
|
formatNumber(total.count_durasi_response_time_bulan_ini),
|
||||||
formatNumber(
|
formatNumber(
|
||||||
total.total_durasi_response_time_bulan_ini / total.count_durasi_response_time_bulan_ini
|
total.total_durasi_response_time_bulan_ini / total.count_durasi_response_time_bulan_ini
|
||||||
),
|
),
|
||||||
formatNumber(total.total_durasi_recovery_time_bulan_ini),
|
formatNumber(total.total_durasi_recovery_time_bulan_ini),
|
||||||
formatNumber(total.count_durasi_recovery_time_bulan_ini),
|
formatNumber(total.count_durasi_recovery_time_bulan_ini),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
total.total_durasi_recovery_time_bulan_ini / total.count_durasi_recovery_time_bulan_ini
|
total.total_durasi_recovery_time_bulan_ini / total.count_durasi_recovery_time_bulan_ini
|
||||||
),
|
),
|
||||||
formatNumber(total.total_durasi_response_time_tahun_ini),
|
formatNumber(total.total_durasi_response_time_tahun_ini),
|
||||||
formatNumber(total.count_durasi_response_time_tahun_ini),
|
formatNumber(total.count_durasi_response_time_tahun_ini),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
total.total_durasi_response_time_tahun_ini / total.count_durasi_response_time_tahun_ini
|
total.total_durasi_response_time_tahun_ini / total.count_durasi_response_time_tahun_ini
|
||||||
),
|
),
|
||||||
formatNumber(total.total_durasi_recovery_time_tahun_ini),
|
formatNumber(total.total_durasi_recovery_time_tahun_ini),
|
||||||
formatNumber(total.count_durasi_recovery_time_tahun_ini),
|
formatNumber(total.count_durasi_recovery_time_tahun_ini),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
total.total_durasi_recovery_time_tahun_ini / total.count_durasi_recovery_time_tahun_ini
|
total.total_durasi_recovery_time_tahun_ini / total.count_durasi_recovery_time_tahun_ini
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
return formattedData
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -68,7 +169,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const date = new Date().getDate()
|
const date = new Date().getDate()
|
||||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
@ -311,7 +412,7 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), reportName)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { exportToPDF, exportToXLSX, exportToDOCX }
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -11,48 +11,111 @@ import { exportToWord } from './doc/MonalisaKR_JumlahKaliKeluhan'
|
|||||||
const reportName = 'Jumlah Kali Keluhan'
|
const reportName = 'Jumlah Kali Keluhan'
|
||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
|
|
||||||
const groupingData = (data: any) => {
|
const getGroupParent = (reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
if (reportMeta.ulp.id != 0) {
|
||||||
|
return {
|
||||||
data.forEach((item: any) => {
|
parent: reportMeta.ulp.name,
|
||||||
const { nama_regional } = item
|
summaryName: reportMeta.ulp.name,
|
||||||
|
summaryKey: 'nama_ulp'
|
||||||
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
|
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 formatData = (rawData: any) => {
|
const groupingData = (data: any, reportMeta: any) => {
|
||||||
const data = groupingData(rawData)
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
if (reportMeta.regional.id == 0) {
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_regional } = item
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -62,56 +125,100 @@ const formatData = (rawData: any) => {
|
|||||||
yoy_tahun_ini: 0
|
yoy_tahun_ini: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
if (reportMeta.regional.id == 0) {
|
||||||
|
const data = groupingData(rawData, reportMeta)
|
||||||
|
|
||||||
let no = 1
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
for (const regional in data) {
|
|
||||||
const summary = data[regional].summary
|
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
|
||||||
|
}
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
regional,
|
formatNumber(total.mom_bulan_kemarin),
|
||||||
formatNumber(summary.mom_bulan_kemarin),
|
formatNumber(total.mom_bulan_ini),
|
||||||
formatNumber(summary.mom_bulan_ini),
|
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||||
),
|
),
|
||||||
formatNumber(summary.yoy_tahun_kemarin),
|
formatNumber(total.yoy_tahun_kemarin),
|
||||||
formatNumber(summary.yoy_tahun_ini),
|
formatNumber(total.yoy_tahun_ini),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
return formattedData
|
||||||
total.mom_bulan_ini += summary.mom_bulan_ini
|
} else {
|
||||||
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
const tempData = groupingData(rawData, reportMeta)
|
||||||
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -119,7 +226,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const date = new Date().getDate()
|
const date = new Date().getDate()
|
||||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
@ -358,7 +465,7 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), reportName)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { exportToPDF, exportToXLSX, exportToDOCX }
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -12,42 +12,105 @@ const reportName = 'Rekapitulasi Keluhan Belum Selesai'
|
|||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
const detailFontSize = 3
|
const detailFontSize = 3
|
||||||
|
|
||||||
const groupingData = (data: any) => {
|
const getGroupParent = (reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
if (reportMeta.ulp.id != 0) {
|
||||||
|
return {
|
||||||
data.forEach((item: any) => {
|
parent: reportMeta.ulp.name,
|
||||||
const { nama_regional } = item
|
summaryName: reportMeta.ulp.name,
|
||||||
|
summaryKey: 'nama_ulp'
|
||||||
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_keluhan: 0,
|
|
||||||
jumlah_informasi: 0,
|
|
||||||
total: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groupedData[regional].summary.jumlah_keluhan += item.jumlah_keluhan
|
|
||||||
groupedData[regional].summary.jumlah_informasi += item.jumlah_informasi
|
|
||||||
groupedData[regional].summary.total += item.total
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupedData
|
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 formatData = (rawData: any) => {
|
const groupingData = (data: any, reportMeta: any) => {
|
||||||
const data = groupingData(rawData)
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
if (reportMeta.regional.id == 0) {
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_regional } = item
|
||||||
|
|
||||||
|
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_keluhan: 0,
|
||||||
|
jumlah_informasi: 0,
|
||||||
|
total: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedData[regional].summary.jumlah_keluhan += item.jumlah_keluhan
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -56,33 +119,63 @@ const formatData = (rawData: any) => {
|
|||||||
total: 0
|
total: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData.push([{ content: 'NASIONAL', colSpan: 5, styles: { fontStyle: 'bold' } }])
|
if (reportMeta.regional.id == 0) {
|
||||||
|
const data = groupingData(rawData, reportMeta)
|
||||||
|
|
||||||
let no = 1
|
formattedData.push([{ content: 'NASIONAL', colSpan: 5, styles: { fontStyle: 'bold' } }])
|
||||||
for (const regional in data) {
|
|
||||||
const summary = data[regional].summary
|
let no = 1
|
||||||
|
for (const regional in data) {
|
||||||
|
const summary = data[regional].summary
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: no++, styles: { halign: 'right' } },
|
||||||
|
regional,
|
||||||
|
formatNumber(summary.jumlah_keluhan),
|
||||||
|
formatNumber(summary.jumlah_informasi),
|
||||||
|
formatNumber(summary.total)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.jumlah_keluhan += summary.jumlah_keluhan
|
||||||
|
total.jumlah_informasi += summary.jumlah_informasi
|
||||||
|
total.total += summary.total
|
||||||
|
}
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
regional,
|
formatNumber(total.jumlah_keluhan),
|
||||||
formatNumber(summary.jumlah_keluhan),
|
formatNumber(total.jumlah_informasi),
|
||||||
formatNumber(summary.jumlah_informasi),
|
formatNumber(total.total)
|
||||||
formatNumber(summary.total)
|
|
||||||
])
|
])
|
||||||
|
|
||||||
total.jumlah_keluhan += summary.jumlah_keluhan
|
return formattedData
|
||||||
total.jumlah_informasi += summary.jumlah_informasi
|
} else {
|
||||||
total.total += summary.total
|
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_keluhan += item.jumlah_keluhan
|
||||||
|
total.jumlah_informasi += item.jumlah_informasi
|
||||||
|
total.total += item.total
|
||||||
|
})
|
||||||
|
|
||||||
|
formattedData.push([{ content: parentName, colSpan: 5, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
const result = [
|
||||||
|
formatNumber(total.jumlah_keluhan),
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData.push([
|
|
||||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
|
||||||
formatNumber(total.jumlah_keluhan),
|
|
||||||
formatNumber(total.jumlah_informasi),
|
|
||||||
formatNumber(total.total)
|
|
||||||
])
|
|
||||||
|
|
||||||
return formattedData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -90,7 +183,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const date = new Date().getDate()
|
const date = new Date().getDate()
|
||||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
@ -475,7 +568,7 @@ const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), reportName)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
|
@ -11,48 +11,111 @@ import { exportToWord } from './doc/MonalisaKR_LaporUlangKeluhan'
|
|||||||
const reportName = 'Rekapitulasi Lapor Ulang Keluhan'
|
const reportName = 'Rekapitulasi Lapor Ulang Keluhan'
|
||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
|
|
||||||
const groupingData = (data: any) => {
|
const getGroupParent = (reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
if (reportMeta.ulp.id != 0) {
|
||||||
|
return {
|
||||||
data.forEach((item: any) => {
|
parent: reportMeta.ulp.name,
|
||||||
const { nama_regional } = item
|
summaryName: reportMeta.ulp.name,
|
||||||
|
summaryKey: 'nama_ulp'
|
||||||
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
|
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 formatData = (rawData: any) => {
|
const groupingData = (data: any, reportMeta: any) => {
|
||||||
const data = groupingData(rawData)
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
if (reportMeta.regional.id == 0) {
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_regional } = item
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -62,56 +125,100 @@ const formatData = (rawData: any) => {
|
|||||||
yoy_tahun_ini: 0
|
yoy_tahun_ini: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
if (reportMeta.regional.id == 0) {
|
||||||
|
const data = groupingData(rawData, reportMeta)
|
||||||
|
|
||||||
let no = 1
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
for (const regional in data) {
|
|
||||||
const summary = data[regional].summary
|
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
|
||||||
|
}
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
regional,
|
formatNumber(total.mom_bulan_kemarin),
|
||||||
formatNumber(summary.mom_bulan_kemarin),
|
formatNumber(total.mom_bulan_ini),
|
||||||
formatNumber(summary.mom_bulan_ini),
|
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
!total.mom_bulan_ini || !total.mom_bulan_kemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
: ((total.mom_bulan_kemarin - total.mom_bulan_ini) / total.mom_bulan_kemarin) * 100
|
||||||
),
|
),
|
||||||
formatNumber(summary.yoy_tahun_kemarin),
|
formatNumber(total.yoy_tahun_kemarin),
|
||||||
formatNumber(summary.yoy_tahun_ini),
|
formatNumber(total.yoy_tahun_ini),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
!total.yoy_tahun_ini || !total.yoy_tahun_kemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
: ((total.yoy_tahun_kemarin - total.yoy_tahun_ini) / total.yoy_tahun_kemarin) * 100
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
return formattedData
|
||||||
total.mom_bulan_ini += summary.mom_bulan_ini
|
} else {
|
||||||
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
const tempData = groupingData(rawData, reportMeta)
|
||||||
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -119,7 +226,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const date = new Date().getDate()
|
const date = new Date().getDate()
|
||||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
@ -358,7 +465,7 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), reportName)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { exportToPDF, exportToXLSX, exportToDOCX }
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -11,48 +11,111 @@ import { exportToWord } from './doc/MonalisaKR_RecoveryTimeKeluhan'
|
|||||||
const reportName = 'Recovery Time (RCT) Keluhan'
|
const reportName = 'Recovery Time (RCT) Keluhan'
|
||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
|
|
||||||
const groupingData = (data: any) => {
|
const getGroupParent = (reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
if (reportMeta.ulp.id != 0) {
|
||||||
|
return {
|
||||||
data.forEach((item: any) => {
|
parent: reportMeta.ulp.name,
|
||||||
const { nama_regional } = item
|
summaryName: reportMeta.ulp.name,
|
||||||
|
summaryKey: 'nama_ulp'
|
||||||
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
|
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 formatData = (rawData: any) => {
|
const groupingData = (data: any, reportMeta: any) => {
|
||||||
const data = groupingData(rawData)
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
if (reportMeta.regional.id == 0) {
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_regional } = item
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -62,67 +125,126 @@ const formatData = (rawData: any) => {
|
|||||||
yoy_tahun_ini: []
|
yoy_tahun_ini: []
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
if (reportMeta.regional.id == 0) {
|
||||||
|
const data = groupingData(rawData, reportMeta)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
let no = 1
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
for (const regional in data) {
|
|
||||||
const summary = data[regional].summary
|
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
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
regional,
|
formatNumber(totalMoMBulanKemarin),
|
||||||
formatNumber(summary.mom_bulan_kemarin),
|
formatNumber(totalMoMBulanIni),
|
||||||
formatNumber(summary.mom_bulan_ini),
|
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||||
),
|
),
|
||||||
formatNumber(summary.yoy_tahun_kemarin),
|
formatNumber(totalYoYTahunKemarin),
|
||||||
formatNumber(summary.yoy_tahun_ini),
|
formatNumber(totalYoYTahunIni),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
return formattedData
|
||||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
} else {
|
||||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
const tempData = groupingData(rawData, reportMeta)
|
||||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -130,7 +252,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const date = new Date().getDate()
|
const date = new Date().getDate()
|
||||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
@ -369,7 +491,7 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), reportName)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { exportToPDF, exportToXLSX, exportToDOCX }
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -11,48 +11,111 @@ import { exportToWord } from './doc/MonalisaKR_ResponseTimeKeluhan'
|
|||||||
const reportName = 'Response Time (RPT) Keluhan'
|
const reportName = 'Response Time (RPT) Keluhan'
|
||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
|
|
||||||
const groupingData = (data: any) => {
|
const getGroupParent = (reportMeta: any) => {
|
||||||
const groupedData: any = {}
|
if (reportMeta.ulp.id != 0) {
|
||||||
|
return {
|
||||||
data.forEach((item: any) => {
|
parent: reportMeta.ulp.name,
|
||||||
const { nama_regional } = item
|
summaryName: reportMeta.ulp.name,
|
||||||
|
summaryKey: 'nama_ulp'
|
||||||
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
|
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 formatData = (rawData: any) => {
|
const groupingData = (data: any, reportMeta: any) => {
|
||||||
const data = groupingData(rawData)
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
if (reportMeta.regional.id == 0) {
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_regional } = item
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -62,67 +125,126 @@ const formatData = (rawData: any) => {
|
|||||||
yoy_tahun_ini: []
|
yoy_tahun_ini: []
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
if (reportMeta.regional.id == 0) {
|
||||||
|
const data = groupingData(rawData, reportMeta)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
let no = 1
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
for (const regional in data) {
|
|
||||||
const summary = data[regional].summary
|
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
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
{ content: 'RATA-RATA', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
regional,
|
formatNumber(totalMoMBulanKemarin),
|
||||||
formatNumber(summary.mom_bulan_kemarin),
|
formatNumber(totalMoMBulanIni),
|
||||||
formatNumber(summary.mom_bulan_ini),
|
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
!totalMoMBulanIni || !totalMoMBulanKemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
: ((totalMoMBulanKemarin - totalMoMBulanIni) / totalMoMBulanKemarin) * 100
|
||||||
),
|
),
|
||||||
formatNumber(summary.yoy_tahun_kemarin),
|
formatNumber(totalYoYTahunKemarin),
|
||||||
formatNumber(summary.yoy_tahun_ini),
|
formatNumber(totalYoYTahunIni),
|
||||||
formatPercentage(
|
formatPercentage(
|
||||||
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
!totalYoYTahunIni || !totalYoYTahunKemarin
|
||||||
? '0%'
|
? '0%'
|
||||||
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
: ((totalYoYTahunKemarin - totalYoYTahunIni) / totalYoYTahunKemarin) * 100
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
return formattedData
|
||||||
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
} else {
|
||||||
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
const tempData = groupingData(rawData, reportMeta)
|
||||||
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -130,7 +252,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
|||||||
const date = new Date().getDate()
|
const date = new Date().getDate()
|
||||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const data = formatData(rawData)
|
const data = formatData(rawData, reportMeta)
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape'
|
orientation: 'landscape'
|
||||||
})
|
})
|
||||||
@ -369,7 +491,7 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), reportName)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), reportName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { exportToPDF, exportToXLSX, exportToDOCX }
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
Reference in New Issue
Block a user