mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Merge branch 'development' into fix/daily-checklist
This commit is contained in:
@@ -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 <div className='text-right'>{formatCurrency(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(totals.avgPricePartner)}
|
||||
{summary
|
||||
? formatCurrency(summary.avg_sales_price)
|
||||
: formatCurrency(totals.avgSalesPrice)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
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 <div className='text-right'>{formatCurrency(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{formatCurrency(totals.totalPartner)}
|
||||
{summary
|
||||
? formatCurrency(summary.total_sales_price)
|
||||
: formatCurrency(totals.totalSalesPrice)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'price_act',
|
||||
accessorKey: 'price',
|
||||
id: 'actual_price',
|
||||
accessorKey: 'actual_price',
|
||||
header: 'Harga Act (Rp)',
|
||||
cell: (props) => {
|
||||
const value = props.getValue() as number;
|
||||
return <div className='text-right'>{formatCurrency(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{summary
|
||||
? formatCurrency(summary.avg_actual_price)
|
||||
: formatCurrency(totals.avgActualPrice)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
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 <div className='text-right'>{formatCurrency(value)}</div>;
|
||||
},
|
||||
footer: () => (
|
||||
<div className='text-right font-semibold text-gray-900'>
|
||||
{summary
|
||||
? formatCurrency(summary.total_actual_price)
|
||||
: formatCurrency(totals.totalActualPrice)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'kandang',
|
||||
|
||||
@@ -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) : '-';
|
||||
|
||||
Vendored
+12
-26
@@ -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 = {
|
||||
|
||||
Vendored
+2
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user