mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
refactor(FE-356): Use summaryTotal and memoize per-weight summary
This commit is contained in:
@@ -219,21 +219,19 @@ const HppPerKandangTab = () => {
|
||||
[hppPerKandang]
|
||||
);
|
||||
|
||||
const summary =
|
||||
isResponseSuccess(hppPerKandang) && hppPerKandang?.data?.summary
|
||||
? hppPerKandang.data.summary
|
||||
: undefined;
|
||||
|
||||
const summaryTotal =
|
||||
isResponseSuccess(hppPerKandang) && hppPerKandang?.data?.summary?.total
|
||||
? hppPerKandang.data.summary.total
|
||||
: undefined;
|
||||
|
||||
const perWeightRangeSummary =
|
||||
isResponseSuccess(hppPerKandang) &&
|
||||
hppPerKandang?.data?.summary?.per_weight_range
|
||||
? hppPerKandang.data.summary.per_weight_range
|
||||
: [];
|
||||
const perWeightRangeSummary = useMemo(
|
||||
() =>
|
||||
isResponseSuccess(hppPerKandang) &&
|
||||
hppPerKandang?.data?.summary?.per_weight_range
|
||||
? hppPerKandang.data.summary.per_weight_range
|
||||
: [],
|
||||
[hppPerKandang]
|
||||
);
|
||||
|
||||
const period =
|
||||
isResponseSuccess(hppPerKandang) && hppPerKandang?.data?.period
|
||||
@@ -318,7 +316,7 @@ const HppPerKandangTab = () => {
|
||||
const allExportData =
|
||||
allDataForExport.rows as HppPerKandangReport['rows'];
|
||||
|
||||
const summary = allDataForExport.summary;
|
||||
const summaryTotal = allDataForExport.summary.total;
|
||||
|
||||
const excelData: { [key: string]: string | number }[] = allExportData.map(
|
||||
(item: HppPerKandangRow, index: number) => ({
|
||||
@@ -352,18 +350,21 @@ const HppPerKandangTab = () => {
|
||||
No: 'TOTAL',
|
||||
Kandang: 'ALL',
|
||||
'Rentang Bobot': '-',
|
||||
'Rata-Rata Bobot (KG)': summary?.average_weight_kg || 0,
|
||||
'Sisa Ayam (Ekor)': summary?.total_remaining_chicken_birds || 0,
|
||||
'Sisa Ayam (KG)': summary?.total_remaining_chicken_weight_kg || 0,
|
||||
'Produksi Telur (Butir)': summary?.total_egg_production_pieces || 0,
|
||||
'Produksi Telur (KG)': summary?.total_egg_production_kg || 0,
|
||||
'Rata-Rata Bobot (KG)': summaryTotal?.average_weight_kg || 0,
|
||||
'Sisa Ayam (Ekor)': summaryTotal?.total_remaining_chicken_birds || 0,
|
||||
'Sisa Ayam (KG)': summaryTotal?.total_remaining_chicken_weight_kg || 0,
|
||||
'Produksi Telur (Butir)':
|
||||
summaryTotal?.total_egg_production_pieces || 0,
|
||||
'Produksi Telur (KG)': summaryTotal?.total_egg_production_kg || 0,
|
||||
'Feed (Supplier)': allFeedSuppliers,
|
||||
'DOC (Supplier)': allDocSuppliers,
|
||||
'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)': 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,
|
||||
'Rata-Rata Harga DOC (RP)':
|
||||
summaryTotal?.total_average_doc_price_rp || 0,
|
||||
'Nilai Nominal Telur (RP)': summaryTotal?.total_egg_value_rp || 0,
|
||||
'HPP Ayam (RP)': summaryTotal?.total_hpp_rp || 0,
|
||||
'HPP Telur (RP/KG)': summaryTotal?.average_egg_hpp_rp_per_kg || 0,
|
||||
'Nilai Nominal Sisa Ayam (RP)':
|
||||
summaryTotal?.total_remaining_value_rp || 0,
|
||||
});
|
||||
|
||||
const worksheet = XLSX.utils.json_to_sheet(excelData);
|
||||
@@ -519,7 +520,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatNumber(summary?.total?.average_weight_kg || 0)}
|
||||
{formatNumber(summaryTotal?.average_weight_kg || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -533,7 +534,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatNumber(summary?.total?.total_remaining_chicken_birds || 0)}
|
||||
{formatNumber(summaryTotal?.total_remaining_chicken_birds || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -547,9 +548,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatNumber(
|
||||
summary?.total?.total_remaining_chicken_weight_kg || 0
|
||||
)}
|
||||
{formatNumber(summaryTotal?.total_remaining_chicken_weight_kg || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -563,7 +562,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatNumber(summary?.total?.total_egg_production_pieces || 0)}
|
||||
{formatNumber(summaryTotal?.total_egg_production_pieces || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -577,9 +576,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatNumber(
|
||||
summary?.total?.total_remaining_chicken_weight_kg || 0
|
||||
)}
|
||||
{formatNumber(summaryTotal?.total_remaining_chicken_weight_kg || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -629,7 +626,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(summary?.total?.total_average_doc_price_rp || 0)}
|
||||
{formatCurrency(summaryTotal?.total_average_doc_price_rp || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -643,7 +640,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(summary?.total?.total_egg_value_rp || 0)}
|
||||
{formatCurrency(summaryTotal?.total_egg_value_rp || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -657,7 +654,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(summary?.total?.total_hpp_rp || 0)}
|
||||
{formatCurrency(summaryTotal?.total_hpp_rp || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -671,7 +668,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(summary?.total?.average_egg_hpp_rp_per_kg || 0)}
|
||||
{formatCurrency(summaryTotal?.average_egg_hpp_rp_per_kg || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
@@ -685,7 +682,7 @@ const HppPerKandangTab = () => {
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(summary?.total?.total_remaining_value_rp || 0)}
|
||||
{formatCurrency(summaryTotal?.total_remaining_value_rp || 0)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user