This commit is contained in:
wayanrivan
2025-06-12 17:44:53 +07:00
2 changed files with 21 additions and 12 deletions

View File

@ -1,3 +1,4 @@
// exportFunctions.ts
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import jsPDF from 'jspdf'; import jsPDF from 'jspdf';
import autoTable from 'jspdf-autotable'; import autoTable from 'jspdf-autotable';
@ -6,6 +7,7 @@ import { format } from 'date-fns';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { toAbsoluteUrl } from '@/utils'; import { toAbsoluteUrl } from '@/utils';
// Types
interface WalletData { interface WalletData {
ID?: string; ID?: string;
name?: string; name?: string;
@ -26,6 +28,7 @@ interface TransactionItem {
notes?: string; notes?: string;
} }
// Category mapping
const categoryMap: Record<string, string> = { const categoryMap: Record<string, string> = {
T: 'TRANSFER', T: 'TRANSFER',
P: 'PURCHASE', P: 'PURCHASE',

View File

@ -1,3 +1,4 @@
// ShowDetailWalletDialog.tsx - Versi yang sudah disederhanakan
import React, { createContext, useCallback, useEffect, useState } from 'react'; import React, { createContext, useCallback, useEffect, useState } from 'react';
import { import {
Dialog, Dialog,
@ -149,6 +150,7 @@ const ShowDetailWalletDialog = () => {
} }
]; ];
// Function untuk mendapatkan data transaksi dengan pagination
const getTransactionLists = useCallback( const getTransactionLists = useCallback(
async (page: number, limit: number, sorting: any, _columnFilters: any) => { async (page: number, limit: number, sorting: any, _columnFilters: any) => {
try { try {
@ -179,6 +181,7 @@ const ShowDetailWalletDialog = () => {
[GetData, filters, selectedWallet] [GetData, filters, selectedWallet]
); );
// Function untuk mendapatkan semua data transaksi
const getAllTransactionData = async () => { const getAllTransactionData = async () => {
try { try {
const response = await GetData( const response = await GetData(
@ -200,21 +203,24 @@ const ShowDetailWalletDialog = () => {
} }
}; };
// Function untuk export Excel - sekarang hanya memanggil function terpisah
const doExportExcel = async () => { const doExportExcel = async () => {
try { try {
if (!selectedWallet) { if (!selectedWallet) {
console.error('Something went wrong. Please try again...'); console.error('Something went wrong. Please try again...');
return; return;
}
const allData = await getAllTransactionData();
await exportToExcel(allData, selectedWallet);
} catch (error) {
console.error('Error in doExportExcel:', error);
toast.error('Failed to export Excel');
} }
};
const allData = await getAllTransactionData();
await exportToExcel(allData, selectedWallet);
} catch (error) {
console.error('Error in doExportExcel:', error);
toast.error('Failed to export Excel');
}
};
// Function untuk export PDF - sekarang hanya memanggil function terpisah
const doExportPDF = async () => { const doExportPDF = async () => {
try { try {
if (!selectedWallet) { if (!selectedWallet) {