feat: create export pdf in rekapitulasi gangguan koreksi transaksi individual
This commit is contained in:
parent
98527693a7
commit
358e99b968
File diff suppressed because it is too large
Load Diff
279
src/report/Gangguan/Rekap/RGangguan_KTI.ts
Normal file
279
src/report/Gangguan/Rekap/RGangguan_KTI.ts
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
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 } from '@/utils/numbers'
|
||||||
|
|
||||||
|
const reportName = 'Rekapitulasi Koreksi Transaksi Individual'
|
||||||
|
|
||||||
|
const formatData = (rawData: any) => {
|
||||||
|
const formattedData: any = []
|
||||||
|
const total: any = {
|
||||||
|
month1: 0,
|
||||||
|
month2: 1,
|
||||||
|
month3: 0,
|
||||||
|
month4: 0,
|
||||||
|
month5: 0,
|
||||||
|
month6: 0,
|
||||||
|
month7: 0,
|
||||||
|
month8: 0,
|
||||||
|
month9: 0,
|
||||||
|
month10: 0,
|
||||||
|
month11: 0,
|
||||||
|
month12: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedData.push([{ content: 'SELURUH UNIT', colSpan: 14, styles: { fontStyle: 'bold' } }])
|
||||||
|
|
||||||
|
formattedData.push(
|
||||||
|
...rawData.map((item: any, i: any) => {
|
||||||
|
total.month1 += item.month1
|
||||||
|
total.month2 += item.month2
|
||||||
|
total.month3 += item.month3
|
||||||
|
total.month4 += item.month4
|
||||||
|
total.month5 += item.month5
|
||||||
|
total.month6 += item.month6
|
||||||
|
total.month7 += item.month7
|
||||||
|
total.month8 += item.month8
|
||||||
|
total.month9 += item.month9
|
||||||
|
total.month10 += item.month10
|
||||||
|
total.month11 += item.month11
|
||||||
|
total.month12 += item.month12
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ content: ++i, styles: { halign: 'right' } },
|
||||||
|
item.nama_uid,
|
||||||
|
formatNumber(item.month1),
|
||||||
|
formatNumber(item.month2),
|
||||||
|
formatNumber(item.month3),
|
||||||
|
formatNumber(item.month4),
|
||||||
|
formatNumber(item.month5),
|
||||||
|
formatNumber(item.month6),
|
||||||
|
formatNumber(item.month7),
|
||||||
|
formatNumber(item.month8),
|
||||||
|
formatNumber(item.month9),
|
||||||
|
formatNumber(item.month10),
|
||||||
|
formatNumber(item.month11),
|
||||||
|
formatNumber(item.month12)
|
||||||
|
]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
formattedData.push([
|
||||||
|
{ content: 'TOTAL', colSpan: 2, styles: { fontStyle: 'bold' } },
|
||||||
|
total.month1,
|
||||||
|
total.month2,
|
||||||
|
total.month3,
|
||||||
|
total.month4,
|
||||||
|
total.month5,
|
||||||
|
total.month6,
|
||||||
|
total.month7,
|
||||||
|
total.month8,
|
||||||
|
total.month9,
|
||||||
|
total.month10,
|
||||||
|
total.month11,
|
||||||
|
total.month12
|
||||||
|
])
|
||||||
|
|
||||||
|
return formattedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatMetaData = (reportMeta: any) => {
|
||||||
|
const periode = reportMeta.periode ? reportMeta.periode.split(' s/d ') : ''
|
||||||
|
|
||||||
|
let dateFromFormat = ''
|
||||||
|
let dateToFormat = ''
|
||||||
|
let dayTo = ''
|
||||||
|
|
||||||
|
if (periode != '') {
|
||||||
|
const dateFrom = new Date(periode[0].split('-').reverse().join('-'))
|
||||||
|
const dateTo = new Date(periode[1].split('-').reverse().join('-'))
|
||||||
|
|
||||||
|
dateFromFormat = `${dateFrom.getDate()}-${dateFrom.toLocaleString('default', {
|
||||||
|
month: 'long'
|
||||||
|
})}-${dateFrom.getFullYear()}`
|
||||||
|
|
||||||
|
dateToFormat = `${dateTo.getDate()}-${dateTo.toLocaleString('default', {
|
||||||
|
month: 'long'
|
||||||
|
})}-${dateTo.getFullYear()}`
|
||||||
|
|
||||||
|
dayTo = dateTo.toLocaleString('default', { weekday: 'long' })
|
||||||
|
}
|
||||||
|
|
||||||
|
return { dateFromFormat, dateToFormat, dayTo }
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportToPDF = (reportMeta: any, rawData: any, preview: boolean = false) => {
|
||||||
|
const data = formatData(rawData)
|
||||||
|
console.log(data)
|
||||||
|
const meta = formatMetaData(reportMeta)
|
||||||
|
const doc = new jsPDF({
|
||||||
|
orientation: 'landscape'
|
||||||
|
})
|
||||||
|
const fontSize = 5
|
||||||
|
|
||||||
|
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()
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'POSKO',
|
||||||
|
':',
|
||||||
|
reportMeta.posko ? reportMeta.posko.name.toUpperCase() : 'Semua Posko'.toUpperCase()
|
||||||
|
]
|
||||||
|
],
|
||||||
|
styles: {
|
||||||
|
fontSize,
|
||||||
|
cellPadding: 0.1,
|
||||||
|
textColor: [0, 0, 0],
|
||||||
|
fontStyle: 'bold'
|
||||||
|
},
|
||||||
|
theme: 'plain',
|
||||||
|
startY: 10
|
||||||
|
})
|
||||||
|
|
||||||
|
autoTable(doc, {
|
||||||
|
head: [
|
||||||
|
[`${reportName}`.toUpperCase()],
|
||||||
|
[`PERIODE TANGGAL : ${meta.dateFromFormat} SD TGL ${meta.dateToFormat}`]
|
||||||
|
],
|
||||||
|
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: 'Bulan',
|
||||||
|
colSpan: 12
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Januari',
|
||||||
|
'Februari',
|
||||||
|
'Maret',
|
||||||
|
'April',
|
||||||
|
'Mei',
|
||||||
|
'Juni',
|
||||||
|
'Juli',
|
||||||
|
'Agustus',
|
||||||
|
'September',
|
||||||
|
'Oktober',
|
||||||
|
'November',
|
||||||
|
'Desember'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
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: [
|
||||||
|
[`${meta.dayTo}, ${meta.dateToFormat}`],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
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) {
|
||||||
|
window.open(doc.output('bloburl'))
|
||||||
|
} else {
|
||||||
|
doc.save(`Laporan ${reportName}.pdf`, { returnPromise: true }).then(() => {
|
||||||
|
console.log('pdf berhasil disimpan')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { exportToPDF }
|
Loading…
x
Reference in New Issue
Block a user