diff --git a/src/app/[lang]/(dashboard)/(private)/dashboards/orders/page.tsx b/src/app/[lang]/(dashboard)/(private)/dashboards/orders/page.tsx index 0028b4b..54936b3 100644 --- a/src/app/[lang]/(dashboard)/(private)/dashboards/orders/page.tsx +++ b/src/app/[lang]/(dashboard)/(private)/dashboards/orders/page.tsx @@ -5,45 +5,16 @@ import Grid from '@mui/material/Grid2' // Component Imports import DistributedBarChartOrder from '@views/dashboards/crm/DistributedBarChartOrder' -import EarningReportsWithTabs from '@views/dashboards/crm/EarningReportsWithTabs' // Server Action Imports import Loading from '../../../../../../components/layout/shared/Loading' import { useSalesAnalytics } from '../../../../../../services/queries/analytics' +import { RecentSale } from '../../../../../../types/services/analytic' +import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport' const DashboardOrder = () => { const { data, isLoading } = useSalesAnalytics() - const formatDate = (dateString: any) => { - return new Date(dateString).toLocaleDateString('id-ID', { - month: 'short', - day: 'numeric' - }) - } - - const transformSalesData = (data: any) => { - return [ - { - type: 'items', - avatarIcon: 'tabler-shopping-cart', - date: data.map((d: any) => formatDate(d.date)), - series: [{ data: data.map((d: any) => d.items) }] - }, - { - type: 'orders', - avatarIcon: 'tabler-chart-bar', - date: data.map((d: any) => formatDate(d.date)), - series: [{ data: data.map((d: any) => d.orders) }] - }, - { - type: 'sales', - avatarIcon: 'tabler-currency-dollar', - date: data.map((d: any) => formatDate(d.date)), - series: [{ data: data.map((d: any) => d.sales) }] - } - ] - } - if (isLoading) return return ( @@ -89,26 +60,8 @@ const DashboardOrder = () => { /> - + - {/* - - - - - - - - - - - - - - - - - */} ) } diff --git a/src/app/[lang]/(dashboard)/(private)/dashboards/overview/page.tsx b/src/app/[lang]/(dashboard)/(private)/dashboards/overview/page.tsx index c0b24a0..77e61d3 100644 --- a/src/app/[lang]/(dashboard)/(private)/dashboards/overview/page.tsx +++ b/src/app/[lang]/(dashboard)/(private)/dashboards/overview/page.tsx @@ -3,31 +3,19 @@ import React from 'react' import { useDashboardAnalytics } from '../../../../../../services/queries/analytics' import Loading from '../../../../../../components/layout/shared/Loading' +import { formatCurrency, formatDate } from '../../../../../../utils/transform' +import ProductSales from '../../../../../../views/dashboards/products/ProductSales' +import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport' +import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport' const DashboardOverview = () => { // Sample data - replace with your actual data const { data: salesData, isLoading } = useDashboardAnalytics() - const formatCurrency = (amount: any) => { - return new Intl.NumberFormat('id-ID', { - style: 'currency', - currency: 'IDR', - minimumFractionDigits: 0 - }).format(amount) - } - - const formatDate = (dateString: any) => { - return new Date(dateString).toLocaleDateString('id-ID', { - day: 'numeric', - month: 'short', - year: 'numeric' - }) - } - if (isLoading) return const MetricCard = ({ iconClass, title, value, subtitle, bgColor = 'bg-blue-500' }: any) => ( -
+

{title}

