feat(FE-355,357): Use summary totals and show egg metrics

This commit is contained in:
rstubryan
2025-12-20 10:13:48 +07:00
parent 18ca7d8a59
commit 9e0631a415
2 changed files with 22 additions and 53 deletions
@@ -30,11 +30,6 @@ import { generateHppPerKandangPDF } from '../export/HppPerkandangExport';
import toast from 'react-hot-toast';
import * as XLSX from 'xlsx';
interface Totals {
total_hpp_rp: number;
total_average_doc_price_rp: number;
}
const HppPerKandangTab = () => {
// ===== STATE MANAGEMENT =====
const [isPdfExportLoading, setIsPdfExportLoading] = useState(false);
@@ -285,46 +280,6 @@ const HppPerKandangTab = () => {
}, [tableFilterState]);
// ===== TABLE COLUMNS DEFINITION =====
const totals: Totals = useMemo(() => {
if (summaryTotal && perWeightRangeSummary.length > 0) {
const totalAverageDocPrice =
perWeightRangeSummary.reduce(
(acc: number, item: HppPerKandangPerWeightRange) =>
acc + (item.average_doc_price_rp || 0),
0
) / perWeightRangeSummary.length;
return {
total_hpp_rp: perWeightRangeSummary.reduce(
(acc: number, item: HppPerKandangPerWeightRange) =>
acc + (item.hpp_rp || 0),
0
),
total_average_doc_price_rp: totalAverageDocPrice,
};
}
if (data.length > 0) {
return {
total_hpp_rp: data.reduce(
(acc: number, item: HppPerKandangRow) => acc + (item.hpp_rp || 0),
0
),
total_average_doc_price_rp:
data.reduce(
(acc: number, item: HppPerKandangRow) =>
acc + (item.average_doc_price_rp || 0),
0
) / data.length,
};
}
return {
total_hpp_rp: 0,
total_average_doc_price_rp: 0,
};
}, [summaryTotal, perWeightRangeSummary, data]);
const allFeedSuppliers = useMemo(() => {
const suppliers = new Set<string>();
data.forEach((item: HppPerKandangRow) => {
@@ -404,9 +359,9 @@ const HppPerKandangTab = () => {
'Produksi Telur (KG)': summary?.total_egg_production_kg || 0,
'Feed (Supplier)': allFeedSuppliers,
'DOC (Supplier)': allDocSuppliers,
'Rata-Rata Harga DOC (RP)': totals?.total_average_doc_price_rp || 0,
'Rata-Rata Harga DOC (RP)': summary?.total_average_doc_price_rp || 0,
'Nilai Nominal Telur (RP)': summary?.total_egg_value_rp || 0,
'HPP Ayam (RP)': totals?.total_hpp_rp || 0,
'HPP Ayam (RP)': summary?.total_hpp_rp || 0,
'HPP Telur (RP/KG)': summary?.average_egg_hpp_rp_per_kg || 0,
'Nilai Nominal Sisa Ayam (RP)': summary?.total_remaining_value_rp || 0,
});
@@ -674,7 +629,7 @@ const HppPerKandangTab = () => {
},
footer: () => (
<div className='text-right font-semibold text-gray-900'>
{formatCurrency(totals?.total_average_doc_price_rp || 0)}
{formatCurrency(summary?.total?.total_average_doc_price_rp || 0)}
</div>
),
},
@@ -702,7 +657,7 @@ const HppPerKandangTab = () => {
},
footer: () => (
<div className='text-right font-semibold text-gray-900'>
{formatCurrency(totals?.total_hpp_rp || 0)}
{formatCurrency(summary?.total?.total_hpp_rp || 0)}
</div>
),
},
@@ -792,8 +747,12 @@ const HppPerKandangTab = () => {
<td className='text-right'>
{formatNumber(item.remaining_chicken_weight_kg)}
</td>
<td className='text-right'>-</td>
<td className='text-right'>-</td>
<td className='text-right'>
{formatNumber(item.egg_production_pieces)}
</td>
<td className='text-right'>
{formatNumber(item.egg_production_kg)}
</td>
<td className=''>
{item.feed_suppliers
?.map((s) => s.alias || s.name)
@@ -807,9 +766,13 @@ const HppPerKandangTab = () => {
<td className='text-right'>
{formatCurrency(item.average_doc_price_rp)}
</td>
<td className='text-right'>-</td>
<td className='text-right'>
{formatCurrency(item.egg_value_rp)}
</td>
<td className='text-right'>{formatCurrency(item.hpp_rp)}</td>
<td className='text-right'>-</td>
<td className='text-right'>
{formatCurrency(item.egg_hpp_rp_per_kg)}
</td>
<td className='text-right'>
{formatCurrency(item.remaining_value_rp)}
</td>
+6
View File
@@ -32,6 +32,8 @@ export type HppPerKandangSummaryTotal = {
total_egg_production_kg: number;
average_egg_hpp_rp_per_kg: number;
total_egg_value_rp: number;
total_hpp_rp: number;
total_average_doc_price_rp: number;
};
export type HppPerKandangPerWeightRange = {
@@ -44,6 +46,10 @@ export type HppPerKandangPerWeightRange = {
remaining_chicken_birds: number;
remaining_chicken_weight_kg: number;
avg_weight_kg: number;
egg_production_pieces: number;
egg_production_kg: number;
egg_hpp_rp_per_kg: number;
egg_value_rp: number;
feed_suppliers: Supplier[];
doc_suppliers: Supplier[];
average_doc_price_rp: number;