feat: create pdf, xlsx and lihat laporan in monalisa rekapitulasi keluhan
This commit is contained in:
parent
948181e726
commit
efd316d90e
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -138,17 +139,16 @@ import {
|
|||||||
DxSummary,
|
DxSummary,
|
||||||
DxTotalItem
|
DxTotalItem
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { apolloClient } from '@/utils/api/api.graphql'
|
import { apolloClient } from '@/utils/api/api.graphql'
|
||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_GangguanPerJenisKeluhan'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -168,33 +168,22 @@ const filters = ref()
|
|||||||
const currentYear = ref(new Date().getFullYear())
|
const currentYear = ref(new Date().getFullYear())
|
||||||
const currentMonth = ref(new Date().getMonth() + 1)
|
const currentMonth = ref(new Date().getMonth() + 1)
|
||||||
const lastYear = ref(new Date().getFullYear() - 1)
|
const lastYear = ref(new Date().getFullYear() - 1)
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: ''
|
||||||
|
})
|
||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
|
||||||
|
|
||||||
exportToExcel({
|
|
||||||
component: e.component,
|
|
||||||
worksheet,
|
|
||||||
autoFilterEnabled: true
|
|
||||||
}).then(() => {
|
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,6 +273,16 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -47,6 +48,14 @@
|
|||||||
css-class="custom-table-column"
|
css-class="custom-table-column"
|
||||||
cell-template="formatText"
|
cell-template="formatText"
|
||||||
/>
|
/>
|
||||||
|
<DxColumn
|
||||||
|
alignment="center"
|
||||||
|
data-field=""
|
||||||
|
caption="NASIONAL"
|
||||||
|
css-class="custom-table-column"
|
||||||
|
cell-template="formatText"
|
||||||
|
:group-index="0"
|
||||||
|
/>
|
||||||
<DxColumn
|
<DxColumn
|
||||||
alignment="center"
|
alignment="center"
|
||||||
:min-width="170"
|
:min-width="170"
|
||||||
@ -381,18 +390,16 @@ import {
|
|||||||
DxSelection,
|
DxSelection,
|
||||||
DxSummary
|
DxSummary
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { apolloClient } from '@/utils/api/api.graphql'
|
import { apolloClient } from '@/utils/api/api.graphql'
|
||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_JumlahDDRPTRCTKeluhan'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -411,33 +418,24 @@ const loadingSubData = ref(false)
|
|||||||
const currentYear = ref(new Date().getFullYear())
|
const currentYear = ref(new Date().getFullYear())
|
||||||
const currentMonth = ref(new Date().getMonth() + 1)
|
const currentMonth = ref(new Date().getMonth() + 1)
|
||||||
const lastYear = ref(new Date().getFullYear() - 1)
|
const lastYear = ref(new Date().getFullYear() - 1)
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: '',
|
||||||
|
currentMonth: currentMonth.value,
|
||||||
|
currentYear: currentYear.value
|
||||||
|
})
|
||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
|
||||||
|
|
||||||
exportToExcel({
|
|
||||||
component: e.component,
|
|
||||||
worksheet,
|
|
||||||
autoFilterEnabled: true
|
|
||||||
}).then(() => {
|
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const getDetail = async () => {
|
const getDetail = async () => {
|
||||||
@ -527,6 +525,18 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`,
|
||||||
|
currentMonth: bulan.id,
|
||||||
|
currentYear: tahun.id
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@ -260,6 +261,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</DxDataGrid>
|
</DxDataGrid>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<BufferDialog v-if="loadingData || loadingSubData" />
|
<BufferDialog v-if="loadingData || loadingSubData" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -283,17 +285,15 @@ import {
|
|||||||
DxSummary,
|
DxSummary,
|
||||||
DxTotalItem
|
DxTotalItem
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { apolloClient } from '@/utils/api/api.graphql'
|
import { apolloClient } from '@/utils/api/api.graphql'
|
||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_JumlahKaliKeluhan'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -316,33 +316,27 @@ const lastYearMoM = ref(
|
|||||||
const currentYear = ref(new Date().getFullYear())
|
const currentYear = ref(new Date().getFullYear())
|
||||||
const currentMonth = ref(new Date().getMonth())
|
const currentMonth = ref(new Date().getMonth())
|
||||||
const lastYear = ref(currentYear.value - 1)
|
const lastYear = ref(currentYear.value - 1)
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: '',
|
||||||
|
lastMonth: new Date().getMonth() == 1 ? 12 : new Date().getMonth() - 1,
|
||||||
|
lastYearMoM: new Date().getMonth() == 1 ? new Date().getFullYear() - 1 : new Date().getFullYear(),
|
||||||
|
currentMonth: new Date().getMonth(),
|
||||||
|
currentYear: new Date().getFullYear(),
|
||||||
|
lastYear: new Date().getFullYear() - 1
|
||||||
|
})
|
||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
|
||||||
|
|
||||||
exportToExcel({
|
|
||||||
component: e.component,
|
|
||||||
worksheet,
|
|
||||||
autoFilterEnabled: true
|
|
||||||
}).then(() => {
|
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,6 +371,21 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`,
|
||||||
|
lastMonth: lastMonth.value,
|
||||||
|
lastYearMoM: lastYearMoM.value,
|
||||||
|
currentMonth: currentMonth.value,
|
||||||
|
currentYear: currentYear.value,
|
||||||
|
lastYear: lastYear.value
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -213,7 +214,7 @@
|
|||||||
:hover-state-enabled="true"
|
:hover-state-enabled="true"
|
||||||
@selection-changed="onDataSubSelectionChanged"
|
@selection-changed="onDataSubSelectionChanged"
|
||||||
:column-width="100"
|
:column-width="100"
|
||||||
@exporting="onExporting"
|
@exporting="onExportingDetail"
|
||||||
:allow-column-resizing="true"
|
:allow-column-resizing="true"
|
||||||
column-resizing-mode="widget"
|
column-resizing-mode="widget"
|
||||||
>
|
>
|
||||||
@ -533,19 +534,20 @@ import {
|
|||||||
DxSummary,
|
DxSummary,
|
||||||
DxTotalItem
|
DxTotalItem
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { apolloClient, queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { apolloClient, queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
|
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
|
||||||
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||||
import InputText from '@/components/InputText.vue'
|
import InputText from '@/components/InputText.vue'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX,
|
||||||
|
exportDetailToPDF,
|
||||||
|
exportDetailToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_KeluhanBelumSelesai'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -565,33 +567,31 @@ const currentYear = ref(new Date().getFullYear())
|
|||||||
const currentMonth = ref(new Date().getMonth())
|
const currentMonth = ref(new Date().getMonth())
|
||||||
const lastYear = ref(currentYear.value - 1)
|
const lastYear = ref(currentYear.value - 1)
|
||||||
const filters = ref()
|
const filters = ref()
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: ''
|
||||||
|
})
|
||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
}
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
}
|
||||||
|
|
||||||
exportToExcel({
|
const onExportingDetail = (e: any) => {
|
||||||
component: e.component,
|
if (e.format === 'pdf') {
|
||||||
worksheet,
|
exportDetailToPDF(reportMeta.value, dataSub.value)
|
||||||
autoFilterEnabled: true
|
} else if (e.format === 'xlsx') {
|
||||||
}).then(() => {
|
exportDetailToXLSX(reportMeta.value, e)
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
} else {
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const getDetail = async () => {
|
const getDetail = async () => {
|
||||||
@ -678,6 +678,16 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -287,18 +288,15 @@ import {
|
|||||||
DxSummary,
|
DxSummary,
|
||||||
DxTotalItem
|
DxTotalItem
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import gql from 'graphql-tag'
|
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { apolloClient, queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { apolloClient, queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_LaporUlangKeluhan'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -322,33 +320,27 @@ const currentYear = ref(new Date().getFullYear())
|
|||||||
const currentMonth = ref(new Date().getMonth())
|
const currentMonth = ref(new Date().getMonth())
|
||||||
const lastYear = ref(currentYear.value - 1)
|
const lastYear = ref(currentYear.value - 1)
|
||||||
const filters = ref()
|
const filters = ref()
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: '',
|
||||||
|
lastMonth: new Date().getMonth() == 1 ? 12 : new Date().getMonth() - 1,
|
||||||
|
lastYearMoM: new Date().getMonth() == 1 ? new Date().getFullYear() - 1 : new Date().getFullYear(),
|
||||||
|
currentMonth: new Date().getMonth(),
|
||||||
|
currentYear: new Date().getFullYear(),
|
||||||
|
lastYear: new Date().getFullYear() - 1
|
||||||
|
})
|
||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
|
||||||
|
|
||||||
exportToExcel({
|
|
||||||
component: e.component,
|
|
||||||
worksheet,
|
|
||||||
autoFilterEnabled: true
|
|
||||||
}).then(() => {
|
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const getDetail = async () => {
|
const getDetail = async () => {
|
||||||
@ -439,6 +431,21 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`,
|
||||||
|
lastMonth: lastMonth.value,
|
||||||
|
lastYearMoM: lastYearMoM.value,
|
||||||
|
currentMonth: currentMonth.value,
|
||||||
|
currentYear: currentYear.value,
|
||||||
|
lastYear: lastYear.value
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -292,18 +293,16 @@ import {
|
|||||||
DxTotalItem,
|
DxTotalItem,
|
||||||
DxGrouping
|
DxGrouping
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { apolloClient } from '@/utils/api/api.graphql'
|
import { apolloClient } from '@/utils/api/api.graphql'
|
||||||
import { provideApolloClient } from '@vue/apollo-composable'
|
import { provideApolloClient } from '@vue/apollo-composable'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_RecoveryTimeKeluhan'
|
||||||
|
|
||||||
const client = apolloClient()
|
const client = apolloClient()
|
||||||
provideApolloClient(client)
|
provideApolloClient(client)
|
||||||
@ -326,36 +325,29 @@ const lastYearMoM = ref(
|
|||||||
const currentYear = ref(new Date().getFullYear())
|
const currentYear = ref(new Date().getFullYear())
|
||||||
const currentMonth = ref(new Date().getMonth())
|
const currentMonth = ref(new Date().getMonth())
|
||||||
const lastYear = ref(currentYear.value - 1)
|
const lastYear = ref(currentYear.value - 1)
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: '',
|
||||||
|
lastMonth: new Date().getMonth() == 1 ? 12 : new Date().getMonth() - 1,
|
||||||
|
lastYearMoM: new Date().getMonth() == 1 ? new Date().getFullYear() - 1 : new Date().getFullYear(),
|
||||||
|
currentMonth: new Date().getMonth(),
|
||||||
|
currentYear: new Date().getFullYear(),
|
||||||
|
lastYear: new Date().getFullYear() - 1
|
||||||
|
})
|
||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
|
||||||
|
|
||||||
exportToExcel({
|
|
||||||
component: e.component,
|
|
||||||
worksheet,
|
|
||||||
autoFilterEnabled: true
|
|
||||||
}).then(() => {
|
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetData = () => {
|
const resetData = () => {
|
||||||
data.value = []
|
data.value = []
|
||||||
dataSub.value = []
|
dataSub.value = []
|
||||||
@ -387,6 +379,21 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`,
|
||||||
|
lastMonth: lastMonth.value,
|
||||||
|
lastYearMoM: lastYearMoM.value,
|
||||||
|
currentMonth: currentMonth.value,
|
||||||
|
currentYear: currentYear.value,
|
||||||
|
lastYear: lastYear.value
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<Filters
|
<Filters
|
||||||
|
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||||
@reset-form="data = []"
|
@reset-form="data = []"
|
||||||
@run-search="() => filterData(filters)"
|
@run-search="() => filterData(filters)"
|
||||||
:report-button="true"
|
:report-button="true"
|
||||||
@ -292,16 +293,14 @@ import {
|
|||||||
DxTotalItem,
|
DxTotalItem,
|
||||||
DxGrouping
|
DxGrouping
|
||||||
} from 'devextreme-vue/data-grid'
|
} from 'devextreme-vue/data-grid'
|
||||||
import { jsPDF } from 'jspdf'
|
|
||||||
import { exportDataGrid as exportToPdf } from 'devextreme/pdf_exporter'
|
|
||||||
import { exportDataGrid as exportToExcel } from 'devextreme/excel_exporter'
|
|
||||||
import { saveAs } from 'file-saver'
|
|
||||||
import { Workbook } from 'exceljs'
|
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
|
||||||
import { getMonthName } from '@/utils/texts'
|
import { getMonthName } from '@/utils/texts'
|
||||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||||
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
import { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||||
|
import {
|
||||||
|
exportToPDF,
|
||||||
|
exportToXLSX
|
||||||
|
} from '@/report/Monalisa/Keluhan/Rekap/MonalisaKR_ResponseTimeKeluhan'
|
||||||
|
|
||||||
const position = { of: '#data' }
|
const position = { of: '#data' }
|
||||||
const showIndicator = ref(true)
|
const showIndicator = ref(true)
|
||||||
@ -315,6 +314,20 @@ const dialogDetail = ref(false)
|
|||||||
const closedialogDetail = () => (dialogDetail.value = false)
|
const closedialogDetail = () => (dialogDetail.value = false)
|
||||||
const loadingData = ref(false)
|
const loadingData = ref(false)
|
||||||
const loadingSubData = ref(false)
|
const loadingSubData = ref(false)
|
||||||
|
const reportMeta = ref({
|
||||||
|
regional: { id: 0, name: 'Semua Regional' },
|
||||||
|
uid: { id: 0, name: 'Semua Unit Induk Distribusi/Wilayah' },
|
||||||
|
up3: { id: 0, name: 'Semua Unit Pelaksanaan Pelayanan Pelanggan' },
|
||||||
|
ulp: { id: 0, name: 'Semua Unit Layanan Pelanggan' },
|
||||||
|
bulan: { id: new Date().getMonth(), name: getMonthName(new Date().getMonth()) },
|
||||||
|
tahun: { id: new Date().getFullYear(), name: new Date().getFullYear().toString() },
|
||||||
|
periode: '',
|
||||||
|
lastMonth: new Date().getMonth() == 1 ? 12 : new Date().getMonth() - 1,
|
||||||
|
lastYearMoM: new Date().getMonth() == 1 ? new Date().getFullYear() - 1 : new Date().getFullYear(),
|
||||||
|
currentMonth: new Date().getMonth(),
|
||||||
|
currentYear: new Date().getFullYear(),
|
||||||
|
lastYear: new Date().getFullYear() - 1
|
||||||
|
})
|
||||||
|
|
||||||
const lastMonth = ref(new Date().getMonth() == 1 ? 12 : new Date().getMonth() - 1)
|
const lastMonth = ref(new Date().getMonth() == 1 ? 12 : new Date().getMonth() - 1)
|
||||||
const lastYearMoM = ref(
|
const lastYearMoM = ref(
|
||||||
@ -326,30 +339,10 @@ const lastYear = ref(currentYear.value - 1)
|
|||||||
|
|
||||||
const onExporting = (e: any) => {
|
const onExporting = (e: any) => {
|
||||||
if (e.format === 'pdf') {
|
if (e.format === 'pdf') {
|
||||||
const doc = new jsPDF()
|
exportToPDF(reportMeta.value, data.value)
|
||||||
|
} else if (e.format === 'xlsx') {
|
||||||
exportToPdf({
|
exportToXLSX(reportMeta.value, e)
|
||||||
jsPDFDocument: doc,
|
|
||||||
component: e.component,
|
|
||||||
indent: 5
|
|
||||||
}).then(() => {
|
|
||||||
doc.save(`.pdf`)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
const workbook = new Workbook()
|
|
||||||
const worksheet = workbook.addWorksheet('Employees')
|
|
||||||
|
|
||||||
exportToExcel({
|
|
||||||
component: e.component,
|
|
||||||
worksheet,
|
|
||||||
autoFilterEnabled: true
|
|
||||||
}).then(() => {
|
|
||||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
|
||||||
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
e.cancel = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,6 +377,21 @@ const filterData = async (params: any) => {
|
|||||||
} else {
|
} else {
|
||||||
data.value = []
|
data.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportMeta.value = {
|
||||||
|
regional: regional,
|
||||||
|
uid: uid,
|
||||||
|
up3: up3,
|
||||||
|
ulp: ulp,
|
||||||
|
bulan: bulan,
|
||||||
|
tahun: tahun,
|
||||||
|
periode: `${bulan.name} ${tahun.name}`,
|
||||||
|
lastMonth: lastMonth.value,
|
||||||
|
lastYearMoM: lastYearMoM.value,
|
||||||
|
currentMonth: currentMonth.value,
|
||||||
|
currentYear: currentYear.value,
|
||||||
|
lastYear: lastYear.value
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -0,0 +1,275 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
|
||||||
|
const reportName = '(Monalisa) Rekapitulasi Keluhan Per Jenis Keluhan'
|
||||||
|
const fontSize = 5
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
jumlah: 0,
|
||||||
|
persen: []
|
||||||
|
}
|
||||||
|
|
||||||
|
rawData.forEach((data: any, index: any) => {
|
||||||
|
formattedData.push([
|
||||||
|
{ content: ++index, styles: { halign: 'right' } },
|
||||||
|
data.id_jenis_keluhan,
|
||||||
|
data.nama_jenis_keluhan,
|
||||||
|
formatNumber(data.jumlah),
|
||||||
|
formatPercentage(data.persen)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.jumlah += data.jumlah
|
||||||
|
total.persen.push(data.persen)
|
||||||
|
})
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{
|
||||||
|
content: 'TOTAL',
|
||||||
|
colSpan: 3
|
||||||
|
},
|
||||||
|
formatNumber(total.jumlah),
|
||||||
|
formatPercentage(total.persen.reduce((a: any, b: any) => a + b, 0) / total.persen.length)
|
||||||
|
])
|
||||||
|
|
||||||
|
return formattedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
|
const day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [['No', 'ID Gangguan', 'Jenis Gangguan', 'Jumlah', '%']],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'TOTAL') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'ENS') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:E1')
|
||||||
|
worksheet.mergeCells('A2:E2')
|
||||||
|
worksheet.mergeCells('A3:E3')
|
||||||
|
worksheet.mergeCells('A4:E4')
|
||||||
|
worksheet.mergeCells('A5:E5')
|
||||||
|
worksheet.mergeCells('A7:E7')
|
||||||
|
worksheet.mergeCells('A8:E8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX }
|
@ -0,0 +1,325 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
|
||||||
|
const reportName = 'Jumlah dan Durasi RPT RCT Keluhan'
|
||||||
|
const fontSize = 5
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
total_durasi_response_time_bulan_ini: 0,
|
||||||
|
count_durasi_response_time_bulan_ini: 0,
|
||||||
|
total_durasi_recovery_time_bulan_ini: 0,
|
||||||
|
count_durasi_recovery_time_bulan_ini: 0,
|
||||||
|
total_durasi_response_time_tahun_ini: 0,
|
||||||
|
count_durasi_response_time_tahun_ini: 0,
|
||||||
|
total_durasi_recovery_time_tahun_ini: 0,
|
||||||
|
count_durasi_recovery_time_tahun_ini: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
rawData.forEach((data: any) => {
|
||||||
|
total.total_durasi_response_time_bulan_ini += data.total_durasi_response_time_bulan_ini
|
||||||
|
total.count_durasi_response_time_bulan_ini += data.count_durasi_response_time_bulan_ini
|
||||||
|
total.total_durasi_recovery_time_bulan_ini += data.total_durasi_recovery_time_bulan_ini
|
||||||
|
total.count_durasi_recovery_time_bulan_ini += data.count_durasi_recovery_time_bulan_ini
|
||||||
|
total.total_durasi_response_time_tahun_ini += data.total_durasi_response_time_tahun_ini
|
||||||
|
total.count_durasi_response_time_tahun_ini += data.count_durasi_response_time_tahun_ini
|
||||||
|
total.total_durasi_recovery_time_tahun_ini += data.total_durasi_recovery_time_tahun_ini
|
||||||
|
total.count_durasi_recovery_time_tahun_ini += data.count_durasi_recovery_time_tahun_ini
|
||||||
|
})
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
'NASIONAL',
|
||||||
|
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 day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'Nama Unit',
|
||||||
|
rowSpan: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Jumlah dan Durasi RPT & RCT Keluhan',
|
||||||
|
colSpan: 12
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: getMonthName(reportMeta.currentMonth) + ' ' + reportMeta.currentYear,
|
||||||
|
colSpan: 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content:
|
||||||
|
's.d' + ' ' + getMonthName(reportMeta.currentMonth) + ' ' + reportMeta.currentYear,
|
||||||
|
colSpan: 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Total RPT',
|
||||||
|
'Jumlah Keluhan',
|
||||||
|
'RPT Keluhan',
|
||||||
|
'Total RCT',
|
||||||
|
'Jumlah Keluhan',
|
||||||
|
'RCT Keluhan',
|
||||||
|
'Total RPT',
|
||||||
|
'Jumlah Keluhan',
|
||||||
|
'RPT Keluhan',
|
||||||
|
'Total RCT',
|
||||||
|
'Jumlah Keluhan',
|
||||||
|
'RCT Keluhan'
|
||||||
|
],
|
||||||
|
['a', 'b', 'c=a/b', 'd', 'e', 'f=d/e', 'a', 'b', 'c=a/b', 'd', 'e', 'f=d/e']
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'RATA-RATA') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:M1')
|
||||||
|
worksheet.mergeCells('A2:M2')
|
||||||
|
worksheet.mergeCells('A3:M3')
|
||||||
|
worksheet.mergeCells('A4:M4')
|
||||||
|
worksheet.mergeCells('A5:M5')
|
||||||
|
worksheet.mergeCells('A7:M7')
|
||||||
|
worksheet.mergeCells('A8:M8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX }
|
@ -0,0 +1,373 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
|
||||||
|
const reportName = 'Jumlah Kali Keluhan'
|
||||||
|
const fontSize = 5
|
||||||
|
const detailFontSize = 3
|
||||||
|
|
||||||
|
const groupingData = (data: any) => {
|
||||||
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const data = groupingData(rawData)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
mom_bulan_kemarin: 0,
|
||||||
|
mom_bulan_ini: 0,
|
||||||
|
yoy_tahun_kemarin: 0,
|
||||||
|
yoy_tahun_ini: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
let no = 1
|
||||||
|
for (const regional in data) {
|
||||||
|
const summary = data[regional].summary
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: no++, styles: { halign: 'right' } },
|
||||||
|
regional,
|
||||||
|
formatNumber(summary.mom_bulan_kemarin),
|
||||||
|
formatNumber(summary.mom_bulan_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||||
|
),
|
||||||
|
formatNumber(summary.yoy_tahun_kemarin),
|
||||||
|
formatNumber(summary.yoy_tahun_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||||
|
total.mom_bulan_ini += summary.mom_bulan_ini
|
||||||
|
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||||
|
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||||
|
}
|
||||||
|
|
||||||
|
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 day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'No',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Nama Unit',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Jumlah Kali Gangguan',
|
||||||
|
colSpan: 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'MOM',
|
||||||
|
colSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'YOY',
|
||||||
|
colSpan: 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
`${getMonthName(reportMeta.lastMonth)} ${reportMeta.lastYearMoM}`,
|
||||||
|
`${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%',
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.lastYear}`,
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'TOTAL') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:G1')
|
||||||
|
worksheet.mergeCells('A2:G2')
|
||||||
|
worksheet.mergeCells('A3:G3')
|
||||||
|
worksheet.mergeCells('A4:G4')
|
||||||
|
worksheet.mergeCells('A5:G5')
|
||||||
|
worksheet.mergeCells('A7:G7')
|
||||||
|
worksheet.mergeCells('A8:G8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX }
|
@ -0,0 +1,489 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber } from '@/utils/numbers'
|
||||||
|
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||||
|
|
||||||
|
const reportName = 'Rekapitulasi Keluhan Belum Selesai'
|
||||||
|
const fontSize = 5
|
||||||
|
const detailFontSize = 3
|
||||||
|
|
||||||
|
const groupingData = (data: any) => {
|
||||||
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
const { nama_regional } = item
|
||||||
|
|
||||||
|
if (!groupedData[nama_regional]) {
|
||||||
|
groupedData[nama_regional] = { data: [] }
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedData[nama_regional].data.push(item)
|
||||||
|
})
|
||||||
|
|
||||||
|
for (const regional in groupedData) {
|
||||||
|
const data = groupedData[regional].data
|
||||||
|
|
||||||
|
data.forEach((item: any) => {
|
||||||
|
if (!groupedData[regional].summary) {
|
||||||
|
groupedData[regional].summary = {
|
||||||
|
jumlah_keluhan: 0,
|
||||||
|
jumlah_informasi: 0,
|
||||||
|
total: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groupedData[regional].summary.jumlah_keluhan += item.jumlah_keluhan
|
||||||
|
groupedData[regional].summary.jumlah_informasi += item.jumlah_informasi
|
||||||
|
groupedData[regional].summary.total += item.total
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const data = groupingData(rawData)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
jumlah_keluhan: 0,
|
||||||
|
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_keluhan),
|
||||||
|
formatNumber(summary.jumlah_informasi),
|
||||||
|
formatNumber(summary.total)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.jumlah_keluhan += summary.jumlah_keluhan
|
||||||
|
total.jumlah_informasi += summary.jumlah_informasi
|
||||||
|
total.total += summary.total
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
|
formatNumber(total.jumlah_keluhan),
|
||||||
|
formatNumber(total.jumlah_informasi),
|
||||||
|
formatNumber(total.total)
|
||||||
|
])
|
||||||
|
|
||||||
|
return formattedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
|
const day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'No',
|
||||||
|
rowSpan: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Nama Unit',
|
||||||
|
rowSpan: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Tahun',
|
||||||
|
colSpan: 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
['Keluhan', 'Informasi', 'Total']
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'TOTAL') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportDetailToPDF = (reportMeta: any, rawData: any) => {
|
||||||
|
const day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [['PT. PLN(Persero)']],
|
||||||
|
styles: {
|
||||||
|
fontSize: detailFontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10,
|
||||||
|
margin: 5
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`Daftar Detail ${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize: detailFontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 18,
|
||||||
|
margin: 5
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
'No',
|
||||||
|
'No Laporan',
|
||||||
|
'UID/UIW',
|
||||||
|
'UP3',
|
||||||
|
'ULP',
|
||||||
|
'ID Pelanggan',
|
||||||
|
'Nama Pelapor',
|
||||||
|
'Alamat Pelapor',
|
||||||
|
'No Telp Pelapor',
|
||||||
|
'Keterangan Pelapor',
|
||||||
|
'Penyebab',
|
||||||
|
'Kode Gangguan',
|
||||||
|
'Jenis Gangguan',
|
||||||
|
'Durasi Response Time',
|
||||||
|
'Durasi Recovery Time',
|
||||||
|
'Tgl Lapor'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: rawData.map((item: any, i: any) => [
|
||||||
|
{ content: i + 1, styles: { halign: 'right' } },
|
||||||
|
item.no_laporan,
|
||||||
|
item.nama_uid,
|
||||||
|
item.nama_ulp,
|
||||||
|
item.id_pelanggan,
|
||||||
|
item.nama_pelapor,
|
||||||
|
item.alamat_pelapor,
|
||||||
|
item.no_telp_pelapor,
|
||||||
|
item.keterangan_pelapor,
|
||||||
|
item.penyebab,
|
||||||
|
item.kode_gangguan,
|
||||||
|
item.jenis_gangguan,
|
||||||
|
item.durasi_response_time ? formatWaktu(item.durasi_response_time) : '-',
|
||||||
|
item.durasi_recovery_time ? formatWaktu(item.durasi_recovery_time) : '-',
|
||||||
|
item.waktu_lapor
|
||||||
|
]),
|
||||||
|
styles: {
|
||||||
|
fontSize: detailFontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 24,
|
||||||
|
margin: 5
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize: detailFontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
doc.save(`Laporan Detail ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:E1')
|
||||||
|
worksheet.mergeCells('A2:E2')
|
||||||
|
worksheet.mergeCells('A3:E3')
|
||||||
|
worksheet.mergeCells('A4:E4')
|
||||||
|
worksheet.mergeCells('A5:E5')
|
||||||
|
worksheet.mergeCells('A7:E7')
|
||||||
|
worksheet.mergeCells('A8:E8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`Detail ${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(worksheet, 3, 1, `Daftar Detail ${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 4, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:P1')
|
||||||
|
worksheet.mergeCells('A3:P3')
|
||||||
|
worksheet.mergeCells('A4:P4')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 6, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(
|
||||||
|
new Blob([buffer], { type: 'application/octet-stream' }),
|
||||||
|
`Laporan Detail ${reportName}.xlsx`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX, exportDetailToPDF, exportDetailToXLSX }
|
@ -0,0 +1,372 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
|
||||||
|
const reportName = 'Rekapitulasi Lapor Ulang Keluhan'
|
||||||
|
const fontSize = 5
|
||||||
|
|
||||||
|
const groupingData = (data: any) => {
|
||||||
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const data = groupingData(rawData)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
mom_bulan_kemarin: 0,
|
||||||
|
mom_bulan_ini: 0,
|
||||||
|
yoy_tahun_kemarin: 0,
|
||||||
|
yoy_tahun_ini: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
let no = 1
|
||||||
|
for (const regional in data) {
|
||||||
|
const summary = data[regional].summary
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: no++, styles: { halign: 'right' } },
|
||||||
|
regional,
|
||||||
|
formatNumber(summary.mom_bulan_kemarin),
|
||||||
|
formatNumber(summary.mom_bulan_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||||
|
),
|
||||||
|
formatNumber(summary.yoy_tahun_kemarin),
|
||||||
|
formatNumber(summary.yoy_tahun_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.mom_bulan_kemarin += summary.mom_bulan_kemarin
|
||||||
|
total.mom_bulan_ini += summary.mom_bulan_ini
|
||||||
|
total.yoy_tahun_kemarin += summary.yoy_tahun_kemarin
|
||||||
|
total.yoy_tahun_ini += summary.yoy_tahun_ini
|
||||||
|
}
|
||||||
|
|
||||||
|
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 day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'No',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Nama Unit',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Lapor Ulang Keluhan',
|
||||||
|
colSpan: 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'MOM',
|
||||||
|
colSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'YOY',
|
||||||
|
colSpan: 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
`${getMonthName(reportMeta.lastMonth)} ${reportMeta.lastYearMoM}`,
|
||||||
|
`${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%',
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.lastYear}`,
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'TOTAL') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:G1')
|
||||||
|
worksheet.mergeCells('A2:G2')
|
||||||
|
worksheet.mergeCells('A3:G3')
|
||||||
|
worksheet.mergeCells('A4:G4')
|
||||||
|
worksheet.mergeCells('A5:G5')
|
||||||
|
worksheet.mergeCells('A7:G7')
|
||||||
|
worksheet.mergeCells('A8:G8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX }
|
@ -0,0 +1,383 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
|
||||||
|
const reportName = 'Recovery Time (RCT) Keluhan'
|
||||||
|
const fontSize = 5
|
||||||
|
|
||||||
|
const groupingData = (data: any) => {
|
||||||
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const data = groupingData(rawData)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
mom_bulan_kemarin: [],
|
||||||
|
mom_bulan_ini: [],
|
||||||
|
yoy_tahun_kemarin: [],
|
||||||
|
yoy_tahun_ini: []
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
let no = 1
|
||||||
|
for (const regional in data) {
|
||||||
|
const summary = data[regional].summary
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: no++, styles: { halign: 'right' } },
|
||||||
|
regional,
|
||||||
|
formatNumber(summary.mom_bulan_kemarin),
|
||||||
|
formatNumber(summary.mom_bulan_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||||
|
),
|
||||||
|
formatNumber(summary.yoy_tahun_kemarin),
|
||||||
|
formatNumber(summary.yoy_tahun_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||||
|
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||||
|
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||||
|
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalMoMBulanKemarin =
|
||||||
|
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||||
|
total.mom_bulan_kemarin.length
|
||||||
|
const totalMoMBulanIni =
|
||||||
|
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||||
|
const totalYoYTahunKemarin =
|
||||||
|
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||||
|
total.yoy_tahun_kemarin.length
|
||||||
|
const totalYoYTahunIni =
|
||||||
|
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||||
|
|
||||||
|
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 day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'No',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Nama Unit',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Jumlah RCT Kali Keluhan',
|
||||||
|
colSpan: 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'MOM',
|
||||||
|
colSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'YOY',
|
||||||
|
colSpan: 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
`${getMonthName(reportMeta.lastMonth)} ${reportMeta.lastYearMoM}`,
|
||||||
|
`${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%',
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.lastYear}`,
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'RATA-RATA') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:G1')
|
||||||
|
worksheet.mergeCells('A2:G2')
|
||||||
|
worksheet.mergeCells('A3:G3')
|
||||||
|
worksheet.mergeCells('A4:G4')
|
||||||
|
worksheet.mergeCells('A5:G5')
|
||||||
|
worksheet.mergeCells('A7:G7')
|
||||||
|
worksheet.mergeCells('A8:G8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX }
|
@ -0,0 +1,383 @@
|
|||||||
|
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'
|
||||||
|
import { Workbook } from 'exceljs'
|
||||||
|
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||||
|
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||||
|
import { getMonthName } from '@/utils/texts'
|
||||||
|
|
||||||
|
const reportName = 'Response Time (RPT) Keluhan'
|
||||||
|
const fontSize = 5
|
||||||
|
|
||||||
|
const groupingData = (data: any) => {
|
||||||
|
const groupedData: any = {}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const data = groupingData(rawData)
|
||||||
|
const formattedData: any = []
|
||||||
|
|
||||||
|
const total: any = {
|
||||||
|
mom_bulan_kemarin: [],
|
||||||
|
mom_bulan_ini: [],
|
||||||
|
yoy_tahun_kemarin: [],
|
||||||
|
yoy_tahun_ini: []
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([{ content: 'NASIONAL', colSpan: 7, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
let no = 1
|
||||||
|
for (const regional in data) {
|
||||||
|
const summary = data[regional].summary
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: no++, styles: { halign: 'right' } },
|
||||||
|
regional,
|
||||||
|
formatNumber(summary.mom_bulan_kemarin),
|
||||||
|
formatNumber(summary.mom_bulan_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.mom_bulan_ini || !summary.mom_bulan_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.mom_bulan_kemarin - summary.mom_bulan_ini) / summary.mom_bulan_kemarin) * 100
|
||||||
|
),
|
||||||
|
formatNumber(summary.yoy_tahun_kemarin),
|
||||||
|
formatNumber(summary.yoy_tahun_ini),
|
||||||
|
formatPercentage(
|
||||||
|
!summary.yoy_tahun_ini || !summary.yoy_tahun_kemarin
|
||||||
|
? '0%'
|
||||||
|
: ((summary.yoy_tahun_kemarin - summary.yoy_tahun_ini) / summary.yoy_tahun_kemarin) * 100
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
total.mom_bulan_kemarin.push(summary.mom_bulan_kemarin)
|
||||||
|
total.mom_bulan_ini.push(summary.mom_bulan_ini)
|
||||||
|
total.yoy_tahun_kemarin.push(summary.yoy_tahun_kemarin)
|
||||||
|
total.yoy_tahun_ini.push(summary.yoy_tahun_ini)
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalMoMBulanKemarin =
|
||||||
|
total.mom_bulan_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||||
|
total.mom_bulan_kemarin.length
|
||||||
|
const totalMoMBulanIni =
|
||||||
|
total.mom_bulan_ini.reduce((a: number, b: number) => a + b, 0) / total.mom_bulan_ini.length
|
||||||
|
const totalYoYTahunKemarin =
|
||||||
|
total.yoy_tahun_kemarin.reduce((a: number, b: number) => a + b, 0) /
|
||||||
|
total.yoy_tahun_kemarin.length
|
||||||
|
const totalYoYTahunIni =
|
||||||
|
total.yoy_tahun_ini.reduce((a: number, b: number) => a + b, 0) / total.yoy_tahun_ini.length
|
||||||
|
|
||||||
|
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 day = new Date().toLocaleString('id-ID', { weekday: 'long' })
|
||||||
|
const date = new Date().getDate()
|
||||||
|
const month = new Date().toLocaleString('id-ID', { month: 'long' })
|
||||||
|
const year = new Date().getFullYear()
|
||||||
|
const data = formatData(rawData)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
['PT. PLN(Persero)', '', ''],
|
||||||
|
[
|
||||||
|
{ content: 'UNIT INDUK', styles: { cellWidth: 40 } },
|
||||||
|
{ content: ':', styles: { cellWidth: 1 } },
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT PELAKSANA PELAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'UNIT LAYANAN PELANGGAN',
|
||||||
|
':',
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'REGIONAL',
|
||||||
|
':',
|
||||||
|
reportMeta.regional
|
||||||
|
? reportMeta.regional.name.toUpperCase()
|
||||||
|
: 'Semua Regional'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [[`${reportName}`.toUpperCase()], [reportMeta.periode]],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 23
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'No',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Nama Unit',
|
||||||
|
rowSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'Jumlah RPT Kali Keluhan',
|
||||||
|
colSpan: 6
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: 'MOM',
|
||||||
|
colSpan: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: 'YOY',
|
||||||
|
colSpan: 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
`${getMonthName(reportMeta.lastMonth)} ${reportMeta.lastYearMoM}`,
|
||||||
|
`${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%',
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.lastYear}`,
|
||||||
|
`s.d ${getMonthName(reportMeta.currentMonth)} ${reportMeta.currentYear}`,
|
||||||
|
'%'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
body: data,
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 1,
|
||||||
|
lineColor: [0, 0, 0],
|
||||||
|
lineWidth: 0.1,
|
||||||
|
cellWidth: 'auto'
|
||||||
|
},
|
||||||
|
rowPageBreak: 'auto',
|
||||||
|
headStyles: {
|
||||||
|
fillColor: [192, 192, 192],
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
cellWidth: 'wrap',
|
||||||
|
halign: 'center',
|
||||||
|
valign: 'middle'
|
||||||
|
},
|
||||||
|
bodyStyles: {
|
||||||
|
textColor: [0, 0, 0]
|
||||||
|
},
|
||||||
|
didParseCell: function (data) {
|
||||||
|
if (data.row.section === 'head') {
|
||||||
|
data.cell.text = data.cell.text.map(function (word: any) {
|
||||||
|
return word.toUpperCase()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.cell.text[0] === 'RATA-RATA') {
|
||||||
|
for (const key in data.row.cells) {
|
||||||
|
data.row.cells[key].styles.fillColor = [192, 192, 192]
|
||||||
|
data.row.cells[key].styles.fontStyle = 'bold'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startY: 30
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${day}, ${date}-${month}-${year}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
content: '(.........................................)',
|
||||||
|
styles: { minCellHeight: 8, valign: 'bottom' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold',
|
||||||
|
halign: 'center'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
tableWidth: 50,
|
||||||
|
margin: { left: 230 }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (preview) {
|
||||||
|
doc.setProperties({
|
||||||
|
title: `${reportName}`
|
||||||
|
})
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToXLSX = (reportMeta: any, e: any) => {
|
||||||
|
const workbook = new Workbook()
|
||||||
|
const worksheet = workbook.addWorksheet(`${reportName}`)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 1, 1, 'PT. PLN(Persero)')
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
`UNIT INDUK : ${
|
||||||
|
reportMeta.uid
|
||||||
|
? reportMeta.uid.name.toUpperCase()
|
||||||
|
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
`UNIT PELAKSANA PELAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.up3
|
||||||
|
? reportMeta.up3.name.toUpperCase()
|
||||||
|
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
`UNIT LAYANAN PELANGGAN : ${
|
||||||
|
reportMeta.ulp
|
||||||
|
? reportMeta.ulp.name.toUpperCase()
|
||||||
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
setHeaderStyle(
|
||||||
|
worksheet,
|
||||||
|
5,
|
||||||
|
1,
|
||||||
|
`REGIONAL : ${
|
||||||
|
reportMeta.regional ? reportMeta.regional.name.toUpperCase() : 'Semua Regional'.toUpperCase()
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
setHeaderStyle(worksheet, 7, 1, `${reportName}`.toUpperCase(), true)
|
||||||
|
setHeaderStyle(worksheet, 8, 1, reportMeta.periode, true)
|
||||||
|
|
||||||
|
worksheet.mergeCells('A1:G1')
|
||||||
|
worksheet.mergeCells('A2:G2')
|
||||||
|
worksheet.mergeCells('A3:G3')
|
||||||
|
worksheet.mergeCells('A4:G4')
|
||||||
|
worksheet.mergeCells('A5:G5')
|
||||||
|
worksheet.mergeCells('A7:G7')
|
||||||
|
worksheet.mergeCells('A8:G8')
|
||||||
|
|
||||||
|
exportToExcel({
|
||||||
|
component: e.component,
|
||||||
|
worksheet,
|
||||||
|
autoFilterEnabled: true,
|
||||||
|
topLeftCell: { row: 10, column: 1 },
|
||||||
|
loadPanel: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||||
|
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), `Laporan ${reportName}.xlsx`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.cancel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF, exportToXLSX }
|
Loading…
x
Reference in New Issue
Block a user