mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
Merge branch 'development' into fix/daily-checklist
This commit is contained in:
@@ -183,6 +183,9 @@ const TransferToLayingsTable = () => {
|
|||||||
|
|
||||||
const isFilterActive = filterCount > 0;
|
const isFilterActive = filterCount > 0;
|
||||||
|
|
||||||
|
const [isLoadingExportingToExcel, setIsLoadingExportingToExcel] =
|
||||||
|
useState(false);
|
||||||
|
|
||||||
// Modal hooks
|
// Modal hooks
|
||||||
const filterModal = useModal();
|
const filterModal = useModal();
|
||||||
const deleteModal = useModal();
|
const deleteModal = useModal();
|
||||||
@@ -453,9 +456,12 @@ const TransferToLayingsTable = () => {
|
|||||||
updateFilter('status', '');
|
updateFilter('status', '');
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: add export to excel functionality
|
const exportToExcelHandler = async () => {
|
||||||
const exportToExcelHandler = () => {
|
setIsLoadingExportingToExcel(true);
|
||||||
toast.error('Not implemented yet');
|
|
||||||
|
await TransferToLayingApi.exportToExcel(getTableFilterQueryString());
|
||||||
|
|
||||||
|
setIsLoadingExportingToExcel(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -615,6 +621,7 @@ const TransferToLayingsTable = () => {
|
|||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='none'
|
color='none'
|
||||||
onClick={exportToExcelHandler}
|
onClick={exportToExcelHandler}
|
||||||
|
isLoading={isLoadingExportingToExcel}
|
||||||
className='w-full p-3 justify-start text-sm text-base-content/50 font-semibold text-nowrap'
|
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} />
|
<Icon icon='heroicons:table-cells' width={20} height={20} />
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import * as XLSX from 'xlsx';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { BaseApiService } from '@/services/api/base';
|
import { BaseApiService } from '@/services/api/base';
|
||||||
import {
|
import {
|
||||||
@@ -11,12 +12,14 @@ import {
|
|||||||
TransferToLaying,
|
TransferToLaying,
|
||||||
UpdateTransferToLayingPayload,
|
UpdateTransferToLayingPayload,
|
||||||
} from '@/types/api/production/transfer-to-laying';
|
} from '@/types/api/production/transfer-to-laying';
|
||||||
import { httpClient } from '@/services/http/client';
|
import { httpClient, httpClientFetcher } from '@/services/http/client';
|
||||||
import {
|
import {
|
||||||
ProjectFlockAvailableQuantity,
|
ProjectFlockAvailableQuantity,
|
||||||
ProjectFlockMaxQuantity,
|
ProjectFlockMaxQuantity,
|
||||||
} from '@/types/api/production/project-flock';
|
} from '@/types/api/production/project-flock';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import { formatDate } from '@/lib/helper';
|
||||||
|
|
||||||
export class TransferToLayingService extends BaseApiService<
|
export class TransferToLayingService extends BaseApiService<
|
||||||
TransferToLaying,
|
TransferToLaying,
|
||||||
@@ -221,6 +224,60 @@ export class TransferToLayingService extends BaseApiService<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async exportToExcel(initialQueryString: string) {
|
||||||
|
const params = new URLSearchParams(initialQueryString);
|
||||||
|
|
||||||
|
params.set('limit', '9999999');
|
||||||
|
|
||||||
|
const queryString = `?${params.toString()}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const transferToLayings = await httpClientFetcher<
|
||||||
|
BaseApiResponse<TransferToLaying[]>
|
||||||
|
>(`${this.basePath}${queryString}`);
|
||||||
|
|
||||||
|
if (isResponseError(transferToLayings)) {
|
||||||
|
toast.error('Gagal melakukan export transfer to laying! Coba lagi.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = transferToLayings.data;
|
||||||
|
|
||||||
|
const formattedRows = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
formattedRows.push({
|
||||||
|
id: rows[i].id,
|
||||||
|
transfer_number: rows[i].transfer_number,
|
||||||
|
transfer_date: formatDate(rows[i].transfer_date, 'DD-MM-YYYY'),
|
||||||
|
project_flock_source: rows[i].from_project_flock.flock_name,
|
||||||
|
project_flock_target: rows[i].to_project_flock.flock_name,
|
||||||
|
pending_usage_qty: rows[i].pending_usage_qty,
|
||||||
|
usage_qty: rows[i].usage_qty,
|
||||||
|
project_flock_source_kandang: rows[i].sources
|
||||||
|
.map((item) => item.source_project_flock_kandang.kandang.name)
|
||||||
|
.join(', '),
|
||||||
|
project_flock_target_kandang: rows[i].targets
|
||||||
|
.map((item) => item.target_project_flock_kandang.kandang.name)
|
||||||
|
.join(', '),
|
||||||
|
created_user: rows[i].created_user.name,
|
||||||
|
created_at: formatDate(rows[i].created_at, 'DD-MM-YYYY'),
|
||||||
|
updated_at: formatDate(rows[i].updated_at, 'DD-MM-YYYY'),
|
||||||
|
notes: rows[i].notes,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const ws = XLSX.utils.json_to_sheet(formattedRows);
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, 'transfer-ke-laying');
|
||||||
|
|
||||||
|
// triggers download in browser
|
||||||
|
XLSX.writeFile(wb, 'transfer-ke-laying.xlsx');
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Gagal melakukan export transfer to laying! Coba lagi.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getApprovalHistory(
|
async getApprovalHistory(
|
||||||
transferToLayingId: number,
|
transferToLayingId: number,
|
||||||
group: boolean = true,
|
group: boolean = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user