361 lines
11 KiB
TypeScript
361 lines
11 KiB
TypeScript
import { formatWaktu } from '@/components/Form/FiltersType/reference'
|
|
|
|
export const exportToWord = (
|
|
rawMeta: any,
|
|
formattedMeta: any,
|
|
rawData: any,
|
|
reportName: String
|
|
) => {
|
|
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 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>UNIT LAYANAN PELANGGAN</h6></td>
|
|
<td><h6>:</h6></td>
|
|
<td><h6>${
|
|
rawMeta.ulp
|
|
? rawMeta.ulp.name.toUpperCase()
|
|
: 'Semua Unit Layanan Pelanggan'.toUpperCase()
|
|
}</h6></td>
|
|
</tr>
|
|
<tr>
|
|
<td><h6>JENIS LAPORAN</h6></td>
|
|
<td><h6>:</h6></td>
|
|
<td><h6>${rawMeta.jenisLaporan.name.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 rowspan="4">Nama Unit</th>
|
|
<th colspan="5">Total WO</th>
|
|
<th colspan="6">Total Pengaduan Yang Diselesaikan Secara Anomali</th>
|
|
<th colspan="6">% Pengaduan Yang Diselesaikan Secara Anomali</th>
|
|
</tr>
|
|
<tr>
|
|
<th>CC 123</th>
|
|
<th>PLN Mobile</th>
|
|
<th>Loket</th>
|
|
<th>Lainnya</th>
|
|
<th>Total</th>
|
|
<th colspan="2">PLN Mobile</th>
|
|
<th colspan="2">CC 123</th>
|
|
<th colspan="2">Total</th>
|
|
<th colspan="2">PLN Mobile</th>
|
|
<th colspan="2">CC 123</th>
|
|
<th colspan="2">Total</th>
|
|
</tr>
|
|
<tr>
|
|
<th rowspan="2">a</th>
|
|
<th rowspan="2">b</th>
|
|
<th rowspan="2">c</th>
|
|
<th rowspan="2">d</th>
|
|
<th rowspan="2">e=a+b+c+d</th>
|
|
<th colspan="2">f</th>
|
|
<th colspan="2">g</th>
|
|
<th colspan="2">h=f+g</th>
|
|
<th colspan="2">i=f/e</th>
|
|
<th colspan="2">j=g/e</th>
|
|
<th colspan="2">k=i+j</th>
|
|
</tr>
|
|
<tr>
|
|
<th>Marking</th>
|
|
<th>Non Marking</th>
|
|
<th>Marking</th>
|
|
<th>Non Marking</th>
|
|
<th>Marking</th>
|
|
<th>Non Marking</th>
|
|
<th>Marking</th>
|
|
<th>Non Marking</th>
|
|
<th>Marking</th>
|
|
<th>Non Marking</th>
|
|
<th>Marking</th>
|
|
<th>Non Marking</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>${tbody}</tbody>
|
|
</table>
|
|
<br>
|
|
<footer>
|
|
<p style="text-align: right; font-size: 10px;">${day}, ${date}-${month}-${year}</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 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 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>UIW/D</th>
|
|
<th>UP3</th>
|
|
<th>Rayon</th>
|
|
<th>No Laporan</th>
|
|
<th>No Laporan Referensi</th>
|
|
<th>Tgl/Jam Lapor</th>
|
|
<th>Tgl/Jam Datang</th>
|
|
<th>Tgl/Jam Nyala</th>
|
|
<th>Durasi Response Time</th>
|
|
<th>Durasi Recovery Time</th>
|
|
<th>Durasi Penugasan Regu</th>
|
|
<th>Durasi Perjalanan Regu</th>
|
|
<th>Jarak Closing</th>
|
|
<th>Dispacth Oleh</th>
|
|
<th>IDPEL/NO METER</th>
|
|
<th>Nama Pelapor</th>
|
|
<th>Alamat Pelapor</th>
|
|
<th>No Telp Pelapor</th>
|
|
<th>Keterangan Pelapor</th>
|
|
<th>Sumber Lapor</th>
|
|
<th>Diselesaikan Oleh</th>
|
|
<th>Status</th>
|
|
<th>Status Induk</th>
|
|
<th>Referensi Marking Induk</th>
|
|
<th>Kode Gangguan</th>
|
|
<th>Jenis Gangguan</th>
|
|
<th>Penyebab</th>
|
|
<th>Tindakan</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_ulp}</td>
|
|
<td>${item.no_laporan}</td>
|
|
<td>${item.no_laporan_referensi}</td>
|
|
<td>${item.waktu_lapor}</td>
|
|
<td>${item.waktu_response}</td>
|
|
<td>${item.waktu_recovery}</td>
|
|
<td>${item.durasi_response_time ? formatWaktu(item.durasi_response_time) : '-'}</td>
|
|
<td>${item.durasi_recovery_time ? formatWaktu(item.durasi_recovery_time) : '-'}</td>
|
|
<td>${item.durasi_dispatch_time ? formatWaktu(item.durasi_dispatch_time) : '-'}</td>
|
|
<td>${item.durasi_perjalanan ? formatWaktu(item.durasi_perjalanan) : '-'}</td>
|
|
<td>${item.distance}</td>
|
|
<td>${item.dispatch_by}</td>
|
|
<td>${item.idpel_nometer}</td>
|
|
<td>${item.nama_pelapor}</td>
|
|
<td>${item.alamat_pelapor}</td>
|
|
<td>${item.no_telp_pelapor}</td>
|
|
<td>${item.keterangan_pelapor}</td>
|
|
<td>${item.media}</td>
|
|
<td>${item.diselesaikan_oleh}</td>
|
|
<td>${item.status_akhir}</td>
|
|
<td>${item.status_induk}</td>
|
|
<td>${item.referensi_marking_induk}</td>
|
|
<td>${item.kode_gangguan}</td>
|
|
<td>${item.jenis_gangguan}</td>
|
|
<td>${item.penyebab}</td>
|
|
<td>${item.tindakan}</td>
|
|
</tr>
|
|
`
|
|
)
|
|
.join('')}
|
|
</tbody>
|
|
</table>
|
|
<br>
|
|
<footer>
|
|
<p style="text-align: right; font-size: 10px;">${day}, ${date}-${month}-${year}</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)
|
|
}
|