mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat: implement export product stock log
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user