mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
feat(FE-355,357): Add aggregated footers for HPP per kandang table
This commit is contained in:
@@ -431,6 +431,52 @@ const HppPerKandangTab = () => {
|
||||
};
|
||||
}, [summary]);
|
||||
|
||||
const allFeedSuppliers = useMemo(() => {
|
||||
const suppliers = new Set<string>();
|
||||
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<string>();
|
||||
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<HppPerKandangReport['rows'][0]>[] => {
|
||||
const tableColumns: ColumnDef<HppPerKandangReport['rows'][0]>[] = [
|
||||
{
|
||||
@@ -447,6 +493,7 @@ const HppPerKandangTab = () => {
|
||||
const kandang = props.row.original.kandang;
|
||||
return kandang?.name || '-';
|
||||
},
|
||||
footer: () => <div className='font-semibold text-gray-900'>ALL</div>,
|
||||
},
|
||||
{
|
||||
id: 'weight_range',
|
||||
@@ -458,6 +505,7 @@ const HppPerKandangTab = () => {
|
||||
? `${formatNumber(weightRange.weight_min)} - ${formatNumber(weightRange.weight_max)}`
|
||||
: '-';
|
||||
},
|
||||
footer: () => <div className='font-semibold text-gray-900'>-</div>,
|
||||
},
|
||||
{
|
||||
id: 'remaining_chicken_birds',
|
||||
@@ -495,6 +543,11 @@ const HppPerKandangTab = () => {
|
||||
const value = props.row.original.avg_weight_kg;
|
||||
return <div className='text-right'>{formatNumber(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatNumber(summary?.average_weight_kg || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
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: () => (
|
||||
<div className='font-semibold text-gray-900'>
|
||||
{allFeedSuppliers || '-'}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
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: () => (
|
||||
<div className='font-semibold text-gray-900'>
|
||||
{allDocSuppliers || '-'}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'average_doc_price_rp',
|
||||
@@ -522,6 +585,11 @@ const HppPerKandangTab = () => {
|
||||
const value = props.row.original.average_doc_price_rp;
|
||||
return <div className='text-right'>{formatCurrency(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(weightedAverageDocPrice)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'hpp_rp',
|
||||
@@ -531,6 +599,11 @@ const HppPerKandangTab = () => {
|
||||
const value = props.row.original.hpp_rp;
|
||||
return <div className='text-right'>{formatCurrency(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(weightedAverageHpp)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'remaining_value_rp',
|
||||
|
||||
Reference in New Issue
Block a user