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
{formatCurrency(value)}
;
},
footer: () => (
- {formatCurrency(totals.avgPricePartner)}
+ {summary
+ ? formatCurrency(summary.avg_sales_price)
+ : formatCurrency(totals.avgSalesPrice)}
),
},
{
- id: 'total_mitra',
- accessorKey: 'total_price',
- header: 'Total Mitra (Rp)',
+ id: 'total_sales_price',
+ accessorKey: 'total_sales_price',
+ header: 'Total Sales (Rp)',
cell: (props) => {
const value = props.getValue() as number;
return {formatCurrency(value)}
;
},
footer: () => (
- {formatCurrency(totals.totalPartner)}
+ {summary
+ ? formatCurrency(summary.total_sales_price)
+ : formatCurrency(totals.totalSalesPrice)}
),
},
{
- id: 'price_act',
- accessorKey: 'price',
+ id: 'actual_price',
+ accessorKey: 'actual_price',
header: 'Harga Act (Rp)',
cell: (props) => {
const value = props.getValue() as number;
return {formatCurrency(value)}
;
},
+ footer: () => (
+
+ {summary
+ ? formatCurrency(summary.avg_actual_price)
+ : formatCurrency(totals.avgActualPrice)}
+
+ ),
},
{
- id: 'total_act',
- accessorKey: 'total_price',
+ id: 'total_actual_price',
+ accessorKey: 'total_actual_price',
header: 'Total Act (Rp)',
cell: (props) => {
const value = props.getValue() as number;
return {formatCurrency(value)}
;
},
+ footer: () => (
+
+ {summary
+ ? formatCurrency(summary.total_actual_price)
+ : formatCurrency(totals.totalActualPrice)}
+
+ ),
},
{
id: 'kandang',
diff --git a/src/components/pages/report/DailyMarketingsTable.tsx b/src/components/pages/report/DailyMarketingsTable.tsx
index b9906e53..67702035 100644
--- a/src/components/pages/report/DailyMarketingsTable.tsx
+++ b/src/components/pages/report/DailyMarketingsTable.tsx
@@ -125,7 +125,7 @@ const DailyMarketingsTable = ({
cell: (props) => formatNumber(props.row.original.average_weight_kg),
footer: () => {
const totalAverageWeightKg = isResponseSuccess(dailyMarketings)
- ? dailyMarketings?.total?.total_average_weight
+ ? dailyMarketings?.total?.average_weight_kg
: 0;
return totalAverageWeightKg ? formatNumber(totalAverageWeightKg) : '-';
@@ -149,7 +149,7 @@ const DailyMarketingsTable = ({
cell: (props) => formatCurrency(props.row.original.sales_price_per_kg),
footer: () => {
const totalSalesPrice = isResponseSuccess(dailyMarketings)
- ? dailyMarketings?.total?.total_sales_price
+ ? dailyMarketings?.total?.average_sales_price
: 0;
return totalSalesPrice ? formatNumber(totalSalesPrice) : '-';
diff --git a/src/types/api/closing.d.ts b/src/types/api/closing.d.ts
index ec256a45..8135c013 100644
--- a/src/types/api/closing.d.ts
+++ b/src/types/api/closing.d.ts
@@ -23,33 +23,18 @@ export type BaseSales = {
qty: number;
weight: number;
avg_weight: number;
- price: number;
- total_price: number;
+ sales_price: number;
+ total_sales_price: number;
+ actual_price: number;
+ total_actual_price: number;
kandang: Kandang;
- payment_status: string;
-};
-
-export type BaseClosingSales = {
- project_type: string;
- flock_id: number;
- period: number;
- sales: BaseSales[];
-};
-
-export type BaseSales = {
- id: number;
- realization_date: string;
- age: number;
- do_number: string;
- product: Product;
- customer: Customer;
- qty: number;
- weight: number;
- avg_weight: number;
- price: number;
- total_price: number;
- kandang: Kandang;
- payment_status: string;
+};
+
+export type ClosingSalesSummary = {
+ total_sales_price: number;
+ avg_sales_price: number;
+ total_actual_price: number;
+ avg_actual_price: number;
};
export type BaseClosingSales = {
@@ -57,6 +42,7 @@ export type BaseClosingSales = {
flock_id: number;
period: number;
sales: BaseSales[];
+ summary: ClosingSalesSummary;
};
export type BaseClosing = {
diff --git a/src/types/api/report/marketing.d.ts b/src/types/api/report/marketing.d.ts
index 925707eb..20c60725 100644
--- a/src/types/api/report/marketing.d.ts
+++ b/src/types/api/report/marketing.d.ts
@@ -41,9 +41,9 @@ export type DailyMarketingRow = BaseMetadata & BaseDailyMarketingRow;
export interface SalesSummary {
total_qty: number;
- total_average_weight: number;
+ average_weight_kg: number;
total_weight_kg: number;
- total_sales_price: number;
+ average_sales_price: number;
total_sales_amount: number;
total_hpp_amount: number;
total_hpp_price_per_kg: number;