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