diff --git a/src/components/pages/closing/sale/SalesReportTable.tsx b/src/components/pages/closing/sale/SalesReportTable.tsx index 6c12347e..6ddd9e4f 100644 --- a/src/components/pages/closing/sale/SalesReportTable.tsx +++ b/src/components/pages/closing/sale/SalesReportTable.tsx @@ -6,7 +6,11 @@ import Table from '@/components/Table'; import Card from '@/components/Card'; import Badge from '@/components/Badge'; import { formatCurrency, formatNumber, formatDate } from '@/lib/helper'; -import { BaseClosingSales, BaseSales } from '@/types/api/closing'; +import { + BaseClosingSales, + BaseSales, + ClosingSalesSummary, +} from '@/types/api/closing'; import { Product } from '@/types/api/master-data/product'; import { Customer } from '@/types/api/master-data/customer'; import { Kandang } from '@/types/api/master-data/kandang'; @@ -24,14 +28,20 @@ const SalesReportTable = ({ return initialValues?.sales || []; }, [initialValues]); + const summary: ClosingSalesSummary | undefined = useMemo(() => { + return initialValues?.summary; + }, [initialValues]); + const totals = useMemo(() => { if (salesData.length === 0) { return { totalQuantity: 0, totalWeight: 0, avgWeight: 0, - avgPricePartner: 0, - totalPartner: 0, + avgSalesPrice: 0, + totalSalesPrice: 0, + avgActualPrice: 0, + totalActualPrice: 0, }; } @@ -45,26 +55,46 @@ const SalesReportTable = ({ ); const avgWeight = totalQuantity > 0 ? totalWeight / totalQuantity : 0; - const validPriceItems = salesData.filter( - (item) => item.price != null && item.price > 0 - ); - const avgPricePartner = - validPriceItems.length > 0 - ? validPriceItems.reduce((sum, item) => sum + item.price, 0) / - validPriceItems.length - : 0; - - const totalPartner = salesData.reduce( - (sum, item) => sum + (item.total_price || 0), + const totalSalesPrice = salesData.reduce( + (sum, item) => sum + (item.total_sales_price || 0), 0 ); + const validSalesPriceItems = salesData.filter( + (item) => item.sales_price != null && item.sales_price > 0 + ); + const avgSalesPrice = + validSalesPriceItems.length > 0 + ? validSalesPriceItems.reduce( + (sum, item) => sum + item.sales_price, + 0 + ) / validSalesPriceItems.length + : 0; + + const totalActualPrice = salesData.reduce( + (sum, item) => sum + (item.total_actual_price || 0), + 0 + ); + + const validActualPriceItems = salesData.filter( + (item) => item.actual_price != null && item.actual_price > 0 + ); + const avgActualPrice = + validActualPriceItems.length > 0 + ? validActualPriceItems.reduce( + (sum, item) => sum + item.actual_price, + 0 + ) / validActualPriceItems.length + : 0; + return { totalQuantity, totalWeight, avgWeight, - avgPricePartner, - totalPartner, + avgSalesPrice, + totalSalesPrice, + avgActualPrice, + totalActualPrice, }; }, [salesData]); @@ -161,50 +191,68 @@ const SalesReportTable = ({ ), }, { - id: 'price_partner', - accessorKey: 'price', - header: 'Harga Mitra (Rp)', + id: 'sales_price', + accessorKey: 'sales_price', + header: 'Harga Sales (Rp)', cell: (props) => { const value = props.getValue() as number; return