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