میزان فروش غذاها
-
-
-
-
- {dataWithPercent.map((entry, index) => (
- |
- ))}
- {
- const labelProps = props as {
- x?: number | string
- y?: number | string
- value?: number | string
- }
- if (
- labelProps.x === undefined ||
- labelProps.y === undefined ||
- labelProps.value === undefined
- ) {
- return null
- }
- const x =
- typeof labelProps.x === 'number'
- ? labelProps.x
- : parseFloat(
- String(labelProps.x)
- ) || 0
- const y =
- typeof labelProps.y === 'number'
- ? labelProps.y
- : parseFloat(
- String(labelProps.y)
- ) || 0
- return (
-
- {labelProps.value}%
-
- )
- }}
- />
-
-
-
-
+ {/* Filters */}
+ {/*
+
+
+
*/}
-
- {dataWithPercent.map((item, index) => (
-
-
-
- {item.name}
-
+ {/* Tabs */}
+ {/*
+
+
+
+
*/}
+
+ {dataWithPercent.length === 0 ? (
+
+ دادهای برای نمایش وجود ندارد
+
+ ) : (
+ <>
+
+
+
+
+ {dataWithPercent.map((entry, index) => (
+ |
+ ))}
+ {
+ const labelProps = props as {
+ x?: number | string
+ y?: number | string
+ value?: number | string
+ }
+ if (
+ labelProps.x === undefined ||
+ labelProps.y === undefined ||
+ labelProps.value === undefined
+ ) {
+ return null
+ }
+ const x =
+ typeof labelProps.x === 'number'
+ ? labelProps.x
+ : parseFloat(
+ String(labelProps.x)
+ ) || 0
+ const y =
+ typeof labelProps.y === 'number'
+ ? labelProps.y
+ : parseFloat(
+ String(labelProps.y)
+ ) || 0
+ return (
+
+ {labelProps.value}%
+
+ )
+ }}
+ />
+
+
+
- ))}
-
+
+
+ {dataWithPercent.map((item, index) => (
+
+ ))}
+
+ >
+ )}
)
}
diff --git a/src/pages/statistics/components/RevenueChart.tsx b/src/pages/statistics/components/RevenueChart.tsx
index 12ca6fc..55d2ba3 100644
--- a/src/pages/statistics/components/RevenueChart.tsx
+++ b/src/pages/statistics/components/RevenueChart.tsx
@@ -16,7 +16,7 @@ import { formatPrice } from '@/helpers/func'
import PageLoading from '@/components/PageLoading'
const RevenueChart: FC = () => {
- const [selectedTab, setSelectedTab] = useState<
+ const [selectedTab] = useState<
'daily' | 'monthly' | 'yearly'
>('monthly')
const [startDate, setStartDate] = useState
('')
@@ -27,13 +27,12 @@ const RevenueChart: FC = () => {
period?: 'daily' | 'monthly' | 'yearly';
startDate?: string;
endDate?: string;
- } = {
- period: selectedTab,
- }
- if (startDate) params.startDate = startDate
- if (endDate) params.endDate = endDate
+ } = {}
+ // فقط اگر تاریخ انتخاب شده باشد ارسال شود
+ if (startDate && startDate.trim() !== '') params.startDate = startDate
+ if (endDate && endDate.trim() !== '') params.endDate = endDate
return params
- }, [selectedTab, startDate, endDate])
+ }, [startDate, endDate])
const { data: paymentsChartData, isLoading } = useGetPaymentsChart(apiParams)
@@ -97,9 +96,56 @@ const RevenueChart: FC = () => {
return value.toLocaleString('fa-IR')
}
- const formatTooltip = (value: number | undefined) => {
- if (value === undefined) return ''
- return value.toLocaleString('fa-IR') + ' تومان'
+ const CustomTooltip = (props: {
+ active?: boolean
+ payload?: Array<{
+ dataKey?: string
+ value?: number
+ color?: string
+ }>
+ label?: string
+ }) => {
+ const { active, payload, label } = props
+ if (!active || !payload || payload.length === 0) {
+ return null
+ }
+
+ const cashValue = payload.find((item) => item.dataKey === 'cash')?.value as number | undefined
+ const onlineValue = payload.find((item) => item.dataKey === 'online')?.value as number | undefined
+
+ return (
+
+
{label}
+
+ {cashValue !== undefined && (
+
+
+
پرداخت نقدی:
+
+ {cashValue.toLocaleString('fa-IR')} تومان
+
+
+ )}
+ {onlineValue !== undefined && (
+
+
+
پرداخت آنلاین:
+
+ {onlineValue.toLocaleString('fa-IR')} تومان
+
+
+ )}
+ {cashValue !== undefined && onlineValue !== undefined && (
+
+ جمع:
+
+ {(cashValue + onlineValue).toLocaleString('fa-IR')} تومان
+
+
+ )}
+
+
+ )
}
if (isLoading) {
@@ -142,7 +188,7 @@ const RevenueChart: FC = () => {
{/* Tabs */}
-
+ {/*
-
+
*/}
{/* مبلغ و درصد */}
@@ -304,15 +350,7 @@ const RevenueChart: FC = () => {
domain={[0, 'dataMax + 2000000']}
tickMargin={50}
/>
-