feat: create export pdf in detail rekapitulasi gangguan all

This commit is contained in:
kur0nek-o
2024-03-29 11:15:14 +07:00
parent 1298e83671
commit f2acec6845
3 changed files with 167 additions and 6 deletions

View File

@ -2,9 +2,9 @@ VITE_BASE_URL=http://localhost:5173
VITE_BASE_DIRECTORY=/
VITE_APP_VERSION=0.0.1
VITE_APP_NAME='Executive Information System'
VITE_APP_GRAPHQL_ENDPOINT=http://127.0.0.1:32169/graphql
# VITE_APP_GRAPHQL_ENDPOINT=http://127.0.0.1:32169/graphql
# VITE_APP_REST_ENDPOINT=http://192.168.191.163:32180
# VITE_APP_GRAPHQL_ENDPOINT=http://10.1.50.173:32180/graphql
VITE_APP_GRAPHQL_ENDPOINT=http://10.1.50.173:32180/graphql
# VITE_APP_GRAPHQL_ENDPOINT=http://192.168.137.46:32169/graphql
VITE_APP_REST_ENDPOINT=http://10.1.50.173:32181

View File

@ -584,7 +584,7 @@
:hover-state-enabled="true"
@selection-changed="onDataSubSelectionChanged"
:column-width="100"
@exporting="onExporting"
@exporting="onExportingDetail"
:allow-column-resizing="true"
column-resizing-mode="widget"
>
@ -1080,7 +1080,7 @@ import DetailDialog from '@/components/Dialogs/DetailDialog.vue'
import InputText from '@/components/InputText.vue'
import { apolloClient } from '@/utils/api/api.graphql'
import { provideApolloClient } from '@vue/apollo-composable'
import { exportToPDF, exportToXLSX } from '@/report/Gangguan/Rekap/RGangguan_ALL'
import { exportToPDF, exportToXLSX, exportDetailToPDF } from '@/report/Gangguan/Rekap/RGangguan_ALL'
const client = apolloClient()
provideApolloClient(client)
@ -1249,6 +1249,15 @@ const onExporting = (e: any) => {
}
}
const onExportingDetail = (e: any) => {
if (e.format === 'pdf') {
exportDetailToPDF(reportMeta.value, dataSub.value)
} else if (e.format === 'xlsx') {
// exportToXLSX(reportMeta.value, e)
} else {
}
}
const onDataSelectionChanged = ({ selectedRowsData }: any) => {
if (selectedRowsData[0] != undefined) {
dataSelected.value = selectedRowsData[0]

View File

@ -21,6 +21,8 @@ import { setHeaderStyle } from '@/report/utils/xlsx'
import { formatNumber, formatPercentage } from '@/utils/numbers'
const reportName = 'Rekapitulasi Gangguan All'
const fontSize = 5
const detailFontSize = 3
const groupingData = (data: any) => {
const groupedData: any = {}
@ -289,7 +291,6 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
const doc = new jsPDF({
orientation: 'landscape'
})
const fontSize = 5
autoTable(doc, {
head: [
@ -470,6 +471,157 @@ const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) =>
}
}
const exportDetailToPDF = (reportMeta: any, rawData: any) => {
const meta = formatMetaData(reportMeta)
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()],
[`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`]
],
styles: {
fontSize: detailFontSize,
cellPadding: 0.1,
textColor: [0, 0, 0],
fontStyle: 'bold',
halign: 'center'
},
theme: 'plain',
startY: 18,
margin: 5
})
autoTable(doc, {
head: [
[
'No',
'Posko',
'No Lapor',
'Tgl/Jam Lapor',
'Tgl/Jam Datang',
'Tgl/Jam Nyala',
'Durasi Response Time',
'Durasi Recovery Time',
'Durasi Penugasan Regu',
'Durasi Perjalanan Regu',
'Jarak Closing (m)',
'Dispatch Oleh',
'IDPEL/NO METER',
'Nama Pelapor',
'Alamat Pelapor',
'No Telp Pelapor',
'Keterangan Pelapor',
'Sumber Lapor',
'Diselesaikan Oleh',
'Status',
'Referensi Marking',
'Kode Gangguan',
'Jenis Gangguan',
'Penyebab',
'Tindakan'
]
],
body: rawData.map((item: any, i: any) => [
{ content: i + 1, styles: { halign: 'right' } },
item.nama_posko,
item.no_laporan,
item.waktu_lapor,
item.waktu_response,
item.waktu_recovery,
item.durasi_response_time,
item.durasi_recovery_time,
'',
'',
item.jarak_closing,
item.dispatch_oleh,
item.idpel_nometer,
item.nama_pelapor,
item.alamat_pelapor,
item.no_telp_pelapor,
item.keterangan_pelapor,
item.pembuat_laporan,
item.diselesaikan_oleh,
item.status_akhir,
item.referensi_marking,
item.kode_gangguan,
item.jenis_gangguan,
item.penyebab,
item.tindakan
]),
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: [
[`${meta.dayTo}, ${meta.dateToFormat}`],
[
{
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 }
})
window.open(doc.output('bloburl'))
// doc.save(`Laporan Detail ${reportName}.pdf`, { returnPromise: true }).then(() => {
// console.log('pdf berhasil disimpan')
// })
}
const exportToXLSX = (reportMeta: any, e: any) => {
const meta = formatMetaData(reportMeta)
const workbook = new Workbook()
@ -535,4 +687,4 @@ const exportToXLSX = (reportMeta: any, e: any) => {
e.cancel = true
}
export { exportToPDF, exportToXLSX }
export { exportToPDF, exportToXLSX, exportDetailToPDF }