mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat: implement purchase export to excel
This commit is contained in:
@@ -192,6 +192,8 @@ const PurchaseTable = () => {
|
|||||||
|
|
||||||
// ===== STATE MANAGEMENT =====
|
// ===== STATE MANAGEMENT =====
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
|
const [isLoadingExportingToExcel, setIsLoadingExportingToExcel] =
|
||||||
|
useState(false);
|
||||||
const [isExportProgressLoading, setIsExportProgressLoading] = useState(false);
|
const [isExportProgressLoading, setIsExportProgressLoading] = useState(false);
|
||||||
const [selectedPurchase, setSelectedPurchase] = useState<Purchase | null>(
|
const [selectedPurchase, setSelectedPurchase] = useState<Purchase | null>(
|
||||||
null
|
null
|
||||||
@@ -475,6 +477,20 @@ const PurchaseTable = () => {
|
|||||||
updateFilter('approval_status', '');
|
updateFilter('approval_status', '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const exportToExcel = useCallback(async () => {
|
||||||
|
setIsLoadingExportingToExcel(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await PurchaseApi.exportToExcel(getTableFilterQueryString());
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
await getExportErrorMessage(error, 'Gagal mengekspor data pembelian')
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setIsLoadingExportingToExcel(false);
|
||||||
|
}
|
||||||
|
}, [getTableFilterQueryString]);
|
||||||
|
|
||||||
const resetExportProgressForm = useCallback(() => {
|
const resetExportProgressForm = useCallback(() => {
|
||||||
setExportProgressStartDate('');
|
setExportProgressStartDate('');
|
||||||
setExportProgressEndDate('');
|
setExportProgressEndDate('');
|
||||||
@@ -610,6 +626,17 @@ const PurchaseTable = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
<Button
|
||||||
|
variant='ghost'
|
||||||
|
color='none'
|
||||||
|
onClick={exportToExcel}
|
||||||
|
isLoading={isLoadingExportingToExcel}
|
||||||
|
className='w-full p-3 justify-start text-sm text-base-content/50 font-semibold text-nowrap'
|
||||||
|
>
|
||||||
|
<Icon icon='heroicons:table-cells' width={20} height={20} />
|
||||||
|
Ekspor ke Excel
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='none'
|
color='none'
|
||||||
|
|||||||
@@ -115,6 +115,33 @@ export const PurchaseApi = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async exportToExcel(initialQueryString: string) {
|
||||||
|
const params = new URLSearchParams(initialQueryString);
|
||||||
|
|
||||||
|
params.set('export', 'excel');
|
||||||
|
params.set('type', 'all');
|
||||||
|
params.set('page', '1');
|
||||||
|
params.set('limit', '99999999999');
|
||||||
|
|
||||||
|
const queryString = `?${params.toString()}`;
|
||||||
|
|
||||||
|
const res = await httpClient<Blob>(`${this.basePath}${queryString}`, {
|
||||||
|
method: 'GET',
|
||||||
|
responseType: 'blob',
|
||||||
|
});
|
||||||
|
|
||||||
|
const url = window.URL.createObjectURL(new Blob([res]));
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
|
||||||
|
const fileName = `pembelian-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`;
|
||||||
|
link.setAttribute('download', fileName);
|
||||||
|
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
},
|
||||||
|
|
||||||
async exportInputProgressToExcel(startDate: string, endDate: string) {
|
async exportInputProgressToExcel(startDate: string, endDate: string) {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user