fix: report in ctt, kwh periksa
This commit is contained in:
parent
9e654bb2c5
commit
7eef6eb39f
@ -1,17 +1,4 @@
|
||||
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 { jsPDF } from 'jspdf'
|
||||
import autoTable from 'jspdf-autotable'
|
||||
|
@ -1,17 +1,4 @@
|
||||
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 { jsPDF } from 'jspdf'
|
||||
import autoTable from 'jspdf-autotable'
|
||||
@ -24,8 +11,66 @@ const reportName = 'Laporan CTT & KWH Periksa'
|
||||
const fontSize = 5
|
||||
const detailFontSize = 4
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
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 total: any = {
|
||||
wo_cc123: 0,
|
||||
wo_pln_mobile: 0,
|
||||
@ -37,29 +82,68 @@ const formatData = (rawData: any) => {
|
||||
history_p2lt: 0
|
||||
}
|
||||
|
||||
rawData.forEach((item: any) => {
|
||||
total.wo_cc123 += item.wo_cc123
|
||||
total.wo_pln_mobile += item.wo_pln_mobile
|
||||
total.wo_comcen += item.wo_comcen
|
||||
total.rekomendasi_mendatangkan_petugas += item.rekomendasi_mendatangkan_petugas
|
||||
total.rekomendasi_diberikan_ke_pelanggan += item.rekomendasi_diberikan_ke_pelanggan
|
||||
total.dpld += item.dpld
|
||||
total.history_p2lt += item.history_p2lt
|
||||
})
|
||||
if (reportMeta.uid.id == 0) {
|
||||
formattedData.push([{ content: 'NASIONAL', colSpan: 9, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const wo_total = total.wo_cc123 + total.wo_pln_mobile + total.wo_comcen
|
||||
rawData.forEach((item: any) => {
|
||||
total.wo_cc123 += item.wo_cc123
|
||||
total.wo_pln_mobile += item.wo_pln_mobile
|
||||
total.wo_comcen += item.wo_comcen
|
||||
total.rekomendasi_mendatangkan_petugas += item.rekomendasi_mendatangkan_petugas
|
||||
total.rekomendasi_diberikan_ke_pelanggan += item.rekomendasi_diberikan_ke_pelanggan
|
||||
total.dpld += item.dpld
|
||||
total.history_p2lt += item.history_p2lt
|
||||
})
|
||||
|
||||
formattedData.push([
|
||||
'Semua Unit',
|
||||
formatNumber(total.wo_cc123),
|
||||
formatNumber(total.wo_pln_mobile),
|
||||
formatNumber(total.wo_comcen),
|
||||
formatNumber(wo_total),
|
||||
formatNumber(total.rekomendasi_mendatangkan_petugas),
|
||||
formatNumber(total.rekomendasi_diberikan_ke_pelanggan),
|
||||
formatNumber(total.dpld),
|
||||
formatNumber(total.history_p2lt)
|
||||
])
|
||||
const wo_total = total.wo_cc123 + total.wo_pln_mobile + total.wo_comcen
|
||||
const result = [
|
||||
formatNumber(total.wo_cc123),
|
||||
formatNumber(total.wo_pln_mobile),
|
||||
formatNumber(total.wo_comcen),
|
||||
formatNumber(wo_total),
|
||||
formatNumber(total.rekomendasi_mendatangkan_petugas),
|
||||
formatNumber(total.rekomendasi_diberikan_ke_pelanggan),
|
||||
formatNumber(total.dpld),
|
||||
formatNumber(total.history_p2lt)
|
||||
]
|
||||
|
||||
formattedData.push(['Semua Unit', ...result])
|
||||
formattedData.push([{ content: 'TOTAL', styles: { fontStyle: 'bold' } }, ...result])
|
||||
} else {
|
||||
const tempData = groupingData(rawData, reportMeta)
|
||||
const data = tempData.data[tempData.summaryName] || tempData.data
|
||||
|
||||
let parentName = tempData.parent
|
||||
let summaryName = tempData.summaryName
|
||||
|
||||
data.forEach((item: any) => {
|
||||
total.wo_cc123 += item.wo_cc123
|
||||
total.wo_pln_mobile += item.wo_pln_mobile
|
||||
total.wo_comcen += item.wo_comcen
|
||||
total.rekomendasi_mendatangkan_petugas += item.rekomendasi_mendatangkan_petugas
|
||||
total.rekomendasi_diberikan_ke_pelanggan += item.rekomendasi_diberikan_ke_pelanggan
|
||||
total.dpld += item.dpld
|
||||
total.history_p2lt += item.history_p2lt
|
||||
})
|
||||
|
||||
const wo_total = total.wo_cc123 + total.wo_pln_mobile + total.wo_comcen
|
||||
|
||||
formattedData.push([{ content: parentName, colSpan: 9, styles: { fontStyle: 'bold' } }])
|
||||
|
||||
const result = [
|
||||
formatNumber(total.wo_cc123),
|
||||
formatNumber(total.wo_pln_mobile),
|
||||
formatNumber(total.wo_comcen),
|
||||
formatNumber(wo_total),
|
||||
formatNumber(total.rekomendasi_mendatangkan_petugas),
|
||||
formatNumber(total.rekomendasi_diberikan_ke_pelanggan),
|
||||
formatNumber(total.dpld),
|
||||
formatNumber(total.history_p2lt)
|
||||
]
|
||||
|
||||
formattedData.push([summaryName, ...result])
|
||||
formattedData.push([{ content: 'TOTAL', styles: { fontStyle: 'bold' } }, ...result])
|
||||
}
|
||||
|
||||
return formattedData
|
||||
}
|
||||
@ -94,7 +178,7 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
|
||||
const date = new Date().getDate()
|
||||
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||
const year = new Date().getFullYear()
|
||||
const data = formatData(rawData)
|
||||
const data = formatData(rawData, reportMeta)
|
||||
console.log(data)
|
||||
const meta = formatMetaData(reportMeta)
|
||||
const doc = new jsPDF({
|
||||
@ -534,7 +618,7 @@ const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
||||
|
||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||
const meta = formatMetaData(reportMeta)
|
||||
exportToWord(reportMeta, meta, formatData(rawData), reportName)
|
||||
exportToWord(reportMeta, meta, formatData(rawData, reportMeta), reportName)
|
||||
}
|
||||
|
||||
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user