Compare commits
16 Commits
16ad569297
...
ad48cdebe7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad48cdebe7 | ||
|
|
eb38bd7f5c | ||
|
|
b8de65bdcf | ||
|
|
4f65b9bbb6 | ||
|
|
bfdcb123d0 | ||
|
|
4ff01920e7 | ||
|
|
38e1bb5027 | ||
|
|
c71529b11d | ||
|
|
c6f2d67baf | ||
|
|
22374dbee1 | ||
|
|
7803eaa13e | ||
|
|
6d2fe8d6f7 | ||
| 3700ce6228 | |||
|
|
2c370b4c15 | ||
|
|
6549773c13 | ||
|
|
274cecd1cb |
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
7
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
7
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/pos-dashboard-v2.iml" filepath="$PROJECT_DIR$/.idea/pos-dashboard-v2.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
.idea/pos-dashboard-v2.iml
generated
Normal file
12
.idea/pos-dashboard-v2.iml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
52
Dockerfile
Normal file
52
Dockerfile
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:18-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Build arguments for environment variables
|
||||||
|
ARG NEXT_PUBLIC_APP_URL
|
||||||
|
ARG NEXT_PUBLIC_DOCS_URL
|
||||||
|
ARG NEXT_PUBLIC_API_URL
|
||||||
|
ARG API_URL
|
||||||
|
ARG BASEPATH
|
||||||
|
ARG MAPBOX_ACCESS_TOKEN
|
||||||
|
|
||||||
|
# Set environment variables for build
|
||||||
|
ENV API_URL=$API_URL
|
||||||
|
ENV BASEPATH=$BASEPATH
|
||||||
|
ENV MAPBOX_ACCESS_TOKEN=$MAPBOX_ACCESS_TOKEN
|
||||||
|
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
|
||||||
|
ENV NEXT_PUBLIC_DOCS_URL=$NEXT_PUBLIC_DOCS_URL
|
||||||
|
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||||
|
|
||||||
|
# Copy all files first
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Build icons
|
||||||
|
RUN npm run build:icons
|
||||||
|
|
||||||
|
# Build the application without linting
|
||||||
|
RUN npm run build:no-lint
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:18-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
RUN addgroup -g 1001 -S nodejs
|
||||||
|
RUN adduser -S nextjs -u 1001
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
ENV PORT=8080
|
||||||
|
|
||||||
|
CMD ["node", "server.js"]
|
||||||
19
deployment.sh
Normal file
19
deployment.sh
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
APP_NAME="apskel-frontend"
|
||||||
|
PORT="8080"
|
||||||
|
|
||||||
|
echo "🔄 Pulling latest code..."
|
||||||
|
git pull
|
||||||
|
|
||||||
|
echo "🐳 Building Docker image..."
|
||||||
|
docker build -t apskel-frontend .
|
||||||
|
|
||||||
|
docker stop $APP_NAME 2>/dev/null
|
||||||
|
docker rm $APP_NAME 2>/dev/null
|
||||||
|
|
||||||
|
docker run -d --name $APP_NAME \
|
||||||
|
-p 8080:$PORT \
|
||||||
|
$APP_NAME:latest
|
||||||
|
|
||||||
|
echo "✅ Deployment complete."
|
||||||
@ -1,29 +1,34 @@
|
|||||||
import type { NextConfig } from 'next'
|
import type { NextConfig } from 'next'
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
output: 'standalone',
|
||||||
basePath: process.env.BASEPATH,
|
basePath: process.env.BASEPATH,
|
||||||
redirects: async () => {
|
eslint: {
|
||||||
return [
|
ignoreDuringBuilds: true,
|
||||||
{
|
},
|
||||||
source: '/',
|
typescript: {
|
||||||
destination: '/en/dashboards/overview',
|
ignoreBuildErrors: true,
|
||||||
permanent: true,
|
},
|
||||||
locale: false
|
redirects: async () => [
|
||||||
},
|
{
|
||||||
{
|
source: '/',
|
||||||
source: '/:lang(en|fr|ar)',
|
destination: '/en/dashboards/overview',
|
||||||
destination: '/:lang/dashboards/overview',
|
permanent: true,
|
||||||
permanent: true,
|
locale: false,
|
||||||
locale: false
|
},
|
||||||
},
|
{
|
||||||
{
|
source: '/:lang(en|fr|ar)',
|
||||||
source: '/((?!(?:en|fr|ar|front-pages|favicon.ico)\\b)):path',
|
destination: '/:lang/dashboards/overview',
|
||||||
destination: '/en/:path',
|
permanent: true,
|
||||||
permanent: true,
|
locale: false,
|
||||||
locale: false
|
},
|
||||||
}
|
{
|
||||||
]
|
source: '/((?!(?:en|fr|ar|front-pages|favicon.ico)\\b)):path',
|
||||||
}
|
destination: '/en/:path',
|
||||||
|
permanent: true,
|
||||||
|
locale: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
export default nextConfig
|
export default nextConfig
|
||||||
|
|||||||
17
package-lock.json
generated
17
package-lock.json
generated
@ -25,6 +25,7 @@
|
|||||||
"@fullcalendar/react": "6.1.15",
|
"@fullcalendar/react": "6.1.15",
|
||||||
"@fullcalendar/timegrid": "6.1.15",
|
"@fullcalendar/timegrid": "6.1.15",
|
||||||
"@hookform/resolvers": "3.9.1",
|
"@hookform/resolvers": "3.9.1",
|
||||||
|
"@iconify/react": "^6.0.1",
|
||||||
"@mui/lab": "6.0.0-beta.19",
|
"@mui/lab": "6.0.0-beta.19",
|
||||||
"@mui/material": "6.2.1",
|
"@mui/material": "6.2.1",
|
||||||
"@mui/material-nextjs": "6.2.1",
|
"@mui/material-nextjs": "6.2.1",
|
||||||
@ -1308,6 +1309,21 @@
|
|||||||
"pathe": "^1.1.2"
|
"pathe": "^1.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@iconify/react": {
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@iconify/react/-/react-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-fCocnAfiGXjrA0u7KkS3W/OQHNp9LRFICudvOtxmS3Mf7U92aDhP50wyzRbobZli51zYt9ksZ9g0J7H586XvOQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@iconify/types": "^2.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/cyberalien"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=16"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@iconify/tools": {
|
"node_modules/@iconify/tools": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@iconify/tools/-/tools-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@iconify/tools/-/tools-4.1.1.tgz",
|
||||||
@ -1332,7 +1348,6 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz",
|
||||||
"integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==",
|
"integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@iconify/utils": {
|
"node_modules/@iconify/utils": {
|
||||||
|
|||||||
@ -11,7 +11,8 @@
|
|||||||
"lint:fix": "next lint --fix",
|
"lint:fix": "next lint --fix",
|
||||||
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
|
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
|
||||||
"build:icons": "tsx src/assets/iconify-icons/bundle-icons-css.ts",
|
"build:icons": "tsx src/assets/iconify-icons/bundle-icons-css.ts",
|
||||||
"removeI18n": "tsx src/remove-translation-scripts/index.ts"
|
"removeI18n": "tsx src/remove-translation-scripts/index.ts",
|
||||||
|
"build:no-lint": "NEXT_DISABLE_ESLINT=true NEXT_DISABLE_TYPECHECK=true next build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emoji-mart/data": "1.2.1",
|
"@emoji-mart/data": "1.2.1",
|
||||||
@ -30,6 +31,7 @@
|
|||||||
"@fullcalendar/react": "6.1.15",
|
"@fullcalendar/react": "6.1.15",
|
||||||
"@fullcalendar/timegrid": "6.1.15",
|
"@fullcalendar/timegrid": "6.1.15",
|
||||||
"@hookform/resolvers": "3.9.1",
|
"@hookform/resolvers": "3.9.1",
|
||||||
|
"@iconify/react": "^6.0.1",
|
||||||
"@mui/lab": "6.0.0-beta.19",
|
"@mui/lab": "6.0.0-beta.19",
|
||||||
"@mui/material": "6.2.1",
|
"@mui/material": "6.2.1",
|
||||||
"@mui/material-nextjs": "6.2.1",
|
"@mui/material-nextjs": "6.2.1",
|
||||||
|
|||||||
@ -7,18 +7,87 @@ import Grid from '@mui/material/Grid2'
|
|||||||
import DistributedBarChartOrder from '@views/dashboards/crm/DistributedBarChartOrder'
|
import DistributedBarChartOrder from '@views/dashboards/crm/DistributedBarChartOrder'
|
||||||
|
|
||||||
// Server Action Imports
|
// Server Action Imports
|
||||||
|
import { TextField, Typography, useTheme } from '@mui/material'
|
||||||
|
import { useState } from 'react'
|
||||||
import Loading from '../../../../../../components/layout/shared/Loading'
|
import Loading from '../../../../../../components/layout/shared/Loading'
|
||||||
import { useSalesAnalytics } from '../../../../../../services/queries/analytics'
|
import { useSalesAnalytics } from '../../../../../../services/queries/analytics'
|
||||||
import { RecentSale } from '../../../../../../types/services/analytic'
|
import { RecentSale } from '../../../../../../types/services/analytic'
|
||||||
|
import { formatDateDDMMYYYY, formatForInputDate } from '../../../../../../utils/transform'
|
||||||
import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport'
|
import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport'
|
||||||
|
|
||||||
const DashboardOrder = () => {
|
const DashboardOrder = () => {
|
||||||
const { data, isLoading } = useSalesAnalytics()
|
const theme = useTheme()
|
||||||
|
|
||||||
|
const today = new Date()
|
||||||
|
const monthAgo = new Date()
|
||||||
|
monthAgo.setDate(today.getDate() - 30)
|
||||||
|
|
||||||
|
const [filter, setFilter] = useState({
|
||||||
|
date_from: formatDateDDMMYYYY(monthAgo),
|
||||||
|
date_to: formatDateDDMMYYYY(today)
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data, isLoading } = useSalesAnalytics({
|
||||||
|
date_from: filter.date_from,
|
||||||
|
date_to: filter.date_to
|
||||||
|
})
|
||||||
|
|
||||||
if (isLoading) return <Loading />
|
if (isLoading) return <Loading />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={6}>
|
<Grid container spacing={6}>
|
||||||
|
<Grid size={{ xs: 12 }}>
|
||||||
|
<div className='flex gap-4 items-center justify-between'>
|
||||||
|
<Typography variant='h1' className='text-3xl font-bold text-gray-900 mb-2'>
|
||||||
|
Orders Analysis Dashboard
|
||||||
|
</Typography>
|
||||||
|
<div className='flex items-center gap-4'>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={formatForInputDate(data?.date_from || new Date())}
|
||||||
|
onChange={e => {
|
||||||
|
setFilter({
|
||||||
|
...filter,
|
||||||
|
date_from: formatDateDDMMYYYY(new Date(e.target.value))
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography>-</Typography>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={
|
||||||
|
data?.date_to
|
||||||
|
? new Date(data?.date_to).toISOString().split('T')[0]
|
||||||
|
: new Date().toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
onChange={e => {}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<Grid size={{ xs: 12, sm: 6, md: 4, lg: 3 }}>
|
<Grid size={{ xs: 12, sm: 6, md: 4, lg: 3 }}>
|
||||||
<DistributedBarChartOrder
|
<DistributedBarChartOrder
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
|||||||
@ -1,18 +1,31 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React from 'react'
|
import { TextField, Typography, useTheme } from '@mui/material'
|
||||||
import { useDashboardAnalytics } from '../../../../../../services/queries/analytics'
|
import { useState } from 'react'
|
||||||
import Loading from '../../../../../../components/layout/shared/Loading'
|
import Loading from '../../../../../../components/layout/shared/Loading'
|
||||||
import { formatCurrency, formatDate, formatShortCurrency } from '../../../../../../utils/transform'
|
import { useDashboardAnalytics } from '../../../../../../services/queries/analytics'
|
||||||
import ProductSales from '../../../../../../views/dashboards/products/ProductSales'
|
import { formatDateDDMMYYYY, formatForInputDate, formatShortCurrency } from '../../../../../../utils/transform'
|
||||||
import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport'
|
|
||||||
import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport'
|
import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport'
|
||||||
|
import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport'
|
||||||
|
import ProductSales from '../../../../../../views/dashboards/products/ProductSales'
|
||||||
|
|
||||||
const DashboardOverview = () => {
|
const DashboardOverview = () => {
|
||||||
// Sample data - replace with your actual data
|
const theme = useTheme()
|
||||||
const { data: salesData, isLoading } = useDashboardAnalytics()
|
|
||||||
|
|
||||||
if (isLoading) return <Loading />
|
const today = new Date()
|
||||||
|
const monthAgo = new Date()
|
||||||
|
monthAgo.setDate(today.getDate() - 30)
|
||||||
|
|
||||||
|
const [filter, setFilter] = useState({
|
||||||
|
date_from: formatDateDDMMYYYY(monthAgo),
|
||||||
|
date_to: formatDateDDMMYYYY(today)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Sample data - replace with your actual data
|
||||||
|
const { data: salesData, isLoading } = useDashboardAnalytics({
|
||||||
|
date_from: filter.date_from,
|
||||||
|
date_to: filter.date_to
|
||||||
|
})
|
||||||
|
|
||||||
const MetricCard = ({ iconClass, title, value, subtitle, bgColor = 'bg-blue-500', isCurrency = false }: any) => (
|
const MetricCard = ({ iconClass, title, value, subtitle, bgColor = 'bg-blue-500', isCurrency = false }: any) => (
|
||||||
<div className='bg-white rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 p-6'>
|
<div className='bg-white rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 p-6'>
|
||||||
@ -29,70 +42,113 @@ const DashboardOverview = () => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
const ProgressBar = ({ percentage, color = 'bg-blue-500' }: any) => (
|
|
||||||
<div className='w-full bg-gray-200 rounded-full h-2'>
|
|
||||||
<div
|
|
||||||
className={`${color} h-2 rounded-full transition-all duration-300`}
|
|
||||||
style={{ width: `${percentage}%` }}
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{salesData && (
|
<div>
|
||||||
<div>
|
{/* Header */}
|
||||||
{/* Header */}
|
<div className='mb-8 flex gap-4 items-center justify-between'>
|
||||||
{/* <div className="mb-8">
|
<Typography variant='h1' className='text-3xl font-bold text-gray-900 mb-2'>
|
||||||
<h1 className="text-3xl font-bold text-gray-900 mb-2">Sales Dashboard</h1>
|
Analysis Dashboard
|
||||||
<p className="text-gray-600">
|
</Typography>
|
||||||
{formatDate(salesData.date_from)} - {formatDate(salesData.date_to)}
|
<div className='flex items-center gap-4'>
|
||||||
</p>
|
<TextField
|
||||||
</div> */}
|
type='date'
|
||||||
|
value={formatForInputDate(salesData?.date_from || new Date())}
|
||||||
{/* Overview Metrics */}
|
onChange={e => {
|
||||||
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8'>
|
setFilter({
|
||||||
<MetricCard
|
...filter,
|
||||||
iconClass='tabler-shopping-cart'
|
date_from: formatDateDDMMYYYY(new Date(e.target.value))
|
||||||
title='Total Orders'
|
})
|
||||||
value={salesData.overview.total_orders.toLocaleString()}
|
}}
|
||||||
subtitle={`${salesData.overview.voided_orders} voided, ${salesData.overview.refunded_orders} refunded`}
|
size='small'
|
||||||
bgColor='bg-blue-500'
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<MetricCard
|
<Typography>-</Typography>
|
||||||
iconClass='tabler-cash'
|
<TextField
|
||||||
title='Total Sales'
|
type='date'
|
||||||
value={formatShortCurrency(salesData.overview.total_sales)}
|
value={
|
||||||
bgColor='bg-green-500'
|
salesData?.date_to
|
||||||
isCurrency={true}
|
? new Date(salesData?.date_to).toISOString().split('T')[0]
|
||||||
/>
|
: new Date().toISOString().split('T')[0]
|
||||||
<MetricCard
|
}
|
||||||
iconClass='tabler-trending-up'
|
onChange={e => {
|
||||||
title='Average Order Value'
|
setFilter({
|
||||||
value={formatShortCurrency(salesData.overview.average_order_value)}
|
...filter,
|
||||||
bgColor='bg-purple-500'
|
date_to: formatDateDDMMYYYY(new Date(e.target.value))
|
||||||
isCurrency={true}
|
})
|
||||||
/>
|
}}
|
||||||
<MetricCard
|
size='small'
|
||||||
iconClass='tabler-users'
|
sx={{
|
||||||
title='Total Customers'
|
'& .MuiOutlinedInput-root': {
|
||||||
value={salesData.overview.total_customers || 'N/A'}
|
'&.Mui-focused fieldset': {
|
||||||
bgColor='bg-orange-500'
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8'>
|
|
||||||
{/* Top Products */}
|
|
||||||
<ProductSales title='Top Products' productData={salesData.top_products} />
|
|
||||||
|
|
||||||
{/* Payment Methods */}
|
|
||||||
<PaymentMethodReport payments={salesData.payment_methods} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Recent Sales */}
|
|
||||||
<OrdersReport title='Recent Sales' orderData={salesData.recent_sales} />
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
{salesData ? (
|
||||||
|
<>
|
||||||
|
{/* Overview Metrics */}
|
||||||
|
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8'>
|
||||||
|
<MetricCard
|
||||||
|
iconClass='tabler-shopping-cart'
|
||||||
|
title='Total Orders'
|
||||||
|
value={salesData.overview.total_orders.toLocaleString()}
|
||||||
|
subtitle={`${salesData.overview.voided_orders} voided, ${salesData.overview.refunded_orders} refunded`}
|
||||||
|
bgColor='bg-blue-500'
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
iconClass='tabler-cash'
|
||||||
|
title='Total Sales'
|
||||||
|
value={formatShortCurrency(salesData.overview.total_sales)}
|
||||||
|
bgColor='bg-green-500'
|
||||||
|
isCurrency={true}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
iconClass='tabler-trending-up'
|
||||||
|
title='Average Order Value'
|
||||||
|
value={formatShortCurrency(salesData.overview.average_order_value)}
|
||||||
|
bgColor='bg-purple-500'
|
||||||
|
isCurrency={true}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
iconClass='tabler-users'
|
||||||
|
title='Total Customers'
|
||||||
|
value={salesData.overview.total_customers || 'N/A'}
|
||||||
|
bgColor='bg-orange-500'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8'>
|
||||||
|
{/* Top Products */}
|
||||||
|
<ProductSales title='Top Products' productData={salesData.top_products} />
|
||||||
|
|
||||||
|
{/* Payment Methods */}
|
||||||
|
<PaymentMethodReport payments={salesData.payment_methods} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Recent Sales */}
|
||||||
|
<OrdersReport title='Recent Sales' orderData={salesData.recent_sales} />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Loading />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,14 +11,82 @@ import Loading from '../../../../../../components/layout/shared/Loading'
|
|||||||
import { usePaymentAnalytics } from '../../../../../../services/queries/analytics'
|
import { usePaymentAnalytics } from '../../../../../../services/queries/analytics'
|
||||||
import { PaymentDataItem } from '../../../../../../types/services/analytic'
|
import { PaymentDataItem } from '../../../../../../types/services/analytic'
|
||||||
import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport'
|
import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport'
|
||||||
|
import { Typography, TextField, useTheme } from '@mui/material'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { formatDateDDMMYYYY, formatForInputDate } from '../../../../../../utils/transform'
|
||||||
|
|
||||||
const DashboardPayment = () => {
|
const DashboardPayment = () => {
|
||||||
const { data, isLoading } = usePaymentAnalytics()
|
const theme = useTheme()
|
||||||
|
|
||||||
|
const today = new Date()
|
||||||
|
const monthAgo = new Date()
|
||||||
|
monthAgo.setDate(today.getDate() - 30)
|
||||||
|
|
||||||
|
const [filter, setFilter] = useState({
|
||||||
|
date_from: formatDateDDMMYYYY(monthAgo),
|
||||||
|
date_to: formatDateDDMMYYYY(today)
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data, isLoading } = usePaymentAnalytics({
|
||||||
|
date_from: filter.date_from,
|
||||||
|
date_to: filter.date_to
|
||||||
|
})
|
||||||
|
|
||||||
if (isLoading) return <Loading />
|
if (isLoading) return <Loading />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={6}>
|
<Grid container spacing={6}>
|
||||||
|
<Grid size={{ xs: 12 }}>
|
||||||
|
<div className='flex gap-4 items-center justify-between'>
|
||||||
|
<Typography variant='h1' className='text-3xl font-bold text-gray-900 mb-2'>
|
||||||
|
Payments Analysis Dashboard
|
||||||
|
</Typography>
|
||||||
|
<div className='flex items-center gap-4'>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={formatForInputDate(data?.date_from || new Date())}
|
||||||
|
onChange={e => {
|
||||||
|
setFilter({
|
||||||
|
...filter,
|
||||||
|
date_from: formatDateDDMMYYYY(new Date(e.target.value))
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography>-</Typography>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={
|
||||||
|
data?.date_to
|
||||||
|
? new Date(data?.date_to).toISOString().split('T')[0]
|
||||||
|
: new Date().toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
onChange={e => {}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Grid>
|
||||||
<Grid size={{ xs: 12, sm: 6, md: 4, lg: 3 }}>
|
<Grid size={{ xs: 12, sm: 6, md: 4, lg: 3 }}>
|
||||||
<DistributedBarChartOrder
|
<DistributedBarChartOrder
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
|||||||
@ -6,47 +6,88 @@ import Grid from '@mui/material/Grid2'
|
|||||||
// Component Imports
|
// Component Imports
|
||||||
|
|
||||||
// Server Action Imports
|
// Server Action Imports
|
||||||
|
import { TextField, Typography, useTheme } from '@mui/material'
|
||||||
|
import { useState } from 'react'
|
||||||
import Loading from '../../../../../../components/layout/shared/Loading'
|
import Loading from '../../../../../../components/layout/shared/Loading'
|
||||||
import { useProductSalesAnalytics } from '../../../../../../services/queries/analytics'
|
import { useProductSalesAnalytics } from '../../../../../../services/queries/analytics'
|
||||||
|
import { formatDateDDMMYYYY, formatForInputDate } from '../../../../../../utils/transform'
|
||||||
import ProductSales from '../../../../../../views/dashboards/products/ProductSales'
|
import ProductSales from '../../../../../../views/dashboards/products/ProductSales'
|
||||||
|
|
||||||
const DashboardProduct = () => {
|
const DashboardProduct = () => {
|
||||||
const { data, isLoading } = useProductSalesAnalytics()
|
const theme = useTheme()
|
||||||
|
|
||||||
const summary = {
|
const today = new Date()
|
||||||
totalProducts: data?.data.length,
|
const monthAgo = new Date()
|
||||||
totalQuantitySold: data?.data.reduce((sum, item) => sum + item.quantity_sold, 0),
|
monthAgo.setDate(today.getDate() - 30)
|
||||||
totalRevenue: data?.data.reduce((sum, item) => sum + item.revenue, 0),
|
|
||||||
totalOrders: data?.data.reduce((sum, item) => sum + item.order_count, 0),
|
|
||||||
averageOrderValue: data?.data
|
|
||||||
? data!.data.reduce((sum, item) => sum + item.revenue, 0) /
|
|
||||||
data!.data.reduce((sum, item) => sum + item.order_count, 0)
|
|
||||||
: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatDate = (dateString: any) => {
|
const [filter, setFilter] = useState({
|
||||||
return new Date(dateString).toLocaleDateString('id-ID', {
|
date_from: formatDateDDMMYYYY(monthAgo),
|
||||||
month: 'short',
|
date_to: formatDateDDMMYYYY(today)
|
||||||
day: 'numeric'
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const transformSalesData = (data: any) => {
|
const { data, isLoading } = useProductSalesAnalytics({
|
||||||
return [
|
date_from: filter.date_from,
|
||||||
{
|
date_to: filter.date_to
|
||||||
type: 'products',
|
})
|
||||||
avatarIcon: 'tabler-package',
|
|
||||||
date: data.map((d: any) => d.product_name),
|
|
||||||
series: [{ data: data.map((d: any) => d.revenue) }]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLoading) return <Loading />
|
if (isLoading) return <Loading />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={6}>
|
<Grid container spacing={6}>
|
||||||
<Grid size={{ xs: 12, lg: 12 }}>{data?.data && <ProductSales title='Product Sales' productData={data.data} />}</Grid>
|
<Grid size={{ xs: 12, lg: 12 }}>
|
||||||
|
<div className='flex gap-4 items-center justify-between'>
|
||||||
|
<Typography variant='h1' className='text-3xl font-bold text-gray-900 mb-2'>
|
||||||
|
Products Analysis Dashboard
|
||||||
|
</Typography>
|
||||||
|
<div className='flex items-center gap-4'>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={formatForInputDate(data?.date_from || new Date())}
|
||||||
|
onChange={e => {
|
||||||
|
setFilter({
|
||||||
|
...filter,
|
||||||
|
date_from: formatDateDDMMYYYY(new Date(e.target.value))
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography>-</Typography>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={
|
||||||
|
data?.date_to
|
||||||
|
? new Date(data?.date_to).toISOString().split('T')[0]
|
||||||
|
: new Date().toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
onChange={e => {}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={{ xs: 12, lg: 12 }}>
|
||||||
|
{data?.data ? <ProductSales title='Product Sales' productData={data.data} /> : <Loading />}
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,23 +2,28 @@
|
|||||||
|
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useProfitLossAnalytics } from '../../../../../../services/queries/analytics'
|
import { useProfitLossAnalytics } from '../../../../../../services/queries/analytics'
|
||||||
import { formatDateDDMMYYYY, formatShortCurrency } from '../../../../../../utils/transform'
|
import { formatDateDDMMYYYY, formatForInputDate, formatShortCurrency } from '../../../../../../utils/transform'
|
||||||
import MultipleSeries from '../../../../../../views/dashboards/profit-loss/EarningReportWithTabs'
|
import MultipleSeries from '../../../../../../views/dashboards/profit-loss/EarningReportWithTabs'
|
||||||
import { DailyData, ProfitLossReport } from '../../../../../../types/services/analytic'
|
import { DailyData, ProfitLossReport } from '../../../../../../types/services/analytic'
|
||||||
import { TextField, Typography, useTheme } from '@mui/material'
|
import { TextField, Typography, useTheme } from '@mui/material'
|
||||||
|
import Loading from '../../../../../../components/layout/shared/Loading'
|
||||||
|
|
||||||
const DashboardProfitloss = () => {
|
const DashboardProfitloss = () => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
|
|
||||||
|
const today = new Date()
|
||||||
|
const monthAgo = new Date()
|
||||||
|
monthAgo.setDate(today.getDate() - 30)
|
||||||
|
|
||||||
const [filter, setFilter] = useState({
|
const [filter, setFilter] = useState({
|
||||||
date_from: new Date().setDate(new Date().getDate() - 30).toString(),
|
date_from: formatDateDDMMYYYY(monthAgo),
|
||||||
date_to: new Date().toString()
|
date_to: formatDateDDMMYYYY(today)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Sample data - replace with your actual data
|
// Sample data - replace with your actual data
|
||||||
const { data: profitData, isLoading } = useProfitLossAnalytics({
|
const { data: profitData, isLoading } = useProfitLossAnalytics({
|
||||||
date_from: formatDateDDMMYYYY(filter.date_from),
|
date_from: filter.date_from,
|
||||||
date_to: formatDateDDMMYYYY(filter.date_to)
|
date_to: filter.date_to
|
||||||
})
|
})
|
||||||
|
|
||||||
const formatCurrency = (amount: any) => {
|
const formatCurrency = (amount: any) => {
|
||||||
@ -99,303 +104,319 @@ const DashboardProfitloss = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{profitData && (
|
<div>
|
||||||
<div>
|
{/* Header */}
|
||||||
{/* Header */}
|
<div className='mb-8 flex gap-4 items-center justify-between'>
|
||||||
<div className='mb-8 flex gap-4 items-center justify-between'>
|
<Typography variant='h1' className='text-3xl font-bold text-gray-900 mb-2'>
|
||||||
<Typography variant='h1' className='text-3xl font-bold text-gray-900 mb-2'>
|
Profit Analysis Dashboard
|
||||||
Profit Analysis Dashboard
|
</Typography>
|
||||||
</Typography>
|
<div className='flex items-center gap-4'>
|
||||||
<div className='flex items-center gap-4'>
|
<TextField
|
||||||
<TextField
|
type='date'
|
||||||
type='date'
|
value={formatForInputDate(profitData?.date_from || new Date())}
|
||||||
value={new Date(profitData.date_from).toISOString().split('T')[0]}
|
onChange={e => {
|
||||||
onChange={e => {}}
|
setFilter({
|
||||||
size='small'
|
...filter,
|
||||||
sx={{
|
date_from: formatDateDDMMYYYY(new Date(e.target.value))
|
||||||
'& .MuiOutlinedInput-root': {
|
})
|
||||||
'&.Mui-focused fieldset': {
|
}}
|
||||||
borderColor: 'primary.main'
|
size='small'
|
||||||
},
|
sx={{
|
||||||
'& fieldset': {
|
'& .MuiOutlinedInput-root': {
|
||||||
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
'&.Mui-focused fieldset': {
|
||||||
}
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography>-</Typography>
|
||||||
|
<TextField
|
||||||
|
type='date'
|
||||||
|
value={
|
||||||
|
profitData?.date_to
|
||||||
|
? new Date(profitData?.date_to).toISOString().split('T')[0]
|
||||||
|
: new Date().toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
onChange={e => {}}
|
||||||
|
size='small'
|
||||||
|
sx={{
|
||||||
|
'& .MuiOutlinedInput-root': {
|
||||||
|
'&.Mui-focused fieldset': {
|
||||||
|
borderColor: 'primary.main'
|
||||||
|
},
|
||||||
|
'& fieldset': {
|
||||||
|
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{profitData ? (
|
||||||
|
<>
|
||||||
|
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8'>
|
||||||
|
<MetricCard
|
||||||
|
iconClass='tabler-currency-dollar'
|
||||||
|
title='Total Revenue'
|
||||||
|
value={formatShortCurrency(profitData.summary.total_revenue)}
|
||||||
|
bgColor='bg-green-500'
|
||||||
|
isCurrency={true}
|
||||||
/>
|
/>
|
||||||
<Typography>-</Typography>
|
<MetricCard
|
||||||
<TextField
|
iconClass='tabler-receipt'
|
||||||
type='date'
|
title='Total Cost'
|
||||||
value={new Date(profitData.date_to).toISOString().split('T')[0]}
|
value={formatShortCurrency(profitData.summary.total_cost)}
|
||||||
onChange={e => {}}
|
bgColor='bg-red-500'
|
||||||
size='small'
|
isCurrency={true}
|
||||||
sx={{
|
/>
|
||||||
'& .MuiOutlinedInput-root': {
|
<MetricCard
|
||||||
'&.Mui-focused fieldset': {
|
iconClass='tabler-trending-up'
|
||||||
borderColor: 'primary.main'
|
title='Gross Profit'
|
||||||
},
|
value={formatShortCurrency(profitData.summary.gross_profit)}
|
||||||
'& fieldset': {
|
subtitle={`Margin: ${formatPercentage(profitData.summary.gross_profit_margin)}`}
|
||||||
borderColor: theme.palette.mode === 'dark' ? 'rgba(231, 227, 252, 0.22)' : theme.palette.divider
|
bgColor='bg-blue-500'
|
||||||
}
|
isNegative={profitData.summary.gross_profit < 0}
|
||||||
}
|
isCurrency={true}
|
||||||
}}
|
/>
|
||||||
|
<MetricCard
|
||||||
|
iconClass='tabler-percentage'
|
||||||
|
title='Profitability Ratio'
|
||||||
|
value={formatPercentage(profitData.summary.profitability_ratio)}
|
||||||
|
subtitle={`Avg Profit: ${formatShortCurrency(profitData.summary.average_profit)}`}
|
||||||
|
bgColor='bg-purple-500'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Summary Metrics */}
|
{/* Additional Summary Metrics */}
|
||||||
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8'>
|
<div className='grid grid-cols-1 md:grid-cols-3 gap-6 mb-8'>
|
||||||
<MetricCard
|
<div className='bg-white rounded-lg shadow-md p-6'>
|
||||||
iconClass='tabler-currency-dollar'
|
<div className='flex items-center mb-4'>
|
||||||
title='Total Revenue'
|
<i className='tabler-wallet text-[24px] text-green-600 mr-2'></i>
|
||||||
value={formatShortCurrency(profitData.summary.total_revenue)}
|
<h3 className='text-lg font-semibold text-gray-900'>Net Profit</h3>
|
||||||
bgColor='bg-green-500'
|
</div>
|
||||||
isCurrency={true}
|
<p className='text-3xl font-bold text-green-600 mb-2'>
|
||||||
/>
|
Rp {formatShortCurrency(profitData.summary.net_profit)}
|
||||||
<MetricCard
|
</p>
|
||||||
iconClass='tabler-receipt'
|
<p className='text-sm text-gray-600'>
|
||||||
title='Total Cost'
|
Margin: {formatPercentage(profitData.summary.net_profit_margin)}
|
||||||
value={formatShortCurrency(profitData.summary.total_cost)}
|
</p>
|
||||||
bgColor='bg-red-500'
|
|
||||||
isCurrency={true}
|
|
||||||
/>
|
|
||||||
<MetricCard
|
|
||||||
iconClass='tabler-trending-up'
|
|
||||||
title='Gross Profit'
|
|
||||||
value={formatShortCurrency(profitData.summary.gross_profit)}
|
|
||||||
subtitle={`Margin: ${formatPercentage(profitData.summary.gross_profit_margin)}`}
|
|
||||||
bgColor='bg-blue-500'
|
|
||||||
isNegative={profitData.summary.gross_profit < 0}
|
|
||||||
isCurrency={true}
|
|
||||||
/>
|
|
||||||
<MetricCard
|
|
||||||
iconClass='tabler-percentage'
|
|
||||||
title='Profitability Ratio'
|
|
||||||
value={formatPercentage(profitData.summary.profitability_ratio)}
|
|
||||||
subtitle={`Avg Profit: ${formatShortCurrency(profitData.summary.average_profit)}`}
|
|
||||||
bgColor='bg-purple-500'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Additional Summary Metrics */}
|
|
||||||
<div className='grid grid-cols-1 md:grid-cols-3 gap-6 mb-8'>
|
|
||||||
<div className='bg-white rounded-lg shadow-md p-6'>
|
|
||||||
<div className='flex items-center mb-4'>
|
|
||||||
<i className='tabler-wallet text-[24px] text-green-600 mr-2'></i>
|
|
||||||
<h3 className='text-lg font-semibold text-gray-900'>Net Profit</h3>
|
|
||||||
</div>
|
</div>
|
||||||
<p className='text-3xl font-bold text-green-600 mb-2'>
|
<div className='bg-white rounded-lg shadow-md p-6'>
|
||||||
Rp {formatShortCurrency(profitData.summary.net_profit)}
|
<div className='flex items-center mb-4'>
|
||||||
</p>
|
<i className='tabler-shopping-cart text-[24px] text-blue-600 mr-2'></i>
|
||||||
<p className='text-sm text-gray-600'>Margin: {formatPercentage(profitData.summary.net_profit_margin)}</p>
|
<h3 className='text-lg font-semibold text-gray-900'>Total Orders</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className='bg-white rounded-lg shadow-md p-6'>
|
<p className='text-3xl font-bold text-blue-600'>{profitData.summary.total_orders}</p>
|
||||||
<div className='flex items-center mb-4'>
|
|
||||||
<i className='tabler-shopping-cart text-[24px] text-blue-600 mr-2'></i>
|
|
||||||
<h3 className='text-lg font-semibold text-gray-900'>Total Orders</h3>
|
|
||||||
</div>
|
</div>
|
||||||
<p className='text-3xl font-bold text-blue-600'>{profitData.summary.total_orders}</p>
|
<div className='bg-white rounded-lg shadow-md p-6'>
|
||||||
</div>
|
<div className='flex items-center mb-4'>
|
||||||
<div className='bg-white rounded-lg shadow-md p-6'>
|
<i className='tabler-discount text-[24px] text-orange-600 mr-2'></i>
|
||||||
<div className='flex items-center mb-4'>
|
<h3 className='text-lg font-semibold text-gray-900'>Tax & Discount</h3>
|
||||||
<i className='tabler-discount text-[24px] text-orange-600 mr-2'></i>
|
</div>
|
||||||
<h3 className='text-lg font-semibold text-gray-900'>Tax & Discount</h3>
|
<p className='text-xl font-bold text-orange-600 mb-1'>
|
||||||
|
Rp {formatShortCurrency(profitData.summary.total_tax + profitData.summary.total_discount)}
|
||||||
|
</p>
|
||||||
|
<p className='text-sm text-gray-600'>
|
||||||
|
Tax: {formatShortCurrency(profitData.summary.total_tax)} | Discount:{' '}
|
||||||
|
{formatShortCurrency(profitData.summary.total_discount)}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p className='text-xl font-bold text-orange-600 mb-1'>
|
|
||||||
Rp {formatShortCurrency(profitData.summary.total_tax + profitData.summary.total_discount)}
|
|
||||||
</p>
|
|
||||||
<p className='text-sm text-gray-600'>
|
|
||||||
Tax: {formatShortCurrency(profitData.summary.total_tax)} | Discount:{' '}
|
|
||||||
{formatShortCurrency(profitData.summary.total_discount)}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Profit Chart */}
|
{/* Profit Chart */}
|
||||||
<div className='mb-8'>
|
<div className='mb-8'>
|
||||||
<MultipleSeries data={transformMultipleData(profitData)} />
|
<MultipleSeries data={transformMultipleData(profitData)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8'>
|
<div className='grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8'>
|
||||||
{/* Daily Breakdown */}
|
{/* Daily Breakdown */}
|
||||||
|
<div className='bg-white rounded-lg shadow-md'>
|
||||||
|
<div className='p-6'>
|
||||||
|
<div className='flex items-center mb-6'>
|
||||||
|
<i className='tabler-calendar text-[24px] text-purple-500 mr-2'></i>
|
||||||
|
<h2 className='text-xl font-semibold text-gray-900'>Daily Breakdown</h2>
|
||||||
|
</div>
|
||||||
|
<div className='overflow-x-auto'>
|
||||||
|
<table className='min-w-full'>
|
||||||
|
<thead>
|
||||||
|
<tr className='bg-gray-50'>
|
||||||
|
<th className='px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase'>Date</th>
|
||||||
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Revenue</th>
|
||||||
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Cost</th>
|
||||||
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Profit</th>
|
||||||
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Margin</th>
|
||||||
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Orders</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className='bg-white divide-y divide-gray-200'>
|
||||||
|
{profitData.data.map((day, index) => (
|
||||||
|
<tr key={index} className='hover:bg-gray-50'>
|
||||||
|
<td className='px-4 py-4 whitespace-nowrap text-sm font-medium text-gray-900'>
|
||||||
|
{formatDate(day.date)}
|
||||||
|
</td>
|
||||||
|
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
||||||
|
{formatCurrency(day.revenue)}
|
||||||
|
</td>
|
||||||
|
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-red-600'>
|
||||||
|
{formatCurrency(day.cost)}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
className={`px-4 py-4 whitespace-nowrap text-right text-sm font-medium ${
|
||||||
|
day.gross_profit >= 0 ? 'text-green-600' : 'text-red-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{formatCurrency(day.gross_profit)}
|
||||||
|
</td>
|
||||||
|
<td className='px-4 py-4 whitespace-nowrap text-right'>
|
||||||
|
<span
|
||||||
|
className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${getProfitabilityColor(
|
||||||
|
day.gross_profit_margin
|
||||||
|
)}`}
|
||||||
|
>
|
||||||
|
{formatPercentage(day.gross_profit_margin)}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
||||||
|
{day.orders}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Top Performing Products */}
|
||||||
|
<div className='bg-white rounded-lg shadow-md'>
|
||||||
|
<div className='p-6'>
|
||||||
|
<div className='flex items-center mb-6'>
|
||||||
|
<i className='tabler-trophy text-[24px] text-gold-500 mr-2'></i>
|
||||||
|
<h2 className='text-xl font-semibold text-gray-900'>Top Performers</h2>
|
||||||
|
</div>
|
||||||
|
<div className='space-y-4'>
|
||||||
|
{profitData.product_data
|
||||||
|
.sort((a, b) => b.gross_profit - a.gross_profit)
|
||||||
|
.slice(0, 5)
|
||||||
|
.map((product, index) => (
|
||||||
|
<div
|
||||||
|
key={product.product_id}
|
||||||
|
className='flex items-center justify-between p-4 bg-gray-50 rounded-lg'
|
||||||
|
>
|
||||||
|
<div className='flex items-center'>
|
||||||
|
<span
|
||||||
|
className={`w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-bold mr-3 ${
|
||||||
|
index === 0
|
||||||
|
? 'bg-yellow-500'
|
||||||
|
: index === 1
|
||||||
|
? 'bg-gray-400'
|
||||||
|
: index === 2
|
||||||
|
? 'bg-orange-500'
|
||||||
|
: 'bg-blue-500'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{index + 1}
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<h3 className='font-medium text-gray-900'>{product.product_name}</h3>
|
||||||
|
<p className='text-sm text-gray-600'>{product.category_name}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='text-right'>
|
||||||
|
<p className={`font-bold ${product.gross_profit >= 0 ? 'text-green-600' : 'text-red-600'}`}>
|
||||||
|
{formatCurrency(product.gross_profit)}
|
||||||
|
</p>
|
||||||
|
<p className='text-xs text-gray-500'>{formatPercentage(product.gross_profit_margin)}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Product Analysis Table */}
|
||||||
<div className='bg-white rounded-lg shadow-md'>
|
<div className='bg-white rounded-lg shadow-md'>
|
||||||
<div className='p-6'>
|
<div className='p-6'>
|
||||||
<div className='flex items-center mb-6'>
|
<div className='flex items-center mb-6'>
|
||||||
<i className='tabler-calendar text-[24px] text-purple-500 mr-2'></i>
|
<i className='tabler-package text-[24px] text-green-500 mr-2'></i>
|
||||||
<h2 className='text-xl font-semibold text-gray-900'>Daily Breakdown</h2>
|
<h2 className='text-xl font-semibold text-gray-900'>Product Analysis</h2>
|
||||||
</div>
|
</div>
|
||||||
<div className='overflow-x-auto'>
|
<div className='overflow-x-auto'>
|
||||||
<table className='min-w-full'>
|
<table className='min-w-full'>
|
||||||
<thead>
|
<thead>
|
||||||
<tr className='bg-gray-50'>
|
<tr className='bg-gray-50'>
|
||||||
<th className='px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase'>Date</th>
|
<th className='px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase'>Product</th>
|
||||||
|
<th className='px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase'>Category</th>
|
||||||
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Qty</th>
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Revenue</th>
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Revenue</th>
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Cost</th>
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Cost</th>
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Profit</th>
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Profit</th>
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Margin</th>
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Margin</th>
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Orders</th>
|
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Per Unit</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className='bg-white divide-y divide-gray-200'>
|
<tbody className='bg-white divide-y divide-gray-200'>
|
||||||
{profitData.data.map((day, index) => (
|
{profitData.product_data
|
||||||
<tr key={index} className='hover:bg-gray-50'>
|
.sort((a, b) => b.gross_profit - a.gross_profit)
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-sm font-medium text-gray-900'>
|
.map(product => (
|
||||||
{formatDate(day.date)}
|
<tr key={product.product_id} className='hover:bg-gray-50'>
|
||||||
</td>
|
<td className='px-4 py-4 whitespace-nowrap'>
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
<div className='text-sm font-medium text-gray-900'>{product.product_name}</div>
|
||||||
{formatCurrency(day.revenue)}
|
</td>
|
||||||
</td>
|
<td className='px-4 py-4 whitespace-nowrap'>
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-red-600'>
|
<span className='inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-blue-100 text-blue-800'>
|
||||||
{formatCurrency(day.cost)}
|
{product.category_name}
|
||||||
</td>
|
</span>
|
||||||
<td
|
</td>
|
||||||
className={`px-4 py-4 whitespace-nowrap text-right text-sm font-medium ${
|
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
||||||
day.gross_profit >= 0 ? 'text-green-600' : 'text-red-600'
|
{product.quantity_sold}
|
||||||
}`}
|
</td>
|
||||||
>
|
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
||||||
{formatCurrency(day.gross_profit)}
|
{formatCurrency(product.revenue)}
|
||||||
</td>
|
</td>
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right'>
|
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-red-600'>
|
||||||
<span
|
{formatCurrency(product.cost)}
|
||||||
className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${getProfitabilityColor(
|
</td>
|
||||||
day.gross_profit_margin
|
<td
|
||||||
)}`}
|
className={`px-4 py-4 whitespace-nowrap text-right text-sm font-medium ${
|
||||||
|
product.gross_profit >= 0 ? 'text-green-600' : 'text-red-600'
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{formatPercentage(day.gross_profit_margin)}
|
{formatCurrency(product.gross_profit)}
|
||||||
</span>
|
</td>
|
||||||
</td>
|
<td className='px-4 py-4 whitespace-nowrap text-right'>
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>{day.orders}</td>
|
<span
|
||||||
</tr>
|
className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${getProfitabilityColor(
|
||||||
))}
|
product.gross_profit_margin
|
||||||
|
)}`}
|
||||||
|
>
|
||||||
|
{formatPercentage(product.gross_profit_margin)}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
className={`px-4 py-4 whitespace-nowrap text-right text-sm ${
|
||||||
|
product.profit_per_unit >= 0 ? 'text-green-600' : 'text-red-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{formatCurrency(product.profit_per_unit)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
{/* Top Performing Products */}
|
) : (
|
||||||
<div className='bg-white rounded-lg shadow-md'>
|
<Loading />
|
||||||
<div className='p-6'>
|
)}
|
||||||
<div className='flex items-center mb-6'>
|
</div>
|
||||||
<i className='tabler-trophy text-[24px] text-gold-500 mr-2'></i>
|
|
||||||
<h2 className='text-xl font-semibold text-gray-900'>Top Performers</h2>
|
|
||||||
</div>
|
|
||||||
<div className='space-y-4'>
|
|
||||||
{profitData.product_data
|
|
||||||
.sort((a, b) => b.gross_profit - a.gross_profit)
|
|
||||||
.slice(0, 5)
|
|
||||||
.map((product, index) => (
|
|
||||||
<div
|
|
||||||
key={product.product_id}
|
|
||||||
className='flex items-center justify-between p-4 bg-gray-50 rounded-lg'
|
|
||||||
>
|
|
||||||
<div className='flex items-center'>
|
|
||||||
<span
|
|
||||||
className={`w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-bold mr-3 ${
|
|
||||||
index === 0
|
|
||||||
? 'bg-yellow-500'
|
|
||||||
: index === 1
|
|
||||||
? 'bg-gray-400'
|
|
||||||
: index === 2
|
|
||||||
? 'bg-orange-500'
|
|
||||||
: 'bg-blue-500'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{index + 1}
|
|
||||||
</span>
|
|
||||||
<div>
|
|
||||||
<h3 className='font-medium text-gray-900'>{product.product_name}</h3>
|
|
||||||
<p className='text-sm text-gray-600'>{product.category_name}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className='text-right'>
|
|
||||||
<p className={`font-bold ${product.gross_profit >= 0 ? 'text-green-600' : 'text-red-600'}`}>
|
|
||||||
{formatCurrency(product.gross_profit)}
|
|
||||||
</p>
|
|
||||||
<p className='text-xs text-gray-500'>{formatPercentage(product.gross_profit_margin)}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Product Analysis Table */}
|
|
||||||
<div className='bg-white rounded-lg shadow-md'>
|
|
||||||
<div className='p-6'>
|
|
||||||
<div className='flex items-center mb-6'>
|
|
||||||
<i className='tabler-package text-[24px] text-green-500 mr-2'></i>
|
|
||||||
<h2 className='text-xl font-semibold text-gray-900'>Product Analysis</h2>
|
|
||||||
</div>
|
|
||||||
<div className='overflow-x-auto'>
|
|
||||||
<table className='min-w-full'>
|
|
||||||
<thead>
|
|
||||||
<tr className='bg-gray-50'>
|
|
||||||
<th className='px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase'>Product</th>
|
|
||||||
<th className='px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase'>Category</th>
|
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Qty</th>
|
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Revenue</th>
|
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Cost</th>
|
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Profit</th>
|
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Margin</th>
|
|
||||||
<th className='px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase'>Per Unit</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody className='bg-white divide-y divide-gray-200'>
|
|
||||||
{profitData.product_data
|
|
||||||
.sort((a, b) => b.gross_profit - a.gross_profit)
|
|
||||||
.map(product => (
|
|
||||||
<tr key={product.product_id} className='hover:bg-gray-50'>
|
|
||||||
<td className='px-4 py-4 whitespace-nowrap'>
|
|
||||||
<div className='text-sm font-medium text-gray-900'>{product.product_name}</div>
|
|
||||||
</td>
|
|
||||||
<td className='px-4 py-4 whitespace-nowrap'>
|
|
||||||
<span className='inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-blue-100 text-blue-800'>
|
|
||||||
{product.category_name}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
|
||||||
{product.quantity_sold}
|
|
||||||
</td>
|
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-gray-900'>
|
|
||||||
{formatCurrency(product.revenue)}
|
|
||||||
</td>
|
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right text-sm text-red-600'>
|
|
||||||
{formatCurrency(product.cost)}
|
|
||||||
</td>
|
|
||||||
<td
|
|
||||||
className={`px-4 py-4 whitespace-nowrap text-right text-sm font-medium ${
|
|
||||||
product.gross_profit >= 0 ? 'text-green-600' : 'text-red-600'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{formatCurrency(product.gross_profit)}
|
|
||||||
</td>
|
|
||||||
<td className='px-4 py-4 whitespace-nowrap text-right'>
|
|
||||||
<span
|
|
||||||
className={`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${getProfitabilityColor(
|
|
||||||
product.gross_profit_margin
|
|
||||||
)}`}
|
|
||||||
>
|
|
||||||
{formatPercentage(product.gross_profit_margin)}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td
|
|
||||||
className={`px-4 py-4 whitespace-nowrap text-right text-sm ${
|
|
||||||
product.profit_per_unit >= 0 ? 'text-green-600' : 'text-red-600'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{formatCurrency(product.profit_per_unit)}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,8 +97,8 @@ const HorizontalMenu = ({ dictionary }: { dictionary: Awaited<ReturnType<typeof
|
|||||||
<MenuItem href={`/${locale}/dashboards/analytics`} icon={<i className='tabler-trending-up' />}>
|
<MenuItem href={`/${locale}/dashboards/analytics`} icon={<i className='tabler-trending-up' />}>
|
||||||
{dictionary['navigation'].analytics}
|
{dictionary['navigation'].analytics}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem href={`/${locale}/dashboards/ecommerce`} icon={<i className='tabler-shopping-cart' />}>
|
<MenuItem href={`/${locale}/dashboards/inventory`} icon={<i className='tabler-shopping-cart' />}>
|
||||||
{dictionary['navigation'].eCommerce}
|
{dictionary['navigation'].inventory}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem href={`/${locale}/dashboards/academy`} icon={<i className='tabler-school' />}>
|
<MenuItem href={`/${locale}/dashboards/academy`} icon={<i className='tabler-school' />}>
|
||||||
{dictionary['navigation'].academy}
|
{dictionary['navigation'].academy}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { CircularProgress } from '@mui/material'
|
|||||||
|
|
||||||
export default function Loading({ size = 60 }: { size?: number }) {
|
export default function Loading({ size = 60 }: { size?: number }) {
|
||||||
return (
|
return (
|
||||||
<div className='fixed inset-0 z-50 flex items-center justify-center bg-white/70'>
|
<div className='absolute inset-0 z-50 flex items-center justify-center bg-white/70'>
|
||||||
<CircularProgress size={size} />
|
<CircularProgress size={size} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
const getToken = () => {
|
const getToken = () => {
|
||||||
return localStorage.getItem('authToken')
|
return localStorage.getItem('authToken')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const api = axios.create({
|
export const api = axios.create({
|
||||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
baseURL: 'https://api-pos.apskel.id/api/v1',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
@ -40,7 +41,7 @@ api.interceptors.response.use(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (status >= 500) {
|
if (status >= 500) {
|
||||||
console.error('Server error:', error.response?.data?.message || 'Terjadi kesalahan server.')
|
toast.error(error.response?.data?.errors[0].cause || 'Terjadi kesalahan server.')
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
import { api } from '../api'
|
import { api } from '../api'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { InventoryAdjustRequest, InventoryRequest } from '../../types/services/inventory'
|
import { InventoryAdjustRequest, InventoryRequest, InventoryRestockRequest } from '../../types/services/inventory'
|
||||||
|
|
||||||
export const useInventoriesMutation = () => {
|
export const useInventoriesMutation = () => {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
@ -34,6 +34,24 @@ export const useInventoriesMutation = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const restockInventory = useMutation({
|
||||||
|
mutationFn: async (newInventory: InventoryRestockRequest) => {
|
||||||
|
newInventory.items.map(item => {
|
||||||
|
item.quantity = Number(item.quantity)
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await api.post('/inventory/restock', newInventory)
|
||||||
|
return response.data
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('Inventory restock successfully!')
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||||
|
},
|
||||||
|
onError: (error: any) => {
|
||||||
|
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const deleteInventory = useMutation({
|
const deleteInventory = useMutation({
|
||||||
mutationFn: async (id: string) => {
|
mutationFn: async (id: string) => {
|
||||||
const response = await api.delete(`/inventory/${id}`)
|
const response = await api.delete(`/inventory/${id}`)
|
||||||
@ -48,5 +66,5 @@ export const useInventoriesMutation = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return { createInventory, adjustInventory, deleteInventory }
|
return { createInventory, adjustInventory, deleteInventory, restockInventory }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,3 +29,15 @@ export interface InventoryAdjustRequest {
|
|||||||
delta: number
|
delta: number
|
||||||
reason: string
|
reason: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Item {
|
||||||
|
item_id: string
|
||||||
|
item_type: string
|
||||||
|
quantity: number | string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InventoryRestockRequest {
|
||||||
|
outlet_id: string
|
||||||
|
items: Item[]
|
||||||
|
reason: string
|
||||||
|
}
|
||||||
|
|||||||
@ -36,12 +36,22 @@ export const formatDate = (dateString: any) => {
|
|||||||
|
|
||||||
export const formatDateDDMMYYYY = (dateString: Date | string) => {
|
export const formatDateDDMMYYYY = (dateString: Date | string) => {
|
||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
|
date.setHours(0, 0, 0, 0)
|
||||||
const day = String(date.getDate()).padStart(2, '0')
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
const year = date.getFullYear()
|
const year = date.getFullYear()
|
||||||
return `${day}-${month}-${year}`
|
return `${day}-${month}-${year}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const formatForInputDate = (dateString: Date | string) => {
|
||||||
|
const date = new Date(dateString)
|
||||||
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
const year = date.getFullYear()
|
||||||
|
return `${year}-${month}-${day}`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const formatDatetime = (dateString: string | number | Date) => {
|
export const formatDatetime = (dateString: string | number | Date) => {
|
||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
|
|
||||||
|
|||||||
@ -220,13 +220,13 @@ const ProductListTable = () => {
|
|||||||
<div className='flex items-center'>
|
<div className='flex items-center'>
|
||||||
<IconButton
|
<IconButton
|
||||||
LinkComponent={Link}
|
LinkComponent={Link}
|
||||||
href={getLocalizedUrl(`/apps/ecommerce/products/${row.original.id}/detail`, locale as Locale)}
|
href={getLocalizedUrl(`/apps/inventory/products/${row.original.id}/detail`, locale as Locale)}
|
||||||
>
|
>
|
||||||
<i className='tabler-eye text-textSecondary' />
|
<i className='tabler-eye text-textSecondary' />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
LinkComponent={Link}
|
LinkComponent={Link}
|
||||||
href={getLocalizedUrl(`/apps/ecommerce/products/${row.original.id}/edit`, locale as Locale)}
|
href={getLocalizedUrl(`/apps/inventory/products/${row.original.id}/edit`, locale as Locale)}
|
||||||
>
|
>
|
||||||
<i className='tabler-edit text-textSecondary' />
|
<i className='tabler-edit text-textSecondary' />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
@ -14,12 +14,12 @@ import Typography from '@mui/material/Typography'
|
|||||||
|
|
||||||
// Components Imports
|
// Components Imports
|
||||||
import CustomTextField from '@core/components/mui/TextField'
|
import CustomTextField from '@core/components/mui/TextField'
|
||||||
import { Autocomplete, CircularProgress } from '@mui/material'
|
import { Autocomplete, CircularProgress, MenuItem } from '@mui/material'
|
||||||
import { useDebounce } from 'use-debounce'
|
import { useDebounce } from 'use-debounce'
|
||||||
import { useInventoriesMutation } from '../../../../../services/mutations/inventories'
|
import { useInventoriesMutation } from '../../../../../services/mutations/inventories'
|
||||||
import { useOutlets } from '../../../../../services/queries/outlets'
|
import { useOutlets } from '../../../../../services/queries/outlets'
|
||||||
import { useProducts } from '../../../../../services/queries/products'
|
import { useProducts } from '../../../../../services/queries/products'
|
||||||
import { InventoryAdjustRequest } from '../../../../../types/services/inventory'
|
import { InventoryRestockRequest, Item } from '../../../../../types/services/inventory'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
open: boolean
|
open: boolean
|
||||||
@ -30,17 +30,22 @@ const AdjustmentStockDrawer = (props: Props) => {
|
|||||||
// Props
|
// Props
|
||||||
const { open, handleClose } = props
|
const { open, handleClose } = props
|
||||||
|
|
||||||
const { mutate: adjustInventory, isPending: isCreating } = useInventoriesMutation().adjustInventory
|
const { restockInventory } = useInventoriesMutation()
|
||||||
|
|
||||||
// States
|
// States
|
||||||
const [productInput, setProductInput] = useState('')
|
const [productInput, setProductInput] = useState('')
|
||||||
const [productDebouncedInput] = useDebounce(productInput, 500) // debounce for better UX
|
const [productDebouncedInput] = useDebounce(productInput, 500) // debounce for better UX
|
||||||
const [outletInput, setOutletInput] = useState('')
|
const [outletInput, setOutletInput] = useState('')
|
||||||
const [outletDebouncedInput] = useDebounce(outletInput, 500) // debounce for better UX
|
const [outletDebouncedInput] = useDebounce(outletInput, 500) // debounce for better UX
|
||||||
const [formData, setFormData] = useState<InventoryAdjustRequest>({
|
const [formData, setFormData] = useState<InventoryRestockRequest>({
|
||||||
product_id: '',
|
|
||||||
outlet_id: '',
|
outlet_id: '',
|
||||||
delta: 0,
|
items: [
|
||||||
|
{
|
||||||
|
item_id: '',
|
||||||
|
item_type: '',
|
||||||
|
quantity: 0
|
||||||
|
}
|
||||||
|
],
|
||||||
reason: ''
|
reason: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -58,14 +63,11 @@ const AdjustmentStockDrawer = (props: Props) => {
|
|||||||
const handleFormSubmit = (e: any) => {
|
const handleFormSubmit = (e: any) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
adjustInventory(
|
restockInventory.mutate(formData, {
|
||||||
{ ...formData, delta: Number(formData.delta) },
|
onSuccess: () => {
|
||||||
{
|
handleReset()
|
||||||
onSuccess: () => {
|
|
||||||
handleReset()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInputChange = (e: any) => {
|
const handleInputChange = (e: any) => {
|
||||||
@ -79,9 +81,14 @@ const AdjustmentStockDrawer = (props: Props) => {
|
|||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
handleClose()
|
handleClose()
|
||||||
setFormData({
|
setFormData({
|
||||||
product_id: '',
|
|
||||||
outlet_id: '',
|
outlet_id: '',
|
||||||
delta: 0,
|
items: [
|
||||||
|
{
|
||||||
|
item_id: '',
|
||||||
|
item_type: '',
|
||||||
|
quantity: 0
|
||||||
|
}
|
||||||
|
],
|
||||||
reason: ''
|
reason: ''
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -136,18 +143,33 @@ const AdjustmentStockDrawer = (props: Props) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<CustomTextField
|
||||||
|
select
|
||||||
|
fullWidth
|
||||||
|
label='Item Type'
|
||||||
|
value={formData.items[0]?.item_type || ''}
|
||||||
|
onChange={e => setFormData({ ...formData, items: [{ ...formData.items[0], item_type: e.target.value }] })}
|
||||||
|
>
|
||||||
|
<MenuItem value='PRODUCT'>Product</MenuItem>
|
||||||
|
{/* <MenuItem value='IGREDIENT'>Ingredient</MenuItem> */}
|
||||||
|
</CustomTextField>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
options={options}
|
options={options}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
getOptionLabel={option => option.name}
|
getOptionLabel={option => option.name}
|
||||||
value={options.find(p => p.id === formData.product_id) || null}
|
value={options.find(p => p.id === formData.items[0].item_id) || null}
|
||||||
onInputChange={(event, newProductInput) => {
|
onInputChange={(event, newProductInput) => {
|
||||||
setProductInput(newProductInput)
|
setProductInput(newProductInput)
|
||||||
}}
|
}}
|
||||||
onChange={(event, newValue) => {
|
onChange={(event, newValue) => {
|
||||||
setFormData({
|
setFormData({
|
||||||
...formData,
|
...formData,
|
||||||
product_id: newValue?.id || ''
|
items: [
|
||||||
|
{
|
||||||
|
...formData.items[0],
|
||||||
|
item_id: newValue?.id || ''
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
renderInput={params => (
|
renderInput={params => (
|
||||||
@ -170,10 +192,20 @@ const AdjustmentStockDrawer = (props: Props) => {
|
|||||||
/>
|
/>
|
||||||
<CustomTextField
|
<CustomTextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label='Delta'
|
label='Quantity'
|
||||||
name='delta'
|
name='quantity'
|
||||||
value={formData.delta}
|
value={formData.items[0].quantity}
|
||||||
onChange={handleInputChange}
|
onChange={e =>
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
...formData.items[0],
|
||||||
|
quantity: e.target.value
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
placeholder='0'
|
placeholder='0'
|
||||||
/>
|
/>
|
||||||
<CustomTextField
|
<CustomTextField
|
||||||
@ -187,8 +219,8 @@ const AdjustmentStockDrawer = (props: Props) => {
|
|||||||
placeholder='Write a Comment...'
|
placeholder='Write a Comment...'
|
||||||
/>
|
/>
|
||||||
<div className='flex items-center gap-4'>
|
<div className='flex items-center gap-4'>
|
||||||
<Button variant='contained' type='submit' disabled={isCreating}>
|
<Button variant='contained' type='submit' disabled={restockInventory.isPending}>
|
||||||
{isCreating ? 'Adjusting...' : 'Adjust'}
|
{restockInventory.isPending ? 'Saving...' : 'Save'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant='tonal' color='error' type='reset' onClick={handleReset}>
|
<Button variant='tonal' color='error' type='reset' onClick={handleReset}>
|
||||||
Discard
|
Discard
|
||||||
|
|||||||
@ -485,7 +485,7 @@ const ReportGeneratorComponent: React.FC<ReportGeneratorProps> = ({
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<InfoBox>
|
<InfoBox>
|
||||||
<Typography variant='body2' sx={{ color: textSecondary }}>
|
<Typography variant='body2' component='div' sx={{ color: textSecondary }}>
|
||||||
{labels.periodLabel || 'Periode:'}{' '}
|
{labels.periodLabel || 'Periode:'}{' '}
|
||||||
<Chip
|
<Chip
|
||||||
label={getPeriodText()}
|
label={getPeriodText()}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user