mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +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 toast from 'react-hot-toast';
|
||||||
import * as XLSX from 'xlsx';
|
import * as XLSX from 'xlsx';
|
||||||
|
|
||||||
interface Totals {
|
|
||||||
total_hpp_rp: number;
|
|
||||||
total_average_doc_price_rp: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const HppPerKandangTab = () => {
|
const HppPerKandangTab = () => {
|
||||||
// ===== STATE MANAGEMENT =====
|
// ===== STATE MANAGEMENT =====
|
||||||
const [isPdfExportLoading, setIsPdfExportLoading] = useState(false);
|
const [isPdfExportLoading, setIsPdfExportLoading] = useState(false);
|
||||||
@@ -285,46 +280,6 @@ const HppPerKandangTab = () => {
|
|||||||
}, [tableFilterState]);
|
}, [tableFilterState]);
|
||||||
|
|
||||||
// ===== TABLE COLUMNS DEFINITION =====
|
// ===== 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 allFeedSuppliers = useMemo(() => {
|
||||||
const suppliers = new Set<string>();
|
const suppliers = new Set<string>();
|
||||||
data.forEach((item: HppPerKandangRow) => {
|
data.forEach((item: HppPerKandangRow) => {
|
||||||
@@ -404,9 +359,9 @@ const HppPerKandangTab = () => {
|
|||||||
'Produksi Telur (KG)': summary?.total_egg_production_kg || 0,
|
'Produksi Telur (KG)': summary?.total_egg_production_kg || 0,
|
||||||
'Feed (Supplier)': allFeedSuppliers,
|
'Feed (Supplier)': allFeedSuppliers,
|
||||||
'DOC (Supplier)': allDocSuppliers,
|
'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,
|
'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,
|
'HPP Telur (RP/KG)': summary?.average_egg_hpp_rp_per_kg || 0,
|
||||||
'Nilai Nominal Sisa Ayam (RP)': summary?.total_remaining_value_rp || 0,
|
'Nilai Nominal Sisa Ayam (RP)': summary?.total_remaining_value_rp || 0,
|
||||||
});
|
});
|
||||||
@@ -674,7 +629,7 @@ const HppPerKandangTab = () => {
|
|||||||
},
|
},
|
||||||
footer: () => (
|
footer: () => (
|
||||||
<div className='text-right font-semibold text-gray-900'>
|
<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>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -702,7 +657,7 @@ const HppPerKandangTab = () => {
|
|||||||
},
|
},
|
||||||
footer: () => (
|
footer: () => (
|
||||||
<div className='text-right font-semibold text-gray-900'>
|
<div className='text-right font-semibold text-gray-900'>
|
||||||
{formatCurrency(totals?.total_hpp_rp || 0)}
|
{formatCurrency(summary?.total?.total_hpp_rp || 0)}
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -792,8 +747,12 @@ const HppPerKandangTab = () => {
|
|||||||
<td className='text-right'>
|
<td className='text-right'>
|
||||||
{formatNumber(item.remaining_chicken_weight_kg)}
|
{formatNumber(item.remaining_chicken_weight_kg)}
|
||||||
</td>
|
</td>
|
||||||
<td className='text-right'>-</td>
|
<td className='text-right'>
|
||||||
<td className='text-right'>-</td>
|
{formatNumber(item.egg_production_pieces)}
|
||||||
|
</td>
|
||||||
|
<td className='text-right'>
|
||||||
|
{formatNumber(item.egg_production_kg)}
|
||||||
|
</td>
|
||||||
<td className=''>
|
<td className=''>
|
||||||
{item.feed_suppliers
|
{item.feed_suppliers
|
||||||
?.map((s) => s.alias || s.name)
|
?.map((s) => s.alias || s.name)
|
||||||
@@ -807,9 +766,13 @@ const HppPerKandangTab = () => {
|
|||||||
<td className='text-right'>
|
<td className='text-right'>
|
||||||
{formatCurrency(item.average_doc_price_rp)}
|
{formatCurrency(item.average_doc_price_rp)}
|
||||||
</td>
|
</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'>{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'>
|
<td className='text-right'>
|
||||||
{formatCurrency(item.remaining_value_rp)}
|
{formatCurrency(item.remaining_value_rp)}
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
+6
@@ -32,6 +32,8 @@ export type HppPerKandangSummaryTotal = {
|
|||||||
total_egg_production_kg: number;
|
total_egg_production_kg: number;
|
||||||
average_egg_hpp_rp_per_kg: number;
|
average_egg_hpp_rp_per_kg: number;
|
||||||
total_egg_value_rp: number;
|
total_egg_value_rp: number;
|
||||||
|
total_hpp_rp: number;
|
||||||
|
total_average_doc_price_rp: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type HppPerKandangPerWeightRange = {
|
export type HppPerKandangPerWeightRange = {
|
||||||
@@ -44,6 +46,10 @@ export type HppPerKandangPerWeightRange = {
|
|||||||
remaining_chicken_birds: number;
|
remaining_chicken_birds: number;
|
||||||
remaining_chicken_weight_kg: number;
|
remaining_chicken_weight_kg: number;
|
||||||
avg_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[];
|
feed_suppliers: Supplier[];
|
||||||
doc_suppliers: Supplier[];
|
doc_suppliers: Supplier[];
|
||||||
average_doc_price_rp: number;
|
average_doc_price_rp: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user