From 146192a5b3304b8e30225dc960b155c00bd287c0 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Tue, 19 May 2026 16:06:41 +0700 Subject: [PATCH 1/3] feat: create exportToExcelGeneral method --- src/services/api/report/debt-supplier.ts | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/services/api/report/debt-supplier.ts b/src/services/api/report/debt-supplier.ts index dad46d18..8198cc57 100644 --- a/src/services/api/report/debt-supplier.ts +++ b/src/services/api/report/debt-supplier.ts @@ -1,4 +1,6 @@ import { BaseApiService } from '@/services/api/base'; +import { httpClient } from '@/services/http/client'; +import { formatDate } from '@/lib/helper'; import { BaseApiResponse } from '@/types/api/api-general'; import { DebtSupplier } from '@/types/api/report/debt-supplier'; @@ -11,6 +13,44 @@ export class DebtSupplierApiService extends BaseApiService< super(basePath); } + async exportToExcelGeneral( + supplier_ids?: string, + filter_by?: string, + start_date?: string, + end_date?: string + ) { + const params = new URLSearchParams(); + + if (supplier_ids) params.set('supplier_ids', supplier_ids); + if (filter_by) params.set('filter_by', filter_by); + if (start_date) params.set('start_date', start_date); + if (end_date) params.set('end_date', end_date); + params.set('export', 'excel-all'); + params.set('page', '1'); + params.set('limit', '99999999999'); + + const queryString = `?${params.toString()}`; + + const res = await httpClient( + `${this.basePath.replace(/\/$/, '')}/debt-supplier${queryString}`, + { + method: 'GET', + responseType: 'blob', + } + ); + + const url = window.URL.createObjectURL(new Blob([res])); + const link = document.createElement('a'); + link.href = url; + + const fileName = `laporan-hutang-supplier-general-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`; + link.setAttribute('download', fileName); + + document.body.appendChild(link); + link.click(); + link.remove(); + } + async getDebtSupplierReport( supplier_ids?: string, filter_by?: string, From ce4f50c92ab8110bda07695a8836912b0331537f Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Tue, 19 May 2026 16:06:54 +0700 Subject: [PATCH 2/3] feat: create Export to Excel - General button --- .../report/finance/tab/DebtSupplierTab.tsx | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/components/pages/report/finance/tab/DebtSupplierTab.tsx b/src/components/pages/report/finance/tab/DebtSupplierTab.tsx index 174ff1e2..be2271f2 100644 --- a/src/components/pages/report/finance/tab/DebtSupplierTab.tsx +++ b/src/components/pages/report/finance/tab/DebtSupplierTab.tsx @@ -77,7 +77,10 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => { // ===== STATE MANAGEMENT ===== const [isPdfExportLoading, setIsPdfExportLoading] = useState(false); const [isExcelExportLoading, setIsExcelExportLoading] = useState(false); - const isAnyExportLoading = isPdfExportLoading || isExcelExportLoading; + const [isExcelGeneralExportLoading, setIsExcelGeneralExportLoading] = + useState(false); + const isAnyExportLoading = + isPdfExportLoading || isExcelExportLoading || isExcelGeneralExportLoading; // ===== PAGINATION STATE ===== const [currentPage, setCurrentPage] = useState(1); @@ -308,6 +311,23 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => { formik.values.endDate, ]); + const handleExportExcelGeneral = useCallback(async () => { + setIsExcelGeneralExportLoading(true); + try { + await DebtSupplierApi.exportToExcelGeneral( + filterParams.supplier_ids, + filterParams.filter_by, + filterParams.start_date, + filterParams.end_date + ); + toast.success('Excel General berhasil dibuat dan diunduh.'); + } catch { + toast.error('Gagal membuat Excel General. Silakan coba lagi.'); + } finally { + setIsExcelGeneralExportLoading(false); + } + }, [filterParams]); + // ===== TAB ACTIONS COMPONENT ===== const TabActions = useMemo(() => { return function TabActionsComponent() { @@ -370,7 +390,17 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => { className='w-full p-3 justify-start text-sm text-base-content/50 font-semibold text-nowrap' > - Export to Excel + Export to Excel - Supplier Per Sheet + +