mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
feat(FE-355,356,357): Add PDF export for HPP per kandang report
This commit is contained in:
@@ -23,6 +23,7 @@ import Button from '@/components/Button';
|
||||
import Dropdown from '@/components/dropdown/Dropdown';
|
||||
import MenuItem from '@/components/menu/MenuItem';
|
||||
import Menu from '@/components/menu/Menu';
|
||||
import { generateHppPerKandangPDF } from '../export/HppPerkandangExport';
|
||||
import toast from 'react-hot-toast';
|
||||
import * as XLSX from 'xlsx';
|
||||
|
||||
@@ -380,6 +381,54 @@ const HppPerKandangTab = () => {
|
||||
kandangOptions,
|
||||
]);
|
||||
|
||||
const handleExportPDF = useCallback(async () => {
|
||||
if (!hppPerKandang || !isResponseSuccess(hppPerKandang)) {
|
||||
toast.error('Tidak ada data untuk diekspor.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const areaName = tableFilterState.area_id
|
||||
? areaOptions.find(
|
||||
(opt) => opt.value === Number(tableFilterState.area_id)
|
||||
)?.label || 'Semua Area'
|
||||
: 'Semua Area';
|
||||
|
||||
const locationName = tableFilterState.location_id
|
||||
? locationOptions.find(
|
||||
(opt) => opt.value === Number(tableFilterState.location_id)
|
||||
)?.label || 'Semua Lokasi'
|
||||
: 'Semua Lokasi';
|
||||
|
||||
const kandangName = tableFilterState.kandang_id
|
||||
? kandangOptions.find(
|
||||
(opt) => opt.value === Number(tableFilterState.kandang_id)
|
||||
)?.label || 'Semua Kandang'
|
||||
: 'Semua Kandang';
|
||||
|
||||
await generateHppPerKandangPDF(hppPerKandang.data, {
|
||||
area_name: areaName,
|
||||
location_name: locationName,
|
||||
kandang_name: kandangName,
|
||||
period: tableFilterState.period,
|
||||
weight_min: tableFilterState.weight_min,
|
||||
weight_max: tableFilterState.weight_max,
|
||||
show_unrecorded: tableFilterState.show_unrecorded.toString(),
|
||||
sort_by: tableFilterState.sort_by,
|
||||
});
|
||||
|
||||
toast.success('PDF berhasil dibuat dan diunduh.');
|
||||
} catch {
|
||||
toast.error('Gagal membuat PDF. Silakan coba lagi.');
|
||||
}
|
||||
}, [
|
||||
hppPerKandang,
|
||||
tableFilterState,
|
||||
areaOptions,
|
||||
locationOptions,
|
||||
kandangOptions,
|
||||
]);
|
||||
|
||||
// ===== TABLE COLUMNS DEFINITION =====
|
||||
const totals: Totals = useMemo(() => {
|
||||
return {
|
||||
@@ -592,12 +641,7 @@ const HppPerKandangTab = () => {
|
||||
>
|
||||
<Menu className='w-32'>
|
||||
<MenuItem title='Excel' onClick={handleExportExcel} />
|
||||
<MenuItem
|
||||
title='PDF'
|
||||
onClick={() => {
|
||||
alert('Fitur belum tersedia');
|
||||
}}
|
||||
/>
|
||||
<MenuItem title='PDF' onClick={handleExportPDF} />
|
||||
</Menu>
|
||||
</Dropdown>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user