Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add driver,customer,farmer count.Add PDF generator #88

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add driver,customer,farmer count.Add PDF generator
  • Loading branch information
GayashanHansaja committed Oct 11, 2024
commit 54c214b8bb1b691f6814aa0b33d2e094c577a88d
12 changes: 12 additions & 0 deletions backend/controllers/Admin/AcustomerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const getAllUsers = async (req, res) => {
}
}



// Fetch single user by ID
export const getUserById = async (req, res) => {
try {
Expand All @@ -24,6 +26,7 @@ export const getUserById = async (req, res) => {
}
}


// Update user by ID
export const updateUserById = async (req, res) => {
const {
Expand Down Expand Up @@ -96,3 +99,12 @@ export const validateUserPassword = async (req, res) => {
res.status(500).json({ message: 'Error validating password', error })
}
}

export const getUserCount = async (req, res) => {
try {
const count = await User.countDocuments()
res.status(200).json({ count })
} catch (error) {
res.status(500).json({ error: 'Error fetching user count' })
}
}
20 changes: 20 additions & 0 deletions backend/controllers/Admin/Afarmer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import Farmer from '../../models/farmerModel'
import mongoose from 'mongoose'
export const getFarmersCount = async (req, res) => {
try {
const count = await Farmer.countDocuments()
res.status(200).json({ count })
} catch (error) {
res.status(500).json({ error: 'Error fetching staff count' })
}
}

export const getAllFarmers = async (req, res) => {
try {
const farmer = await Farmer.find({}) // Change sorting to firstName
res.status(200).json(farmer)
} catch (error) {
res.status(500).json({ message: error.message })
}
}
1 change: 1 addition & 0 deletions backend/controllers/DLDriverController.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,4 @@ export {
verifyPassword,
getAllDrivers,
}

8 changes: 8 additions & 0 deletions backend/controllers/couponController.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ export const deleteCoupon = async (req, res) => {
res.status(500).json({ message: error.message })
}
}
export const getCouponCount = async (req, res) => {
try {
const count = await Coupon.countDocuments()
res.status(200).json({ count })
} catch (error) {
res.status(500).json({ error: 'Error fetching coupon count' })
}
}
17 changes: 17 additions & 0 deletions backend/controllers/farmerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,20 @@ export {
deleteFarmerAccount,
getFarmerById,
}
export const getAllFarmers = async (req, res) => {
try {
const farmer = await Farmer.find({}) // Change sorting to firstName
res.status(200).json(farmer)
} catch (error) {
res.status(500).json({ message: error.message })
}
}

export const getFarmersCount = async (req, res) => {
try {
const count = await Farmer.countDocuments()
res.status(200).json({ count })
} catch (error) {
res.status(500).json({ error: 'Error fetching staff count' })
}
}
12 changes: 12 additions & 0 deletions backend/routes/Admin/AfarmerRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express from 'express'
import {
getFarmersCount,
getAllFarmers,
} from '../../controllers/Admin/Afarmer'

const router = express.Router()

router.get('/', getAllFarmers)
router.post('/count', getFarmersCount)

export default router
3 changes: 3 additions & 0 deletions backend/routes/Admin/AuserRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import {
updateUserById,
deleteUserById,
validateUserPassword,
getUserCount
} from '../../controllers/Admin/AcustomerController.js'

const router = express.Router()

router.get('/count',getUserCount)

// Get all users
router.get('/', getAllUsers)

Expand Down
2 changes: 2 additions & 0 deletions backend/routes/couponRouter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express'
import {
getCouponCount,
createCoupon,
validCoupon,
getAllCoupons,
Expand All @@ -10,6 +11,7 @@ import {

const couponRouter = express.Router()

couponRouter.get('/count', getCouponCount)
couponRouter.post('/valid-coupon', validCoupon)
couponRouter.post('/', createCoupon)
couponRouter.get('/', getAllCoupons)
Expand Down
5 changes: 5 additions & 0 deletions backend/routes/farmerRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
logoutFarmer,
deleteFarmerAccount,
getFarmerById,
getAllFarmers,
getFarmersCount,
} from '../controllers/farmerController.js'
import { protect } from '../middlewares/farmerauthMiddleware.js'

Expand All @@ -15,6 +17,9 @@ const router = express.Router()
// Register a new farmer
router.post('/register', registerFarmer)

router.get('/',getAllFarmers)
router.get('/count',getFarmersCount)

// Authenticate farmer and get token
router.post('/login', authFarmer)

Expand Down
4 changes: 3 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import AddStaff from './Pages/Admin/AaddStaff'
import UpdateStaff from './Pages/Admin/AupdateStaff'
import AddCoupon from './Pages/Admin/AaddCoupons'
import UpdateCoupon from './Pages/Admin/AupdateCoupon'
import AdminLayout from './Layouts/Alayout'

// Farmer Pages
import FarmerLogin from './Pages/farmer/FarmerLogin'
Expand Down Expand Up @@ -172,7 +173,8 @@ const router = createBrowserRouter(
</Route>

{/* Admin Routes */}
<Route path="/">
<Route path="/" element={<AdminLayout/>}>

<Route path="/AdminDashboard" element={<AdminDashboard />} />

{/* Staff */}
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/Components/Admin/Aheader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Link } from 'react-router-dom'
import logo from '../../assets/Logo.png'
const Header = () => {
return (
<div>
<div className="flex items-center justify-between py-6 mx-auto border-b max-w-7xl">
<div>
<Link to="/">
<img src={logo} alt="Logo" width={160} height={160} />
</Link>
</div>

<div className="flex items-center gap-4 text-sm">
<div className="flex items-center gap-4">
<h1>Welcome to FarmCart🌱 </h1>
<Link
to="/help"
className="text-black hover:text-[#99DD05] cursor-pointer hover:underline text-sm"
>
Help & Support
</Link>
</div>
</div>
</div>
</div>
)
}

export default Header
23 changes: 16 additions & 7 deletions frontend/src/Components/Admin/AsideBar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { FaHome, FaUsers, FaStore, FaCog, FaSignOutAlt } from 'react-icons/fa'
import { FaHome, FaUsers, FaUserAlt, FaTags, FaChartLine, FaSignOutAlt } from 'react-icons/fa'

const AdminSidebar = () => {
return (
Expand All @@ -13,7 +13,7 @@ const AdminSidebar = () => {
className="flex items-center px-4 py-2 text-gray-700 hover:bg-green-500 hover:text-white rounded text-left"
>
<FaHome className="w-5 h-5 mr-3" />
<span>Home</span>
<span>Dashboard</span>
</Link>
</li>
<li>
Expand All @@ -30,28 +30,37 @@ const AdminSidebar = () => {
to="/users"
className="flex items-center px-4 py-2 text-gray-700 hover:bg-green-500 hover:text-white rounded text-left"
>
<FaStore className="w-5 h-5 mr-3" />
<FaUserAlt className="w-5 h-5 mr-3" />
<span>Users</span>
</Link>
</li>
<li>
<Link
to="/coupens"
to="/coupons"
className="flex items-center px-4 py-2 text-gray-700 hover:bg-green-500 hover:text-white rounded text-left"
>
<FaCog className="w-5 h-5 mr-3" />
<span>Coupens</span>
<FaTags className="w-5 h-5 mr-3" />
<span>Coupons</span>
</Link>
</li>
<li>
<Link
to="/finance"
className="flex items-center px-4 py-2 text-gray-700 hover:bg-green-500 hover:text-white rounded text-left"
>
<FaSignOutAlt className="w-5 h-5 mr-3" />
<FaChartLine className="w-5 h-5 mr-3" />
<span>Finance</span>
</Link>
</li>
<li>
<Link
to="/logout"
className="flex items-center px-4 py-2 text-gray-700 hover:bg-green-500 hover:text-white rounded text-left"
>
<FaSignOutAlt className="w-5 h-5 mr-3" />
<span>Logout</span>
</Link>
</li>
</ul>
</nav>
</div>
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/Components/Admin/DailyOrdersChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@ const DailyOrdersChart = () => {

return (
<div className="max-w-4xl mx-auto p-6 bg-white shadow-md rounded-lg mt-8">
<h2 className="text-2xl font-bold text-green-600 mb-6">Daily Orders</h2>
<h2 className="text-2xl font-bold text-black mb-6">Daily Orders</h2>
{chartData.labels ? (
<>
<Line data={chartData} ref={chartRef} id="bidStatus" />
<button
onClick={downloadChart}
className="mt-6 px-4 py-2 bg-green-500 text-white font-semibold rounded hover:bg-green-600"
>
Download Chart as PNG
</button>
onClick={downloadChart}
className="mt-6 px-6 py-2 ml-0 border-2 rounded-full border-[#99DD05] text-grey font-semibold flex items-center gap-2 hover:bg-[#f5fce6] hover:text-black transition-all"
>
Download Chart as PNG
</button>


</>
) : (
<p>Loading chart...</p>
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/Layouts/Alayout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Outlet } from 'react-router-dom'
import Footer from '../Components/Home/FooterDashboard'
import Header from '../Components/Admin/Aheader'

function AdminLayout() {
return (
<>
<div className="sticky top-0 bg-white shadow-md bg-opacity-70 backdrop-blur-md z-50">
<Header />

</div>

<Outlet />
<div className="sticky top-0 bg-white shadow-md bg-opacity-70 backdrop-blur-md z-50">
<Footer />
</div>
</>
)
}

export default AdminLayout
Loading
Loading