Merge branch 'dev-bagus' of https://github.com/defuj/eis into dev-defuj
This commit is contained in:
commit
6a7621b435
@ -5545,10 +5545,6 @@ body {
|
||||
grid-column-start: 2;
|
||||
}
|
||||
|
||||
.sm\:m-8 {
|
||||
margin: 2rem;
|
||||
}
|
||||
|
||||
.sm\:mx-0 {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@reset-form="data = []"
|
||||
@run-search="() => filterData(filters)"
|
||||
:report-button="true"
|
||||
@ -285,18 +286,13 @@ import {
|
||||
DxSummary,
|
||||
DxTotalItem
|
||||
} 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 { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import { exportToPDF, exportToXLSX } from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_ENSGangguan'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -319,6 +315,20 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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 resetData = () => {
|
||||
data.value = []
|
||||
@ -351,6 +361,21 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
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) => {
|
||||
console.error(err)
|
||||
@ -362,30 +387,10 @@ const filterData = async (params: any) => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@reset-form="data = []"
|
||||
@run-search="() => filterData(filters)"
|
||||
:report-button="true"
|
||||
@ -203,7 +204,7 @@
|
||||
:hover-state-enabled="true"
|
||||
@selection-changed="onDataSubSelectionChanged"
|
||||
:column-width="100"
|
||||
@exporting="onExporting"
|
||||
@exporting="onExportingDetail"
|
||||
:allow-column-resizing="true"
|
||||
column-resizing-mode="widget"
|
||||
>
|
||||
@ -500,6 +501,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</DetailDialog>
|
||||
|
||||
<BufferDialog v-if="loadingData || loadingSubData" />
|
||||
</template>
|
||||
|
||||
@ -523,12 +525,6 @@ import {
|
||||
DxSummary,
|
||||
DxTotalItem
|
||||
} 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 { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
|
||||
@ -537,6 +533,13 @@ import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import { getMonthName } from '@/utils/texts'
|
||||
import {
|
||||
exportToPDF,
|
||||
exportToXLSX,
|
||||
exportDetailToPDF,
|
||||
exportDetailToXLSX
|
||||
} from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_GangguanBelumSelesai'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -555,6 +558,15 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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: ''
|
||||
})
|
||||
|
||||
const closeDialog = () => {
|
||||
dialogDetail.value = false
|
||||
@ -589,6 +601,16 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
data.value = []
|
||||
}
|
||||
|
||||
reportMeta.value = {
|
||||
regional: regional,
|
||||
uid: uid,
|
||||
up3: up3,
|
||||
ulp: ulp,
|
||||
bulan: bulan,
|
||||
tahun: tahun,
|
||||
periode: `${bulan.name} ${tahun.name}`
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
@ -600,33 +622,21 @@ const filterData = async (params: any) => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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 onExportingDetail = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
exportDetailToPDF(reportMeta.value, dataSub.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportDetailToXLSX(reportMeta.value, e)
|
||||
} else {
|
||||
}
|
||||
}
|
||||
const getDetail = async () => {
|
||||
const dateValue = filters.value.periode.split(' s/d ')
|
||||
const selected = dataSelected.value
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@reset-form="data = []"
|
||||
@run-search="() => filterData(filters)"
|
||||
:report-button="true"
|
||||
@ -152,17 +153,16 @@ import {
|
||||
DxSummary,
|
||||
DxTotalItem
|
||||
} 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 { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import { getMonthName } from '@/utils/texts'
|
||||
import {
|
||||
exportToPDF,
|
||||
exportToXLSX
|
||||
} from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_GangguanPerJenisGangguan'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -181,6 +181,15 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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: ''
|
||||
})
|
||||
|
||||
const resetData = () => {
|
||||
data.value = []
|
||||
@ -207,6 +216,16 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
data.value = []
|
||||
}
|
||||
|
||||
reportMeta.value = {
|
||||
regional: regional,
|
||||
uid: uid,
|
||||
up3: up3,
|
||||
ulp: ulp,
|
||||
bulan: bulan,
|
||||
tahun: tahun,
|
||||
periode: `${bulan.name} ${tahun.name}`
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
@ -218,30 +237,10 @@ const filterData = async (params: any) => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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 () => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@reset-form="data = []"
|
||||
@run-search="() => filterData(filters)"
|
||||
:report-button="true"
|
||||
@ -7,6 +8,7 @@
|
||||
>
|
||||
<Type2 @update:filters="(value) => (filters = value)" />
|
||||
</Filters>
|
||||
|
||||
<div>
|
||||
<DxDataGrid
|
||||
ref="dataGridRef"
|
||||
@ -379,18 +381,16 @@ import {
|
||||
DxSelection,
|
||||
DxSummary
|
||||
} 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 { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import {
|
||||
exportToPDF,
|
||||
exportToXLSX
|
||||
} from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_JumlahDDRPTRCTGangguan'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -408,6 +408,17 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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: '',
|
||||
currentMonth: currentMonth.value,
|
||||
currentYear: currentYear.value
|
||||
})
|
||||
|
||||
const resetData = () => {
|
||||
data.value = []
|
||||
@ -433,6 +444,18 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
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) => {
|
||||
console.error(err)
|
||||
@ -447,30 +470,10 @@ const filterData = async (params: any) => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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 () => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@reset-form="data = []"
|
||||
@run-search="() => filterData(filters)"
|
||||
:report-button="true"
|
||||
@ -287,18 +288,13 @@ import {
|
||||
DxSummary,
|
||||
DxTotalItem
|
||||
} 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 { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import { exportToPDF, exportToXLSX } from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_LaporUlang'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -321,6 +317,20 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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 resetData = () => {
|
||||
data.value = []
|
||||
@ -353,6 +363,21 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
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) => {
|
||||
console.error(err)
|
||||
@ -363,30 +388,10 @@ const filterData = async (params: any) => {
|
||||
}
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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 () => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
:report-button="true"
|
||||
@reset-form="data = []"
|
||||
@run-search="() => filterData(filters)"
|
||||
@ -270,6 +271,7 @@
|
||||
</template>
|
||||
</DxDataGrid>
|
||||
</div>
|
||||
|
||||
<BufferDialog v-if="loadingData || loadingSubData" />
|
||||
</template>
|
||||
|
||||
@ -292,18 +294,16 @@ import {
|
||||
DxSummary,
|
||||
DxTotalItem
|
||||
} 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 { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import {
|
||||
exportToPDF,
|
||||
exportToXLSX
|
||||
} from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_RecoveryTimeGangguan'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -326,6 +326,20 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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 resetData = () => {
|
||||
data.value = []
|
||||
@ -358,6 +372,21 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
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) => {
|
||||
console.error(err)
|
||||
@ -369,30 +398,10 @@ const filterData = async (params: any) => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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 () => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<Filters
|
||||
@run-report="() => exportToPDF(reportMeta, data, true)"
|
||||
@reset-form="data = []"
|
||||
:report-button="true"
|
||||
@run-search="() => filterData(filters)"
|
||||
@ -270,6 +271,7 @@
|
||||
</template>
|
||||
</DxDataGrid>
|
||||
</div>
|
||||
|
||||
<BufferDialog v-if="loadingData || loadingSubData" />
|
||||
</template>
|
||||
|
||||
@ -292,18 +294,16 @@ import {
|
||||
DxSummary,
|
||||
DxTotalItem
|
||||
} 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 { queries, requestGraphQl } from '@/utils/api/api.graphql'
|
||||
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
|
||||
import { apolloClient } from '@/utils/api/api.graphql'
|
||||
import { provideApolloClient } from '@vue/apollo-composable'
|
||||
import BufferDialog from '@/components/Dialogs/BufferDialog.vue'
|
||||
import {
|
||||
exportToPDF,
|
||||
exportToXLSX
|
||||
} from '@/report/Monalisa/Gangguan/Rekap/MonalisaGR_ResponseTimeGangguan'
|
||||
|
||||
const client = apolloClient()
|
||||
provideApolloClient(client)
|
||||
@ -326,6 +326,20 @@ const dialogDetail = ref(false)
|
||||
const closedialogDetail = () => (dialogDetail.value = false)
|
||||
const loadingData = 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 resetData = () => {
|
||||
data.value = []
|
||||
@ -358,6 +372,21 @@ const filterData = async (params: any) => {
|
||||
} else {
|
||||
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) => {
|
||||
console.error(err)
|
||||
@ -369,30 +398,10 @@ const filterData = async (params: any) => {
|
||||
|
||||
const onExporting = (e: any) => {
|
||||
if (e.format === 'pdf') {
|
||||
const doc = new jsPDF()
|
||||
|
||||
exportToPdf({
|
||||
jsPDFDocument: doc,
|
||||
component: e.component,
|
||||
indent: 5
|
||||
}).then(() => {
|
||||
doc.save(`.pdf`)
|
||||
})
|
||||
exportToPDF(reportMeta.value, data.value)
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} 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 () => {
|
||||
|
372
src/report/Monalisa/Gangguan/Rekap/MonalisaGR_ENSGangguan.ts
Normal file
372
src/report/Monalisa/Gangguan/Rekap/MonalisaGR_ENSGangguan.ts
Normal file
@ -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 ENS Gangguan'
|
||||
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: 'ENS 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,493 @@
|
||||
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 Gangguan 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_gangguan: 0,
|
||||
jumlah_informasi: 0,
|
||||
total: 0
|
||||
}
|
||||
}
|
||||
|
||||
groupedData[regional].summary.jumlah_gangguan += item.jumlah_gangguan
|
||||
groupedData[regional].summary.jumlah_informasi += item.jumlah_informasi
|
||||
groupedData[regional].summary.total += item.total
|
||||
})
|
||||
}
|
||||
|
||||
return groupedData
|
||||
}
|
||||
|
||||
const formatData = (rawData: any) => {
|
||||
const data = groupingData(rawData)
|
||||
const formattedData: any = []
|
||||
|
||||
const total: any = {
|
||||
jumlah_gangguan: 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_gangguan),
|
||||
formatNumber(summary.jumlah_informasi),
|
||||
formatNumber(summary.total)
|
||||
])
|
||||
|
||||
total.jumlah_gangguan += summary.jumlah_gangguan
|
||||
total.jumlah_informasi += summary.jumlah_informasi
|
||||
total.total += summary.total
|
||||
}
|
||||
|
||||
formattedData.push([
|
||||
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||
formatNumber(total.jumlah_gangguan),
|
||||
formatNumber(total.jumlah_informasi),
|
||||
formatNumber(total.total)
|
||||
])
|
||||
|
||||
return formattedData
|
||||
}
|
||||
|
||||
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||
const 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
|
||||
}
|
||||
],
|
||||
['Gangguan', '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 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 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,286 @@
|
||||
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 = 'Rekapitulasi Gangguan Per Jenis Gangguan'
|
||||
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_gangguan,
|
||||
data.nama_jenis_gangguan,
|
||||
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)
|
||||
])
|
||||
|
||||
formattedData.push([
|
||||
{
|
||||
content: 'ENS',
|
||||
colSpan: 3
|
||||
},
|
||||
{
|
||||
content: '19.169.174,65',
|
||||
colSpan: 2
|
||||
}
|
||||
])
|
||||
|
||||
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 Gangguan'
|
||||
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 Gangguan',
|
||||
colSpan: 12
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
content: getMonthName(reportMeta.currentMonth) + ' ' + reportMeta.currentYear,
|
||||
colSpan: 6
|
||||
},
|
||||
{
|
||||
content:
|
||||
's.d' + ' ' + getMonthName(reportMeta.currentMonth) + ' ' + reportMeta.currentYear,
|
||||
colSpan: 6
|
||||
}
|
||||
],
|
||||
[
|
||||
'Total RPT',
|
||||
'Jumlah Gangguan',
|
||||
'RPT Gangguan',
|
||||
'Total RCT',
|
||||
'Jumlah Gangguan',
|
||||
'RCT Gangguan',
|
||||
'Total RPT',
|
||||
'Jumlah Gangguan',
|
||||
'RPT Gangguan',
|
||||
'Total RCT',
|
||||
'Jumlah Gangguan',
|
||||
'RCT Gangguan'
|
||||
],
|
||||
['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 }
|
@ -21,7 +21,7 @@ import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||
import { getMonthName } from '@/utils/texts'
|
||||
|
||||
const reportName = 'Rekapitulasi Gangguan All'
|
||||
const reportName = 'Jumlah Kali Gangguan'
|
||||
const fontSize = 5
|
||||
const detailFontSize = 3
|
||||
|
||||
|
372
src/report/Monalisa/Gangguan/Rekap/MonalisaGR_LaporUlang.ts
Normal file
372
src/report/Monalisa/Gangguan/Rekap/MonalisaGR_LaporUlang.ts
Normal file
@ -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 Gangguan'
|
||||
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 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,384 @@
|
||||
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 { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||
import { getMonthName } from '@/utils/texts'
|
||||
|
||||
const reportName = 'Recovery Time (RCT) Gangguan'
|
||||
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 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] === '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,384 @@
|
||||
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 { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||
import { setHeaderStyle } from '@/report/utils/xlsx'
|
||||
import { formatNumber, formatPercentage } from '@/utils/numbers'
|
||||
import { getMonthName } from '@/utils/texts'
|
||||
|
||||
const reportName = 'Response Time (RPT) Gangguan'
|
||||
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 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] === '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