mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-355,357): Use summary totals and show egg metrics
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user