radja terakhir

This commit is contained in:
Raja Oktafrianto
2025-06-05 19:04:37 +07:00
parent 3ab4a8a8e0
commit 86e9811c5a
4 changed files with 149 additions and 104 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

View File

@ -119,7 +119,7 @@ const AddDialog = () => {
} }
const response = await GetData(`${API_URL_CUSTOMER}/customer/list`, { const response = await GetData(`${API_URL_CUSTOMER}/customer/list`, {
limit: 100, limit: 1000,
page: 1, page: 1,
with_deleted: false, with_deleted: false,
order_field: 'fullname', order_field: 'fullname',

View File

@ -158,7 +158,7 @@ const ManageNotifContextProvider = ({ children }: { children: React.ReactNode })
const getNotificationList = async (page: number, limit: number, sorting: any, filter: any) => { const getNotificationList = async (page: number, limit: number, sorting: any, filter: any) => {
try { try {
const sortField = sorting.length > 0 ? sorting[0].id : 'created_at'; const sortField = sorting.length > 0 ? sorting[0].id : 'created_at';
const sortDirection = sorting.length > 0 ? (sorting[0].desc ? 'DESC' : 'ASC') : 'DESC'; const sortDirection = sorting.length > 0 ? (sorting[0].desc ? 'ASC' : 'DESC') : 'ASC';
// Initialize filter object // Initialize filter object
let filterParams: any = {}; let filterParams: any = {};
@ -219,7 +219,7 @@ const ManageNotifContextProvider = ({ children }: { children: React.ReactNode })
pagination={{ size: 10 }} pagination={{ size: 10 }}
toolbar={<ListToolBar />} toolbar={<ListToolBar />}
layout={{ card: true }} layout={{ card: true }}
sorting={[{ id: 'created_at', desc: true }]} sorting={[{ id: 'created_at', desc: false }]}
serverSide={true} serverSide={true}
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
getNotificationList(pageIndex, pageSize, sorting, columnFilters) getNotificationList(pageIndex, pageSize, sorting, columnFilters)

View File

@ -11,13 +11,19 @@ import { useCallApi } from '@/hooks';
import { apiConfig } from '@/config/api.config'; import { apiConfig } from '@/config/api.config';
import { DataGridColumnHeader, DataGridProvider } from '@/components'; import { DataGridColumnHeader, DataGridProvider } from '@/components';
import { useManageStatementContext } from '../hooks/useManageWalletStatementContext'; import { useManageStatementContext } from '../hooks/useManageWalletStatementContext';
import { Toaster } from 'sonner'; import { toast, Toaster } from 'sonner';
import { format } from 'date-fns'; import { format } from 'date-fns';
import FilterSection from './FilterSection'; import FilterSection from './FilterSection';
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import jsPDF from 'jspdf'; import jsPDF from 'jspdf';
import 'jspdf-autotable'; import 'jspdf-autotable';
interface AutoTableData {
pageNumber: number;
table: any;
doc: jsPDF;
}
interface ContextProps { interface ContextProps {
doExportData: (sorting: any, filter: any) => Promise<any>; doExportData: (sorting: any, filter: any) => Promise<any>;
doExportExcel: () => Promise<void>; doExportExcel: () => Promise<void>;
@ -379,32 +385,67 @@ const ShowDetailWalletDialog = () => {
} }
}; };
const doExportPDF = async () => { // Perbaikan untuk fungsi doExportPDF
const doExportPDF = async () => {
try { try {
// Import jsPDF dengan cara yang benar
const jsPDF = (await import('jspdf')).default;
// Import autoTable plugin
const autoTable = (await import('jspdf-autotable')).default;
const allData = await getAllTransactionData(); const allData = await getAllTransactionData();
const formattedData = formatTransactionData(allData); const formattedData = formatTransactionData(allData);
const pdf = new jsPDF('l', 'mm', 'a4'); // Buat instance jsPDF
const pdf = new jsPDF({
orientation: 'landscape', // Ubah ke landscape untuk tabel yang lebar
unit: 'mm',
format: 'a4'
});
pdf.setFontSize(20); // Header perusahaan
pdf.setFontSize(18);
pdf.setFont('helvetica', 'bold'); pdf.setFont('helvetica', 'bold');
pdf.text('T•PAY', 148, 20, { align: 'center' }); pdf.text('T•PAY', pdf.internal.pageSize.getWidth() / 2, 20, { align: 'center' });
pdf.setFontSize(12); pdf.setFontSize(12);
pdf.setFont('helvetica', 'normal'); pdf.setFont('helvetica', 'normal');
pdf.text('Telin Digital Solution', 148, 30, { align: 'center' }); pdf.text('Telin Digital Solution', pdf.internal.pageSize.getWidth() / 2, 28, { align: 'center' });
pdf.text('Av. Pres. Nicolau Lobato, Dili', 148, 36, { align: 'center' }); pdf.text('Av. Pres. Nicolau Lobato, Dili', pdf.internal.pageSize.getWidth() / 2, 34, { align: 'center' });
pdf.text('Tel : (+670) 7414747 / 147', 148, 42, { align: 'center' }); pdf.text('Tel: (+670) 74147147 / 147', pdf.internal.pageSize.getWidth() / 2, 40, { align: 'center' });
pdf.text('www.t-pay.tl', 148, 48, { align: 'center' }); pdf.text('www.t-pay.tl', pdf.internal.pageSize.getWidth() / 2, 46, { align: 'center' });
pdf.setFontSize(14); // Garis pemisah
pdf.setDrawColor(0, 0, 0);
pdf.setLineWidth(0.5);
pdf.line(20, 52, pdf.internal.pageSize.getWidth() - 20, 52);
// Judul laporan
pdf.setFontSize(16);
pdf.setFont('helvetica', 'bold'); pdf.setFont('helvetica', 'bold');
pdf.text('Wallet Statement Details', 148, 60, { align: 'center' }); pdf.text('Wallet Statement Details', pdf.internal.pageSize.getWidth() / 2, 62, { align: 'center' });
// Informasi tambahan
pdf.setFontSize(10); pdf.setFontSize(10);
pdf.setFont('helvetica', 'normal'); pdf.setFont('helvetica', 'normal');
pdf.text(`Export Date: ${format(new Date(), 'dd MMM yyyy HH:mm:ss')}`, 20, 70); pdf.text(`Export Date: ${format(new Date(), 'dd MMM yyyy HH:mm:ss')}`, 20, 72);
pdf.text(`Wallet ID: ${selectedWallet?.ID || '-'}`, 20, 76); pdf.text(`Wallet ID: ${selectedWallet?.ID || '-'}`, 20, 78);
// Siapkan data tabel
const tableHeaders = [
'Transaction Code',
'MSISDN Reffer',
'Transaction Type',
'Type',
'Pre Amount',
'Amount',
'Post Amount',
'Category',
'Date',
'Purpose',
'Notes'
];
const tableData = formattedData.map((item) => [ const tableData = formattedData.map((item) => [
item['Transaction Code'], item['Transaction Code'],
@ -420,57 +461,61 @@ const ShowDetailWalletDialog = () => {
item['Notes'] item['Notes']
]); ]);
(pdf as any).autoTable({ // Gunakan autoTable dengan cara yang benar
head: [ autoTable(pdf, {
[ head: [tableHeaders],
'Transaction Code',
'MSISDN Reffer',
'Transaction Type',
'Type',
'Pre Amount',
'Amount',
'Post Amount',
'Category',
'Date',
'Purpose',
'Notes'
]
],
body: tableData, body: tableData,
startY: 85, startY: 85,
styles: { styles: {
fontSize: 8, fontSize: 7,
cellPadding: 2 cellPadding: 2,
overflow: 'linebreak',
halign: 'center'
}, },
headStyles: { headStyles: {
fillColor: [66, 66, 66], fillColor: [68, 114, 196],
textColor: [255, 255, 255], textColor: [255, 255, 255],
fontStyle: 'bold' fontStyle: 'bold',
halign: 'center'
}, },
columnStyles: { columnStyles: {
0: { cellWidth: 20 }, 0: { cellWidth: 25, halign: 'left' }, // Transaction Code
1: { cellWidth: 20 }, 1: { cellWidth: 20, halign: 'left' }, // MSISDN Reffer
2: { cellWidth: 25 }, 2: { cellWidth: 25, halign: 'left' }, // Transaction Type
3: { cellWidth: 15 }, 3: { cellWidth: 15, halign: 'center' }, // Type
4: { cellWidth: 18 }, 4: { cellWidth: 18, halign: 'right' }, // Pre Amount
5: { cellWidth: 18 }, 5: { cellWidth: 18, halign: 'right' }, // Amount
6: { cellWidth: 18 }, 6: { cellWidth: 18, halign: 'right' }, // Post Amount
7: { cellWidth: 25 }, 7: { cellWidth: 20, halign: 'left' }, // Category
8: { cellWidth: 25 }, 8: { cellWidth: 30, halign: 'left' }, // Date
9: { cellWidth: 30 }, 9: { cellWidth: 25, halign: 'left' }, // Purpose
10: { cellWidth: 30 } 10: { cellWidth: 25, halign: 'left' } // Notes
}, },
margin: { top: 85, left: 10, right: 10 } margin: { top: 85, left: 10, right: 10 },
tableWidth: 'auto',
// Callback untuk styling baris
didDrawCell: (data: any) => {
// Tambahkan border pada setiap cell
if (data.section === 'body') {
pdf.setDrawColor(200, 200, 200);
pdf.setLineWidth(0.1);
}
}
}); });
// Generate nama file
const fileName = `wallet_statement_${selectedWallet?.ID}_${format(new Date(), 'yyyyMMdd_HHmmss')}.pdf`; const fileName = `wallet_statement_${selectedWallet?.ID}_${format(new Date(), 'yyyyMMdd_HHmmss')}.pdf`;
// Save file
pdf.save(fileName); pdf.save(fileName);
// console.log('PDF export completed successfully'); toast.success('PDF exported successfully');
} catch (error) { } catch (error) {
console.error('Error exporting to PDF:', error); console.error('Error exporting to PDF:', error);
toast.error('Failed to export PDF');
} }
}; };
const doExportData = async (sorting: any, filter: any) => { const doExportData = async (sorting: any, filter: any) => {
const user = localStorage.getItem( const user = localStorage.getItem(