fix: report in monalisa gangguan
This commit is contained in:
@ -1,17 +1,4 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
@ -26,48 +13,111 @@ const reportName = 'Dispacthing Time (DT) Gangguan'
|
|||||||
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 = {
|
|
||||||
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 = {
|
||||||
@ -77,67 +127,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: 'TOTAL 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: 'TOTAL 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: '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) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -145,7 +254,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'
|
||||||
})
|
})
|
||||||
@ -466,34 +575,38 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
worksheet,
|
worksheet,
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
`UNIT INDUK : ${reportMeta.uid
|
`UNIT INDUK : ${
|
||||||
? reportMeta.uid.name.toUpperCase()
|
reportMeta.uid
|
||||||
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
3,
|
3,
|
||||||
1,
|
1,
|
||||||
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${reportMeta.up3
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
? reportMeta.up3.name.toUpperCase()
|
reportMeta.up3
|
||||||
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
4,
|
4,
|
||||||
1,
|
1,
|
||||||
`UNIT LAYANAN PELANGGAN : ${reportMeta.ulp
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
? reportMeta.ulp.name.toUpperCase()
|
reportMeta.ulp
|
||||||
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
5,
|
5,
|
||||||
1,
|
1,
|
||||||
`REGIONAL : ${reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -558,9 +671,16 @@ const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportDetailToWord(reportMeta, rawData, `Laporan Detail ${reportName}`, null)
|
exportDetailToWord(reportMeta, rawData, `Laporan Detail ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportDetailToPDF, exportToXLSX, exportDetailToXLSX, exportToDOCX, exportDetailToDOCX }
|
export {
|
||||||
|
exportToPDF,
|
||||||
|
exportDetailToPDF,
|
||||||
|
exportToXLSX,
|
||||||
|
exportDetailToXLSX,
|
||||||
|
exportToDOCX,
|
||||||
|
exportDetailToDOCX
|
||||||
|
}
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
@ -24,48 +11,111 @@ import { exportToWord } from './doc/MonalisaGR_ENSGangguan_DOC'
|
|||||||
const reportName = 'Rekapitulasi ENS Gangguan'
|
const reportName = 'Rekapitulasi ENS Gangguan'
|
||||||
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 = {
|
||||||
@ -75,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) => {
|
||||||
@ -132,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'
|
||||||
})
|
})
|
||||||
@ -370,6 +464,6 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
e.cancel = true
|
e.cancel = true
|
||||||
}
|
}
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX , exportToDOCX}
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
@ -25,42 +12,105 @@ const reportName = 'Rekapitulasi Gangguan 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_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
|
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_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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any, reportMeta: any) => {
|
||||||
const formattedData: any = []
|
const formattedData: any = []
|
||||||
|
|
||||||
const total: any = {
|
const total: any = {
|
||||||
@ -69,33 +119,69 @@ 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
|
const total: any = {
|
||||||
for (const regional in data) {
|
jumlah_gangguan: 0,
|
||||||
const summary = data[regional].summary
|
jumlah_informasi: 0,
|
||||||
|
total: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
formattedData.push([
|
formattedData.push([
|
||||||
{ content: no++, styles: { halign: 'right' } },
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
regional,
|
formatNumber(total.jumlah_gangguan),
|
||||||
formatNumber(summary.jumlah_gangguan),
|
formatNumber(total.jumlah_informasi),
|
||||||
formatNumber(summary.jumlah_informasi),
|
formatNumber(total.total)
|
||||||
formatNumber(summary.total)
|
|
||||||
])
|
])
|
||||||
|
|
||||||
total.jumlah_gangguan += summary.jumlah_gangguan
|
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_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
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
@ -103,7 +189,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'
|
||||||
})
|
})
|
||||||
@ -392,34 +478,38 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
worksheet,
|
worksheet,
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
`UNIT INDUK : ${reportMeta.uid
|
`UNIT INDUK : ${
|
||||||
? reportMeta.uid.name.toUpperCase()
|
reportMeta.uid
|
||||||
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
3,
|
3,
|
||||||
1,
|
1,
|
||||||
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${reportMeta.up3
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
? reportMeta.up3.name.toUpperCase()
|
reportMeta.up3
|
||||||
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
4,
|
4,
|
||||||
1,
|
1,
|
||||||
`UNIT LAYANAN PELANGGAN : ${reportMeta.ulp
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
? reportMeta.ulp.name.toUpperCase()
|
reportMeta.ulp
|
||||||
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
5,
|
5,
|
||||||
1,
|
1,
|
||||||
`REGIONAL : ${reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -488,9 +578,16 @@ const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportDetailToWord(reportMeta, rawData, `Laporan Detail ${reportName}`, null)
|
exportDetailToWord(reportMeta, rawData, `Laporan Detail ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportDetailToPDF, exportToXLSX, exportDetailToXLSX, exportToDOCX, exportDetailToDOCX }
|
export {
|
||||||
|
exportToPDF,
|
||||||
|
exportDetailToPDF,
|
||||||
|
exportToXLSX,
|
||||||
|
exportDetailToXLSX,
|
||||||
|
exportToDOCX,
|
||||||
|
exportDetailToDOCX
|
||||||
|
}
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
@ -287,4 +274,4 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX , exportToDOCX}
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
@ -24,7 +11,72 @@ import { exportToWord } from './doc/MonalisaGR_JumlahDDRPTRCTGangguan_DOC'
|
|||||||
const reportName = 'Jumlah dan Durasi RPT RCT Gangguan'
|
const reportName = 'Jumlah dan Durasi RPT RCT Gangguan'
|
||||||
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: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = {
|
||||||
@ -38,42 +90,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) => {
|
||||||
@ -81,7 +179,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'
|
||||||
})
|
})
|
||||||
@ -324,6 +422,6 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX , exportToDOCX}
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -1,22 +1,8 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
import { Workbook } from 'exceljs'
|
import { Workbook } from 'exceljs'
|
||||||
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
|
||||||
import { setHeaderStyle } from '@/report/utils/xlsx'
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
@ -24,50 +10,112 @@ import { exportToWord } from './doc/MonalisaGR_JumlahKaliGangguan_DOC'
|
|||||||
|
|
||||||
const reportName = 'Jumlah Kali Gangguan'
|
const reportName = 'Jumlah Kali Gangguan'
|
||||||
const fontSize = 5
|
const fontSize = 5
|
||||||
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 = {
|
|
||||||
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 = {
|
||||||
@ -77,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) => {
|
||||||
@ -134,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'
|
||||||
})
|
})
|
||||||
@ -309,34 +401,38 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
worksheet,
|
worksheet,
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
`UNIT INDUK : ${reportMeta.uid
|
`UNIT INDUK : ${
|
||||||
? reportMeta.uid.name.toUpperCase()
|
reportMeta.uid
|
||||||
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
3,
|
3,
|
||||||
1,
|
1,
|
||||||
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${reportMeta.up3
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
? reportMeta.up3.name.toUpperCase()
|
reportMeta.up3
|
||||||
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
4,
|
4,
|
||||||
1,
|
1,
|
||||||
`UNIT LAYANAN PELANGGAN : ${reportMeta.ulp
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
? reportMeta.ulp.name.toUpperCase()
|
reportMeta.ulp
|
||||||
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
setHeaderStyle(
|
setHeaderStyle(
|
||||||
worksheet,
|
worksheet,
|
||||||
5,
|
5,
|
||||||
1,
|
1,
|
||||||
`REGIONAL : ${reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -370,6 +466,6 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
console.log(reportMeta, rawData)
|
console.log(reportMeta, rawData)
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX, exportToDOCX }
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
@ -24,48 +11,111 @@ import { exportToWord } from './doc/MonalisaGR_LaporUlang_DOC'
|
|||||||
const reportName = 'Rekapitulasi Lapor Ulang Gangguan'
|
const reportName = 'Rekapitulasi Lapor Ulang Gangguan'
|
||||||
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 = {
|
||||||
@ -75,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) => {
|
||||||
@ -132,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'
|
||||||
})
|
})
|
||||||
@ -371,6 +465,6 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX , exportToDOCX}
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -1,22 +1,8 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
import { Workbook } from 'exceljs'
|
import { Workbook } from 'exceljs'
|
||||||
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
|
||||||
import { setHeaderStyle } from '@/report/utils/xlsx'
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
@ -25,48 +11,111 @@ import { exportToWord } from './doc/MonalisaGR_RecoveryTimeGangguan_DOC'
|
|||||||
const reportName = 'Recovery Time (RCT) Gangguan'
|
const reportName = 'Recovery Time (RCT) Gangguan'
|
||||||
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 = {
|
||||||
@ -76,67 +125,125 @@ 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)
|
||||||
|
|
||||||
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) => {
|
||||||
@ -144,7 +251,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'
|
||||||
})
|
})
|
||||||
@ -383,6 +490,6 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX , exportToDOCX}
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
@ -1,22 +1,8 @@
|
|||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
||||||
import {
|
|
||||||
Document,
|
|
||||||
AlignmentType,
|
|
||||||
Packer,
|
|
||||||
Paragraph,
|
|
||||||
Table,
|
|
||||||
TableCell,
|
|
||||||
TableRow,
|
|
||||||
VerticalAlign,
|
|
||||||
TextRun,
|
|
||||||
WidthType,
|
|
||||||
PageOrientation
|
|
||||||
} from 'docx'
|
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { jsPDF } from 'jspdf'
|
import { jsPDF } from 'jspdf'
|
||||||
import autoTable from 'jspdf-autotable'
|
import autoTable from 'jspdf-autotable'
|
||||||
import { Workbook } from 'exceljs'
|
import { Workbook } from 'exceljs'
|
||||||
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
|
||||||
import { setHeaderStyle } from '@/report/utils/xlsx'
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
@ -25,48 +11,111 @@ import { exportToWord } from './doc/MonalisaGR_ResponseTimeGangguan_DOC'
|
|||||||
const reportName = 'Response Time (RPT) Gangguan'
|
const reportName = 'Response Time (RPT) Gangguan'
|
||||||
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 = {
|
||||||
@ -76,67 +125,125 @@ 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)
|
||||||
|
|
||||||
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) => {
|
||||||
@ -144,7 +251,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'
|
||||||
})
|
})
|
||||||
@ -383,6 +490,6 @@ const exportToXLSX = (reportMeta: any, e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||||
exportToWord(reportMeta, formatData(rawData), `Laporan ${reportName}`, null)
|
exportToWord(reportMeta, formatData(rawData, reportMeta), `Laporan ${reportName}`, null)
|
||||||
}
|
}
|
||||||
export { exportToPDF, exportToXLSX , exportToDOCX}
|
export { exportToPDF, exportToXLSX, exportToDOCX }
|
||||||
|
Reference in New Issue
Block a user