mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-356): Add egg production and HPP fields to PDF export
This commit is contained in:
@@ -165,7 +165,8 @@ interface WeightRangeGroup {
|
||||
}
|
||||
|
||||
const groupDataByWeightRange = (
|
||||
data: HppPerKandangReport['rows']
|
||||
data: HppPerKandangReport['rows'],
|
||||
summary: HppPerKandangReport['summary']
|
||||
): WeightRangeGroup[] => {
|
||||
const groups: {
|
||||
[key: string]: WeightRangeGroup;
|
||||
@@ -220,8 +221,12 @@ const groupDataByWeightRange = (
|
||||
group.totals.total_remaining_chicken_weight_kg /
|
||||
group.totals.total_remaining_chicken_birds;
|
||||
group.totals.average_doc_price_rp =
|
||||
group.items.reduce((sum, item) => sum + item.average_doc_price_rp, 0) /
|
||||
group.items.length;
|
||||
group.items.length > 0
|
||||
? group.items.reduce(
|
||||
(sum, item) => sum + item.average_doc_price_rp,
|
||||
0
|
||||
) / group.items.length
|
||||
: 0;
|
||||
});
|
||||
|
||||
return Object.values(groups).sort((a, b) => a.weight_min - b.weight_min);
|
||||
@@ -241,11 +246,27 @@ const getParameterText = (params: HppPerKandangExportParams['params']) => {
|
||||
return paramsText;
|
||||
};
|
||||
|
||||
const getTotalsForExport = (data: HppPerKandangReport['rows']) => {
|
||||
const totalHppRp = data.reduce((sum, item) => sum + (item.hpp_rp || 0), 0);
|
||||
const avgDocPrice =
|
||||
data.length > 0
|
||||
? data.reduce((sum, item) => sum + (item.average_doc_price_rp || 0), 0) /
|
||||
data.length
|
||||
: 0;
|
||||
|
||||
return {
|
||||
total_hpp_rp: totalHppRp,
|
||||
total_average_doc_price_rp: avgDocPrice,
|
||||
};
|
||||
};
|
||||
|
||||
const createPDFDocument = (
|
||||
data: HppPerKandangExportParams['data'],
|
||||
params: HppPerKandangExportParams['params']
|
||||
) => {
|
||||
const groupedByWeightRange = groupDataByWeightRange(data.rows);
|
||||
const summary = data.summary;
|
||||
const exportTotals = getTotalsForExport(data.rows);
|
||||
const groupedByWeightRange = groupDataByWeightRange(data.rows, summary);
|
||||
|
||||
return (
|
||||
<Document>
|
||||
@@ -283,6 +304,12 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Rata-Rata Bobot (Kg)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1 }]}>
|
||||
<Text>Produksi Telur (Butir)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1 }]}>
|
||||
<Text>Produksi Telur (Kg)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeader, { flex: 1.5 }]}>
|
||||
<Text>Feed (Supplier)</Text>
|
||||
</View>
|
||||
@@ -292,8 +319,14 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Rata-Rata Harga DOC</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Nilai Nominal Telur</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1 }]}>
|
||||
<Text>HPP</Text>
|
||||
<Text>HPP Ayam</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>HPP Telur (RP/KG)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Nominal Sisa</Text>
|
||||
@@ -332,6 +365,26 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>{formatNumber(group.totals.average_weight_kg)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1 }]}>
|
||||
<Text>
|
||||
{formatNumber(
|
||||
group.items.reduce(
|
||||
(sum, item) => sum + (item.egg_production_pieces || 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1 }]}>
|
||||
<Text>
|
||||
{formatNumber(
|
||||
group.items.reduce(
|
||||
(sum, item) => sum + (item.egg_production_kg || 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCell, { flex: 1.5 }]}>
|
||||
<Text>{group.totals.all_feed_suppliers.join(' | ')}</Text>
|
||||
</View>
|
||||
@@ -341,15 +394,34 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>{formatNumber(group.totals.average_doc_price_rp)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>
|
||||
{formatNumber(
|
||||
group.items.reduce(
|
||||
(sum, item) => sum + (item.egg_value_rp || 0),
|
||||
0
|
||||
)
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1 }]}>
|
||||
<Text>
|
||||
{
|
||||
(group.totals.total_remaining_chicken_birds > 0
|
||||
{formatNumber(
|
||||
group.totals.total_remaining_chicken_birds > 0
|
||||
? group.totals.total_hpp_rp /
|
||||
group.totals.total_remaining_chicken_birds
|
||||
: 0,
|
||||
2)
|
||||
}
|
||||
group.totals.total_remaining_chicken_birds
|
||||
: 0
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>
|
||||
{formatNumber(
|
||||
group.items.reduce(
|
||||
(sum, item) => sum + (item.egg_hpp_rp_per_kg || 0),
|
||||
0
|
||||
) / group.items.length || 0
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
@@ -378,14 +450,20 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellHeader, { flex: 1 }]}>
|
||||
<Text>Rentang BW</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1 }]}>
|
||||
<Text>Rata-Rata Bobot (Kg)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 0.8 }]}>
|
||||
<Text>Sisa Ekor</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 0.8 }]}>
|
||||
<Text>Sisa Kg</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1 }]}>
|
||||
<Text>Rata-Rata Bobot (Kg)</Text>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 0.8 }]}>
|
||||
<Text>Produksi Telur (Butir)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 0.8 }]}>
|
||||
<Text>Produksi Telur (Kg)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeader, { flex: 1.2 }]}>
|
||||
<Text>Feed (Supplier)</Text>
|
||||
@@ -396,8 +474,14 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Rata-Rata Harga DOC</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Nilai Nominal Telur</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 0.8 }]}>
|
||||
<Text>HPP</Text>
|
||||
<Text>HPP Ayam</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1 }]}>
|
||||
<Text>HPP Telur (RP/KG)</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellHeaderRight, { flex: 1.2 }]}>
|
||||
<Text>Nominal Sisa</Text>
|
||||
@@ -427,14 +511,20 @@ const createPDFDocument = (
|
||||
{item.weight_range.weight_max.toFixed(2)}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1 }]}>
|
||||
<Text>{formatNumber(item.avg_weight_kg)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 0.8 }]}>
|
||||
<Text>{formatNumber(item.remaining_chicken_birds)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 0.8 }]}>
|
||||
<Text>{formatNumber(item.remaining_chicken_weight_kg)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1 }]}>
|
||||
<Text>{formatNumber(item.avg_weight_kg)}</Text>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 0.8 }]}>
|
||||
<Text>{formatNumber(item.egg_production_pieces)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 0.8 }]}>
|
||||
<Text>{formatNumber(item.egg_production_kg)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCell, { flex: 1.2 }]}>
|
||||
<Text>
|
||||
@@ -453,9 +543,15 @@ const createPDFDocument = (
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>{formatNumber(item.average_doc_price_rp)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>{formatNumber(item.egg_value_rp)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 0.8 }]}>
|
||||
<Text>{formatNumber(item.hpp_rp)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1 }]}>
|
||||
<Text>{formatNumber(item.egg_hpp_rp_per_kg)}</Text>
|
||||
</View>
|
||||
<View style={[pdfStyles.tableCellRight, { flex: 1.2 }]}>
|
||||
<Text>{formatNumber(item.remaining_value_rp)}</Text>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user