feat: create export doc in laporan cico
This commit is contained in:
parent
a4d1d9574d
commit
0b85dcf211
@ -888,7 +888,9 @@ import {
|
||||
exportToPDF,
|
||||
exportToXLSX,
|
||||
exportDetailToPDF,
|
||||
exportDetailToXLSX
|
||||
exportDetailToXLSX,
|
||||
exportToDOCX,
|
||||
exportDetailToDOCX
|
||||
} from '@/report/Cico/LaporanCICO'
|
||||
|
||||
const client = apolloClient()
|
||||
@ -967,6 +969,7 @@ const onExporting = (e: any) => {
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportToXLSX(reportMeta.value, e)
|
||||
} else {
|
||||
exportToDOCX(reportMeta.value, data.value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -976,6 +979,7 @@ const onExportingDetail = (e: any) => {
|
||||
} else if (e.format === 'xlsx') {
|
||||
exportDetailToXLSX(reportMeta.value, e)
|
||||
} else {
|
||||
exportDetailToDOCX(reportMeta.value, dataSub.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,10 @@ 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 { formatNumber } from '@/utils/numbers'
|
||||
import { exportToWord, exportDetailToWord } from './doc/LaporanCICO'
|
||||
|
||||
const reportName = 'Laporan Check In Check Out (CICO)'
|
||||
const reportName = 'Check In Check Out (CICO)'
|
||||
const fontSize = 5
|
||||
const detailFontSize = 3
|
||||
|
||||
@ -537,4 +538,21 @@ const exportDetailToXLSX = (reportMeta: any, e: any) => {
|
||||
e.cancel = true
|
||||
}
|
||||
|
||||
export { exportToPDF, exportToXLSX, exportDetailToPDF, exportDetailToXLSX }
|
||||
const exportToDOCX = (reportMeta: any, rawData: any) => {
|
||||
const meta = formatMetaData(reportMeta)
|
||||
exportToWord(reportMeta, meta, formatData(rawData), reportName)
|
||||
}
|
||||
|
||||
const exportDetailToDOCX = (reportMeta: any, rawData: any) => {
|
||||
const meta = formatMetaData(reportMeta)
|
||||
exportDetailToWord(meta, rawData, reportName)
|
||||
}
|
||||
|
||||
export {
|
||||
exportToPDF,
|
||||
exportToXLSX,
|
||||
exportDetailToPDF,
|
||||
exportDetailToXLSX,
|
||||
exportToDOCX,
|
||||
exportDetailToDOCX
|
||||
}
|
||||
|
334
src/report/Cico/doc/LaporanCICO.ts
Normal file
334
src/report/Cico/doc/LaporanCICO.ts
Normal file
@ -0,0 +1,334 @@
|
||||
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
||||
|
||||
export const exportToWord = (
|
||||
rawMeta: any,
|
||||
formattedMeta: any,
|
||||
rawData: any,
|
||||
reportName: String
|
||||
) => {
|
||||
const filename = 'Laporan ' + reportName + '.doc'
|
||||
|
||||
let tbody = ''
|
||||
|
||||
for (let index = 0; index < rawData.length; index++) {
|
||||
const element = rawData[index]
|
||||
|
||||
let column = `<tr>`
|
||||
let styleTotal = ''
|
||||
|
||||
for (let i = 0; i < element.length; i++) {
|
||||
const content = element[i]
|
||||
const colSpan = content?.colSpan !== undefined ? `colspan="${content.colSpan}"` : ''
|
||||
|
||||
if (content && (content.content === 'TOTAL' || content.content === 'GRAND TOTAL')) {
|
||||
styleTotal = 'style="background-color: #c0c0c0; font-weight: bold;"'
|
||||
}
|
||||
|
||||
i === 0
|
||||
? (column += `<th ${styleTotal} ${colSpan} align="left">${content.content || content}</th>`)
|
||||
: (column += `<td ${styleTotal}>${content}</td>`)
|
||||
}
|
||||
|
||||
column += `</tr>`
|
||||
tbody += column
|
||||
}
|
||||
|
||||
let preHtml = `
|
||||
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>${reportName}</title>
|
||||
<style type="text/css" media="print">
|
||||
@page Section1 {
|
||||
size:841.95pt 21.0cm;
|
||||
mso-page-orientation:landscape;
|
||||
margin:72.0pt 72.0pt 72.0pt 72.0pt;
|
||||
mso-header-margin:35.4pt;
|
||||
mso-footer-margin:35.4pt;
|
||||
mso-paper-source:0;
|
||||
}
|
||||
|
||||
div.Section1 {
|
||||
page:Section1;
|
||||
}
|
||||
|
||||
table.meta tr td {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table.main {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
text-transform: uppercase;
|
||||
font-size: 8px;
|
||||
}
|
||||
|
||||
table.main thead tr {
|
||||
background-color: #c0c0c0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
`
|
||||
|
||||
const body = `
|
||||
<div class=Section1>
|
||||
<header>
|
||||
<h6>PT. PLN(Persero)</h6>
|
||||
|
||||
<table class="meta">
|
||||
<tr>
|
||||
<td><h6>UNIT INDUK</h6></td>
|
||||
<td><h6>:</h6></td>
|
||||
<td><h6>${
|
||||
rawMeta.uid
|
||||
? rawMeta.uid.name.toUpperCase()
|
||||
: 'Semua Unit Induk Distribusi/Wilayah'.toUpperCase()
|
||||
}</h6></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><h6>UNIT PELAKSANA PELAYANAN PELANGGAN</h6></td>
|
||||
<td><h6>:</h6></td>
|
||||
<td><h6>${
|
||||
rawMeta.up3
|
||||
? rawMeta.up3.name.toUpperCase()
|
||||
: 'Semua Unit Pelaksanaan Pelayanan Pelanggan'.toUpperCase()
|
||||
}</h6></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><h6>POSKO</h6></td>
|
||||
<td><h6>:</h6></td>
|
||||
<td><h6>${
|
||||
rawMeta.posko ? rawMeta.posko.name.toUpperCase() : 'Semua Posko'.toUpperCase()
|
||||
}</h6></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<th><h6>${reportName.toUpperCase()}</h6></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><h6>${`PERIODE TANGGAL : ${formattedMeta.dateFromFormat} SD TGL ${formattedMeta.dateToFormat}`}</h6></th>
|
||||
</tr>
|
||||
</table>
|
||||
</header>
|
||||
|
||||
<br>
|
||||
|
||||
<table border="1" class="main">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User Regu</th>
|
||||
<th>Personil Yantek</th>
|
||||
<th>Jumlah WO Gangguan Individual</th>
|
||||
<th>Rata-rata Durasi WO Gangguan</th>
|
||||
<th>Rata-rata RPT WO Gangguan</th>
|
||||
<th>Rata-rata RCT WO Gangguan</th>
|
||||
<th>Jumlah WO Penugasan Khusus</th>
|
||||
<th>Rata-rata WO Penugasan Khusus</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>${tbody}</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<footer>
|
||||
<p style="text-align: right; font-size: 10px;">${formattedMeta.dayTo}, ${formattedMeta.dateToFormat}</p>
|
||||
<br>
|
||||
<p style="text-align: right; font-size: 10px;">(.........................................)</p>
|
||||
</footer>
|
||||
</div>
|
||||
`
|
||||
|
||||
const postHtml = '</body></html>'
|
||||
const html = preHtml + body + postHtml
|
||||
const url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html)
|
||||
const downloadLink = document.createElement('a')
|
||||
|
||||
document.body.appendChild(downloadLink)
|
||||
downloadLink.href = url
|
||||
downloadLink.download = filename
|
||||
downloadLink.click()
|
||||
document.body.removeChild(downloadLink)
|
||||
}
|
||||
|
||||
export const exportDetailToWord = (formattedMeta: any, rawData: any, reportName: String) => {
|
||||
const filename = 'Laporan Detail ' + reportName + '.doc'
|
||||
|
||||
let preHtml = `
|
||||
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Daftar Detail ${reportName}</title>
|
||||
<style type="text/css" media="print">
|
||||
@page Section1 {
|
||||
size:841.95pt 21.0cm;
|
||||
mso-page-orientation:landscape;
|
||||
margin:1.0cm 1.0cm 1.0cm 1.0cm;
|
||||
mso-header-margin:35.4pt;
|
||||
mso-footer-margin:35.4pt;
|
||||
mso-paper-source:0;
|
||||
}
|
||||
|
||||
div.Section1 {
|
||||
page:Section1;
|
||||
}
|
||||
|
||||
table.meta tr td {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table.main {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
text-transform: uppercase;
|
||||
font-size: 5px;
|
||||
}
|
||||
|
||||
table.main thead tr {
|
||||
background-color: #c0c0c0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
`
|
||||
|
||||
const body = `
|
||||
<div class=Section1>
|
||||
<header>
|
||||
<h6>PT. PLN(Persero)</h6>
|
||||
<br>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<th><h6>${'DAFTAR DETAIL ' + reportName.toUpperCase()}</h6></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><h6>${`PERIODE TANGGAL : ${formattedMeta.dateFromFormat} SD TGL ${formattedMeta.dateToFormat}`}</h6></th>
|
||||
</tr>
|
||||
</table>
|
||||
</header>
|
||||
|
||||
<br>
|
||||
|
||||
<table border="1" class="main">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>UID/UIW</th>
|
||||
<th>UP3</th>
|
||||
<th>Posko</th>
|
||||
<th>Sumber Lapor</th>
|
||||
<th>Create By</th>
|
||||
<th>Dispacth By</th>
|
||||
<th>User Regu</th>
|
||||
<th>Nama Regu</th>
|
||||
<th>Nama Petugas</th>
|
||||
<th>Shift</th>
|
||||
<th>Check In Petugas</th>
|
||||
<th>No Laporan</th>
|
||||
<th>Tgl Lapor</th>
|
||||
<th>Tgl Penugasan Baru</th>
|
||||
<th>Tgl Dalam Perjalanan</th>
|
||||
<th>Tgl Pengerjaan</th>
|
||||
<th>Tgl Nyala Sementara</th>
|
||||
<th>Tgl Nyala</th>
|
||||
<th>Tgl Selesai</th>
|
||||
<th>Durasi Perjalanan</th>
|
||||
<th>Durasi WO</th>
|
||||
<th>Check Out Petugas</th>
|
||||
<th>RPT</th>
|
||||
<th>RCT</th>
|
||||
<th>Rating</th>
|
||||
<th>Jml Pelanggan Padam</th>
|
||||
<th>Fasilitas</th>
|
||||
<th>Sub Fasilitas</th>
|
||||
<th>Peralatan</th>
|
||||
<th>Dampak Kerusakan</th>
|
||||
<th>Penyebab</th>
|
||||
<th>Kelompok Penyebab</th>
|
||||
<th>Cuaca</th>
|
||||
<th>Keterangan Pelapor</th>
|
||||
<th>Keterangan</th>
|
||||
<th>Penyebab Padam</th>
|
||||
<th>Tindakan</th>
|
||||
<th>APKT Status</th>
|
||||
<th>Referensi Marking</th>
|
||||
<th>BLTH</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${rawData
|
||||
.map(
|
||||
(item: any, i: any) => `
|
||||
<tr>
|
||||
<td>${i + 1}</td>
|
||||
<td>${item.nama_uid}</td>
|
||||
<td>${item.nama_up3}</td>
|
||||
<td>${item.nama_posko}</td>
|
||||
<td>${item.media}</td>
|
||||
<td>${item.pembuat_laporan}</td>
|
||||
<td>${item.dispacth_by}</td>
|
||||
<td>${item.waktu_dispacth}</td>
|
||||
<td>${item.user_regu}</td>
|
||||
<td>${item.nama_regu}</td>
|
||||
<td>${item.personil_yantek}</td>
|
||||
<td>${item.shift}</td>
|
||||
<td>${item.check_in_petugas}</td>
|
||||
<td>${item.no_laporan}</td>
|
||||
<td>${item.waktu_lapor}</td>
|
||||
<td>${item.waktu_dispacth}</td>
|
||||
<td>${item.waktu_perjalanan}</td>
|
||||
<td>${item.waktu_response}</td>
|
||||
<td>${item.waktu_nyala_sementara}</td>
|
||||
<td>${item.waktu_nyala}</td>
|
||||
<td>${item.waktu_selesai}</td>
|
||||
<td>${item.durasi_waktu_response}</td>
|
||||
<td>${item.durasi_wo}</td>
|
||||
<td>${item.check_out_petugas}</td>
|
||||
<td>${item.durasi_menit_response}</td>
|
||||
<td>${item.durasi_menit_recovery}</td>
|
||||
<td>${item.rating}</td>
|
||||
<td>${item.jml_pelanggan_padam}</td>
|
||||
<td>${item.fasilitas}</td>
|
||||
<td>${item.sub_fasilitas}</td>
|
||||
<td>${item.peralatan}</td>
|
||||
<td>${item.dampak_kerusakan}</td>
|
||||
<td>${item.penyebab}</td>
|
||||
<td>${item.kelompok_penyebab}</td>
|
||||
<td>${item.cuaca}</td>
|
||||
<td>${item.keterangan_pelapor}</td>
|
||||
<td>${item.keterangan}</td>
|
||||
<td>${item.penyebab_padam}</td>
|
||||
<td>${item.tindakan}</td>
|
||||
<td>${item.status_akhir}</td>
|
||||
<td>${item.referensi_marking}</td>
|
||||
<td>${item.blth}</td>
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<footer>
|
||||
<p style="text-align: right; font-size: 10px;">${formattedMeta.dayTo}, ${formattedMeta.dateToFormat}</p>
|
||||
<br>
|
||||
<p style="text-align: right; font-size: 10px;">(.........................................)</p>
|
||||
</footer>
|
||||
</div>
|
||||
`
|
||||
|
||||
const postHtml = '</body></html>'
|
||||
const html = preHtml + body + postHtml
|
||||
const url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html)
|
||||
const downloadLink = document.createElement('a')
|
||||
|
||||
document.body.appendChild(downloadLink)
|
||||
downloadLink.href = url
|
||||
downloadLink.download = filename
|
||||
downloadLink.click()
|
||||
document.body.removeChild(downloadLink)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user