diff --git a/src/components/pages/report/sale/tab/HppPerKandangTab.tsx b/src/components/pages/report/sale/tab/HppPerKandangTab.tsx index 6d72f2d8..7982ba99 100644 --- a/src/components/pages/report/sale/tab/HppPerKandangTab.tsx +++ b/src/components/pages/report/sale/tab/HppPerKandangTab.tsx @@ -431,6 +431,52 @@ const HppPerKandangTab = () => { }; }, [summary]); + const allFeedSuppliers = useMemo(() => { + const suppliers = new Set(); + data.forEach((item) => { + item.feed_suppliers?.forEach((s) => { + suppliers.add(s.alias || s.name); + }); + }); + return Array.from(suppliers).join(' | '); + }, [data]); + + const allDocSuppliers = useMemo(() => { + const suppliers = new Set(); + data.forEach((item) => { + item.doc_suppliers?.forEach((s) => { + suppliers.add(s.alias || s.name); + }); + }); + return Array.from(suppliers).join(' | '); + }, [data]); + + const weightedAverageDocPrice = useMemo(() => { + if (data.length === 0) return 0; + const totalValue = data.reduce( + (sum, item) => sum + (item.hpp_rp * item.remaining_chicken_birds || 0), + 0 + ); + const totalChickens = data.reduce( + (sum, item) => sum + (item.remaining_chicken_birds || 0), + 0 + ); + return totalChickens > 0 ? totalValue / totalChickens : 0; + }, [data]); + + const weightedAverageHpp = useMemo(() => { + if (data.length === 0) return 0; + const totalValue = data.reduce( + (sum, item) => sum + (item.hpp_rp * item.remaining_chicken_birds || 0), + 0 + ); + const totalChickens = data.reduce( + (sum, item) => sum + (item.remaining_chicken_birds || 0), + 0 + ); + return totalChickens > 0 ? totalValue / totalChickens : 0; + }, [data]); + const getTableColumns = (): ColumnDef[] => { const tableColumns: ColumnDef[] = [ { @@ -447,6 +493,7 @@ const HppPerKandangTab = () => { const kandang = props.row.original.kandang; return kandang?.name || '-'; }, + footer: () =>
ALL
, }, { id: 'weight_range', @@ -458,6 +505,7 @@ const HppPerKandangTab = () => { ? `${formatNumber(weightRange.weight_min)} - ${formatNumber(weightRange.weight_max)}` : '-'; }, + footer: () =>
-
, }, { id: 'remaining_chicken_birds', @@ -495,6 +543,11 @@ const HppPerKandangTab = () => { const value = props.row.original.avg_weight_kg; return
{formatNumber(value)}
; }, + footer: () => ( +
+ {formatNumber(summary?.average_weight_kg || 0)} +
+ ), }, { id: 'feed_suppliers', @@ -504,6 +557,11 @@ const HppPerKandangTab = () => { const suppliers = props.row.original.feed_suppliers; return suppliers?.map((s) => s.alias || s.name).join(' | ') || '-'; }, + footer: () => ( +
+ {allFeedSuppliers || '-'} +
+ ), }, { id: 'doc_suppliers', @@ -513,6 +571,11 @@ const HppPerKandangTab = () => { const suppliers = props.row.original.doc_suppliers; return suppliers?.map((s) => s.alias || s.name).join(' | ') || '-'; }, + footer: () => ( +
+ {allDocSuppliers || '-'} +
+ ), }, { id: 'average_doc_price_rp', @@ -522,6 +585,11 @@ const HppPerKandangTab = () => { const value = props.row.original.average_doc_price_rp; return
{formatCurrency(value)}
; }, + footer: () => ( +
+ {formatCurrency(weightedAverageDocPrice)} +
+ ), }, { id: 'hpp_rp', @@ -531,6 +599,11 @@ const HppPerKandangTab = () => { const value = props.row.original.hpp_rp; return
{formatCurrency(value)}
; }, + footer: () => ( +
+ {formatCurrency(weightedAverageHpp)} +
+ ), }, { id: 'remaining_value_rp',