mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
7e6f250864
Add exportToExcelSupplierPerSheet and exportToExcelGeneral methods to LogisticApiService, hitting the existing purchase-supplier endpoint with export=excel / export=excel-all query params and downloading the server blob response. Replace the client-side Excel generation in PurchasesPerSupplierTab with calls to these two service methods, and split the single Export to Excel button into Export to Excel - Supplier Per Sheet and Export to Excel - General.
166 lines
4.6 KiB
TypeScript
166 lines
4.6 KiB
TypeScript
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 { LogisticPurchasePerSupplierReport } from '@/types/api/report/logistic-stock';
|
|
|
|
export class LogisticApiService extends BaseApiService<
|
|
LogisticPurchasePerSupplierReport,
|
|
unknown,
|
|
unknown
|
|
> {
|
|
constructor(basePath: string) {
|
|
super(basePath);
|
|
}
|
|
|
|
private buildPurchaseSupplierParams(
|
|
area_id?: string,
|
|
supplier_id?: string,
|
|
product_id?: string,
|
|
product_category_id?: string,
|
|
start_date?: string,
|
|
end_date?: string,
|
|
sort_by?: string,
|
|
filter_by?: string
|
|
): URLSearchParams {
|
|
const params = new URLSearchParams();
|
|
if (area_id) params.set('area_id', area_id);
|
|
if (supplier_id) params.set('supplier_id', supplier_id);
|
|
if (product_id) params.set('product_id', product_id);
|
|
if (product_category_id)
|
|
params.set('product_category_id', product_category_id);
|
|
if (filter_by === 'received_date' && start_date)
|
|
params.set('received_date', start_date);
|
|
if (filter_by === 'po_date' && start_date)
|
|
params.set('po_date', start_date);
|
|
if (start_date) params.set('start_date', start_date);
|
|
if (end_date) params.set('end_date', end_date);
|
|
if (sort_by) params.set('sort_by', sort_by);
|
|
if (filter_by) params.set('filter_by', filter_by);
|
|
return params;
|
|
}
|
|
|
|
async exportToExcelSupplierPerSheet(
|
|
area_id?: string,
|
|
supplier_id?: string,
|
|
product_id?: string,
|
|
product_category_id?: string,
|
|
start_date?: string,
|
|
end_date?: string,
|
|
sort_by?: string,
|
|
filter_by?: string
|
|
) {
|
|
const params = this.buildPurchaseSupplierParams(
|
|
area_id,
|
|
supplier_id,
|
|
product_id,
|
|
product_category_id,
|
|
start_date,
|
|
end_date,
|
|
sort_by,
|
|
filter_by
|
|
);
|
|
params.set('export', 'excel');
|
|
params.set('page', '1');
|
|
params.set('limit', '99999999999');
|
|
|
|
const res = await httpClient<Blob>(
|
|
`${this.basePath.replace(/\/$/, '')}/purchase-supplier?${params.toString()}`,
|
|
{ method: 'GET', responseType: 'blob' }
|
|
);
|
|
|
|
const url = window.URL.createObjectURL(new Blob([res]));
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.setAttribute(
|
|
'download',
|
|
`laporan-pembelian-per-supplier-per-sheet-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`
|
|
);
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
link.remove();
|
|
}
|
|
|
|
async exportToExcelGeneral(
|
|
area_id?: string,
|
|
supplier_id?: string,
|
|
product_id?: string,
|
|
product_category_id?: string,
|
|
start_date?: string,
|
|
end_date?: string,
|
|
sort_by?: string,
|
|
filter_by?: string
|
|
) {
|
|
const params = this.buildPurchaseSupplierParams(
|
|
area_id,
|
|
supplier_id,
|
|
product_id,
|
|
product_category_id,
|
|
start_date,
|
|
end_date,
|
|
sort_by,
|
|
filter_by
|
|
);
|
|
params.set('export', 'excel-all');
|
|
params.set('page', '1');
|
|
params.set('limit', '99999999999');
|
|
|
|
const res = await httpClient<Blob>(
|
|
`${this.basePath.replace(/\/$/, '')}/purchase-supplier?${params.toString()}`,
|
|
{ method: 'GET', responseType: 'blob' }
|
|
);
|
|
|
|
const url = window.URL.createObjectURL(new Blob([res]));
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.setAttribute(
|
|
'download',
|
|
`laporan-pembelian-per-supplier-general-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`
|
|
);
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
link.remove();
|
|
}
|
|
|
|
async getLogisticPurchasePerSupplierReport(
|
|
area_id?: string,
|
|
supplier_id?: string,
|
|
product_id?: string,
|
|
product_category_id?: string,
|
|
received_date?: string,
|
|
po_date?: string,
|
|
start_date?: string,
|
|
end_date?: string,
|
|
sort_by?: string,
|
|
filter_by?: string,
|
|
page?: number,
|
|
limit?: number
|
|
): Promise<BaseApiResponse<LogisticPurchasePerSupplierReport> | undefined> {
|
|
return await this.customRequest<
|
|
BaseApiResponse<LogisticPurchasePerSupplierReport>
|
|
>(`purchase-supplier`, {
|
|
method: 'GET',
|
|
params: {
|
|
area_id: area_id,
|
|
supplier_id: supplier_id,
|
|
product_id: product_id,
|
|
product_category_id: product_category_id,
|
|
received_date: received_date,
|
|
po_date: po_date,
|
|
start_date: start_date,
|
|
end_date: end_date,
|
|
sort_by: sort_by,
|
|
filter_by: filter_by,
|
|
page: page,
|
|
limit: limit,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
export const LogisticApi = new LogisticApiService('reports');
|
|
|
|
// export const LogisticApi = new LogisticApiService(
|
|
// 'http://localhost:4010/api/reports/logistics'
|
|
// );
|