From e3146832a5a67377364410933c67e60b82f6c6de Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Sun, 24 Nov 2024 19:23:33 +0400 Subject: [PATCH] feat: expenses in statistics --- src/client/models/ProfitChartDataItem.ts | 1 + src/client/models/ProfitTableDataItem.ts | 1 + .../components/ProfitChart/ProfitChart.tsx | 7 ++-- .../components/ProfitTable/hooks/columns.tsx | 32 ++++++++++++++----- .../tabs/ProfitTab/components/Total/Total.tsx | 28 ++++++++++------ 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/client/models/ProfitChartDataItem.ts b/src/client/models/ProfitChartDataItem.ts index bb63817..1ed5684 100644 --- a/src/client/models/ProfitChartDataItem.ts +++ b/src/client/models/ProfitChartDataItem.ts @@ -6,6 +6,7 @@ export type ProfitChartDataItem = { date: string; revenue: number; profit: number; + expenses: number; dealsCount: number; }; diff --git a/src/client/models/ProfitTableDataItem.ts b/src/client/models/ProfitTableDataItem.ts index b755b96..52790ea 100644 --- a/src/client/models/ProfitTableDataItem.ts +++ b/src/client/models/ProfitTableDataItem.ts @@ -6,6 +6,7 @@ export type ProfitTableDataItem = { groupedValue: (string | number); revenue: number; profit: number; + expenses?: (number | null); dealsCount: number; }; diff --git a/src/pages/StatisticsPage/tabs/ProfitTab/components/ProfitChart/ProfitChart.tsx b/src/pages/StatisticsPage/tabs/ProfitTab/components/ProfitChart/ProfitChart.tsx index 08e9f72..f8ae199 100644 --- a/src/pages/StatisticsPage/tabs/ProfitTab/components/ProfitChart/ProfitChart.tsx +++ b/src/pages/StatisticsPage/tabs/ProfitTab/components/ProfitChart/ProfitChart.tsx @@ -26,6 +26,7 @@ export const ProfitChart = () => { [ { name: "profit", label: "Прибыль", color: "indigo.6" }, { name: "revenue", label: "Выручка", color: "teal.6" }, + { name: "expenses", label: "Расходы", color: "red.6" }, ], [ { name: "dealsCount", label: "Количество сделок", color: "indigo.6" }, @@ -34,6 +35,8 @@ export const ProfitChart = () => { const units = ["₽", "шт"]; + const chartSizes = ["42vh", "28vh"]; + return (
@@ -42,13 +45,13 @@ export const ProfitChart = () => { form={form} /> - + {getChartsSeries.map((series, idx) => { return ( { [GroupStatisticsTable.BY_MANAGERS]: "Менеджер", }; + const getConditionalColumns = (): MRT_ColumnDef[] => { + if (groupTableBy === GroupStatisticsTable.BY_DATES) { + return [ + { + accessorKey: "revenue", + header: "Выручка", + Cell: ({ row }) => + row.original.revenue.toLocaleString("ru-RU") + "₽", + size: 50, + }, + { + accessorKey: "expenses", + header: "Расходы", + Cell: ({ row }) => + row.original.expenses?.toLocaleString("ru-RU") + "₽", + size: 50, + } + ] as MRT_ColumnDef[]; + } + return []; + }; + return useMemo[]>( () => [ { @@ -35,13 +57,14 @@ export const useProfitTableColumns = ({ groupTableBy }: Props) => { } return row.original.groupedValue; }, - size: 60, + size: groupTableBy === GroupStatisticsTable.BY_DATES ? 40 : 80, }, { accessorKey: "dealsCount", header: "Кол-во", size: 40, }, + ...getConditionalColumns(), { accessorKey: "profit", header: "Прибыль", @@ -49,13 +72,6 @@ export const useProfitTableColumns = ({ groupTableBy }: Props) => { row.original.profit.toLocaleString("ru-RU") + "₽", size: 50, }, - { - accessorKey: "revenue", - header: "Выручка", - Cell: ({ row }) => - row.original.revenue.toLocaleString("ru-RU") + "₽", - size: 50, - }, ], [groupTableBy], ); diff --git a/src/pages/StatisticsPage/tabs/ProfitTab/components/Total/Total.tsx b/src/pages/StatisticsPage/tabs/ProfitTab/components/Total/Total.tsx index 03fdd5a..cfd4cc9 100644 --- a/src/pages/StatisticsPage/tabs/ProfitTab/components/Total/Total.tsx +++ b/src/pages/StatisticsPage/tabs/ProfitTab/components/Total/Total.tsx @@ -7,14 +7,18 @@ type Props = { }; export const Total = ({ profitData }: Props) => { - const totalProfit = profitData.reduce( - (sum, dataItem) => dataItem.profit + sum, - 0, - ); const totalRevenue = profitData.reduce( (sum, dataItem) => dataItem.revenue + sum, 0, ); + const totalExpense = profitData.reduce( + (sum, dataItem) => dataItem.expenses + sum, + 0, + ); + const totalProfit = profitData.reduce( + (sum, dataItem) => dataItem.profit + sum, + 0, + ); const totalCount = profitData.reduce( (sum, dataItem) => dataItem.dealsCount + sum, 0, @@ -23,15 +27,19 @@ export const Total = ({ profitData }: Props) => { return ( -
- Прибыль: {new Intl.NumberFormat("ru-RU").format(totalProfit)} ₽ -
- -
+
Выручка: {new Intl.NumberFormat("ru-RU").format(totalRevenue)} ₽
-
+
+ Расходы: {new Intl.NumberFormat("ru-RU").format(totalExpense)} ₽ +
+ +
+ Прибыль: {new Intl.NumberFormat("ru-RU").format(totalProfit)} ₽ +
+ +
Сделок: {new Intl.NumberFormat("ru-RU").format(totalCount)} шт