@@ -93,14 +81,14 @@ const DashboardOverview = () => { {/* Additional Metrics */}
-
+

Voided Orders

{salesData.overview.voided_orders}

-
+

Refunded Orders

@@ -111,170 +99,14 @@ const DashboardOverview = () => {
{/* Top Products */} -
-
-
- -

Top Products

-
-
- - - - - - - - - - - - - {salesData.top_products.map((product, index) => ( - - - - - - - - - ))} - -
- Product - - Category - - Qty Sold - - Revenue - - Avg Price - - Orders -
-
- - {product.product_name} -
-
- - {product.category_name} - - - {product.quantity_sold} - - {formatCurrency(product.revenue)} - - {formatCurrency(product.average_price)} - - {product.order_count} -
-
-
-
+ {/* Payment Methods */} -
-
-
- -

Payment Methods

-
-
- {salesData.payment_methods.map(method => ( -
-
- {method.payment_method_name} - {method.percentage.toFixed(1)}% -
- -
- {formatCurrency(method.total_amount)} - {method.order_count} orders -
-
- ))} -
-
-
+
{/* Recent Sales */} -
-
-
- -

Recent Sales

-
-
- - - - - - - - - - - - - - {salesData.recent_sales.map((sale, index) => ( - - - - - - - - - - ))} - -
- Date - - Sales - - Orders - - Items - - Tax - - Discount - - Net Sales -
- {formatDate(sale.date)} - - {formatCurrency(sale.sales)} - {sale.orders}{sale.items} - {formatCurrency(sale.tax)} - - {formatCurrency(sale.discount)} - - {formatCurrency(sale.net_sales)} -
-
-
-
+
)} diff --git a/src/app/[lang]/(dashboard)/(private)/dashboards/payment-methods/page.tsx b/src/app/[lang]/(dashboard)/(private)/dashboards/payment-methods/page.tsx index cf4c6ef..bd5a706 100644 --- a/src/app/[lang]/(dashboard)/(private)/dashboards/payment-methods/page.tsx +++ b/src/app/[lang]/(dashboard)/(private)/dashboards/payment-methods/page.tsx @@ -5,27 +5,16 @@ import Grid from '@mui/material/Grid2' // Component Imports import DistributedBarChartOrder from '@views/dashboards/crm/DistributedBarChartOrder' -import EarningReportsWithTabs from '@views/dashboards/crm/EarningReportsWithTabs' // Server Action Imports import Loading from '../../../../../../components/layout/shared/Loading' import { usePaymentAnalytics } from '../../../../../../services/queries/analytics' import { PaymentDataItem } from '../../../../../../types/services/analytic' +import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport' const DashboardPayment = () => { const { data, isLoading } = usePaymentAnalytics() - const transformSalesData = (data: PaymentDataItem[]) => { - return [ - { - type: 'payment', - avatarIcon: 'tabler-package', - date: data.map((d: PaymentDataItem) => d.payment_method_name), - series: [{ data: data.map((d: PaymentDataItem) => d.total_amount) }] - } - ] - } - if (isLoading) return return ( @@ -71,26 +60,8 @@ const DashboardPayment = () => { /> - + - {/* - - - - - - - - - - - - - - - - - */} ) } diff --git a/src/app/[lang]/(dashboard)/(private)/dashboards/products/page.tsx b/src/app/[lang]/(dashboard)/(private)/dashboards/products/page.tsx index 463e39d..3575aca 100644 --- a/src/app/[lang]/(dashboard)/(private)/dashboards/products/page.tsx +++ b/src/app/[lang]/(dashboard)/(private)/dashboards/products/page.tsx @@ -10,6 +10,7 @@ import EarningReportsWithTabs from '@views/dashboards/crm/EarningReportsWithTabs // Server Action Imports import Loading from '../../../../../../components/layout/shared/Loading' import { useProductSalesAnalytics } from '../../../../../../services/queries/analytics' +import ProductSales from '../../../../../../views/dashboards/products/ProductSales' const DashboardProduct = () => { const { data, isLoading } = useProductSalesAnalytics() @@ -47,67 +48,7 @@ const DashboardProduct = () => { return ( - - - - - - - - - - - - - - - - {/* - - - - - - - - - - - - - - - - - */} + {data?.data && } ) } diff --git a/src/utils/transform.ts b/src/utils/transform.ts index a161f9d..df861eb 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -15,13 +15,11 @@ export const formatShortCurrency = (num: number): string => { return num.toString() } -export const formatDate = (dateString: string) => { - return new Date(dateString).toLocaleDateString('en-US', { - year: 'numeric', - month: 'long', +export const formatDate = (dateString: any) => { + return new Date(dateString).toLocaleDateString('id-ID', { day: 'numeric', - hour: '2-digit', - minute: '2-digit' + month: 'short', + year: 'numeric' }) } diff --git a/src/views/dashboards/orders/OrdersReport.tsx b/src/views/dashboards/orders/OrdersReport.tsx new file mode 100644 index 0000000..cbb7221 --- /dev/null +++ b/src/views/dashboards/orders/OrdersReport.tsx @@ -0,0 +1,65 @@ +import { RecentSale } from '../../../types/services/analytic' +import { formatCurrency, formatDate } from '../../../utils/transform' + +const OrdersReport = ({ orderData, title }: { orderData: RecentSale[]; title: string }) => { + return ( +
+
+
+ +

{title}

+
+
+ + + + + + + + + + + + + + {orderData.map((sale, index) => ( + + + + + + + + + + ))} + +
Date + Sales + + Orders + + Items + Tax + Discount + + Net Sales +
+ {formatDate(sale.date)} + + {formatCurrency(sale.sales)} + {sale.orders}{sale.items} + {formatCurrency(sale.tax)} + + {formatCurrency(sale.discount)} + + {formatCurrency(sale.net_sales)} +
+
+
+
+ ) +} + +export default OrdersReport diff --git a/src/views/dashboards/payment-methods/PaymentMethodReport.tsx b/src/views/dashboards/payment-methods/PaymentMethodReport.tsx new file mode 100644 index 0000000..2ddafee --- /dev/null +++ b/src/views/dashboards/payment-methods/PaymentMethodReport.tsx @@ -0,0 +1,44 @@ +import { PaymentDataItem } from '../../../types/services/analytic' +import { formatCurrency } from '../../../utils/transform' + +const PaymentMethodReport = ({ payments }: { payments: PaymentDataItem[] }) => { + const ProgressBar = ({ percentage, color = 'bg-blue-500' }: any) => ( +
+
+
+ ) + + return ( +
+
+
+ +

Payment Methods

+
+
+ {payments.map(method => ( +
+
+ {method.payment_method_name} + {method.percentage.toFixed(1)}% +
+ +
+ {formatCurrency(method.total_amount)} + {method.order_count} orders +
+
+ ))} +
+
+
+ ) +} + +export default PaymentMethodReport diff --git a/src/views/dashboards/products/ProductSales.tsx b/src/views/dashboards/products/ProductSales.tsx new file mode 100644 index 0000000..b3a49b8 --- /dev/null +++ b/src/views/dashboards/products/ProductSales.tsx @@ -0,0 +1,82 @@ +import { ProductData } from '../../../types/services/analytic' +import { formatCurrency } from '../../../utils/transform' + +const ProductSales = ({ productData, title }: { productData: ProductData[], title: string }) => { + return ( +
+
+
+ +

{title}

+
+
+ + + + + + + + + + + + + {productData.map((product, index) => ( + + + + + + + + + ))} + +
+ Product + + Category + + Qty Sold + + Revenue + + Avg Price + + Orders +
+
+ + {product.product_name} +
+
+ + {product.category_name} + + + {product.quantity_sold} + + {formatCurrency(product.revenue)} + + {formatCurrency(product.average_price)} + + {product.order_count} +
+
+
+
+ ) +} + +export default ProductSales