feat: create pdf export in daftar keluhan dialihkan ke posko lain

This commit is contained in:
kur0nek-o 2024-03-12 22:29:42 +07:00
parent e9b05e76d0
commit f3dfec2dd0

View File

@ -1,56 +1,175 @@
<template>
<Filters @reset-form="data = []" @run-search="() => filterData(filters)" class="mb-4">
<Type3 @update:filters="(value) => filters = value" />
<Type3 @update:filters="(value) => (filters = value)" />
</Filters>
<div id="data">
<DxDataGrid class="max-h-[calc(100vh-140px)] mb-10" :data-source="data" :show-column-lines="true"
:show-row-lines="false" :show-borders="true" :row-alternation-enabled="true" :hover-state-enabled="true"
@selection-changed="onSelectionChanged" :column-width="100" @exporting="onExporting" :allow-column-resizing="true"
column-resizing-mode="widget" :word-wrap-enabled="true">
<DxDataGrid
class="max-h-[calc(100vh-140px)] mb-10"
:data-source="data"
:show-column-lines="true"
:show-row-lines="false"
:show-borders="true"
:row-alternation-enabled="true"
:hover-state-enabled="true"
@selection-changed="onSelectionChanged"
:column-width="100"
@exporting="onExporting"
:allow-column-resizing="true"
column-resizing-mode="widget"
:word-wrap-enabled="true"
>
<DxSelection mode="single" />
<DxPaging :page-size="5" :enabled="true" />
<DxPager :visible="true" :allowed-page-sizes="[5, 10, 20]" display-mode="full" :show-page-size-selector="true"
:show-info="true" :show-navigation-buttons="true" />
<DxLoadPanel :position="position" :show-indicator="showIndicator" :show-pane="showPane" :shading="shading"
v-if="loading" v-model:visible="loading" :enabled="true" />
<DxPager
:visible="true"
:allowed-page-sizes="[5, 10, 20]"
display-mode="full"
:show-page-size-selector="true"
:show-info="true"
:show-navigation-buttons="true"
/>
<DxLoadPanel
:position="position"
:show-indicator="showIndicator"
:show-pane="showPane"
:shading="shading"
v-if="loading"
v-model:visible="loading"
:enabled="true"
/>
<DxSearchPanel :visible="true" :highlight-case-sensitive="true" />
<DxExport :enabled="true" :formats="['pdf', 'xlsx', 'document']" :allow-export-selected-data="false" />
<DxExport
:enabled="true"
:formats="['pdf', 'xlsx', 'document']"
:allow-export-selected-data="false"
/>
<DxColumnFixing :enabled="true" />
<DxColumn css-class="custom-table-column !align-top" :width="50" alignment="center"
:calculateCellValue="(item: any) => data.findIndex((i) => i == item) + 1" data-type="number" caption="No"
cell-template="cellRight" />
<DxColumn :width="170" alignment="center" data-field="no_laporan" caption="No Laporan"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="170" alignment="center" data-field="pembuat_laporan" caption="Pembuat Laporan"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="170" alignment="center" data-field="waktu_lapor" caption="Tgl Lapor"
css-class="custom-table-column !align-top" />
<DxColumn :width="170" alignment="center" data-field="waktu_dialihkan" caption="Tgl Dialihkan"
css-class="custom-table-column !align-top" />
<DxColumn :width="170" alignment="center" data-field="waktu_response" caption="Tgl Response"
css-class="custom-table-column !align-top" />
<DxColumn :width="170" alignment="center" data-field="waktu_recovery" caption="Tgl Recovery"
css-class="custom-table-column !align-top" />
<DxColumn :width="170" alignment="center" data-field="durasi_response_time" caption="Durasi Response Time"
css-class="custom-table-column !align-top" cell-template="data-waktu" />
<DxColumn :width="170" alignment="center" data-field="durasi_recovery_time" caption="Durasi Recovery Time"
css-class="custom-table-column !align-top" cell-template="data-waktu" />
<DxColumn :width="170" alignment="center" data-field="nama_unit_lama" caption="Unit Asal"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="120" alignment="center" data-field="status_akhir" caption="Status"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="170" alignment="center" data-field="idpel_nometer" caption="IDPEL/NO METER"
css-class="custom-table-column !align-top" />
<DxColumn :width="170" alignment="center" data-field="nama_pelapor" caption="Nama Pelapor"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="170" alignment="center" data-field="alamat_pelapor" caption="Alamat Pelapor"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="170" alignment="center" data-field="no_telp_pelapor" caption="No Telp Pelapor"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn :width="170" alignment="center" data-field="keterangan_pelapor" caption="Keterangan Pelapor"
css-class="custom-table-column !align-top" cell-template="cellLeft" />
<DxColumn
css-class="custom-table-column !align-top"
:width="50"
alignment="center"
:calculateCellValue="(item: any) => data.findIndex((i) => i == item) + 1"
data-type="number"
caption="No"
cell-template="cellRight"
/>
<DxColumn
:width="170"
alignment="center"
data-field="no_laporan"
caption="No Laporan"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="170"
alignment="center"
data-field="pembuat_laporan"
caption="Pembuat Laporan"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="170"
alignment="center"
data-field="waktu_lapor"
caption="Tgl Lapor"
css-class="custom-table-column !align-top"
/>
<DxColumn
:width="170"
alignment="center"
data-field="waktu_dialihkan"
caption="Tgl Dialihkan"
css-class="custom-table-column !align-top"
/>
<DxColumn
:width="170"
alignment="center"
data-field="waktu_response"
caption="Tgl Response"
css-class="custom-table-column !align-top"
/>
<DxColumn
:width="170"
alignment="center"
data-field="waktu_recovery"
caption="Tgl Recovery"
css-class="custom-table-column !align-top"
/>
<DxColumn
:width="170"
alignment="center"
data-field="durasi_response_time"
caption="Durasi Response Time"
css-class="custom-table-column !align-top"
cell-template="data-waktu"
/>
<DxColumn
:width="170"
alignment="center"
data-field="durasi_recovery_time"
caption="Durasi Recovery Time"
css-class="custom-table-column !align-top"
cell-template="data-waktu"
/>
<DxColumn
:width="170"
alignment="center"
data-field="nama_unit_lama"
caption="Unit Asal"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="120"
alignment="center"
data-field="status_akhir"
caption="Status"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="170"
alignment="center"
data-field="idpel_nometer"
caption="IDPEL/NO METER"
css-class="custom-table-column !align-top"
/>
<DxColumn
:width="170"
alignment="center"
data-field="nama_pelapor"
caption="Nama Pelapor"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="170"
alignment="center"
data-field="alamat_pelapor"
caption="Alamat Pelapor"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="170"
alignment="center"
data-field="no_telp_pelapor"
caption="No Telp Pelapor"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<DxColumn
:width="170"
alignment="center"
data-field="keterangan_pelapor"
caption="Keterangan Pelapor"
css-class="custom-table-column !align-top"
cell-template="cellLeft"
/>
<template #cellCenter="{ data }">
<p class="cursor-pointer">
@ -66,9 +185,13 @@
<template #cellRight="{ data }">
<p class="text-right cursor-pointer">
{{ isNumber(data.text) ? data.column.caption == '%' ? formatPercentage(data.text) :
formatNumber(data.text) :
data.text }}
{{
isNumber(data.text)
? data.column.caption == '%'
? formatPercentage(data.text)
: formatNumber(data.text)
: data.text
}}
</p>
</template>
@ -97,7 +220,6 @@ import {
DxSearchPanel,
DxSelection
} 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'
@ -106,6 +228,8 @@ import { useQuery } from '@vue/apollo-composable'
import { queries } from '@/utils/api/api.graphql'
import { dummyData } from '@/utils/dummy'
import { formatNumber, formatPercentage, isNumber } from '@/utils/numbers'
import { jsPDF } from 'jspdf'
import autoTable from 'jspdf-autotable'
const position = { of: '#data' }
const showIndicator = ref(true)
@ -114,18 +238,58 @@ const showPane = ref(true)
const onExporting = (e: any) => {
if (e.format === 'pdf') {
const doc = new jsPDF()
exportToPdf({
jsPDFDocument: doc,
component: e.component,
indent: 5
}).then(() => {
doc.save(`.pdf`)
const doc = new jsPDF({
orientation: 'landscape'
})
autoTable(doc, {
head: [
[
'No Laporan',
'Pembuat Laporan',
'Tgl Lapor',
'Tgl Dialihkan',
'Tgl Response',
'Tgl Recovery',
'Durasi Response Time',
'Durasi Recovery Time',
'Posko Asal',
'Posko Tujuan',
'Status',
'IDPEL/NO METER',
'Nama Pelapor',
'Alamat Pelapor',
'No Telp Pelapor',
'Keterangan Pelapor'
]
],
body: data.value.map((item: any) => [
item.no_laporan,
item.pembuat_laporan,
item.waktu_lapor,
item.waktu_dialihkan,
item.waktu_response,
item.waktu_recovery,
item.durasi_response_time,
item.durasi_recovery_time,
item.nama_unit_lama,
item.nama_unit_tujuan,
item.status_akhir,
item.idpel_nometer,
item.nama_pelapor,
item.alamat_pelapor,
item.no_telp_pelapor,
item.keterangan_pelapor
]),
styles: {
fontSize: 4
}
})
doc.save('Daftar Gangguan Dialihkan Ke Posko Lain.pdf')
} else {
const workbook = new Workbook()
const worksheet = workbook.addWorksheet('Employees')
const worksheet = workbook.addWorksheet('Daftar Gangguan Dialihkan Ke Posko Lain')
exportToExcel({
component: e.component,
@ -133,7 +297,10 @@ const onExporting = (e: any) => {
autoFilterEnabled: true
}).then(() => {
workbook.xlsx.writeBuffer().then((buffer: any) => {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'DataGrid.xlsx')
saveAs(
new Blob([buffer], { type: 'application/octet-stream' }),
'Daftar Gangguan Dialihkan Ke Posko Lain.xlsx'
)
})
})