feat: profit table and division of charts in statistics

This commit is contained in:
2024-11-17 01:23:04 +04:00
parent 608a063369
commit 3b8c75d3d3
29 changed files with 571 additions and 305 deletions

View File

@@ -0,0 +1,53 @@
import { useMemo } from "react";
import { MRT_ColumnDef } from "mantine-react-table";
import { ProfitTableDataItem } from "../../../../../../../client";
import { GroupStatisticsTable } from "../../ProfitTableSegmentedControl/ProfitTableSegmentedControl.tsx";
import { DealStatus, DealStatusDictionary } from "../../../../../../../shared/enums/DealStatus.ts";
type Props = {
groupTableBy: GroupStatisticsTable;
}
export const useProfitTableColumns = ({ groupTableBy }: Props) => {
const groupedValueHeader = {
[GroupStatisticsTable.BY_DATES]: "Дата",
[GroupStatisticsTable.BY_CLIENTS]: "Клиент",
[GroupStatisticsTable.BY_STATUSES]: "Статус",
[GroupStatisticsTable.BY_MARKETPLACES]: "Маркетплейс",
[GroupStatisticsTable.BY_WAREHOUSES]: "Склад отгрузки",
};
return useMemo<MRT_ColumnDef<ProfitTableDataItem>[]>(
() => [
{
accessorKey: "groupedValue",
header: groupedValueHeader[groupTableBy],
enableSorting: groupTableBy === GroupStatisticsTable.BY_DATES,
Cell: ({ row }) => {
if (groupTableBy === GroupStatisticsTable.BY_STATUSES) {
const statusIndex = row.original.groupedValue as DealStatus;
return DealStatusDictionary[statusIndex];
}
return row.original.groupedValue;
},
},
{
accessorKey: "dealsCount",
header: "Кол-во",
},
{
accessorKey: "profit",
header: "Прибыль",
Cell: ({ row }) =>
row.original.profit.toLocaleString("ru-RU") + "₽",
},
{
accessorKey: "revenue",
header: "Выручка",
Cell: ({ row }) =>
row.original.revenue.toLocaleString("ru-RU") + "₽",
},
],
[groupTableBy],
);
};