fix price chart
This commit is contained in:
@@ -102,22 +102,56 @@ const RevenueChart: FC = () => {
|
||||
dataKey?: string
|
||||
value?: number
|
||||
color?: string
|
||||
payload?: {
|
||||
cash?: number
|
||||
online?: number
|
||||
month?: string
|
||||
}
|
||||
}>
|
||||
label?: string
|
||||
}) => {
|
||||
const { active, payload, label } = props
|
||||
if (!active || !payload || payload.length === 0) {
|
||||
if (!active || !payload || payload.length === 0 || !label) {
|
||||
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
|
||||
// استفاده از paymentsChartData.data مستقیم برای دریافت دادههای واقعی
|
||||
// پیدا کردن آخرین آیتمی که label آن با formatDateLabel match میکند
|
||||
let dataPoint: { cash: number; online: number } | null = null
|
||||
|
||||
if (paymentsChartData?.data) {
|
||||
// پیدا کردن همه آیتمهای match شده و استفاده از آخرین
|
||||
const matchingItems: Array<{ cash: number; online: number }> = []
|
||||
for (const item of paymentsChartData.data) {
|
||||
const formattedLabel = formatDateLabel(item.date, selectedTab)
|
||||
if (formattedLabel === label) {
|
||||
matchingItems.push({ cash: item.cash, online: item.online })
|
||||
}
|
||||
}
|
||||
if (matchingItems.length > 0) {
|
||||
dataPoint = matchingItems[matchingItems.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
// اگر پیدا نکردیم، از chartData استفاده میکنیم
|
||||
if (!dataPoint) {
|
||||
const matchingItems = chartData.filter((item) => item.month === label)
|
||||
if (matchingItems.length > 0) {
|
||||
dataPoint = matchingItems[matchingItems.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
if (!dataPoint) {
|
||||
return null
|
||||
}
|
||||
|
||||
const cashValue = dataPoint.cash
|
||||
const onlineValue = dataPoint.online
|
||||
|
||||
return (
|
||||
<div className='bg-white p-3 rounded-xl shadow-lg border border-gray-200'>
|
||||
<p className='text-sm font-medium text-gray-900 mb-2'>{label}</p>
|
||||
<div className='space-y-1'>
|
||||
{cashValue !== undefined && (
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='w-2 h-2 rounded-full bg-[#B0BAC9]' />
|
||||
<span className='text-xs text-gray-600'>پرداخت نقدی:</span>
|
||||
@@ -125,8 +159,6 @@ const RevenueChart: FC = () => {
|
||||
{cashValue.toLocaleString('fa-IR')} تومان
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{onlineValue !== undefined && (
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='w-2 h-2 rounded-full bg-[#6B7FED]' />
|
||||
<span className='text-xs text-gray-600'>پرداخت آنلاین:</span>
|
||||
@@ -134,15 +166,12 @@ const RevenueChart: FC = () => {
|
||||
{onlineValue.toLocaleString('fa-IR')} تومان
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{cashValue !== undefined && onlineValue !== undefined && (
|
||||
<div className='pt-1 mt-1 border-t border-gray-100'>
|
||||
<span className='text-xs text-gray-600'>جمع:</span>
|
||||
<span className='text-xs font-medium text-gray-900 mr-2'>
|
||||
{(cashValue + onlineValue).toLocaleString('fa-IR')} تومان
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -159,7 +188,7 @@ const RevenueChart: FC = () => {
|
||||
return (
|
||||
<div className='bg-white rounded-3xl p-6 shadow-sm h-full overflow-visible'>
|
||||
{/* Header */}
|
||||
<div className='flex items-start justify-between mb-5'>
|
||||
<div className='flex items-start justify-between my-5'>
|
||||
<h3 className='text-base font-bold'>مجموع درآمد</h3>
|
||||
|
||||
|
||||
|
||||
+10
-8
@@ -77,6 +77,15 @@ const SideBar: FC = () => {
|
||||
activeName=''
|
||||
/>
|
||||
|
||||
<SideBarItem
|
||||
icon={<DocumentText variant={isActive('orders') ? 'Bold' : 'Outline'} color={isActive('orders') ? 'black' : '#8C90A3'} size={iconSizeSideBar} />}
|
||||
title={t('sidebar.orders')}
|
||||
isActive={isActive('orders')}
|
||||
link={Pages.orders.list}
|
||||
name='orders'
|
||||
activeName='orders'
|
||||
/>
|
||||
|
||||
<SideBarItem
|
||||
icon={<Element3 variant={isActive('foods') ? 'Bold' : 'Outline'} color={isActive('foods') ? 'black' : '#8C90A3'} size={iconSizeSideBar} />}
|
||||
title={t('sidebar.foods')}
|
||||
@@ -103,14 +112,7 @@ const SideBar: FC = () => {
|
||||
activeName='payment_methods'
|
||||
/>
|
||||
|
||||
<SideBarItem
|
||||
icon={<DocumentText variant={isActive('orders') ? 'Bold' : 'Outline'} color={isActive('orders') ? 'black' : '#8C90A3'} size={iconSizeSideBar} />}
|
||||
title={t('sidebar.orders')}
|
||||
isActive={isActive('orders')}
|
||||
link={Pages.orders.list}
|
||||
name='orders'
|
||||
activeName='orders'
|
||||
/>
|
||||
|
||||
<SideBarItem
|
||||
icon={<People variant={isActive('customers') ? 'Bold' : 'Outline'} color={isActive('customers') ? 'black' : '#8C90A3'} size={iconSizeSideBar} />}
|
||||
title={t('sidebar.customers')}
|
||||
|
||||
@@ -33,11 +33,11 @@ const CustomersSubMenu: FC = () => {
|
||||
isActive={isActive('list')}
|
||||
link={Pages.customers.list}
|
||||
/>
|
||||
<SubMenuItem
|
||||
{/* <SubMenuItem
|
||||
title={t('submenu.add_customer')}
|
||||
isActive={isActive('add')}
|
||||
link={Pages.customers.add}
|
||||
/>
|
||||
/> */}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -33,11 +33,11 @@ const OrdersSubMenu: FC = () => {
|
||||
isActive={isActive('list')}
|
||||
link={Pages.orders.list}
|
||||
/>
|
||||
<SubMenuItem
|
||||
{/* <SubMenuItem
|
||||
title={t('submenu.add_order')}
|
||||
isActive={isActive('add')}
|
||||
link={Pages.orders.add}
|
||||
/>
|
||||
/> */}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user