feat: implement export product stock log

This commit is contained in:
ValdiANS
2026-05-08 18:57:21 +07:00
parent ba3cb98e2c
commit e7f378823c
3 changed files with 115 additions and 23 deletions
+41 -1
View File
@@ -13,7 +13,9 @@ import {
CreateInventoryAdjustmentPayload,
InventoryAdjustment,
} from '@/types/api/inventory/adjustment';
import { InventoryProduct } from '@/types/api/inventory/product';
import { InventoryProduct, StockLog } from '@/types/api/inventory/product';
import { httpClient } from '../http/client';
import { formatDate } from '@/lib/helper';
export const ProductWarehouseApi = new BaseApiService<
ProductWarehouse,
@@ -65,3 +67,41 @@ export const InventoryProductApi = new BaseApiService<
unknown,
unknown
>('/inventory/product-stocks');
export class StockLogService extends BaseApiService<
StockLog,
unknown,
unknown
> {
constructor(basePath: string = '/inventory/stock-logs') {
super(basePath);
}
async exportToExcel(warehouseName: string, initialQueryString: string) {
const params = new URLSearchParams(initialQueryString);
params.set('export', 'excel');
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 = `informasi-stok-produk-${warehouseName.toLowerCase().replaceAll(' ', '-')}-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`;
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
link.remove();
}
}
export const StockLogApi = new StockLogService('/inventory/stock-logs');