Spaces:
Sleeping
Sleeping
mahmoud commited on
Commit ·
66821dd
0
Parent(s):
upload frontend & backend folders
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- backend/.env +5 -0
- backend/.gitignore +24 -0
- backend/config/database.js +11 -0
- backend/controller/authController.js +520 -0
- backend/controller/customerController.js +160 -0
- backend/controller/expenseController.js +32 -0
- backend/controller/invoiceController.js +281 -0
- backend/controller/productController.js +121 -0
- backend/controller/reportController.js +294 -0
- backend/controller/supplierController.js +236 -0
- backend/index.js +46 -0
- backend/middleware/authMiddleware.js +57 -0
- backend/models/CustomerModel.js +55 -0
- backend/models/ExpenseModel.js +46 -0
- backend/models/InvoiceModel.js +124 -0
- backend/models/ProductModel.js +63 -0
- backend/models/SupplierInvoiceModel.js +61 -0
- backend/models/SupplierModel.js +38 -0
- backend/models/TenantModel.js +64 -0
- backend/models/UserModel.js +80 -0
- backend/package-lock.json +1535 -0
- backend/package.json +22 -0
- backend/routes/authRoutes.js +37 -0
- backend/routes/customerRoutes.js +19 -0
- backend/routes/expenseRoutes.js +12 -0
- backend/routes/invoiceRoutes.js +25 -0
- backend/routes/productRoutes.js +19 -0
- backend/routes/reportRoutes.js +12 -0
- backend/routes/supplierRoutes.js +23 -0
- backend/utils/authCookies.js +73 -0
- frontend/.env +1 -0
- frontend/.gitignore +24 -0
- frontend/README.md +16 -0
- frontend/eslint.config.js +29 -0
- frontend/index.html +13 -0
- frontend/main.js +13 -0
- frontend/package-lock.json +0 -0
- frontend/package.json +58 -0
- frontend/src/App.jsx +31 -0
- frontend/src/Context/AuthContext.jsx +58 -0
- frontend/src/common/LoaderSpinner.jsx +12 -0
- frontend/src/common/Pagination.jsx +94 -0
- frontend/src/components/AddCustomer.jsx +117 -0
- frontend/src/components/CustomerDetails/CustomerDetails.jsx +288 -0
- frontend/src/components/CustomerDetails/EditInvoiceItemModal.jsx +159 -0
- frontend/src/components/CustomerDetails/PayInvoiceModal.jsx +126 -0
- frontend/src/components/CustomerDetails/PrintInvoice.jsx +112 -0
- frontend/src/components/Customers/Customer.jsx +29 -0
- frontend/src/components/Customers/CustomerBoxView.jsx +148 -0
- frontend/src/components/Customers/CustomersWorkspace.jsx +271 -0
backend/.env
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PORT = 5000
|
| 2 |
+
NODE_ENV = development
|
| 3 |
+
DB_URL=mongodb://127.0.0.1:27017/sales_system
|
| 4 |
+
# DB_URL=mongodb+srv://mahmoudshalaby:SNipxrdETGSJWVw0@salsesmultiuserscluster.rv1c8at.mongodb.net/Sales_MultiUsers_DB
|
| 5 |
+
FRONTEND_URL=http://localhost:5173
|
backend/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
backend/config/database.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from 'mongoose';
|
| 2 |
+
|
| 3 |
+
export const dbConnection = async () => {
|
| 4 |
+
try {
|
| 5 |
+
await mongoose.connect(process.env.DB_URL);
|
| 6 |
+
console.log('Connected To DB Successfully!');
|
| 7 |
+
}
|
| 8 |
+
catch (err) {
|
| 9 |
+
console.log('DB Connection Failed' + err);
|
| 10 |
+
}
|
| 11 |
+
}
|
backend/controller/authController.js
ADDED
|
@@ -0,0 +1,520 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import User from "../models/UserModel.js";
|
| 2 |
+
import Tenant from "../models/TenantModel.js";
|
| 3 |
+
import {
|
| 4 |
+
buildTenantCredentialsWhatsApp,
|
| 5 |
+
clearAuthCookie,
|
| 6 |
+
createSessionToken,
|
| 7 |
+
setAuthCookie,
|
| 8 |
+
toSlug,
|
| 9 |
+
} from "../utils/authCookies.js";
|
| 10 |
+
|
| 11 |
+
const sanitizeTenant = (tenant) => {
|
| 12 |
+
if (!tenant) {
|
| 13 |
+
return null;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
return {
|
| 17 |
+
_id: tenant._id,
|
| 18 |
+
name: tenant.name,
|
| 19 |
+
slug: tenant.slug,
|
| 20 |
+
ownerName: tenant.ownerName,
|
| 21 |
+
ownerEmail: tenant.ownerEmail,
|
| 22 |
+
ownerPhone: tenant.ownerPhone,
|
| 23 |
+
whatsappNumber: tenant.whatsappNumber,
|
| 24 |
+
address: tenant.address,
|
| 25 |
+
status: tenant.status,
|
| 26 |
+
settings: tenant.settings,
|
| 27 |
+
createdAt: tenant.createdAt,
|
| 28 |
+
};
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
const sanitizeUser = (user) => ({
|
| 32 |
+
_id: user._id,
|
| 33 |
+
username: user.username,
|
| 34 |
+
fullName: user.fullName,
|
| 35 |
+
email: user.email,
|
| 36 |
+
phone: user.phone,
|
| 37 |
+
role: user.role,
|
| 38 |
+
status: user.status,
|
| 39 |
+
tenant: sanitizeTenant(user.tenant),
|
| 40 |
+
createdAt: user.createdAt,
|
| 41 |
+
lastLoginAt: user.lastLoginAt,
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
const createUniqueSlug = async (name) => {
|
| 45 |
+
const baseSlug = toSlug(name) || "business";
|
| 46 |
+
let slug = baseSlug;
|
| 47 |
+
let counter = 1;
|
| 48 |
+
|
| 49 |
+
while (await Tenant.findOne({ slug })) {
|
| 50 |
+
counter += 1;
|
| 51 |
+
slug = `${baseSlug}-${counter}`;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
return slug;
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
export const checkAdmin = async (req, res) => {
|
| 58 |
+
try {
|
| 59 |
+
const count = await User.countDocuments({ role: "super_admin" });
|
| 60 |
+
res.status(200).json({ hasAdmin: count > 0 });
|
| 61 |
+
} catch (error) {
|
| 62 |
+
res.status(500).json({ message: error.message });
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
export const setupAdmin = async (req, res) => {
|
| 67 |
+
try {
|
| 68 |
+
const count = await User.countDocuments({ role: "super_admin" });
|
| 69 |
+
if (count > 0) {
|
| 70 |
+
return res.status(400).json({ message: "Platform admin has already been set up" });
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
const body = req.body || {};
|
| 74 |
+
const username = (body.username || "").trim() || "superadmin";
|
| 75 |
+
const password = (body.password || "").trim() || "ChangeMe123!";
|
| 76 |
+
const fullName = (body.fullName || "").trim() || "Platform Admin";
|
| 77 |
+
const email = (body.email || "").trim().toLowerCase() || undefined;
|
| 78 |
+
|
| 79 |
+
await User.create({
|
| 80 |
+
username,
|
| 81 |
+
password,
|
| 82 |
+
fullName,
|
| 83 |
+
email,
|
| 84 |
+
role: "super_admin",
|
| 85 |
+
});
|
| 86 |
+
|
| 87 |
+
res.status(201).json({
|
| 88 |
+
message: "Platform admin account created successfully",
|
| 89 |
+
credentials: {
|
| 90 |
+
username,
|
| 91 |
+
password,
|
| 92 |
+
},
|
| 93 |
+
});
|
| 94 |
+
} catch (err) {
|
| 95 |
+
res.status(500).json({ message: err.message });
|
| 96 |
+
}
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
export const login = async (req, res) => {
|
| 100 |
+
try {
|
| 101 |
+
const identifier = req.body.identifier?.trim() || req.body.username?.trim();
|
| 102 |
+
const { password } = req.body;
|
| 103 |
+
|
| 104 |
+
if (!identifier || !password) {
|
| 105 |
+
return res.status(400).json({ message: "Login credentials are required" });
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
const user = await User.findOne({
|
| 109 |
+
$or: [{ username: identifier }, { email: identifier.toLowerCase() }],
|
| 110 |
+
}).populate("tenant");
|
| 111 |
+
|
| 112 |
+
if (!user || !user.matchPassword(password)) {
|
| 113 |
+
return res.status(401).json({ message: "Invalid username or password" });
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
if (user.status !== "active") {
|
| 117 |
+
return res.status(403).json({ message: "User account is suspended" });
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if (user.tenant && user.tenant.status !== "active") {
|
| 121 |
+
return res.status(403).json({ message: "Tenant account is suspended" });
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
const token = createSessionToken();
|
| 125 |
+
user.sessionToken = token;
|
| 126 |
+
user.lastLoginAt = new Date();
|
| 127 |
+
await user.save();
|
| 128 |
+
setAuthCookie(res, token);
|
| 129 |
+
|
| 130 |
+
res.status(200).json({
|
| 131 |
+
message: "Login successful",
|
| 132 |
+
user: sanitizeUser(user),
|
| 133 |
+
});
|
| 134 |
+
} catch (err) {
|
| 135 |
+
res.status(500).json({ message: err.message });
|
| 136 |
+
}
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
export const logout = async (req, res) => {
|
| 140 |
+
try {
|
| 141 |
+
if (req.user) {
|
| 142 |
+
req.user.sessionToken = null;
|
| 143 |
+
await req.user.save();
|
| 144 |
+
}
|
| 145 |
+
clearAuthCookie(res);
|
| 146 |
+
res.status(200).json({ message: "Logout successful" });
|
| 147 |
+
} catch (err) {
|
| 148 |
+
res.status(500).json({ message: err.message });
|
| 149 |
+
}
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
export const getCurrentUser = async (req, res) => {
|
| 153 |
+
try {
|
| 154 |
+
if (!req.user) {
|
| 155 |
+
return res.status(401).json({ message: "Unauthorized" });
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
res.status(200).json({
|
| 159 |
+
user: sanitizeUser(req.user),
|
| 160 |
+
});
|
| 161 |
+
} catch (error) {
|
| 162 |
+
res.status(500).json({ message: error.message });
|
| 163 |
+
}
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
export const getUsers = async (req, res) => {
|
| 167 |
+
try {
|
| 168 |
+
let filter = {};
|
| 169 |
+
|
| 170 |
+
if (req.user.role === "super_admin") {
|
| 171 |
+
filter = req.query.tenantId ? { tenant: req.query.tenantId } : { role: "super_admin" };
|
| 172 |
+
} else {
|
| 173 |
+
filter = { tenant: req.user.tenant._id };
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
const users = await User.find(filter).populate("tenant").sort({ createdAt: -1 });
|
| 177 |
+
res.status(200).json(users.map(sanitizeUser));
|
| 178 |
+
} catch (error) {
|
| 179 |
+
res.status(500).json({ message: error.message });
|
| 180 |
+
}
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
export const createUser = async (req, res) => {
|
| 184 |
+
if (!req.user?.tenant) {
|
| 185 |
+
return res.status(403).json({ message: "Internal user management is only available inside tenant accounts" });
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
if (!["owner", "admin"].includes(req.user.role)) {
|
| 189 |
+
return res.status(403).json({ message: "Only tenant management roles can create users" });
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
const username = req.body.username?.trim();
|
| 193 |
+
const fullName = req.body.fullName?.trim() || username;
|
| 194 |
+
const password = req.body.password?.trim();
|
| 195 |
+
const email = req.body.email?.trim()?.toLowerCase() || undefined;
|
| 196 |
+
const phone = req.body.phone?.trim() || "";
|
| 197 |
+
const role = req.body.role || "cashier";
|
| 198 |
+
|
| 199 |
+
if (!username || !password) {
|
| 200 |
+
return res.status(400).json({ message: "Username and password are required" });
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (!["admin", "cashier"].includes(role)) {
|
| 204 |
+
return res.status(400).json({ message: "Unsupported role" });
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
try {
|
| 208 |
+
const usernameExists = await User.findOne({ username });
|
| 209 |
+
if (usernameExists) {
|
| 210 |
+
return res.status(400).json({ message: "Username is already in use" });
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
if (email) {
|
| 214 |
+
const emailExists = await User.findOne({ email });
|
| 215 |
+
if (emailExists) {
|
| 216 |
+
return res.status(400).json({ message: "Email is already in use" });
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
const user = await User.create({
|
| 221 |
+
username,
|
| 222 |
+
fullName,
|
| 223 |
+
email,
|
| 224 |
+
phone,
|
| 225 |
+
password,
|
| 226 |
+
role,
|
| 227 |
+
tenant: req.user.tenant._id,
|
| 228 |
+
});
|
| 229 |
+
|
| 230 |
+
await user.populate("tenant");
|
| 231 |
+
|
| 232 |
+
res.status(201).json({
|
| 233 |
+
message: "User created successfully",
|
| 234 |
+
user: sanitizeUser(user),
|
| 235 |
+
});
|
| 236 |
+
} catch (err) {
|
| 237 |
+
res.status(500).json({ message: err.message });
|
| 238 |
+
}
|
| 239 |
+
};
|
| 240 |
+
|
| 241 |
+
export const deleteUser = async (req, res) => {
|
| 242 |
+
if (!req.user?.tenant || !["owner", "admin"].includes(req.user.role)) {
|
| 243 |
+
return res.status(403).json({ message: "You do not have permission to delete users" });
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
if (req.user._id.toString() === req.params.id) {
|
| 247 |
+
return res.status(400).json({ message: "You cannot delete your own active account" });
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
try {
|
| 251 |
+
const targetUser = await User.findOne({
|
| 252 |
+
_id: req.params.id,
|
| 253 |
+
tenant: req.user.tenant._id,
|
| 254 |
+
});
|
| 255 |
+
|
| 256 |
+
if (!targetUser) {
|
| 257 |
+
return res.status(404).json({ message: "User not found" });
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
if (targetUser.role === "owner") {
|
| 261 |
+
return res.status(400).json({ message: "Owner accounts cannot be deleted from this screen" });
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
await targetUser.deleteOne();
|
| 265 |
+
res.status(200).json({ message: "User deleted successfully" });
|
| 266 |
+
} catch (error) {
|
| 267 |
+
res.status(500).json({ message: error.message });
|
| 268 |
+
}
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
export const updateUser = async (req, res) => {
|
| 272 |
+
if (!req.user?.tenant || !["owner", "admin"].includes(req.user.role)) {
|
| 273 |
+
return res.status(403).json({ message: "You do not have permission to edit users" });
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
try {
|
| 277 |
+
const targetUser = await User.findOne({
|
| 278 |
+
_id: req.params.id,
|
| 279 |
+
tenant: req.user.tenant._id,
|
| 280 |
+
}).populate("tenant");
|
| 281 |
+
|
| 282 |
+
if (!targetUser) {
|
| 283 |
+
return res.status(404).json({ message: "User not found" });
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
if (targetUser.role === "owner") {
|
| 287 |
+
return res.status(400).json({ message: "Owner accounts cannot be edited from this screen" });
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
if (req.user.role === "admin" && targetUser.role !== "cashier") {
|
| 291 |
+
return res.status(403).json({ message: "Admins can only manage cashier accounts" });
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
if (req.user._id.toString() === targetUser._id.toString() && req.body.status === "suspended") {
|
| 295 |
+
return res.status(400).json({ message: "You cannot suspend your own active session" });
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
if (req.body.role) {
|
| 299 |
+
if (!["admin", "cashier"].includes(req.body.role)) {
|
| 300 |
+
return res.status(400).json({ message: "Unsupported role" });
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
if (req.user.role === "admin" && req.body.role === "admin") {
|
| 304 |
+
return res.status(403).json({ message: "Admins cannot promote users to admin" });
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
targetUser.role = req.body.role;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
if (req.body.status) {
|
| 311 |
+
if (!["active", "suspended"].includes(req.body.status)) {
|
| 312 |
+
return res.status(400).json({ message: "Unsupported status" });
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
targetUser.status = req.body.status;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
targetUser.fullName = req.body.fullName?.trim() || targetUser.fullName;
|
| 319 |
+
targetUser.email = req.body.email?.trim()?.toLowerCase() || targetUser.email;
|
| 320 |
+
targetUser.phone = req.body.phone?.trim() || targetUser.phone;
|
| 321 |
+
|
| 322 |
+
await targetUser.save();
|
| 323 |
+
|
| 324 |
+
res.status(200).json({
|
| 325 |
+
message: "User updated successfully",
|
| 326 |
+
user: sanitizeUser(targetUser),
|
| 327 |
+
});
|
| 328 |
+
} catch (error) {
|
| 329 |
+
res.status(500).json({ message: error.message });
|
| 330 |
+
}
|
| 331 |
+
};
|
| 332 |
+
|
| 333 |
+
export const getTenants = async (req, res) => {
|
| 334 |
+
if (req.user.role !== "super_admin") {
|
| 335 |
+
return res.status(403).json({ message: "Only the platform admin can access tenants" });
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
try {
|
| 339 |
+
const tenants = await Tenant.find().sort({ createdAt: -1 });
|
| 340 |
+
res.status(200).json(tenants.map(sanitizeTenant));
|
| 341 |
+
} catch (error) {
|
| 342 |
+
res.status(500).json({ message: error.message });
|
| 343 |
+
}
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
export const getTenantProfile = async (req, res) => {
|
| 347 |
+
if (!req.user?.tenant) {
|
| 348 |
+
return res.status(403).json({ message: "This profile is only available for tenant users" });
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
try {
|
| 352 |
+
res.status(200).json({
|
| 353 |
+
tenant: sanitizeTenant(req.user.tenant),
|
| 354 |
+
});
|
| 355 |
+
} catch (error) {
|
| 356 |
+
res.status(500).json({ message: error.message });
|
| 357 |
+
}
|
| 358 |
+
};
|
| 359 |
+
|
| 360 |
+
export const updateTenantProfile = async (req, res) => {
|
| 361 |
+
if (!req.user?.tenant) {
|
| 362 |
+
return res.status(403).json({ message: "This profile is only available for tenant users" });
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
if (!["owner", "admin"].includes(req.user.role)) {
|
| 366 |
+
return res.status(403).json({ message: "Only tenant management roles can update company settings" });
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
try {
|
| 370 |
+
const tenant = await Tenant.findById(req.user.tenant._id);
|
| 371 |
+
|
| 372 |
+
if (!tenant) {
|
| 373 |
+
return res.status(404).json({ message: "Tenant not found" });
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
tenant.name = req.body.name?.trim() || tenant.name;
|
| 377 |
+
tenant.ownerName = req.body.ownerName?.trim() || tenant.ownerName;
|
| 378 |
+
tenant.ownerEmail = req.body.ownerEmail?.trim()?.toLowerCase() || "";
|
| 379 |
+
tenant.ownerPhone = req.body.ownerPhone?.trim() || "";
|
| 380 |
+
tenant.whatsappNumber = req.body.whatsappNumber?.trim() || "";
|
| 381 |
+
tenant.address = req.body.address?.trim() || "";
|
| 382 |
+
tenant.settings = {
|
| 383 |
+
...tenant.settings,
|
| 384 |
+
currency: req.body.currency?.trim() || tenant.settings?.currency || "EGP",
|
| 385 |
+
lowStockThreshold:
|
| 386 |
+
Number(req.body.lowStockThreshold) > 0
|
| 387 |
+
? Number(req.body.lowStockThreshold)
|
| 388 |
+
: tenant.settings?.lowStockThreshold || 5,
|
| 389 |
+
};
|
| 390 |
+
|
| 391 |
+
await tenant.save();
|
| 392 |
+
|
| 393 |
+
const owner = await User.findOne({ tenant: tenant._id, role: "owner" });
|
| 394 |
+
if (owner) {
|
| 395 |
+
owner.fullName = tenant.ownerName;
|
| 396 |
+
owner.email = tenant.ownerEmail || undefined;
|
| 397 |
+
owner.phone = tenant.ownerPhone;
|
| 398 |
+
await owner.save();
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
await req.user.populate("tenant");
|
| 402 |
+
|
| 403 |
+
res.status(200).json({
|
| 404 |
+
message: "Company profile updated successfully",
|
| 405 |
+
tenant: sanitizeTenant(tenant),
|
| 406 |
+
});
|
| 407 |
+
} catch (error) {
|
| 408 |
+
res.status(500).json({ message: error.message });
|
| 409 |
+
}
|
| 410 |
+
};
|
| 411 |
+
|
| 412 |
+
export const updateTenantStatus = async (req, res) => {
|
| 413 |
+
if (req.user.role !== "super_admin") {
|
| 414 |
+
return res.status(403).json({ message: "Only the platform admin can update tenant status" });
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
const status = req.body.status;
|
| 418 |
+
if (!["active", "suspended"].includes(status)) {
|
| 419 |
+
return res.status(400).json({ message: "Invalid tenant status" });
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
try {
|
| 423 |
+
const tenant = await Tenant.findById(req.params.id);
|
| 424 |
+
if (!tenant) {
|
| 425 |
+
return res.status(404).json({ message: "Tenant not found" });
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
tenant.status = status;
|
| 429 |
+
await tenant.save();
|
| 430 |
+
|
| 431 |
+
await User.updateMany({ tenant: tenant._id }, { status });
|
| 432 |
+
|
| 433 |
+
res.status(200).json({
|
| 434 |
+
message: `Tenant marked as ${status}`,
|
| 435 |
+
tenant: sanitizeTenant(tenant),
|
| 436 |
+
});
|
| 437 |
+
} catch (error) {
|
| 438 |
+
res.status(500).json({ message: error.message });
|
| 439 |
+
}
|
| 440 |
+
};
|
| 441 |
+
|
| 442 |
+
export const createTenantOwner = async (req, res) => {
|
| 443 |
+
if (req.user.role !== "super_admin") {
|
| 444 |
+
return res.status(403).json({ message: "Only the platform admin can create tenants" });
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
try {
|
| 448 |
+
const companyName = req.body.companyName?.trim();
|
| 449 |
+
const ownerName = req.body.ownerName?.trim();
|
| 450 |
+
const username = req.body.username?.trim();
|
| 451 |
+
const password = req.body.password?.trim();
|
| 452 |
+
const email = req.body.email?.trim()?.toLowerCase() || "";
|
| 453 |
+
const phone = req.body.phone?.trim() || "";
|
| 454 |
+
const whatsappNumber = req.body.whatsappNumber?.trim() || phone;
|
| 455 |
+
const address = req.body.address?.trim() || "";
|
| 456 |
+
|
| 457 |
+
if (!companyName || !ownerName || !username || !password) {
|
| 458 |
+
return res.status(400).json({ message: "Company and owner details are required" });
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
const existingUsername = await User.findOne({ username });
|
| 462 |
+
if (existingUsername) {
|
| 463 |
+
return res.status(400).json({ message: "Username is already in use" });
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
if (email) {
|
| 467 |
+
const existingEmail = await User.findOne({ email });
|
| 468 |
+
if (existingEmail) {
|
| 469 |
+
return res.status(400).json({ message: "Email is already in use" });
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
const slug = await createUniqueSlug(companyName);
|
| 474 |
+
|
| 475 |
+
const tenant = await Tenant.create({
|
| 476 |
+
name: companyName,
|
| 477 |
+
slug,
|
| 478 |
+
ownerName,
|
| 479 |
+
ownerEmail: email,
|
| 480 |
+
ownerPhone: phone,
|
| 481 |
+
whatsappNumber,
|
| 482 |
+
address,
|
| 483 |
+
});
|
| 484 |
+
|
| 485 |
+
const owner = await User.create({
|
| 486 |
+
username,
|
| 487 |
+
fullName: ownerName,
|
| 488 |
+
email: email || undefined,
|
| 489 |
+
phone,
|
| 490 |
+
password,
|
| 491 |
+
role: "owner",
|
| 492 |
+
tenant: tenant._id,
|
| 493 |
+
});
|
| 494 |
+
|
| 495 |
+
await owner.populate("tenant");
|
| 496 |
+
|
| 497 |
+
const loginUrl = `${(process.env.FRONTEND_URL || "http://localhost:5173").replace(/\/$/, "")}/login`;
|
| 498 |
+
const onboarding = buildTenantCredentialsWhatsApp({
|
| 499 |
+
companyName: tenant.name,
|
| 500 |
+
ownerName,
|
| 501 |
+
username,
|
| 502 |
+
temporaryPassword: password,
|
| 503 |
+
loginUrl,
|
| 504 |
+
});
|
| 505 |
+
|
| 506 |
+
res.status(201).json({
|
| 507 |
+
message: "Tenant owner account created successfully",
|
| 508 |
+
tenant: sanitizeTenant(tenant),
|
| 509 |
+
owner: sanitizeUser(owner),
|
| 510 |
+
onboarding: {
|
| 511 |
+
loginUrl,
|
| 512 |
+
temporaryPassword: password,
|
| 513 |
+
whatsappMessage: onboarding.message,
|
| 514 |
+
whatsappLink: onboarding.whatsappLink,
|
| 515 |
+
},
|
| 516 |
+
});
|
| 517 |
+
} catch (error) {
|
| 518 |
+
res.status(500).json({ message: error.message });
|
| 519 |
+
}
|
| 520 |
+
};
|
backend/controller/customerController.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Customer from "../models/CustomerModel.js";
|
| 2 |
+
import Invoice from "../models/InvoiceModel.js";
|
| 3 |
+
|
| 4 |
+
export const createCustomer = async (req, res) => {
|
| 5 |
+
try {
|
| 6 |
+
const tenantId = req.user.tenant._id;
|
| 7 |
+
const name = req.body.name?.trim();
|
| 8 |
+
|
| 9 |
+
if (!name) {
|
| 10 |
+
return res.status(400).json({ message: "Customer name is required" });
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (name.length < 3) {
|
| 14 |
+
return res.status(400).json({ message: "Customer name must be at least 3 characters" });
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const exists = await Customer.findOne({
|
| 18 |
+
tenant: tenantId,
|
| 19 |
+
name: new RegExp(`^${name}$`, "i"),
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
if (exists) {
|
| 23 |
+
return res.status(400).json({ message: "Customer already exists" });
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
const customer = await Customer.create({
|
| 27 |
+
tenant: tenantId,
|
| 28 |
+
name,
|
| 29 |
+
phone: req.body.phone?.trim() || "",
|
| 30 |
+
email: req.body.email?.trim()?.toLowerCase() || "",
|
| 31 |
+
address: req.body.address?.trim() || "",
|
| 32 |
+
notes: req.body.notes?.trim() || "",
|
| 33 |
+
createdBy: req.user._id,
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
res.status(201).json(customer);
|
| 37 |
+
} catch (err) {
|
| 38 |
+
res.status(500).json({ message: err.message });
|
| 39 |
+
}
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
export const getCustomers = async (req, res) => {
|
| 43 |
+
try {
|
| 44 |
+
const tenantId = req.user.tenant._id;
|
| 45 |
+
const page = parseInt(req.query.page) || 1;
|
| 46 |
+
const limit = parseInt(req.query.limit) || 5;
|
| 47 |
+
const skip = (page - 1) * limit;
|
| 48 |
+
const search = req.query.search || "";
|
| 49 |
+
|
| 50 |
+
const matchQuery = {
|
| 51 |
+
tenant: tenantId,
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
if (search) {
|
| 55 |
+
matchQuery.name = { $regex: search, $options: "i" };
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
const results = await Customer.aggregate([
|
| 59 |
+
{ $match: matchQuery },
|
| 60 |
+
{
|
| 61 |
+
$facet: {
|
| 62 |
+
data: [
|
| 63 |
+
{ $sort: { createdAt: -1 } },
|
| 64 |
+
{ $skip: skip },
|
| 65 |
+
{ $limit: limit },
|
| 66 |
+
{
|
| 67 |
+
$lookup: {
|
| 68 |
+
from: "invoices",
|
| 69 |
+
let: {
|
| 70 |
+
customerId: "$_id",
|
| 71 |
+
tenantId: "$tenant",
|
| 72 |
+
},
|
| 73 |
+
pipeline: [
|
| 74 |
+
{
|
| 75 |
+
$match: {
|
| 76 |
+
$expr: {
|
| 77 |
+
$and: [
|
| 78 |
+
{ $eq: ["$customer", "$$customerId"] },
|
| 79 |
+
{ $eq: ["$tenant", "$$tenantId"] },
|
| 80 |
+
],
|
| 81 |
+
},
|
| 82 |
+
},
|
| 83 |
+
},
|
| 84 |
+
],
|
| 85 |
+
as: "invoices",
|
| 86 |
+
},
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
$addFields: {
|
| 90 |
+
totalInvoicesAmount: { $sum: "$invoices.totalAmount" },
|
| 91 |
+
totalDebt: { $sum: "$invoices.remainingAmount" },
|
| 92 |
+
},
|
| 93 |
+
},
|
| 94 |
+
],
|
| 95 |
+
totalCount: [
|
| 96 |
+
{ $count: "count" }
|
| 97 |
+
]
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
]);
|
| 101 |
+
|
| 102 |
+
const customers = results[0].data;
|
| 103 |
+
const total = results[0].totalCount[0]?.count || 0;
|
| 104 |
+
|
| 105 |
+
res.status(200).json({
|
| 106 |
+
data: customers,
|
| 107 |
+
pagination: {
|
| 108 |
+
total,
|
| 109 |
+
page,
|
| 110 |
+
limit,
|
| 111 |
+
totalPages: Math.ceil(total / limit),
|
| 112 |
+
},
|
| 113 |
+
});
|
| 114 |
+
} catch (error) {
|
| 115 |
+
res.status(500).json({ message: error.message });
|
| 116 |
+
}
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
+
export const getCustomerById = async (req, res) => {
|
| 120 |
+
try {
|
| 121 |
+
const customer = await Customer.findOne({
|
| 122 |
+
_id: req.params.id,
|
| 123 |
+
tenant: req.user.tenant._id,
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
if (!customer) {
|
| 127 |
+
return res.status(404).json({ message: "Customer not found" });
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
const invoice = await Invoice.findOne({
|
| 131 |
+
customer: customer._id,
|
| 132 |
+
tenant: req.user.tenant._id,
|
| 133 |
+
});
|
| 134 |
+
|
| 135 |
+
res.status(200).json({
|
| 136 |
+
...customer.toObject(),
|
| 137 |
+
invoice,
|
| 138 |
+
});
|
| 139 |
+
} catch (error) {
|
| 140 |
+
res.status(500).json({ message: error.message });
|
| 141 |
+
}
|
| 142 |
+
};
|
| 143 |
+
|
| 144 |
+
export const deleteCustomer = async (req, res) => {
|
| 145 |
+
try {
|
| 146 |
+
const customerId = req.params.id;
|
| 147 |
+
await Customer.findOneAndDelete({
|
| 148 |
+
_id: customerId,
|
| 149 |
+
tenant: req.user.tenant._id,
|
| 150 |
+
});
|
| 151 |
+
await Invoice.deleteMany({
|
| 152 |
+
customer: customerId,
|
| 153 |
+
tenant: req.user.tenant._id,
|
| 154 |
+
});
|
| 155 |
+
|
| 156 |
+
res.status(200).json({ message: "Customer and linked invoices deleted successfully" });
|
| 157 |
+
} catch (error) {
|
| 158 |
+
res.status(500).json({ message: error.message });
|
| 159 |
+
}
|
| 160 |
+
};
|
backend/controller/expenseController.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Expense from "../models/ExpenseModel.js";
|
| 2 |
+
|
| 3 |
+
export const addExpense = async (req, res) => {
|
| 4 |
+
try {
|
| 5 |
+
const { title, amount, category, paymentMethod, notes, date } = req.body;
|
| 6 |
+
const expense = await Expense.create({
|
| 7 |
+
tenant: req.user.tenant._id,
|
| 8 |
+
title,
|
| 9 |
+
amount,
|
| 10 |
+
category,
|
| 11 |
+
paymentMethod,
|
| 12 |
+
notes,
|
| 13 |
+
date: date || Date.now(),
|
| 14 |
+
createdBy: req.user._id,
|
| 15 |
+
});
|
| 16 |
+
res.status(201).json(expense);
|
| 17 |
+
} catch (error) {
|
| 18 |
+
res.status(500).json({ message: error.message });
|
| 19 |
+
}
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
export const deleteExpense = async (req, res) => {
|
| 23 |
+
try {
|
| 24 |
+
await Expense.findOneAndDelete({
|
| 25 |
+
_id: req.params.id,
|
| 26 |
+
tenant: req.user.tenant._id,
|
| 27 |
+
});
|
| 28 |
+
res.status(200).json({ message: "Expense deleted successfully" });
|
| 29 |
+
} catch (error) {
|
| 30 |
+
res.status(500).json({ message: error.message });
|
| 31 |
+
}
|
| 32 |
+
};
|
backend/controller/invoiceController.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Invoice from "../models/InvoiceModel.js";
|
| 2 |
+
import Product from "../models/ProductModel.js";
|
| 3 |
+
import Customer from "../models/CustomerModel.js";
|
| 4 |
+
|
| 5 |
+
const generateInvoiceNumber = async (tenantId) => {
|
| 6 |
+
const count = await Invoice.countDocuments({ tenant: tenantId });
|
| 7 |
+
return `INV-${String(count + 1).padStart(5, "0")}`;
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
export const addItemToInvoice = async (req, res) => {
|
| 11 |
+
try {
|
| 12 |
+
const { customerId } = req.params;
|
| 13 |
+
const { items } = req.body;
|
| 14 |
+
const tenantId = req.user.tenant?._id;
|
| 15 |
+
if (!tenantId) {
|
| 16 |
+
return res.status(403).json({ message: "No tenant associated with this account" });
|
| 17 |
+
}
|
| 18 |
+
if (!Array.isArray(items) || items.length === 0) {
|
| 19 |
+
return res.status(400).json({ message: "At least one item is required" });
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
const customer = await Customer.findOne({ _id: customerId, tenant: tenantId });
|
| 23 |
+
if (!customer) {
|
| 24 |
+
return res.status(404).json({ message: "Customer not found" });
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
let invoice = await Invoice.findOne({
|
| 28 |
+
customer: customerId,
|
| 29 |
+
tenant: tenantId,
|
| 30 |
+
status: { $in: ["open", "partial"] },
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
if (!invoice) {
|
| 34 |
+
invoice = new Invoice({
|
| 35 |
+
tenant: tenantId,
|
| 36 |
+
customer: customerId,
|
| 37 |
+
invoiceNumber: await generateInvoiceNumber(tenantId),
|
| 38 |
+
issuedBy: req.user._id,
|
| 39 |
+
});
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
for (const item of items) {
|
| 43 |
+
if (item.productId) {
|
| 44 |
+
const product = await Product.findOne({ _id: item.productId, tenant: tenantId });
|
| 45 |
+
if (!product) {
|
| 46 |
+
return res.status(404).json({ message: `Product not found: ${item.name}` });
|
| 47 |
+
}
|
| 48 |
+
if (product.stock < Number(item.quantity)) {
|
| 49 |
+
return res.status(400).json({
|
| 50 |
+
message: `Not enough stock for ${item.name}. Available: ${product.stock}`,
|
| 51 |
+
});
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
for (const item of items) {
|
| 57 |
+
const quantity = Number(item.quantity || 0);
|
| 58 |
+
const price = Number(item.price || 0);
|
| 59 |
+
const total = quantity * price;
|
| 60 |
+
|
| 61 |
+
invoice.items.push({
|
| 62 |
+
name: item.name,
|
| 63 |
+
quantity,
|
| 64 |
+
price,
|
| 65 |
+
total,
|
| 66 |
+
...(item.productId ? { productId: item.productId } : {}),
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
if (item.productId) {
|
| 70 |
+
await Product.findOneAndUpdate(
|
| 71 |
+
{ _id: item.productId, tenant: tenantId },
|
| 72 |
+
{ $inc: { stock: -quantity } }
|
| 73 |
+
);
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
await invoice.save();
|
| 77 |
+
res.status(200).json(invoice);
|
| 78 |
+
} catch (err) {
|
| 79 |
+
console.log('❌ ERROR:', err.message);
|
| 80 |
+
console.log('❌ STACK:', err.stack);
|
| 81 |
+
res.status(500).json({ message: err.message });
|
| 82 |
+
}
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
export const getInvoices = async (req, res) => {
|
| 86 |
+
try {
|
| 87 |
+
const page = parseInt(req.query.page) || 1;
|
| 88 |
+
const limit = parseInt(req.query.limit) || 5;
|
| 89 |
+
const skip = (page - 1) * limit;
|
| 90 |
+
const search = req.query.search || "";
|
| 91 |
+
|
| 92 |
+
const query = { tenant: req.user.tenant._id };
|
| 93 |
+
if (search) {
|
| 94 |
+
query.invoiceNumber = { $regex: search, $options: "i" };
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
const total = await Invoice.countDocuments(query);
|
| 98 |
+
const invoices = await Invoice.find(query)
|
| 99 |
+
.populate("customer")
|
| 100 |
+
.sort({ createdAt: -1 })
|
| 101 |
+
.skip(skip)
|
| 102 |
+
.limit(limit);
|
| 103 |
+
|
| 104 |
+
res.status(200).json({
|
| 105 |
+
data: invoices,
|
| 106 |
+
pagination: {
|
| 107 |
+
total,
|
| 108 |
+
page,
|
| 109 |
+
limit,
|
| 110 |
+
totalPages: Math.ceil(total / limit),
|
| 111 |
+
},
|
| 112 |
+
});
|
| 113 |
+
} catch (err) {
|
| 114 |
+
res.status(500).json({ message: err.message });
|
| 115 |
+
}
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
export const getInvoicesByCustomer = async (req, res) => {
|
| 119 |
+
try {
|
| 120 |
+
const invoices = await Invoice.find({
|
| 121 |
+
customer: req.params.customerId,
|
| 122 |
+
tenant: req.user.tenant._id,
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
res.json(invoices);
|
| 126 |
+
} catch (err) {
|
| 127 |
+
res.status(500).json({ message: err.message });
|
| 128 |
+
}
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
export const getInvoiceById = async (req, res) => {
|
| 132 |
+
try {
|
| 133 |
+
const { id } = req.params;
|
| 134 |
+
|
| 135 |
+
const invoice = await Invoice.findOne({
|
| 136 |
+
_id: id,
|
| 137 |
+
tenant: req.user.tenant._id,
|
| 138 |
+
})
|
| 139 |
+
.populate("customer", "name")
|
| 140 |
+
.populate("items");
|
| 141 |
+
|
| 142 |
+
if (!invoice) {
|
| 143 |
+
return res.status(404).json({ message: "Invoice not found" });
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
res.status(200).json(invoice);
|
| 147 |
+
} catch (error) {
|
| 148 |
+
res.status(500).json({ message: error.message });
|
| 149 |
+
}
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
export const updateInvoiceItem = async (req, res) => {
|
| 153 |
+
try {
|
| 154 |
+
const { invoiceId, itemId } = req.params;
|
| 155 |
+
const { name, quantity, price } = req.body;
|
| 156 |
+
|
| 157 |
+
const invoice = await Invoice.findOne({
|
| 158 |
+
_id: invoiceId,
|
| 159 |
+
tenant: req.user.tenant._id,
|
| 160 |
+
});
|
| 161 |
+
|
| 162 |
+
if (!invoice) {
|
| 163 |
+
return res.status(404).json({ message: "Invoice not found" });
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
const item = invoice.items.id(itemId);
|
| 167 |
+
if (!item) {
|
| 168 |
+
return res.status(404).json({ message: "Invoice item not found" });
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
const newQuantity = Number(quantity);
|
| 172 |
+
const newPrice = Number(price);
|
| 173 |
+
|
| 174 |
+
if (item.productId) {
|
| 175 |
+
const quantityDifference = newQuantity - Number(item.quantity);
|
| 176 |
+
const product = await Product.findOne({
|
| 177 |
+
_id: item.productId,
|
| 178 |
+
tenant: req.user.tenant._id,
|
| 179 |
+
});
|
| 180 |
+
|
| 181 |
+
if (!product) {
|
| 182 |
+
return res.status(404).json({ message: "Linked product no longer exists" });
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
if (quantityDifference > 0 && product.stock < quantityDifference) {
|
| 186 |
+
return res.status(400).json({ message: "Current stock is too low for this quantity change" });
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
if (quantityDifference !== 0) {
|
| 190 |
+
await Product.findOneAndUpdate(
|
| 191 |
+
{ _id: item.productId, tenant: req.user.tenant._id },
|
| 192 |
+
{ $inc: { stock: -quantityDifference } }
|
| 193 |
+
);
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
item.name = name;
|
| 198 |
+
item.quantity = newQuantity;
|
| 199 |
+
item.price = newPrice;
|
| 200 |
+
item.total = newQuantity * newPrice;
|
| 201 |
+
|
| 202 |
+
await invoice.save();
|
| 203 |
+
|
| 204 |
+
res.status(200).json({
|
| 205 |
+
message: "Invoice item updated successfully",
|
| 206 |
+
invoice,
|
| 207 |
+
});
|
| 208 |
+
} catch (error) {
|
| 209 |
+
res.status(500).json({ message: error.message });
|
| 210 |
+
}
|
| 211 |
+
};
|
| 212 |
+
|
| 213 |
+
export const deleteInvoiceItem = async (req, res) => {
|
| 214 |
+
try {
|
| 215 |
+
const { invoiceId, itemId } = req.params;
|
| 216 |
+
|
| 217 |
+
const invoice = await Invoice.findOne({
|
| 218 |
+
_id: invoiceId,
|
| 219 |
+
tenant: req.user.tenant._id,
|
| 220 |
+
});
|
| 221 |
+
|
| 222 |
+
if (!invoice) {
|
| 223 |
+
return res.status(404).json({ message: "Invoice not found" });
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
const item = invoice.items.id(itemId);
|
| 227 |
+
if (!item) {
|
| 228 |
+
return res.status(404).json({ message: "Invoice item not found" });
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
if (item.productId) {
|
| 232 |
+
await Product.findOneAndUpdate(
|
| 233 |
+
{ _id: item.productId, tenant: req.user.tenant._id },
|
| 234 |
+
{ $inc: { stock: Number(item.quantity) } }
|
| 235 |
+
);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
item.deleteOne();
|
| 239 |
+
await invoice.save();
|
| 240 |
+
|
| 241 |
+
res.json(invoice);
|
| 242 |
+
} catch (error) {
|
| 243 |
+
res.status(500).json({ message: error.message });
|
| 244 |
+
}
|
| 245 |
+
};
|
| 246 |
+
|
| 247 |
+
export const payInvoice = async (req, res) => {
|
| 248 |
+
try {
|
| 249 |
+
const { customerId } = req.params;
|
| 250 |
+
const amount = Number(req.body.amount);
|
| 251 |
+
|
| 252 |
+
if (!amount || amount <= 0) {
|
| 253 |
+
return res.status(400).json({ message: "Payment amount must be greater than zero" });
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
const invoice = await Invoice.findOne({
|
| 257 |
+
customer: customerId,
|
| 258 |
+
tenant: req.user.tenant._id,
|
| 259 |
+
status: { $in: ["open", "partial"] },
|
| 260 |
+
});
|
| 261 |
+
|
| 262 |
+
if (!invoice || invoice.remainingAmount <= 0) {
|
| 263 |
+
return res.status(404).json({ message: "There is no outstanding invoice for this customer" });
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
if (amount > invoice.remainingAmount) {
|
| 267 |
+
return res.status(400).json({ message: "Payment amount is greater than the remaining balance" });
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
invoice.payments.push({
|
| 271 |
+
amount,
|
| 272 |
+
method: req.body.paymentMethod || "cash",
|
| 273 |
+
receivedBy: req.user._id,
|
| 274 |
+
});
|
| 275 |
+
|
| 276 |
+
await invoice.save();
|
| 277 |
+
res.json(invoice);
|
| 278 |
+
} catch (err) {
|
| 279 |
+
res.status(500).json({ message: err.message });
|
| 280 |
+
}
|
| 281 |
+
};
|
backend/controller/productController.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Product from "../models/ProductModel.js";
|
| 2 |
+
|
| 3 |
+
export const createProduct = async (req, res) => {
|
| 4 |
+
try {
|
| 5 |
+
const { name, price, stock, description, barcode, sku, unit, lowStockThreshold, costPrice } = req.body;
|
| 6 |
+
const tenantId = req.user.tenant._id;
|
| 7 |
+
|
| 8 |
+
const exists = await Product.findOne({
|
| 9 |
+
tenant: tenantId,
|
| 10 |
+
$or: [{ name }, ...(barcode ? [{ barcode }] : [])],
|
| 11 |
+
});
|
| 12 |
+
|
| 13 |
+
if (exists) {
|
| 14 |
+
return res.status(400).json({ message: "Product already exists" });
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const product = await Product.create({
|
| 18 |
+
tenant: tenantId,
|
| 19 |
+
name,
|
| 20 |
+
price,
|
| 21 |
+
stock,
|
| 22 |
+
description,
|
| 23 |
+
barcode,
|
| 24 |
+
sku,
|
| 25 |
+
unit,
|
| 26 |
+
lowStockThreshold: lowStockThreshold || req.user.tenant.settings?.lowStockThreshold || 5,
|
| 27 |
+
costPrice: costPrice || 0,
|
| 28 |
+
createdBy: req.user._id,
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
res.status(201).json(product);
|
| 32 |
+
} catch (error) {
|
| 33 |
+
res.status(500).json({ message: error.message });
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
export const getProducts = async (req, res) => {
|
| 38 |
+
try {
|
| 39 |
+
const page = parseInt(req.query.page) || 1;
|
| 40 |
+
const limit = parseInt(req.query.limit) || 5;
|
| 41 |
+
const skip = (page - 1) * limit;
|
| 42 |
+
const search = req.query.search || "";
|
| 43 |
+
|
| 44 |
+
const query = { tenant: req.user.tenant._id };
|
| 45 |
+
if (search) {
|
| 46 |
+
query.name = { $regex: search, $options: "i" };
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const total = await Product.countDocuments(query);
|
| 50 |
+
const products = await Product.find(query)
|
| 51 |
+
.sort({ createdAt: -1 })
|
| 52 |
+
.skip(skip)
|
| 53 |
+
.limit(limit);
|
| 54 |
+
|
| 55 |
+
res.status(200).json({
|
| 56 |
+
data: products.map((product) => ({
|
| 57 |
+
...product.toObject(),
|
| 58 |
+
isLowStock:
|
| 59 |
+
Number(product.stock) <=
|
| 60 |
+
Number(product.lowStockThreshold || req.user.tenant.settings?.lowStockThreshold || 5),
|
| 61 |
+
})),
|
| 62 |
+
pagination: {
|
| 63 |
+
total,
|
| 64 |
+
page,
|
| 65 |
+
limit,
|
| 66 |
+
totalPages: Math.ceil(total / limit),
|
| 67 |
+
},
|
| 68 |
+
});
|
| 69 |
+
} catch (error) {
|
| 70 |
+
res.status(500).json({ message: error.message });
|
| 71 |
+
}
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
export const updateProduct = async (req, res) => {
|
| 75 |
+
try {
|
| 76 |
+
const { id } = req.params;
|
| 77 |
+
const { name, price, stock, description, barcode, sku, unit, lowStockThreshold, costPrice } = req.body;
|
| 78 |
+
|
| 79 |
+
const product = await Product.findOne({
|
| 80 |
+
_id: id,
|
| 81 |
+
tenant: req.user.tenant._id,
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
if (!product) {
|
| 85 |
+
return res.status(404).json({ message: "Product not found" });
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
product.name = name ?? product.name;
|
| 89 |
+
product.price = price ?? product.price;
|
| 90 |
+
product.stock = stock ?? product.stock;
|
| 91 |
+
product.description = description ?? product.description;
|
| 92 |
+
product.barcode = barcode ?? product.barcode;
|
| 93 |
+
product.sku = sku ?? product.sku;
|
| 94 |
+
product.unit = unit ?? product.unit;
|
| 95 |
+
product.lowStockThreshold = lowStockThreshold ?? product.lowStockThreshold;
|
| 96 |
+
product.costPrice = costPrice ?? product.costPrice;
|
| 97 |
+
await product.save();
|
| 98 |
+
|
| 99 |
+
res.status(200).json(product);
|
| 100 |
+
} catch (error) {
|
| 101 |
+
res.status(500).json({ message: error.message });
|
| 102 |
+
}
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
export const deleteProduct = async (req, res) => {
|
| 106 |
+
try {
|
| 107 |
+
const { id } = req.params;
|
| 108 |
+
const product = await Product.findOneAndDelete({
|
| 109 |
+
_id: id,
|
| 110 |
+
tenant: req.user.tenant._id,
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
if (!product) {
|
| 114 |
+
return res.status(404).json({ message: "Product not found" });
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
res.status(200).json({ message: "Product deleted successfully" });
|
| 118 |
+
} catch (error) {
|
| 119 |
+
res.status(500).json({ message: error.message });
|
| 120 |
+
}
|
| 121 |
+
};
|
backend/controller/reportController.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Invoice from "../models/InvoiceModel.js";
|
| 2 |
+
import Expense from "../models/ExpenseModel.js";
|
| 3 |
+
import Product from "../models/ProductModel.js";
|
| 4 |
+
import Customer from "../models/CustomerModel.js";
|
| 5 |
+
import Supplier from "../models/SupplierModel.js";
|
| 6 |
+
import SupplierInvoice from "../models/SupplierInvoiceModel.js";
|
| 7 |
+
import User from "../models/UserModel.js";
|
| 8 |
+
|
| 9 |
+
const isWithinRange = (value, start, end) => {
|
| 10 |
+
const date = new Date(value);
|
| 11 |
+
return date >= start && date <= end;
|
| 12 |
+
};
|
| 13 |
+
|
| 14 |
+
const toNumber = (value) => Number(value || 0);
|
| 15 |
+
|
| 16 |
+
const createRange = (req) => {
|
| 17 |
+
const end = req.query.end ? new Date(req.query.end) : new Date();
|
| 18 |
+
const start = req.query.start ? new Date(req.query.start) : new Date(end);
|
| 19 |
+
|
| 20 |
+
if (!req.query.start) {
|
| 21 |
+
start.setDate(start.getDate() - 29);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
start.setHours(0, 0, 0, 0);
|
| 25 |
+
end.setHours(23, 59, 59, 999);
|
| 26 |
+
|
| 27 |
+
return { start, end };
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
const buildDailyBreakdown = (days, invoices, expenses) => {
|
| 31 |
+
const points = [];
|
| 32 |
+
|
| 33 |
+
for (let index = days - 1; index >= 0; index -= 1) {
|
| 34 |
+
const day = new Date();
|
| 35 |
+
day.setDate(day.getDate() - index);
|
| 36 |
+
day.setHours(0, 0, 0, 0);
|
| 37 |
+
|
| 38 |
+
const endOfDay = new Date(day);
|
| 39 |
+
endOfDay.setHours(23, 59, 59, 999);
|
| 40 |
+
|
| 41 |
+
const sales = invoices
|
| 42 |
+
.filter((invoice) => isWithinRange(invoice.createdAt, day, endOfDay))
|
| 43 |
+
.reduce((sum, invoice) => sum + toNumber(invoice.totalAmount), 0);
|
| 44 |
+
|
| 45 |
+
const collections = invoices.reduce((sum, invoice) => {
|
| 46 |
+
const payments = invoice.payments?.filter((payment) => isWithinRange(payment.date, day, endOfDay)) || [];
|
| 47 |
+
return sum + payments.reduce((paymentSum, payment) => paymentSum + toNumber(payment.amount), 0);
|
| 48 |
+
}, 0);
|
| 49 |
+
|
| 50 |
+
const dayExpenses = expenses
|
| 51 |
+
.filter((expense) => isWithinRange(expense.date, day, endOfDay))
|
| 52 |
+
.reduce((sum, expense) => sum + toNumber(expense.amount), 0);
|
| 53 |
+
|
| 54 |
+
points.push({
|
| 55 |
+
date: day.toISOString(),
|
| 56 |
+
label: day.toLocaleDateString("en-US", { month: "short", day: "numeric" }),
|
| 57 |
+
sales,
|
| 58 |
+
collections,
|
| 59 |
+
expenses: dayExpenses,
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
return points;
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
export const getDashboardOverview = async (req, res) => {
|
| 67 |
+
try {
|
| 68 |
+
const tenantId = req.user.tenant._id;
|
| 69 |
+
const { start, end } = createRange(req);
|
| 70 |
+
|
| 71 |
+
const [invoices, expenses, products, customers, suppliers, supplierInvoices, users] = await Promise.all([
|
| 72 |
+
Invoice.find({ tenant: tenantId }).populate("customer", "name"),
|
| 73 |
+
Expense.find({ tenant: tenantId }).sort({ date: -1 }),
|
| 74 |
+
Product.find({ tenant: tenantId }).sort({ stock: 1, createdAt: -1 }),
|
| 75 |
+
Customer.find({ tenant: tenantId }).sort({ createdAt: -1 }),
|
| 76 |
+
Supplier.find({ tenant: tenantId }).sort({ createdAt: -1 }),
|
| 77 |
+
SupplierInvoice.find({ tenant: tenantId }).populate("supplier", "name"),
|
| 78 |
+
User.find({ tenant: tenantId }).sort({ createdAt: -1 }),
|
| 79 |
+
]);
|
| 80 |
+
|
| 81 |
+
const rangeInvoices = invoices.filter((invoice) => isWithinRange(invoice.createdAt, start, end));
|
| 82 |
+
const rangeExpenses = expenses.filter((expense) => isWithinRange(expense.date, start, end));
|
| 83 |
+
|
| 84 |
+
const collectionsInRange = invoices.reduce((sum, invoice) => {
|
| 85 |
+
const payments = invoice.payments?.filter((payment) => isWithinRange(payment.date, start, end)) || [];
|
| 86 |
+
return sum + payments.reduce((paymentSum, payment) => paymentSum + toNumber(payment.amount), 0);
|
| 87 |
+
}, 0);
|
| 88 |
+
|
| 89 |
+
const salesInRange = rangeInvoices.reduce((sum, invoice) => sum + toNumber(invoice.totalAmount), 0);
|
| 90 |
+
const expensesInRange = rangeExpenses.reduce((sum, expense) => sum + toNumber(expense.amount), 0);
|
| 91 |
+
const outstandingReceivables = invoices.reduce((sum, invoice) => sum + toNumber(invoice.remainingAmount), 0);
|
| 92 |
+
const supplierOutstanding = supplierInvoices.reduce(
|
| 93 |
+
(sum, invoice) => sum + toNumber(invoice.remainingAmount),
|
| 94 |
+
0
|
| 95 |
+
);
|
| 96 |
+
const lowStockItems = products.filter(
|
| 97 |
+
(product) => toNumber(product.stock) <= toNumber(product.lowStockThreshold || req.user.tenant.settings?.lowStockThreshold || 5)
|
| 98 |
+
);
|
| 99 |
+
const inventoryValue = products.reduce(
|
| 100 |
+
(sum, product) => sum + toNumber(product.stock) * toNumber(product.costPrice || product.price),
|
| 101 |
+
0
|
| 102 |
+
);
|
| 103 |
+
const inventoryRetailValue = products.reduce(
|
| 104 |
+
(sum, product) => sum + toNumber(product.stock) * toNumber(product.price),
|
| 105 |
+
0
|
| 106 |
+
);
|
| 107 |
+
|
| 108 |
+
const topCustomers = invoices
|
| 109 |
+
.reduce((accumulator, invoice) => {
|
| 110 |
+
const key = invoice.customer?._id?.toString() || invoice.customer?.toString() || "unknown";
|
| 111 |
+
const current = accumulator.get(key) || {
|
| 112 |
+
customerId: invoice.customer?._id || null,
|
| 113 |
+
customerName: invoice.customer?.name || "Walk-in customer",
|
| 114 |
+
sales: 0,
|
| 115 |
+
outstanding: 0,
|
| 116 |
+
invoices: 0,
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
+
current.sales += toNumber(invoice.totalAmount);
|
| 120 |
+
current.outstanding += toNumber(invoice.remainingAmount);
|
| 121 |
+
current.invoices += 1;
|
| 122 |
+
accumulator.set(key, current);
|
| 123 |
+
return accumulator;
|
| 124 |
+
}, new Map());
|
| 125 |
+
|
| 126 |
+
const limit = parseInt(req.query.limit) || 5;
|
| 127 |
+
const lowStockPage = parseInt(req.query.lowStockPage) || 1;
|
| 128 |
+
const customersPage = parseInt(req.query.customersPage) || 1;
|
| 129 |
+
const paymentsPage = parseInt(req.query.paymentsPage) || 1;
|
| 130 |
+
const invoicesPage = parseInt(req.query.invoicesPage) || 1;
|
| 131 |
+
|
| 132 |
+
const lowStockSkip = (lowStockPage - 1) * limit;
|
| 133 |
+
const paginatedLowStockItems = lowStockItems.slice(lowStockSkip, lowStockSkip + limit).map((product) => ({
|
| 134 |
+
_id: product._id,
|
| 135 |
+
name: product.name,
|
| 136 |
+
stock: toNumber(product.stock),
|
| 137 |
+
lowStockThreshold: toNumber(product.lowStockThreshold),
|
| 138 |
+
price: toNumber(product.price),
|
| 139 |
+
unit: product.unit,
|
| 140 |
+
}));
|
| 141 |
+
|
| 142 |
+
const topCustomersArray = [...topCustomers.values()].sort((a, b) => b.sales - a.sales);
|
| 143 |
+
const customersSkip = (customersPage - 1) * limit;
|
| 144 |
+
const paginatedTopCustomers = topCustomersArray.slice(customersSkip, customersSkip + limit);
|
| 145 |
+
|
| 146 |
+
const allRecentPayments = invoices
|
| 147 |
+
.flatMap((invoice) =>
|
| 148 |
+
(invoice.payments || []).map((payment) => ({
|
| 149 |
+
amount: toNumber(payment.amount),
|
| 150 |
+
date: payment.date,
|
| 151 |
+
method: payment.method || "cash",
|
| 152 |
+
customerName: invoice.customer?.name || "Walk-in customer",
|
| 153 |
+
customerId: invoice.customer?._id || null,
|
| 154 |
+
invoiceNumber: invoice.invoiceNumber,
|
| 155 |
+
}))
|
| 156 |
+
)
|
| 157 |
+
.filter((payment) => isWithinRange(payment.date, start, end))
|
| 158 |
+
.sort((a, b) => new Date(b.date) - new Date(a.date));
|
| 159 |
+
const paymentsSkip = (paymentsPage - 1) * limit;
|
| 160 |
+
const paginatedRecentPayments = allRecentPayments.slice(paymentsSkip, paymentsSkip + limit);
|
| 161 |
+
|
| 162 |
+
const allRecentInvoices = [...rangeInvoices]
|
| 163 |
+
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
| 164 |
+
.map((invoice) => ({
|
| 165 |
+
_id: invoice._id,
|
| 166 |
+
invoiceNumber: invoice.invoiceNumber,
|
| 167 |
+
customerName: invoice.customer?.name || "Walk-in customer",
|
| 168 |
+
totalAmount: toNumber(invoice.totalAmount),
|
| 169 |
+
remainingAmount: toNumber(invoice.remainingAmount),
|
| 170 |
+
status: invoice.status,
|
| 171 |
+
createdAt: invoice.createdAt,
|
| 172 |
+
}));
|
| 173 |
+
const invoicesSkip = (invoicesPage - 1) * limit;
|
| 174 |
+
const paginatedRecentInvoices = allRecentInvoices.slice(invoicesSkip, invoicesSkip + limit);
|
| 175 |
+
|
| 176 |
+
res.status(200).json({
|
| 177 |
+
dateRange: {
|
| 178 |
+
start,
|
| 179 |
+
end,
|
| 180 |
+
},
|
| 181 |
+
metrics: {
|
| 182 |
+
salesInRange,
|
| 183 |
+
collectionsInRange,
|
| 184 |
+
expensesInRange,
|
| 185 |
+
netCashFlow: collectionsInRange - expensesInRange,
|
| 186 |
+
outstandingReceivables,
|
| 187 |
+
supplierOutstanding,
|
| 188 |
+
customersCount: customers.length,
|
| 189 |
+
suppliersCount: suppliers.length,
|
| 190 |
+
usersCount: users.length,
|
| 191 |
+
invoicesCount: invoices.length,
|
| 192 |
+
invoicesInRange: rangeInvoices.length,
|
| 193 |
+
paidInvoicesCount: invoices.filter((invoice) => invoice.status === "paid").length,
|
| 194 |
+
partialInvoicesCount: invoices.filter((invoice) => invoice.status === "partial").length,
|
| 195 |
+
averageInvoiceValue: invoices.length ? invoices.reduce((sum, invoice) => sum + toNumber(invoice.totalAmount), 0) / invoices.length : 0,
|
| 196 |
+
inventoryUnits: products.reduce((sum, product) => sum + toNumber(product.stock), 0),
|
| 197 |
+
inventoryValue,
|
| 198 |
+
inventoryRetailValue,
|
| 199 |
+
lowStockCount: lowStockItems.length,
|
| 200 |
+
},
|
| 201 |
+
trends: {
|
| 202 |
+
last7Days: buildDailyBreakdown(7, invoices, expenses),
|
| 203 |
+
},
|
| 204 |
+
lowStockItems: {
|
| 205 |
+
data: paginatedLowStockItems,
|
| 206 |
+
pagination: { total: lowStockItems.length, page: lowStockPage, limit, totalPages: Math.ceil(lowStockItems.length / limit) }
|
| 207 |
+
},
|
| 208 |
+
topCustomers: {
|
| 209 |
+
data: paginatedTopCustomers,
|
| 210 |
+
pagination: { total: topCustomersArray.length, page: customersPage, limit, totalPages: Math.ceil(topCustomersArray.length / limit) }
|
| 211 |
+
},
|
| 212 |
+
recentInvoices: {
|
| 213 |
+
data: paginatedRecentInvoices,
|
| 214 |
+
pagination: { total: allRecentInvoices.length, page: invoicesPage, limit, totalPages: Math.ceil(allRecentInvoices.length / limit) }
|
| 215 |
+
},
|
| 216 |
+
recentPayments: {
|
| 217 |
+
data: paginatedRecentPayments,
|
| 218 |
+
pagination: { total: allRecentPayments.length, page: paymentsPage, limit, totalPages: Math.ceil(allRecentPayments.length / limit) }
|
| 219 |
+
},
|
| 220 |
+
recentExpenses: rangeExpenses.slice(0, 8).map((expense) => ({
|
| 221 |
+
_id: expense._id,
|
| 222 |
+
title: expense.title,
|
| 223 |
+
amount: toNumber(expense.amount),
|
| 224 |
+
date: expense.date,
|
| 225 |
+
})),
|
| 226 |
+
});
|
| 227 |
+
} catch (error) {
|
| 228 |
+
res.status(500).json({ message: error.message });
|
| 229 |
+
}
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
export const getDailyReport = async (req, res) => {
|
| 233 |
+
try {
|
| 234 |
+
const startOfDay = new Date();
|
| 235 |
+
startOfDay.setHours(0, 0, 0, 0);
|
| 236 |
+
|
| 237 |
+
const endOfDay = new Date();
|
| 238 |
+
endOfDay.setHours(23, 59, 59, 999);
|
| 239 |
+
|
| 240 |
+
const invoices = await Invoice.find({ tenant: req.user.tenant._id }).populate("customer", "name");
|
| 241 |
+
|
| 242 |
+
let totalCashCollected = 0;
|
| 243 |
+
let totalSalesToday = 0;
|
| 244 |
+
let newInvoicesCount = 0;
|
| 245 |
+
const dailyPaymentsList = [];
|
| 246 |
+
|
| 247 |
+
invoices.forEach((invoice) => {
|
| 248 |
+
invoice.payments?.forEach((payment) => {
|
| 249 |
+
if (isWithinRange(payment.date, startOfDay, endOfDay)) {
|
| 250 |
+
totalCashCollected += toNumber(payment.amount);
|
| 251 |
+
dailyPaymentsList.push({
|
| 252 |
+
amount: toNumber(payment.amount),
|
| 253 |
+
date: payment.date,
|
| 254 |
+
customerName: invoice.customer?.name || "Deleted customer",
|
| 255 |
+
customerId: invoice.customer?._id || null,
|
| 256 |
+
invoiceNumber: invoice.invoiceNumber,
|
| 257 |
+
});
|
| 258 |
+
}
|
| 259 |
+
});
|
| 260 |
+
|
| 261 |
+
invoice.items?.forEach((item) => {
|
| 262 |
+
const itemDate = item.date ? new Date(item.date) : new Date(invoice.createdAt);
|
| 263 |
+
if (isWithinRange(itemDate, startOfDay, endOfDay)) {
|
| 264 |
+
totalSalesToday += toNumber(item.total);
|
| 265 |
+
}
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
if (isWithinRange(invoice.createdAt, startOfDay, endOfDay)) {
|
| 269 |
+
newInvoicesCount += 1;
|
| 270 |
+
}
|
| 271 |
+
});
|
| 272 |
+
|
| 273 |
+
dailyPaymentsList.sort((a, b) => new Date(b.date) - new Date(a.date));
|
| 274 |
+
|
| 275 |
+
const expenses = await Expense.find({
|
| 276 |
+
tenant: req.user.tenant._id,
|
| 277 |
+
date: { $gte: startOfDay, $lte: endOfDay },
|
| 278 |
+
}).sort({ date: -1 });
|
| 279 |
+
|
| 280 |
+
const totalExpenses = expenses.reduce((sum, expense) => sum + toNumber(expense.amount), 0);
|
| 281 |
+
|
| 282 |
+
res.status(200).json({
|
| 283 |
+
totalCashCollected,
|
| 284 |
+
totalSalesToday,
|
| 285 |
+
newInvoicesCount,
|
| 286 |
+
recentPayments: dailyPaymentsList,
|
| 287 |
+
expensesList: expenses,
|
| 288 |
+
totalExpenses,
|
| 289 |
+
netCashInDrawer: totalCashCollected - totalExpenses,
|
| 290 |
+
});
|
| 291 |
+
} catch (error) {
|
| 292 |
+
res.status(500).json({ message: error.message });
|
| 293 |
+
}
|
| 294 |
+
};
|
backend/controller/supplierController.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Supplier from "../models/SupplierModel.js";
|
| 2 |
+
import SupplierInvoice from "../models/SupplierInvoiceModel.js";
|
| 3 |
+
import Product from "../models/ProductModel.js";
|
| 4 |
+
|
| 5 |
+
export const createSupplier = async (req, res) => {
|
| 6 |
+
try {
|
| 7 |
+
const name = req.body.name?.trim();
|
| 8 |
+
const tenantId = req.user.tenant._id;
|
| 9 |
+
|
| 10 |
+
if (!name) {
|
| 11 |
+
return res.status(400).json({ message: "Supplier name is required" });
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const exists = await Supplier.findOne({
|
| 15 |
+
tenant: tenantId,
|
| 16 |
+
name: new RegExp(`^${name}$`, "i"),
|
| 17 |
+
});
|
| 18 |
+
if (exists) {
|
| 19 |
+
return res.status(400).json({ message: "Supplier already exists" });
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
const supplier = await Supplier.create({
|
| 23 |
+
tenant: tenantId,
|
| 24 |
+
name,
|
| 25 |
+
phone: req.body.phone?.trim() || "",
|
| 26 |
+
whatsappNumber: req.body.whatsappNumber?.trim() || "",
|
| 27 |
+
notes: req.body.notes?.trim() || "",
|
| 28 |
+
createdBy: req.user._id,
|
| 29 |
+
});
|
| 30 |
+
res.status(201).json(supplier);
|
| 31 |
+
} catch (err) {
|
| 32 |
+
res.status(500).json({ message: err.message });
|
| 33 |
+
}
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
export const getSuppliers = async (req, res) => {
|
| 37 |
+
try {
|
| 38 |
+
const tenantId = req.user.tenant._id;
|
| 39 |
+
const page = parseInt(req.query.page) || 1;
|
| 40 |
+
const limit = parseInt(req.query.limit) || 5;
|
| 41 |
+
const skip = (page - 1) * limit;
|
| 42 |
+
const search = req.query.search || "";
|
| 43 |
+
|
| 44 |
+
const matchQuery = {
|
| 45 |
+
tenant: tenantId,
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
if (search) {
|
| 49 |
+
matchQuery.name = { $regex: search, $options: "i" };
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
const results = await Supplier.aggregate([
|
| 53 |
+
{ $match: matchQuery },
|
| 54 |
+
{
|
| 55 |
+
$facet: {
|
| 56 |
+
data: [
|
| 57 |
+
{ $sort: { createdAt: -1 } },
|
| 58 |
+
{ $skip: skip },
|
| 59 |
+
{ $limit: limit },
|
| 60 |
+
{
|
| 61 |
+
$lookup: {
|
| 62 |
+
from: "supplierinvoices",
|
| 63 |
+
let: {
|
| 64 |
+
supplierId: "$_id",
|
| 65 |
+
tenantId: "$tenant",
|
| 66 |
+
},
|
| 67 |
+
pipeline: [
|
| 68 |
+
{
|
| 69 |
+
$match: {
|
| 70 |
+
$expr: {
|
| 71 |
+
$and: [
|
| 72 |
+
{ $eq: ["$supplier", "$$supplierId"] },
|
| 73 |
+
{ $eq: ["$tenant", "$$tenantId"] },
|
| 74 |
+
],
|
| 75 |
+
},
|
| 76 |
+
},
|
| 77 |
+
},
|
| 78 |
+
],
|
| 79 |
+
as: "invoices",
|
| 80 |
+
},
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
$addFields: {
|
| 84 |
+
totalDebt: { $sum: "$invoices.remainingAmount" },
|
| 85 |
+
},
|
| 86 |
+
},
|
| 87 |
+
],
|
| 88 |
+
totalCount: [
|
| 89 |
+
{ $count: "count" }
|
| 90 |
+
]
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
]);
|
| 94 |
+
|
| 95 |
+
const suppliers = results[0].data;
|
| 96 |
+
const total = results[0].totalCount[0]?.count || 0;
|
| 97 |
+
|
| 98 |
+
res.status(200).json({
|
| 99 |
+
data: suppliers,
|
| 100 |
+
pagination: {
|
| 101 |
+
total,
|
| 102 |
+
page,
|
| 103 |
+
limit,
|
| 104 |
+
totalPages: Math.ceil(total / limit),
|
| 105 |
+
},
|
| 106 |
+
});
|
| 107 |
+
} catch (error) {
|
| 108 |
+
res.status(500).json({ message: error.message });
|
| 109 |
+
}
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
export const getSupplierById = async (req, res) => {
|
| 113 |
+
try {
|
| 114 |
+
const supplier = await Supplier.findOne({
|
| 115 |
+
_id: req.params.id,
|
| 116 |
+
tenant: req.user.tenant._id,
|
| 117 |
+
});
|
| 118 |
+
if (!supplier) {
|
| 119 |
+
return res.status(404).json({ message: "Supplier not found" });
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
const invoice = await SupplierInvoice.findOne({
|
| 123 |
+
supplier: supplier._id,
|
| 124 |
+
tenant: req.user.tenant._id,
|
| 125 |
+
});
|
| 126 |
+
res.status(200).json({ ...supplier.toObject(), invoice });
|
| 127 |
+
} catch (error) {
|
| 128 |
+
res.status(500).json({ message: error.message });
|
| 129 |
+
}
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
export const deleteSupplier = async (req, res) => {
|
| 133 |
+
try {
|
| 134 |
+
const supplierId = req.params.id;
|
| 135 |
+
await Supplier.findOneAndDelete({
|
| 136 |
+
_id: supplierId,
|
| 137 |
+
tenant: req.user.tenant._id,
|
| 138 |
+
});
|
| 139 |
+
await SupplierInvoice.deleteMany({
|
| 140 |
+
supplier: supplierId,
|
| 141 |
+
tenant: req.user.tenant._id,
|
| 142 |
+
});
|
| 143 |
+
res.status(200).json({ message: "Supplier and linked purchase invoices deleted successfully" });
|
| 144 |
+
} catch (error) {
|
| 145 |
+
res.status(500).json({ message: error.message });
|
| 146 |
+
}
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
export const addPurchasesToSupplier = async (req, res) => {
|
| 150 |
+
try {
|
| 151 |
+
const { items } = req.body;
|
| 152 |
+
const supplierId = req.params.id;
|
| 153 |
+
const tenantId = req.user.tenant._id;
|
| 154 |
+
|
| 155 |
+
const supplier = await Supplier.findOne({
|
| 156 |
+
_id: supplierId,
|
| 157 |
+
tenant: tenantId,
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
if (!supplier) {
|
| 161 |
+
return res.status(404).json({ message: "Supplier not found" });
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
let invoice = await SupplierInvoice.findOne({
|
| 165 |
+
supplier: supplierId,
|
| 166 |
+
tenant: tenantId,
|
| 167 |
+
});
|
| 168 |
+
if (!invoice) {
|
| 169 |
+
invoice = new SupplierInvoice({
|
| 170 |
+
supplier: supplierId,
|
| 171 |
+
tenant: tenantId,
|
| 172 |
+
createdBy: req.user._id,
|
| 173 |
+
});
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
for (const item of items) {
|
| 177 |
+
const quantity = Number(item.quantity || 0);
|
| 178 |
+
const price = Number(item.price || 0);
|
| 179 |
+
const total = price * quantity;
|
| 180 |
+
|
| 181 |
+
invoice.items.push({
|
| 182 |
+
...item,
|
| 183 |
+
quantity,
|
| 184 |
+
price,
|
| 185 |
+
total,
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
if (item.productId) {
|
| 189 |
+
await Product.findOneAndUpdate(
|
| 190 |
+
{ _id: item.productId, tenant: tenantId },
|
| 191 |
+
{ $inc: { stock: quantity } }
|
| 192 |
+
);
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
await invoice.save();
|
| 197 |
+
res.status(200).json(invoice);
|
| 198 |
+
} catch (error) {
|
| 199 |
+
res.status(500).json({ message: error.message });
|
| 200 |
+
}
|
| 201 |
+
};
|
| 202 |
+
|
| 203 |
+
export const paySupplier = async (req, res) => {
|
| 204 |
+
try {
|
| 205 |
+
const amount = Number(req.body.amount);
|
| 206 |
+
const supplierId = req.params.id;
|
| 207 |
+
|
| 208 |
+
const invoice = await SupplierInvoice.findOne({
|
| 209 |
+
supplier: supplierId,
|
| 210 |
+
tenant: req.user.tenant._id,
|
| 211 |
+
});
|
| 212 |
+
if (!invoice) {
|
| 213 |
+
return res.status(404).json({ message: "No purchase invoice was found for this supplier" });
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
if (!amount || amount <= 0) {
|
| 217 |
+
return res.status(400).json({ message: "Payment amount must be greater than zero" });
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
if (amount > invoice.remainingAmount) {
|
| 221 |
+
return res.status(400).json({ message: "Payment amount is greater than the remaining balance" });
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
invoice.payments.push({
|
| 225 |
+
amount,
|
| 226 |
+
date: new Date(),
|
| 227 |
+
method: req.body.paymentMethod || "cash",
|
| 228 |
+
paidBy: req.user._id,
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
await invoice.save();
|
| 232 |
+
res.status(200).json(invoice);
|
| 233 |
+
} catch (error) {
|
| 234 |
+
res.status(500).json({ message: error.message });
|
| 235 |
+
}
|
| 236 |
+
};
|
backend/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import dotenv from 'dotenv';
|
| 3 |
+
import cors from 'cors';
|
| 4 |
+
import morgan from 'morgan';
|
| 5 |
+
import compression from 'compression';
|
| 6 |
+
import customersRoutes from "./routes/customerRoutes.js";
|
| 7 |
+
import invoicesRoutes from "./routes/invoiceRoutes.js";
|
| 8 |
+
import reportsRoutes from "./routes/reportRoutes.js";
|
| 9 |
+
import productRoutes from "./routes/productRoutes.js";
|
| 10 |
+
import expenseRoutes from "./routes/expenseRoutes.js";
|
| 11 |
+
import supplierRoutes from "./routes/supplierRoutes.js";
|
| 12 |
+
import authRoutes from "./routes/authRoutes.js";
|
| 13 |
+
import { dbConnection } from './config/database.js';
|
| 14 |
+
|
| 15 |
+
dotenv.config();
|
| 16 |
+
|
| 17 |
+
const app = express();
|
| 18 |
+
dbConnection();
|
| 19 |
+
|
| 20 |
+
const allowedOrigin = process.env.FRONTEND_URL || 'http://localhost:5173';
|
| 21 |
+
|
| 22 |
+
app.use(cors({
|
| 23 |
+
origin: allowedOrigin,
|
| 24 |
+
credentials: true,
|
| 25 |
+
}));
|
| 26 |
+
|
| 27 |
+
app.use(compression());
|
| 28 |
+
app.use(express.urlencoded({ extended: true, limit: '15kb' }));
|
| 29 |
+
app.use(express.json({ limit: '15kb' }));
|
| 30 |
+
app.use(morgan('dev'));
|
| 31 |
+
|
| 32 |
+
app.use('/customers', customersRoutes);
|
| 33 |
+
app.use('/invoices', invoicesRoutes);
|
| 34 |
+
app.use('/reports', reportsRoutes);
|
| 35 |
+
app.use('/products', productRoutes);
|
| 36 |
+
app.use('/expenses', expenseRoutes);
|
| 37 |
+
app.use('/suppliers', supplierRoutes);
|
| 38 |
+
app.use('/auth', authRoutes);
|
| 39 |
+
app.get('/', (req, res) => {
|
| 40 |
+
res.status(200).json({ message: 'App Is running' });
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
const PORT = process.env.PORT || 5000;
|
| 44 |
+
app.listen(PORT, () => {
|
| 45 |
+
console.log(`Server running on port ${PORT}`);
|
| 46 |
+
});
|
backend/middleware/authMiddleware.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import User from "../models/UserModel.js";
|
| 2 |
+
import { AUTH_COOKIE_NAME, parseCookies } from "../utils/authCookies.js";
|
| 3 |
+
|
| 4 |
+
export const protect = async (req, res, next) => {
|
| 5 |
+
try {
|
| 6 |
+
const cookies = parseCookies(req.headers.cookie);
|
| 7 |
+
let token = cookies[AUTH_COOKIE_NAME];
|
| 8 |
+
|
| 9 |
+
if (!token && req.headers.authorization?.startsWith("Bearer")) {
|
| 10 |
+
token = req.headers.authorization.split(" ")[1];
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (!token) {
|
| 14 |
+
return res.status(401).json({ message: "Unauthorized" });
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const user = await User.findOne({ sessionToken: token }).populate("tenant");
|
| 18 |
+
|
| 19 |
+
if (!user) {
|
| 20 |
+
return res.status(401).json({ message: "Session is invalid or expired" });
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
if (user.status !== "active") {
|
| 24 |
+
return res.status(403).json({ message: "User account is suspended" });
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
if (user.tenant && user.tenant.status !== "active") {
|
| 28 |
+
return res.status(403).json({ message: "Tenant account is suspended" });
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
req.user = user;
|
| 32 |
+
req.tenantId = user.tenant?._id?.toString() || null;
|
| 33 |
+
next();
|
| 34 |
+
} catch (error) {
|
| 35 |
+
res.status(401).json({ message: "Unable to verify session" });
|
| 36 |
+
}
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
export const authorize = (...roles) => (req, res, next) => {
|
| 40 |
+
if (!req.user) {
|
| 41 |
+
return res.status(401).json({ message: "Login required" });
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
if (!roles.includes(req.user.role)) {
|
| 45 |
+
return res.status(403).json({ message: "You do not have permission for this action" });
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
next();
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
export const requireTenantUser = (req, res, next) => {
|
| 52 |
+
if (!req.user?.tenant) {
|
| 53 |
+
return res.status(403).json({ message: "This action is only available to tenant users" });
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
next();
|
| 57 |
+
};
|
backend/models/CustomerModel.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const customerSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
tenant: {
|
| 6 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 7 |
+
ref: "Tenant",
|
| 8 |
+
required: true,
|
| 9 |
+
index: true,
|
| 10 |
+
},
|
| 11 |
+
name: {
|
| 12 |
+
type: String,
|
| 13 |
+
required: [true, "You must enter customer name"],
|
| 14 |
+
minlength: [3, "Customer Name must be at least 3"],
|
| 15 |
+
maxlength: [20, "Customer max 20"],
|
| 16 |
+
trim: true,
|
| 17 |
+
},
|
| 18 |
+
phone: {
|
| 19 |
+
type: String,
|
| 20 |
+
default: "",
|
| 21 |
+
},
|
| 22 |
+
email: {
|
| 23 |
+
type: String,
|
| 24 |
+
trim: true,
|
| 25 |
+
lowercase: true,
|
| 26 |
+
default: "",
|
| 27 |
+
},
|
| 28 |
+
address: {
|
| 29 |
+
type: String,
|
| 30 |
+
default: "",
|
| 31 |
+
},
|
| 32 |
+
notes: {
|
| 33 |
+
type: String,
|
| 34 |
+
default: "",
|
| 35 |
+
},
|
| 36 |
+
createdBy: {
|
| 37 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 38 |
+
ref: "User",
|
| 39 |
+
default: null,
|
| 40 |
+
},
|
| 41 |
+
invoices: [
|
| 42 |
+
{
|
| 43 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 44 |
+
ref: "Invoice",
|
| 45 |
+
},
|
| 46 |
+
],
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
timestamps: true,
|
| 50 |
+
}
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
customerSchema.index({ tenant: 1, name: 1 });
|
| 54 |
+
|
| 55 |
+
export default mongoose.model("Customer", customerSchema);
|
backend/models/ExpenseModel.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const expenseSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
tenant: {
|
| 6 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 7 |
+
ref: "Tenant",
|
| 8 |
+
required: true,
|
| 9 |
+
index: true,
|
| 10 |
+
},
|
| 11 |
+
title: {
|
| 12 |
+
type: String,
|
| 13 |
+
required: true,
|
| 14 |
+
},
|
| 15 |
+
category: {
|
| 16 |
+
type: String,
|
| 17 |
+
default: "general",
|
| 18 |
+
},
|
| 19 |
+
amount: {
|
| 20 |
+
type: Number,
|
| 21 |
+
required: true,
|
| 22 |
+
},
|
| 23 |
+
paymentMethod: {
|
| 24 |
+
type: String,
|
| 25 |
+
default: "cash",
|
| 26 |
+
},
|
| 27 |
+
notes: {
|
| 28 |
+
type: String,
|
| 29 |
+
default: "",
|
| 30 |
+
},
|
| 31 |
+
date: {
|
| 32 |
+
type: Date,
|
| 33 |
+
default: Date.now,
|
| 34 |
+
},
|
| 35 |
+
createdBy: {
|
| 36 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 37 |
+
ref: "User",
|
| 38 |
+
default: null,
|
| 39 |
+
},
|
| 40 |
+
},
|
| 41 |
+
{ timestamps: true }
|
| 42 |
+
);
|
| 43 |
+
|
| 44 |
+
expenseSchema.index({ tenant: 1, date: -1 });
|
| 45 |
+
|
| 46 |
+
export default mongoose.model("Expense", expenseSchema);
|
backend/models/InvoiceModel.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const invoiceSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
tenant: {
|
| 6 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 7 |
+
ref: "Tenant",
|
| 8 |
+
required: true,
|
| 9 |
+
index: true,
|
| 10 |
+
},
|
| 11 |
+
invoiceNumber: {
|
| 12 |
+
type: String,
|
| 13 |
+
required: true,
|
| 14 |
+
trim: true,
|
| 15 |
+
},
|
| 16 |
+
customer: {
|
| 17 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 18 |
+
ref: "Customer",
|
| 19 |
+
required: true,
|
| 20 |
+
},
|
| 21 |
+
issuedBy: {
|
| 22 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 23 |
+
ref: "User",
|
| 24 |
+
default: null,
|
| 25 |
+
},
|
| 26 |
+
items: [
|
| 27 |
+
{
|
| 28 |
+
name: String,
|
| 29 |
+
price: Number,
|
| 30 |
+
quantity: Number,
|
| 31 |
+
total: Number,
|
| 32 |
+
date: { type: Date, default: Date.now },
|
| 33 |
+
productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product" },
|
| 34 |
+
},
|
| 35 |
+
],
|
| 36 |
+
subtotal: {
|
| 37 |
+
type: Number,
|
| 38 |
+
default: 0,
|
| 39 |
+
},
|
| 40 |
+
discount: {
|
| 41 |
+
type: Number,
|
| 42 |
+
default: 0,
|
| 43 |
+
},
|
| 44 |
+
taxAmount: {
|
| 45 |
+
type: Number,
|
| 46 |
+
default: 0,
|
| 47 |
+
},
|
| 48 |
+
totalAmount: {
|
| 49 |
+
type: Number,
|
| 50 |
+
default: 0,
|
| 51 |
+
},
|
| 52 |
+
payments: [
|
| 53 |
+
{
|
| 54 |
+
amount: Number,
|
| 55 |
+
date: { type: Date, default: Date.now },
|
| 56 |
+
method: {
|
| 57 |
+
type: String,
|
| 58 |
+
default: "cash",
|
| 59 |
+
},
|
| 60 |
+
receivedBy: {
|
| 61 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 62 |
+
ref: "User",
|
| 63 |
+
default: null,
|
| 64 |
+
},
|
| 65 |
+
},
|
| 66 |
+
],
|
| 67 |
+
paidAmount: {
|
| 68 |
+
type: Number,
|
| 69 |
+
default: 0,
|
| 70 |
+
},
|
| 71 |
+
remainingAmount: {
|
| 72 |
+
type: Number,
|
| 73 |
+
default: 0,
|
| 74 |
+
},
|
| 75 |
+
status: {
|
| 76 |
+
type: String,
|
| 77 |
+
enum: ["draft", "open", "partial", "paid", "cancelled"],
|
| 78 |
+
default: "open",
|
| 79 |
+
},
|
| 80 |
+
notes: {
|
| 81 |
+
type: String,
|
| 82 |
+
default: "",
|
| 83 |
+
},
|
| 84 |
+
},
|
| 85 |
+
{ timestamps: true }
|
| 86 |
+
);
|
| 87 |
+
|
| 88 |
+
invoiceSchema.index({ tenant: 1, invoiceNumber: 1 }, { unique: true });
|
| 89 |
+
|
| 90 |
+
invoiceSchema.methods.calculateTotals = function () {
|
| 91 |
+
this.items.forEach((item) => {
|
| 92 |
+
item.total = Number(item.price || 0) * Number(item.quantity || 0);
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
this.subtotal = this.items.reduce((sum, item) => sum + Number(item.total || 0), 0);
|
| 96 |
+
this.totalAmount = Math.max(this.subtotal - Number(this.discount || 0) + Number(this.taxAmount || 0), 0);
|
| 97 |
+
|
| 98 |
+
if (this.payments?.length || this.isModified("payments")) {
|
| 99 |
+
this.paidAmount = this.payments.reduce(
|
| 100 |
+
(sum, payment) => sum + Number(payment.amount || 0),
|
| 101 |
+
0
|
| 102 |
+
);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
this.remainingAmount = Math.max(this.totalAmount - Number(this.paidAmount || 0), 0);
|
| 106 |
+
|
| 107 |
+
if (this.status === "cancelled") {
|
| 108 |
+
return;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
if (this.remainingAmount <= 0) {
|
| 112 |
+
this.status = "paid";
|
| 113 |
+
} else if (this.paidAmount > 0) {
|
| 114 |
+
this.status = "partial";
|
| 115 |
+
} else {
|
| 116 |
+
this.status = "open";
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
invoiceSchema.pre("save", function () {
|
| 121 |
+
this.calculateTotals();
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
export default mongoose.model("Invoice", invoiceSchema);
|
backend/models/ProductModel.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const productSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
tenant: {
|
| 6 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 7 |
+
ref: "Tenant",
|
| 8 |
+
required: true,
|
| 9 |
+
index: true,
|
| 10 |
+
},
|
| 11 |
+
name: {
|
| 12 |
+
type: String,
|
| 13 |
+
required: true,
|
| 14 |
+
},
|
| 15 |
+
description: {
|
| 16 |
+
type: String,
|
| 17 |
+
default: "",
|
| 18 |
+
},
|
| 19 |
+
price: {
|
| 20 |
+
type: Number,
|
| 21 |
+
required: true,
|
| 22 |
+
},
|
| 23 |
+
costPrice: {
|
| 24 |
+
type: Number,
|
| 25 |
+
default: 0,
|
| 26 |
+
},
|
| 27 |
+
stock: {
|
| 28 |
+
type: Number,
|
| 29 |
+
required: true,
|
| 30 |
+
default: 0,
|
| 31 |
+
},
|
| 32 |
+
barcode: {
|
| 33 |
+
type: String,
|
| 34 |
+
default: "",
|
| 35 |
+
},
|
| 36 |
+
sku: {
|
| 37 |
+
type: String,
|
| 38 |
+
default: "",
|
| 39 |
+
},
|
| 40 |
+
unit: {
|
| 41 |
+
type: String,
|
| 42 |
+
default: "piece",
|
| 43 |
+
},
|
| 44 |
+
lowStockThreshold: {
|
| 45 |
+
type: Number,
|
| 46 |
+
default: 5,
|
| 47 |
+
},
|
| 48 |
+
createdBy: {
|
| 49 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 50 |
+
ref: "User",
|
| 51 |
+
default: null,
|
| 52 |
+
},
|
| 53 |
+
},
|
| 54 |
+
{ timestamps: true }
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
productSchema.index({ tenant: 1, name: 1 });
|
| 58 |
+
productSchema.index(
|
| 59 |
+
{ tenant: 1, barcode: 1 },
|
| 60 |
+
{ unique: true, partialFilterExpression: { barcode: { $type: "string", $ne: "" } } }
|
| 61 |
+
);
|
| 62 |
+
|
| 63 |
+
export default mongoose.model("Product", productSchema);
|
backend/models/SupplierInvoiceModel.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const supplierInvoiceSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
tenant: {
|
| 6 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 7 |
+
ref: "Tenant",
|
| 8 |
+
required: true,
|
| 9 |
+
index: true,
|
| 10 |
+
},
|
| 11 |
+
supplier: {
|
| 12 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 13 |
+
ref: "Supplier",
|
| 14 |
+
required: true,
|
| 15 |
+
},
|
| 16 |
+
createdBy: {
|
| 17 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 18 |
+
ref: "User",
|
| 19 |
+
default: null,
|
| 20 |
+
},
|
| 21 |
+
totalAmount: { type: Number, default: 0 },
|
| 22 |
+
paidAmount: { type: Number, default: 0 },
|
| 23 |
+
remainingAmount: { type: Number, default: 0 },
|
| 24 |
+
items: [
|
| 25 |
+
{
|
| 26 |
+
name: String,
|
| 27 |
+
price: Number,
|
| 28 |
+
quantity: Number,
|
| 29 |
+
total: Number,
|
| 30 |
+
date: { type: Date, default: Date.now },
|
| 31 |
+
productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product" },
|
| 32 |
+
},
|
| 33 |
+
],
|
| 34 |
+
payments: [
|
| 35 |
+
{
|
| 36 |
+
amount: Number,
|
| 37 |
+
date: { type: Date, default: Date.now },
|
| 38 |
+
method: {
|
| 39 |
+
type: String,
|
| 40 |
+
default: "cash",
|
| 41 |
+
},
|
| 42 |
+
paidBy: {
|
| 43 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 44 |
+
ref: "User",
|
| 45 |
+
default: null,
|
| 46 |
+
},
|
| 47 |
+
},
|
| 48 |
+
],
|
| 49 |
+
},
|
| 50 |
+
{ timestamps: true }
|
| 51 |
+
);
|
| 52 |
+
|
| 53 |
+
supplierInvoiceSchema.index({ tenant: 1, supplier: 1 });
|
| 54 |
+
|
| 55 |
+
supplierInvoiceSchema.pre("save", function () {
|
| 56 |
+
this.totalAmount = this.items.reduce((sum, item) => sum + Number(item.total || 0), 0);
|
| 57 |
+
this.paidAmount = this.payments.reduce((sum, payment) => sum + Number(payment.amount || 0), 0);
|
| 58 |
+
this.remainingAmount = Math.max(this.totalAmount - this.paidAmount, 0);
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
export default mongoose.model("SupplierInvoice", supplierInvoiceSchema);
|
backend/models/SupplierModel.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const supplierSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
tenant: {
|
| 6 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 7 |
+
ref: "Tenant",
|
| 8 |
+
required: true,
|
| 9 |
+
index: true,
|
| 10 |
+
},
|
| 11 |
+
name: {
|
| 12 |
+
type: String,
|
| 13 |
+
required: true,
|
| 14 |
+
},
|
| 15 |
+
phone: {
|
| 16 |
+
type: String,
|
| 17 |
+
default: "",
|
| 18 |
+
},
|
| 19 |
+
whatsappNumber: {
|
| 20 |
+
type: String,
|
| 21 |
+
default: "",
|
| 22 |
+
},
|
| 23 |
+
notes: {
|
| 24 |
+
type: String,
|
| 25 |
+
default: "",
|
| 26 |
+
},
|
| 27 |
+
createdBy: {
|
| 28 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 29 |
+
ref: "User",
|
| 30 |
+
default: null,
|
| 31 |
+
},
|
| 32 |
+
},
|
| 33 |
+
{ timestamps: true }
|
| 34 |
+
);
|
| 35 |
+
|
| 36 |
+
supplierSchema.index({ tenant: 1, name: 1 });
|
| 37 |
+
|
| 38 |
+
export default mongoose.model("Supplier", supplierSchema);
|
backend/models/TenantModel.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
|
| 3 |
+
const tenantSchema = new mongoose.Schema(
|
| 4 |
+
{
|
| 5 |
+
name: {
|
| 6 |
+
type: String,
|
| 7 |
+
required: true,
|
| 8 |
+
trim: true,
|
| 9 |
+
},
|
| 10 |
+
slug: {
|
| 11 |
+
type: String,
|
| 12 |
+
required: true,
|
| 13 |
+
trim: true,
|
| 14 |
+
lowercase: true,
|
| 15 |
+
unique: true,
|
| 16 |
+
},
|
| 17 |
+
ownerName: {
|
| 18 |
+
type: String,
|
| 19 |
+
required: true,
|
| 20 |
+
trim: true,
|
| 21 |
+
},
|
| 22 |
+
ownerEmail: {
|
| 23 |
+
type: String,
|
| 24 |
+
trim: true,
|
| 25 |
+
lowercase: true,
|
| 26 |
+
default: "",
|
| 27 |
+
},
|
| 28 |
+
ownerPhone: {
|
| 29 |
+
type: String,
|
| 30 |
+
trim: true,
|
| 31 |
+
default: "",
|
| 32 |
+
},
|
| 33 |
+
whatsappNumber: {
|
| 34 |
+
type: String,
|
| 35 |
+
trim: true,
|
| 36 |
+
default: "",
|
| 37 |
+
},
|
| 38 |
+
address: {
|
| 39 |
+
type: String,
|
| 40 |
+
trim: true,
|
| 41 |
+
default: "",
|
| 42 |
+
},
|
| 43 |
+
status: {
|
| 44 |
+
type: String,
|
| 45 |
+
enum: ["active", "suspended"],
|
| 46 |
+
default: "active",
|
| 47 |
+
},
|
| 48 |
+
settings: {
|
| 49 |
+
currency: {
|
| 50 |
+
type: String,
|
| 51 |
+
default: "EGP",
|
| 52 |
+
},
|
| 53 |
+
lowStockThreshold: {
|
| 54 |
+
type: Number,
|
| 55 |
+
default: 5,
|
| 56 |
+
},
|
| 57 |
+
},
|
| 58 |
+
},
|
| 59 |
+
{ timestamps: true }
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
tenantSchema.index({ name: 1 });
|
| 63 |
+
|
| 64 |
+
export default mongoose.model("Tenant", tenantSchema);
|
backend/models/UserModel.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
import crypto from "crypto";
|
| 3 |
+
|
| 4 |
+
const userSchema = new mongoose.Schema(
|
| 5 |
+
{
|
| 6 |
+
username: {
|
| 7 |
+
type: String,
|
| 8 |
+
required: true,
|
| 9 |
+
unique: true,
|
| 10 |
+
trim: true,
|
| 11 |
+
},
|
| 12 |
+
fullName: {
|
| 13 |
+
type: String,
|
| 14 |
+
trim: true,
|
| 15 |
+
default: "",
|
| 16 |
+
},
|
| 17 |
+
email: {
|
| 18 |
+
type: String,
|
| 19 |
+
trim: true,
|
| 20 |
+
lowercase: true,
|
| 21 |
+
unique: true,
|
| 22 |
+
sparse: true,
|
| 23 |
+
},
|
| 24 |
+
phone: {
|
| 25 |
+
type: String,
|
| 26 |
+
trim: true,
|
| 27 |
+
default: "",
|
| 28 |
+
},
|
| 29 |
+
password: {
|
| 30 |
+
type: String,
|
| 31 |
+
required: true,
|
| 32 |
+
},
|
| 33 |
+
role: {
|
| 34 |
+
type: String,
|
| 35 |
+
enum: ["super_admin", "owner", "admin", "cashier"],
|
| 36 |
+
default: "cashier",
|
| 37 |
+
},
|
| 38 |
+
status: {
|
| 39 |
+
type: String,
|
| 40 |
+
enum: ["active", "suspended"],
|
| 41 |
+
default: "active",
|
| 42 |
+
},
|
| 43 |
+
tenant: {
|
| 44 |
+
type: mongoose.Schema.Types.ObjectId,
|
| 45 |
+
ref: "Tenant",
|
| 46 |
+
default: null,
|
| 47 |
+
},
|
| 48 |
+
sessionToken: {
|
| 49 |
+
type: String,
|
| 50 |
+
default: null,
|
| 51 |
+
},
|
| 52 |
+
lastLoginAt: {
|
| 53 |
+
type: Date,
|
| 54 |
+
default: null,
|
| 55 |
+
},
|
| 56 |
+
},
|
| 57 |
+
{ timestamps: true }
|
| 58 |
+
);
|
| 59 |
+
|
| 60 |
+
userSchema.index({ tenant: 1, role: 1 });
|
| 61 |
+
|
| 62 |
+
userSchema.pre("save", async function () {
|
| 63 |
+
if (!this.isModified("password")) return;
|
| 64 |
+
|
| 65 |
+
const salt = crypto.randomBytes(16).toString("hex");
|
| 66 |
+
const hash = crypto.pbkdf2Sync(this.password, salt, 1000, 64, "sha512").toString("hex");
|
| 67 |
+
this.password = `${salt}:${hash}`;
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
userSchema.methods.matchPassword = function (enteredPassword) {
|
| 71 |
+
try {
|
| 72 |
+
const [salt, originalHash] = this.password.split(":");
|
| 73 |
+
const attemptHash = crypto.pbkdf2Sync(enteredPassword, salt, 1000, 64, "sha512").toString("hex");
|
| 74 |
+
return originalHash === attemptHash;
|
| 75 |
+
} catch (err) {
|
| 76 |
+
return false;
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
export default mongoose.model("User", userSchema);
|
backend/package-lock.json
ADDED
|
@@ -0,0 +1,1535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "backend",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"lockfileVersion": 3,
|
| 5 |
+
"requires": true,
|
| 6 |
+
"packages": {
|
| 7 |
+
"": {
|
| 8 |
+
"name": "backend",
|
| 9 |
+
"version": "1.0.0",
|
| 10 |
+
"license": "ISC",
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"compression": "^1.8.1",
|
| 13 |
+
"cors": "^2.8.5",
|
| 14 |
+
"dotenv": "^17.2.3",
|
| 15 |
+
"express": "^5.2.1",
|
| 16 |
+
"mongoose": "^9.0.2",
|
| 17 |
+
"morgan": "^1.10.1",
|
| 18 |
+
"nodemon": "^3.1.11"
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
+
"node_modules/@mongodb-js/saslprep": {
|
| 22 |
+
"version": "1.4.4",
|
| 23 |
+
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.4.tgz",
|
| 24 |
+
"integrity": "sha512-p7X/ytJDIdwUfFL/CLOhKgdfJe1Fa8uw9seJYvdOmnP9JBWGWHW69HkOixXS6Wy9yvGf1MbhcS6lVmrhy4jm2g==",
|
| 25 |
+
"license": "MIT",
|
| 26 |
+
"dependencies": {
|
| 27 |
+
"sparse-bitfield": "^3.0.3"
|
| 28 |
+
}
|
| 29 |
+
},
|
| 30 |
+
"node_modules/@types/webidl-conversions": {
|
| 31 |
+
"version": "7.0.3",
|
| 32 |
+
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
| 33 |
+
"integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==",
|
| 34 |
+
"license": "MIT"
|
| 35 |
+
},
|
| 36 |
+
"node_modules/@types/whatwg-url": {
|
| 37 |
+
"version": "13.0.0",
|
| 38 |
+
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz",
|
| 39 |
+
"integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==",
|
| 40 |
+
"license": "MIT",
|
| 41 |
+
"dependencies": {
|
| 42 |
+
"@types/webidl-conversions": "*"
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"node_modules/accepts": {
|
| 46 |
+
"version": "2.0.0",
|
| 47 |
+
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
|
| 48 |
+
"integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==",
|
| 49 |
+
"license": "MIT",
|
| 50 |
+
"dependencies": {
|
| 51 |
+
"mime-types": "^3.0.0",
|
| 52 |
+
"negotiator": "^1.0.0"
|
| 53 |
+
},
|
| 54 |
+
"engines": {
|
| 55 |
+
"node": ">= 0.6"
|
| 56 |
+
}
|
| 57 |
+
},
|
| 58 |
+
"node_modules/anymatch": {
|
| 59 |
+
"version": "3.1.3",
|
| 60 |
+
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
| 61 |
+
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
|
| 62 |
+
"license": "ISC",
|
| 63 |
+
"dependencies": {
|
| 64 |
+
"normalize-path": "^3.0.0",
|
| 65 |
+
"picomatch": "^2.0.4"
|
| 66 |
+
},
|
| 67 |
+
"engines": {
|
| 68 |
+
"node": ">= 8"
|
| 69 |
+
}
|
| 70 |
+
},
|
| 71 |
+
"node_modules/balanced-match": {
|
| 72 |
+
"version": "1.0.2",
|
| 73 |
+
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
| 74 |
+
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
| 75 |
+
"license": "MIT"
|
| 76 |
+
},
|
| 77 |
+
"node_modules/basic-auth": {
|
| 78 |
+
"version": "2.0.1",
|
| 79 |
+
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
|
| 80 |
+
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
|
| 81 |
+
"license": "MIT",
|
| 82 |
+
"dependencies": {
|
| 83 |
+
"safe-buffer": "5.1.2"
|
| 84 |
+
},
|
| 85 |
+
"engines": {
|
| 86 |
+
"node": ">= 0.8"
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
+
"node_modules/basic-auth/node_modules/safe-buffer": {
|
| 90 |
+
"version": "5.1.2",
|
| 91 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
| 92 |
+
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
| 93 |
+
"license": "MIT"
|
| 94 |
+
},
|
| 95 |
+
"node_modules/binary-extensions": {
|
| 96 |
+
"version": "2.3.0",
|
| 97 |
+
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
|
| 98 |
+
"integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==",
|
| 99 |
+
"license": "MIT",
|
| 100 |
+
"engines": {
|
| 101 |
+
"node": ">=8"
|
| 102 |
+
},
|
| 103 |
+
"funding": {
|
| 104 |
+
"url": "https://github.com/sponsors/sindresorhus"
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
"node_modules/body-parser": {
|
| 108 |
+
"version": "2.2.1",
|
| 109 |
+
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.1.tgz",
|
| 110 |
+
"integrity": "sha512-nfDwkulwiZYQIGwxdy0RUmowMhKcFVcYXUU7m4QlKYim1rUtg83xm2yjZ40QjDuc291AJjjeSc9b++AWHSgSHw==",
|
| 111 |
+
"license": "MIT",
|
| 112 |
+
"dependencies": {
|
| 113 |
+
"bytes": "^3.1.2",
|
| 114 |
+
"content-type": "^1.0.5",
|
| 115 |
+
"debug": "^4.4.3",
|
| 116 |
+
"http-errors": "^2.0.0",
|
| 117 |
+
"iconv-lite": "^0.7.0",
|
| 118 |
+
"on-finished": "^2.4.1",
|
| 119 |
+
"qs": "^6.14.0",
|
| 120 |
+
"raw-body": "^3.0.1",
|
| 121 |
+
"type-is": "^2.0.1"
|
| 122 |
+
},
|
| 123 |
+
"engines": {
|
| 124 |
+
"node": ">=18"
|
| 125 |
+
},
|
| 126 |
+
"funding": {
|
| 127 |
+
"type": "opencollective",
|
| 128 |
+
"url": "https://opencollective.com/express"
|
| 129 |
+
}
|
| 130 |
+
},
|
| 131 |
+
"node_modules/brace-expansion": {
|
| 132 |
+
"version": "1.1.12",
|
| 133 |
+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
|
| 134 |
+
"integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
|
| 135 |
+
"license": "MIT",
|
| 136 |
+
"dependencies": {
|
| 137 |
+
"balanced-match": "^1.0.0",
|
| 138 |
+
"concat-map": "0.0.1"
|
| 139 |
+
}
|
| 140 |
+
},
|
| 141 |
+
"node_modules/braces": {
|
| 142 |
+
"version": "3.0.3",
|
| 143 |
+
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
| 144 |
+
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
| 145 |
+
"license": "MIT",
|
| 146 |
+
"dependencies": {
|
| 147 |
+
"fill-range": "^7.1.1"
|
| 148 |
+
},
|
| 149 |
+
"engines": {
|
| 150 |
+
"node": ">=8"
|
| 151 |
+
}
|
| 152 |
+
},
|
| 153 |
+
"node_modules/bson": {
|
| 154 |
+
"version": "7.0.0",
|
| 155 |
+
"resolved": "https://registry.npmjs.org/bson/-/bson-7.0.0.tgz",
|
| 156 |
+
"integrity": "sha512-Kwc6Wh4lQ5OmkqqKhYGKIuELXl+EPYSCObVE6bWsp1T/cGkOCBN0I8wF/T44BiuhHyNi1mmKVPXk60d41xZ7kw==",
|
| 157 |
+
"license": "Apache-2.0",
|
| 158 |
+
"engines": {
|
| 159 |
+
"node": ">=20.19.0"
|
| 160 |
+
}
|
| 161 |
+
},
|
| 162 |
+
"node_modules/bytes": {
|
| 163 |
+
"version": "3.1.2",
|
| 164 |
+
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
| 165 |
+
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
| 166 |
+
"license": "MIT",
|
| 167 |
+
"engines": {
|
| 168 |
+
"node": ">= 0.8"
|
| 169 |
+
}
|
| 170 |
+
},
|
| 171 |
+
"node_modules/call-bind-apply-helpers": {
|
| 172 |
+
"version": "1.0.2",
|
| 173 |
+
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
| 174 |
+
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
| 175 |
+
"license": "MIT",
|
| 176 |
+
"dependencies": {
|
| 177 |
+
"es-errors": "^1.3.0",
|
| 178 |
+
"function-bind": "^1.1.2"
|
| 179 |
+
},
|
| 180 |
+
"engines": {
|
| 181 |
+
"node": ">= 0.4"
|
| 182 |
+
}
|
| 183 |
+
},
|
| 184 |
+
"node_modules/call-bound": {
|
| 185 |
+
"version": "1.0.4",
|
| 186 |
+
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
|
| 187 |
+
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
| 188 |
+
"license": "MIT",
|
| 189 |
+
"dependencies": {
|
| 190 |
+
"call-bind-apply-helpers": "^1.0.2",
|
| 191 |
+
"get-intrinsic": "^1.3.0"
|
| 192 |
+
},
|
| 193 |
+
"engines": {
|
| 194 |
+
"node": ">= 0.4"
|
| 195 |
+
},
|
| 196 |
+
"funding": {
|
| 197 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 198 |
+
}
|
| 199 |
+
},
|
| 200 |
+
"node_modules/chokidar": {
|
| 201 |
+
"version": "3.6.0",
|
| 202 |
+
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
| 203 |
+
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
| 204 |
+
"license": "MIT",
|
| 205 |
+
"dependencies": {
|
| 206 |
+
"anymatch": "~3.1.2",
|
| 207 |
+
"braces": "~3.0.2",
|
| 208 |
+
"glob-parent": "~5.1.2",
|
| 209 |
+
"is-binary-path": "~2.1.0",
|
| 210 |
+
"is-glob": "~4.0.1",
|
| 211 |
+
"normalize-path": "~3.0.0",
|
| 212 |
+
"readdirp": "~3.6.0"
|
| 213 |
+
},
|
| 214 |
+
"engines": {
|
| 215 |
+
"node": ">= 8.10.0"
|
| 216 |
+
},
|
| 217 |
+
"funding": {
|
| 218 |
+
"url": "https://paulmillr.com/funding/"
|
| 219 |
+
},
|
| 220 |
+
"optionalDependencies": {
|
| 221 |
+
"fsevents": "~2.3.2"
|
| 222 |
+
}
|
| 223 |
+
},
|
| 224 |
+
"node_modules/compressible": {
|
| 225 |
+
"version": "2.0.18",
|
| 226 |
+
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
| 227 |
+
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
| 228 |
+
"license": "MIT",
|
| 229 |
+
"dependencies": {
|
| 230 |
+
"mime-db": ">= 1.43.0 < 2"
|
| 231 |
+
},
|
| 232 |
+
"engines": {
|
| 233 |
+
"node": ">= 0.6"
|
| 234 |
+
}
|
| 235 |
+
},
|
| 236 |
+
"node_modules/compression": {
|
| 237 |
+
"version": "1.8.1",
|
| 238 |
+
"resolved": "https://registry.npmjs.org/compression/-/compression-1.8.1.tgz",
|
| 239 |
+
"integrity": "sha512-9mAqGPHLakhCLeNyxPkK4xVo746zQ/czLH1Ky+vkitMnWfWZps8r0qXuwhwizagCRttsL4lfG4pIOvaWLpAP0w==",
|
| 240 |
+
"license": "MIT",
|
| 241 |
+
"dependencies": {
|
| 242 |
+
"bytes": "3.1.2",
|
| 243 |
+
"compressible": "~2.0.18",
|
| 244 |
+
"debug": "2.6.9",
|
| 245 |
+
"negotiator": "~0.6.4",
|
| 246 |
+
"on-headers": "~1.1.0",
|
| 247 |
+
"safe-buffer": "5.2.1",
|
| 248 |
+
"vary": "~1.1.2"
|
| 249 |
+
},
|
| 250 |
+
"engines": {
|
| 251 |
+
"node": ">= 0.8.0"
|
| 252 |
+
}
|
| 253 |
+
},
|
| 254 |
+
"node_modules/compression/node_modules/debug": {
|
| 255 |
+
"version": "2.6.9",
|
| 256 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
| 257 |
+
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
| 258 |
+
"license": "MIT",
|
| 259 |
+
"dependencies": {
|
| 260 |
+
"ms": "2.0.0"
|
| 261 |
+
}
|
| 262 |
+
},
|
| 263 |
+
"node_modules/compression/node_modules/ms": {
|
| 264 |
+
"version": "2.0.0",
|
| 265 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
| 266 |
+
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
| 267 |
+
"license": "MIT"
|
| 268 |
+
},
|
| 269 |
+
"node_modules/compression/node_modules/negotiator": {
|
| 270 |
+
"version": "0.6.4",
|
| 271 |
+
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.4.tgz",
|
| 272 |
+
"integrity": "sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w==",
|
| 273 |
+
"license": "MIT",
|
| 274 |
+
"engines": {
|
| 275 |
+
"node": ">= 0.6"
|
| 276 |
+
}
|
| 277 |
+
},
|
| 278 |
+
"node_modules/concat-map": {
|
| 279 |
+
"version": "0.0.1",
|
| 280 |
+
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
| 281 |
+
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
| 282 |
+
"license": "MIT"
|
| 283 |
+
},
|
| 284 |
+
"node_modules/content-disposition": {
|
| 285 |
+
"version": "1.0.1",
|
| 286 |
+
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz",
|
| 287 |
+
"integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==",
|
| 288 |
+
"license": "MIT",
|
| 289 |
+
"engines": {
|
| 290 |
+
"node": ">=18"
|
| 291 |
+
},
|
| 292 |
+
"funding": {
|
| 293 |
+
"type": "opencollective",
|
| 294 |
+
"url": "https://opencollective.com/express"
|
| 295 |
+
}
|
| 296 |
+
},
|
| 297 |
+
"node_modules/content-type": {
|
| 298 |
+
"version": "1.0.5",
|
| 299 |
+
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
| 300 |
+
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
| 301 |
+
"license": "MIT",
|
| 302 |
+
"engines": {
|
| 303 |
+
"node": ">= 0.6"
|
| 304 |
+
}
|
| 305 |
+
},
|
| 306 |
+
"node_modules/cookie": {
|
| 307 |
+
"version": "0.7.2",
|
| 308 |
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
| 309 |
+
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
| 310 |
+
"license": "MIT",
|
| 311 |
+
"engines": {
|
| 312 |
+
"node": ">= 0.6"
|
| 313 |
+
}
|
| 314 |
+
},
|
| 315 |
+
"node_modules/cookie-signature": {
|
| 316 |
+
"version": "1.2.2",
|
| 317 |
+
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
|
| 318 |
+
"integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==",
|
| 319 |
+
"license": "MIT",
|
| 320 |
+
"engines": {
|
| 321 |
+
"node": ">=6.6.0"
|
| 322 |
+
}
|
| 323 |
+
},
|
| 324 |
+
"node_modules/cors": {
|
| 325 |
+
"version": "2.8.5",
|
| 326 |
+
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
| 327 |
+
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
| 328 |
+
"license": "MIT",
|
| 329 |
+
"dependencies": {
|
| 330 |
+
"object-assign": "^4",
|
| 331 |
+
"vary": "^1"
|
| 332 |
+
},
|
| 333 |
+
"engines": {
|
| 334 |
+
"node": ">= 0.10"
|
| 335 |
+
}
|
| 336 |
+
},
|
| 337 |
+
"node_modules/debug": {
|
| 338 |
+
"version": "4.4.3",
|
| 339 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
| 340 |
+
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
| 341 |
+
"license": "MIT",
|
| 342 |
+
"dependencies": {
|
| 343 |
+
"ms": "^2.1.3"
|
| 344 |
+
},
|
| 345 |
+
"engines": {
|
| 346 |
+
"node": ">=6.0"
|
| 347 |
+
},
|
| 348 |
+
"peerDependenciesMeta": {
|
| 349 |
+
"supports-color": {
|
| 350 |
+
"optional": true
|
| 351 |
+
}
|
| 352 |
+
}
|
| 353 |
+
},
|
| 354 |
+
"node_modules/depd": {
|
| 355 |
+
"version": "2.0.0",
|
| 356 |
+
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
| 357 |
+
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
| 358 |
+
"license": "MIT",
|
| 359 |
+
"engines": {
|
| 360 |
+
"node": ">= 0.8"
|
| 361 |
+
}
|
| 362 |
+
},
|
| 363 |
+
"node_modules/dotenv": {
|
| 364 |
+
"version": "17.2.3",
|
| 365 |
+
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz",
|
| 366 |
+
"integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==",
|
| 367 |
+
"license": "BSD-2-Clause",
|
| 368 |
+
"engines": {
|
| 369 |
+
"node": ">=12"
|
| 370 |
+
},
|
| 371 |
+
"funding": {
|
| 372 |
+
"url": "https://dotenvx.com"
|
| 373 |
+
}
|
| 374 |
+
},
|
| 375 |
+
"node_modules/dunder-proto": {
|
| 376 |
+
"version": "1.0.1",
|
| 377 |
+
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
| 378 |
+
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
| 379 |
+
"license": "MIT",
|
| 380 |
+
"dependencies": {
|
| 381 |
+
"call-bind-apply-helpers": "^1.0.1",
|
| 382 |
+
"es-errors": "^1.3.0",
|
| 383 |
+
"gopd": "^1.2.0"
|
| 384 |
+
},
|
| 385 |
+
"engines": {
|
| 386 |
+
"node": ">= 0.4"
|
| 387 |
+
}
|
| 388 |
+
},
|
| 389 |
+
"node_modules/ee-first": {
|
| 390 |
+
"version": "1.1.1",
|
| 391 |
+
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
| 392 |
+
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
| 393 |
+
"license": "MIT"
|
| 394 |
+
},
|
| 395 |
+
"node_modules/encodeurl": {
|
| 396 |
+
"version": "2.0.0",
|
| 397 |
+
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
|
| 398 |
+
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
| 399 |
+
"license": "MIT",
|
| 400 |
+
"engines": {
|
| 401 |
+
"node": ">= 0.8"
|
| 402 |
+
}
|
| 403 |
+
},
|
| 404 |
+
"node_modules/es-define-property": {
|
| 405 |
+
"version": "1.0.1",
|
| 406 |
+
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
| 407 |
+
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
| 408 |
+
"license": "MIT",
|
| 409 |
+
"engines": {
|
| 410 |
+
"node": ">= 0.4"
|
| 411 |
+
}
|
| 412 |
+
},
|
| 413 |
+
"node_modules/es-errors": {
|
| 414 |
+
"version": "1.3.0",
|
| 415 |
+
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
| 416 |
+
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
| 417 |
+
"license": "MIT",
|
| 418 |
+
"engines": {
|
| 419 |
+
"node": ">= 0.4"
|
| 420 |
+
}
|
| 421 |
+
},
|
| 422 |
+
"node_modules/es-object-atoms": {
|
| 423 |
+
"version": "1.1.1",
|
| 424 |
+
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
| 425 |
+
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
| 426 |
+
"license": "MIT",
|
| 427 |
+
"dependencies": {
|
| 428 |
+
"es-errors": "^1.3.0"
|
| 429 |
+
},
|
| 430 |
+
"engines": {
|
| 431 |
+
"node": ">= 0.4"
|
| 432 |
+
}
|
| 433 |
+
},
|
| 434 |
+
"node_modules/escape-html": {
|
| 435 |
+
"version": "1.0.3",
|
| 436 |
+
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
| 437 |
+
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
| 438 |
+
"license": "MIT"
|
| 439 |
+
},
|
| 440 |
+
"node_modules/etag": {
|
| 441 |
+
"version": "1.8.1",
|
| 442 |
+
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
| 443 |
+
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
| 444 |
+
"license": "MIT",
|
| 445 |
+
"engines": {
|
| 446 |
+
"node": ">= 0.6"
|
| 447 |
+
}
|
| 448 |
+
},
|
| 449 |
+
"node_modules/express": {
|
| 450 |
+
"version": "5.2.1",
|
| 451 |
+
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
|
| 452 |
+
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
|
| 453 |
+
"license": "MIT",
|
| 454 |
+
"dependencies": {
|
| 455 |
+
"accepts": "^2.0.0",
|
| 456 |
+
"body-parser": "^2.2.1",
|
| 457 |
+
"content-disposition": "^1.0.0",
|
| 458 |
+
"content-type": "^1.0.5",
|
| 459 |
+
"cookie": "^0.7.1",
|
| 460 |
+
"cookie-signature": "^1.2.1",
|
| 461 |
+
"debug": "^4.4.0",
|
| 462 |
+
"depd": "^2.0.0",
|
| 463 |
+
"encodeurl": "^2.0.0",
|
| 464 |
+
"escape-html": "^1.0.3",
|
| 465 |
+
"etag": "^1.8.1",
|
| 466 |
+
"finalhandler": "^2.1.0",
|
| 467 |
+
"fresh": "^2.0.0",
|
| 468 |
+
"http-errors": "^2.0.0",
|
| 469 |
+
"merge-descriptors": "^2.0.0",
|
| 470 |
+
"mime-types": "^3.0.0",
|
| 471 |
+
"on-finished": "^2.4.1",
|
| 472 |
+
"once": "^1.4.0",
|
| 473 |
+
"parseurl": "^1.3.3",
|
| 474 |
+
"proxy-addr": "^2.0.7",
|
| 475 |
+
"qs": "^6.14.0",
|
| 476 |
+
"range-parser": "^1.2.1",
|
| 477 |
+
"router": "^2.2.0",
|
| 478 |
+
"send": "^1.1.0",
|
| 479 |
+
"serve-static": "^2.2.0",
|
| 480 |
+
"statuses": "^2.0.1",
|
| 481 |
+
"type-is": "^2.0.1",
|
| 482 |
+
"vary": "^1.1.2"
|
| 483 |
+
},
|
| 484 |
+
"engines": {
|
| 485 |
+
"node": ">= 18"
|
| 486 |
+
},
|
| 487 |
+
"funding": {
|
| 488 |
+
"type": "opencollective",
|
| 489 |
+
"url": "https://opencollective.com/express"
|
| 490 |
+
}
|
| 491 |
+
},
|
| 492 |
+
"node_modules/fill-range": {
|
| 493 |
+
"version": "7.1.1",
|
| 494 |
+
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
| 495 |
+
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
| 496 |
+
"license": "MIT",
|
| 497 |
+
"dependencies": {
|
| 498 |
+
"to-regex-range": "^5.0.1"
|
| 499 |
+
},
|
| 500 |
+
"engines": {
|
| 501 |
+
"node": ">=8"
|
| 502 |
+
}
|
| 503 |
+
},
|
| 504 |
+
"node_modules/finalhandler": {
|
| 505 |
+
"version": "2.1.1",
|
| 506 |
+
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz",
|
| 507 |
+
"integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==",
|
| 508 |
+
"license": "MIT",
|
| 509 |
+
"dependencies": {
|
| 510 |
+
"debug": "^4.4.0",
|
| 511 |
+
"encodeurl": "^2.0.0",
|
| 512 |
+
"escape-html": "^1.0.3",
|
| 513 |
+
"on-finished": "^2.4.1",
|
| 514 |
+
"parseurl": "^1.3.3",
|
| 515 |
+
"statuses": "^2.0.1"
|
| 516 |
+
},
|
| 517 |
+
"engines": {
|
| 518 |
+
"node": ">= 18.0.0"
|
| 519 |
+
},
|
| 520 |
+
"funding": {
|
| 521 |
+
"type": "opencollective",
|
| 522 |
+
"url": "https://opencollective.com/express"
|
| 523 |
+
}
|
| 524 |
+
},
|
| 525 |
+
"node_modules/forwarded": {
|
| 526 |
+
"version": "0.2.0",
|
| 527 |
+
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
| 528 |
+
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
| 529 |
+
"license": "MIT",
|
| 530 |
+
"engines": {
|
| 531 |
+
"node": ">= 0.6"
|
| 532 |
+
}
|
| 533 |
+
},
|
| 534 |
+
"node_modules/fresh": {
|
| 535 |
+
"version": "2.0.0",
|
| 536 |
+
"resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
|
| 537 |
+
"integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==",
|
| 538 |
+
"license": "MIT",
|
| 539 |
+
"engines": {
|
| 540 |
+
"node": ">= 0.8"
|
| 541 |
+
}
|
| 542 |
+
},
|
| 543 |
+
"node_modules/fsevents": {
|
| 544 |
+
"version": "2.3.3",
|
| 545 |
+
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
| 546 |
+
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
| 547 |
+
"hasInstallScript": true,
|
| 548 |
+
"license": "MIT",
|
| 549 |
+
"optional": true,
|
| 550 |
+
"os": [
|
| 551 |
+
"darwin"
|
| 552 |
+
],
|
| 553 |
+
"engines": {
|
| 554 |
+
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
| 555 |
+
}
|
| 556 |
+
},
|
| 557 |
+
"node_modules/function-bind": {
|
| 558 |
+
"version": "1.1.2",
|
| 559 |
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
| 560 |
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
| 561 |
+
"license": "MIT",
|
| 562 |
+
"funding": {
|
| 563 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 564 |
+
}
|
| 565 |
+
},
|
| 566 |
+
"node_modules/get-intrinsic": {
|
| 567 |
+
"version": "1.3.0",
|
| 568 |
+
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
| 569 |
+
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
| 570 |
+
"license": "MIT",
|
| 571 |
+
"dependencies": {
|
| 572 |
+
"call-bind-apply-helpers": "^1.0.2",
|
| 573 |
+
"es-define-property": "^1.0.1",
|
| 574 |
+
"es-errors": "^1.3.0",
|
| 575 |
+
"es-object-atoms": "^1.1.1",
|
| 576 |
+
"function-bind": "^1.1.2",
|
| 577 |
+
"get-proto": "^1.0.1",
|
| 578 |
+
"gopd": "^1.2.0",
|
| 579 |
+
"has-symbols": "^1.1.0",
|
| 580 |
+
"hasown": "^2.0.2",
|
| 581 |
+
"math-intrinsics": "^1.1.0"
|
| 582 |
+
},
|
| 583 |
+
"engines": {
|
| 584 |
+
"node": ">= 0.4"
|
| 585 |
+
},
|
| 586 |
+
"funding": {
|
| 587 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 588 |
+
}
|
| 589 |
+
},
|
| 590 |
+
"node_modules/get-proto": {
|
| 591 |
+
"version": "1.0.1",
|
| 592 |
+
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
| 593 |
+
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
| 594 |
+
"license": "MIT",
|
| 595 |
+
"dependencies": {
|
| 596 |
+
"dunder-proto": "^1.0.1",
|
| 597 |
+
"es-object-atoms": "^1.0.0"
|
| 598 |
+
},
|
| 599 |
+
"engines": {
|
| 600 |
+
"node": ">= 0.4"
|
| 601 |
+
}
|
| 602 |
+
},
|
| 603 |
+
"node_modules/glob-parent": {
|
| 604 |
+
"version": "5.1.2",
|
| 605 |
+
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
| 606 |
+
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
| 607 |
+
"license": "ISC",
|
| 608 |
+
"dependencies": {
|
| 609 |
+
"is-glob": "^4.0.1"
|
| 610 |
+
},
|
| 611 |
+
"engines": {
|
| 612 |
+
"node": ">= 6"
|
| 613 |
+
}
|
| 614 |
+
},
|
| 615 |
+
"node_modules/gopd": {
|
| 616 |
+
"version": "1.2.0",
|
| 617 |
+
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
| 618 |
+
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
| 619 |
+
"license": "MIT",
|
| 620 |
+
"engines": {
|
| 621 |
+
"node": ">= 0.4"
|
| 622 |
+
},
|
| 623 |
+
"funding": {
|
| 624 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 625 |
+
}
|
| 626 |
+
},
|
| 627 |
+
"node_modules/has-flag": {
|
| 628 |
+
"version": "3.0.0",
|
| 629 |
+
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
| 630 |
+
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
|
| 631 |
+
"license": "MIT",
|
| 632 |
+
"engines": {
|
| 633 |
+
"node": ">=4"
|
| 634 |
+
}
|
| 635 |
+
},
|
| 636 |
+
"node_modules/has-symbols": {
|
| 637 |
+
"version": "1.1.0",
|
| 638 |
+
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
| 639 |
+
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
| 640 |
+
"license": "MIT",
|
| 641 |
+
"engines": {
|
| 642 |
+
"node": ">= 0.4"
|
| 643 |
+
},
|
| 644 |
+
"funding": {
|
| 645 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 646 |
+
}
|
| 647 |
+
},
|
| 648 |
+
"node_modules/hasown": {
|
| 649 |
+
"version": "2.0.2",
|
| 650 |
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
| 651 |
+
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
| 652 |
+
"license": "MIT",
|
| 653 |
+
"dependencies": {
|
| 654 |
+
"function-bind": "^1.1.2"
|
| 655 |
+
},
|
| 656 |
+
"engines": {
|
| 657 |
+
"node": ">= 0.4"
|
| 658 |
+
}
|
| 659 |
+
},
|
| 660 |
+
"node_modules/http-errors": {
|
| 661 |
+
"version": "2.0.1",
|
| 662 |
+
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
|
| 663 |
+
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
|
| 664 |
+
"license": "MIT",
|
| 665 |
+
"dependencies": {
|
| 666 |
+
"depd": "~2.0.0",
|
| 667 |
+
"inherits": "~2.0.4",
|
| 668 |
+
"setprototypeof": "~1.2.0",
|
| 669 |
+
"statuses": "~2.0.2",
|
| 670 |
+
"toidentifier": "~1.0.1"
|
| 671 |
+
},
|
| 672 |
+
"engines": {
|
| 673 |
+
"node": ">= 0.8"
|
| 674 |
+
},
|
| 675 |
+
"funding": {
|
| 676 |
+
"type": "opencollective",
|
| 677 |
+
"url": "https://opencollective.com/express"
|
| 678 |
+
}
|
| 679 |
+
},
|
| 680 |
+
"node_modules/iconv-lite": {
|
| 681 |
+
"version": "0.7.1",
|
| 682 |
+
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.1.tgz",
|
| 683 |
+
"integrity": "sha512-2Tth85cXwGFHfvRgZWszZSvdo+0Xsqmw8k8ZwxScfcBneNUraK+dxRxRm24nszx80Y0TVio8kKLt5sLE7ZCLlw==",
|
| 684 |
+
"license": "MIT",
|
| 685 |
+
"dependencies": {
|
| 686 |
+
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
| 687 |
+
},
|
| 688 |
+
"engines": {
|
| 689 |
+
"node": ">=0.10.0"
|
| 690 |
+
},
|
| 691 |
+
"funding": {
|
| 692 |
+
"type": "opencollective",
|
| 693 |
+
"url": "https://opencollective.com/express"
|
| 694 |
+
}
|
| 695 |
+
},
|
| 696 |
+
"node_modules/ignore-by-default": {
|
| 697 |
+
"version": "1.0.1",
|
| 698 |
+
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
| 699 |
+
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
|
| 700 |
+
"license": "ISC"
|
| 701 |
+
},
|
| 702 |
+
"node_modules/inherits": {
|
| 703 |
+
"version": "2.0.4",
|
| 704 |
+
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
| 705 |
+
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
| 706 |
+
"license": "ISC"
|
| 707 |
+
},
|
| 708 |
+
"node_modules/ipaddr.js": {
|
| 709 |
+
"version": "1.9.1",
|
| 710 |
+
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
| 711 |
+
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
| 712 |
+
"license": "MIT",
|
| 713 |
+
"engines": {
|
| 714 |
+
"node": ">= 0.10"
|
| 715 |
+
}
|
| 716 |
+
},
|
| 717 |
+
"node_modules/is-binary-path": {
|
| 718 |
+
"version": "2.1.0",
|
| 719 |
+
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
|
| 720 |
+
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
|
| 721 |
+
"license": "MIT",
|
| 722 |
+
"dependencies": {
|
| 723 |
+
"binary-extensions": "^2.0.0"
|
| 724 |
+
},
|
| 725 |
+
"engines": {
|
| 726 |
+
"node": ">=8"
|
| 727 |
+
}
|
| 728 |
+
},
|
| 729 |
+
"node_modules/is-extglob": {
|
| 730 |
+
"version": "2.1.1",
|
| 731 |
+
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
| 732 |
+
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
| 733 |
+
"license": "MIT",
|
| 734 |
+
"engines": {
|
| 735 |
+
"node": ">=0.10.0"
|
| 736 |
+
}
|
| 737 |
+
},
|
| 738 |
+
"node_modules/is-glob": {
|
| 739 |
+
"version": "4.0.3",
|
| 740 |
+
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
| 741 |
+
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
| 742 |
+
"license": "MIT",
|
| 743 |
+
"dependencies": {
|
| 744 |
+
"is-extglob": "^2.1.1"
|
| 745 |
+
},
|
| 746 |
+
"engines": {
|
| 747 |
+
"node": ">=0.10.0"
|
| 748 |
+
}
|
| 749 |
+
},
|
| 750 |
+
"node_modules/is-number": {
|
| 751 |
+
"version": "7.0.0",
|
| 752 |
+
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
| 753 |
+
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
| 754 |
+
"license": "MIT",
|
| 755 |
+
"engines": {
|
| 756 |
+
"node": ">=0.12.0"
|
| 757 |
+
}
|
| 758 |
+
},
|
| 759 |
+
"node_modules/is-promise": {
|
| 760 |
+
"version": "4.0.0",
|
| 761 |
+
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
|
| 762 |
+
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
|
| 763 |
+
"license": "MIT"
|
| 764 |
+
},
|
| 765 |
+
"node_modules/kareem": {
|
| 766 |
+
"version": "3.0.0",
|
| 767 |
+
"resolved": "https://registry.npmjs.org/kareem/-/kareem-3.0.0.tgz",
|
| 768 |
+
"integrity": "sha512-RKhaOBSPN8L7y4yAgNhDT2602G5FD6QbOIISbjN9D6mjHPeqeg7K+EB5IGSU5o81/X2Gzm3ICnAvQW3x3OP8HA==",
|
| 769 |
+
"license": "Apache-2.0",
|
| 770 |
+
"engines": {
|
| 771 |
+
"node": ">=18.0.0"
|
| 772 |
+
}
|
| 773 |
+
},
|
| 774 |
+
"node_modules/math-intrinsics": {
|
| 775 |
+
"version": "1.1.0",
|
| 776 |
+
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
| 777 |
+
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
| 778 |
+
"license": "MIT",
|
| 779 |
+
"engines": {
|
| 780 |
+
"node": ">= 0.4"
|
| 781 |
+
}
|
| 782 |
+
},
|
| 783 |
+
"node_modules/media-typer": {
|
| 784 |
+
"version": "1.1.0",
|
| 785 |
+
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz",
|
| 786 |
+
"integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==",
|
| 787 |
+
"license": "MIT",
|
| 788 |
+
"engines": {
|
| 789 |
+
"node": ">= 0.8"
|
| 790 |
+
}
|
| 791 |
+
},
|
| 792 |
+
"node_modules/memory-pager": {
|
| 793 |
+
"version": "1.5.0",
|
| 794 |
+
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
| 795 |
+
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
|
| 796 |
+
"license": "MIT"
|
| 797 |
+
},
|
| 798 |
+
"node_modules/merge-descriptors": {
|
| 799 |
+
"version": "2.0.0",
|
| 800 |
+
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz",
|
| 801 |
+
"integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==",
|
| 802 |
+
"license": "MIT",
|
| 803 |
+
"engines": {
|
| 804 |
+
"node": ">=18"
|
| 805 |
+
},
|
| 806 |
+
"funding": {
|
| 807 |
+
"url": "https://github.com/sponsors/sindresorhus"
|
| 808 |
+
}
|
| 809 |
+
},
|
| 810 |
+
"node_modules/mime-db": {
|
| 811 |
+
"version": "1.54.0",
|
| 812 |
+
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
|
| 813 |
+
"integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
|
| 814 |
+
"license": "MIT",
|
| 815 |
+
"engines": {
|
| 816 |
+
"node": ">= 0.6"
|
| 817 |
+
}
|
| 818 |
+
},
|
| 819 |
+
"node_modules/mime-types": {
|
| 820 |
+
"version": "3.0.2",
|
| 821 |
+
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
|
| 822 |
+
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
|
| 823 |
+
"license": "MIT",
|
| 824 |
+
"dependencies": {
|
| 825 |
+
"mime-db": "^1.54.0"
|
| 826 |
+
},
|
| 827 |
+
"engines": {
|
| 828 |
+
"node": ">=18"
|
| 829 |
+
},
|
| 830 |
+
"funding": {
|
| 831 |
+
"type": "opencollective",
|
| 832 |
+
"url": "https://opencollective.com/express"
|
| 833 |
+
}
|
| 834 |
+
},
|
| 835 |
+
"node_modules/minimatch": {
|
| 836 |
+
"version": "3.1.2",
|
| 837 |
+
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
| 838 |
+
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
| 839 |
+
"license": "ISC",
|
| 840 |
+
"dependencies": {
|
| 841 |
+
"brace-expansion": "^1.1.7"
|
| 842 |
+
},
|
| 843 |
+
"engines": {
|
| 844 |
+
"node": "*"
|
| 845 |
+
}
|
| 846 |
+
},
|
| 847 |
+
"node_modules/mongodb": {
|
| 848 |
+
"version": "7.0.0",
|
| 849 |
+
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz",
|
| 850 |
+
"integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==",
|
| 851 |
+
"license": "Apache-2.0",
|
| 852 |
+
"dependencies": {
|
| 853 |
+
"@mongodb-js/saslprep": "^1.3.0",
|
| 854 |
+
"bson": "^7.0.0",
|
| 855 |
+
"mongodb-connection-string-url": "^7.0.0"
|
| 856 |
+
},
|
| 857 |
+
"engines": {
|
| 858 |
+
"node": ">=20.19.0"
|
| 859 |
+
},
|
| 860 |
+
"peerDependencies": {
|
| 861 |
+
"@aws-sdk/credential-providers": "^3.806.0",
|
| 862 |
+
"@mongodb-js/zstd": "^7.0.0",
|
| 863 |
+
"gcp-metadata": "^7.0.1",
|
| 864 |
+
"kerberos": "^7.0.0",
|
| 865 |
+
"mongodb-client-encryption": ">=7.0.0 <7.1.0",
|
| 866 |
+
"snappy": "^7.3.2",
|
| 867 |
+
"socks": "^2.8.6"
|
| 868 |
+
},
|
| 869 |
+
"peerDependenciesMeta": {
|
| 870 |
+
"@aws-sdk/credential-providers": {
|
| 871 |
+
"optional": true
|
| 872 |
+
},
|
| 873 |
+
"@mongodb-js/zstd": {
|
| 874 |
+
"optional": true
|
| 875 |
+
},
|
| 876 |
+
"gcp-metadata": {
|
| 877 |
+
"optional": true
|
| 878 |
+
},
|
| 879 |
+
"kerberos": {
|
| 880 |
+
"optional": true
|
| 881 |
+
},
|
| 882 |
+
"mongodb-client-encryption": {
|
| 883 |
+
"optional": true
|
| 884 |
+
},
|
| 885 |
+
"snappy": {
|
| 886 |
+
"optional": true
|
| 887 |
+
},
|
| 888 |
+
"socks": {
|
| 889 |
+
"optional": true
|
| 890 |
+
}
|
| 891 |
+
}
|
| 892 |
+
},
|
| 893 |
+
"node_modules/mongodb-connection-string-url": {
|
| 894 |
+
"version": "7.0.0",
|
| 895 |
+
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.0.tgz",
|
| 896 |
+
"integrity": "sha512-irhhjRVLE20hbkRl4zpAYLnDMM+zIZnp0IDB9akAFFUZp/3XdOfwwddc7y6cNvF2WCEtfTYRwYbIfYa2kVY0og==",
|
| 897 |
+
"license": "Apache-2.0",
|
| 898 |
+
"dependencies": {
|
| 899 |
+
"@types/whatwg-url": "^13.0.0",
|
| 900 |
+
"whatwg-url": "^14.1.0"
|
| 901 |
+
},
|
| 902 |
+
"engines": {
|
| 903 |
+
"node": ">=20.19.0"
|
| 904 |
+
}
|
| 905 |
+
},
|
| 906 |
+
"node_modules/mongoose": {
|
| 907 |
+
"version": "9.0.2",
|
| 908 |
+
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.0.2.tgz",
|
| 909 |
+
"integrity": "sha512-+GCaqwE+X//yN9eo2M2L/n+mVti9J6vH5iQKbhD+2AArZd5iaZqK/DkmkE4S6/iYYMyVQPTXsRk7jyVOYEtJzA==",
|
| 910 |
+
"license": "MIT",
|
| 911 |
+
"dependencies": {
|
| 912 |
+
"kareem": "3.0.0",
|
| 913 |
+
"mongodb": "~7.0",
|
| 914 |
+
"mpath": "0.9.0",
|
| 915 |
+
"mquery": "6.0.0",
|
| 916 |
+
"ms": "2.1.3",
|
| 917 |
+
"sift": "17.1.3"
|
| 918 |
+
},
|
| 919 |
+
"engines": {
|
| 920 |
+
"node": ">=20.19.0"
|
| 921 |
+
},
|
| 922 |
+
"funding": {
|
| 923 |
+
"type": "opencollective",
|
| 924 |
+
"url": "https://opencollective.com/mongoose"
|
| 925 |
+
}
|
| 926 |
+
},
|
| 927 |
+
"node_modules/morgan": {
|
| 928 |
+
"version": "1.10.1",
|
| 929 |
+
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.1.tgz",
|
| 930 |
+
"integrity": "sha512-223dMRJtI/l25dJKWpgij2cMtywuG/WiUKXdvwfbhGKBhy1puASqXwFzmWZ7+K73vUPoR7SS2Qz2cI/g9MKw0A==",
|
| 931 |
+
"license": "MIT",
|
| 932 |
+
"dependencies": {
|
| 933 |
+
"basic-auth": "~2.0.1",
|
| 934 |
+
"debug": "2.6.9",
|
| 935 |
+
"depd": "~2.0.0",
|
| 936 |
+
"on-finished": "~2.3.0",
|
| 937 |
+
"on-headers": "~1.1.0"
|
| 938 |
+
},
|
| 939 |
+
"engines": {
|
| 940 |
+
"node": ">= 0.8.0"
|
| 941 |
+
}
|
| 942 |
+
},
|
| 943 |
+
"node_modules/morgan/node_modules/debug": {
|
| 944 |
+
"version": "2.6.9",
|
| 945 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
| 946 |
+
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
| 947 |
+
"license": "MIT",
|
| 948 |
+
"dependencies": {
|
| 949 |
+
"ms": "2.0.0"
|
| 950 |
+
}
|
| 951 |
+
},
|
| 952 |
+
"node_modules/morgan/node_modules/ms": {
|
| 953 |
+
"version": "2.0.0",
|
| 954 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
| 955 |
+
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
| 956 |
+
"license": "MIT"
|
| 957 |
+
},
|
| 958 |
+
"node_modules/morgan/node_modules/on-finished": {
|
| 959 |
+
"version": "2.3.0",
|
| 960 |
+
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
| 961 |
+
"integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==",
|
| 962 |
+
"license": "MIT",
|
| 963 |
+
"dependencies": {
|
| 964 |
+
"ee-first": "1.1.1"
|
| 965 |
+
},
|
| 966 |
+
"engines": {
|
| 967 |
+
"node": ">= 0.8"
|
| 968 |
+
}
|
| 969 |
+
},
|
| 970 |
+
"node_modules/mpath": {
|
| 971 |
+
"version": "0.9.0",
|
| 972 |
+
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz",
|
| 973 |
+
"integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==",
|
| 974 |
+
"license": "MIT",
|
| 975 |
+
"engines": {
|
| 976 |
+
"node": ">=4.0.0"
|
| 977 |
+
}
|
| 978 |
+
},
|
| 979 |
+
"node_modules/mquery": {
|
| 980 |
+
"version": "6.0.0",
|
| 981 |
+
"resolved": "https://registry.npmjs.org/mquery/-/mquery-6.0.0.tgz",
|
| 982 |
+
"integrity": "sha512-b2KQNsmgtkscfeDgkYMcWGn9vZI9YoXh802VDEwE6qc50zxBFQ0Oo8ROkawbPAsXCY1/Z1yp0MagqsZStPWJjw==",
|
| 983 |
+
"license": "MIT",
|
| 984 |
+
"engines": {
|
| 985 |
+
"node": ">=20.19.0"
|
| 986 |
+
}
|
| 987 |
+
},
|
| 988 |
+
"node_modules/ms": {
|
| 989 |
+
"version": "2.1.3",
|
| 990 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 991 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 992 |
+
"license": "MIT"
|
| 993 |
+
},
|
| 994 |
+
"node_modules/negotiator": {
|
| 995 |
+
"version": "1.0.0",
|
| 996 |
+
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
|
| 997 |
+
"integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==",
|
| 998 |
+
"license": "MIT",
|
| 999 |
+
"engines": {
|
| 1000 |
+
"node": ">= 0.6"
|
| 1001 |
+
}
|
| 1002 |
+
},
|
| 1003 |
+
"node_modules/nodemon": {
|
| 1004 |
+
"version": "3.1.11",
|
| 1005 |
+
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.11.tgz",
|
| 1006 |
+
"integrity": "sha512-is96t8F/1//UHAjNPHpbsNY46ELPpftGUoSVNXwUfMk/qdjSylYrWSu1XavVTBOn526kFiOR733ATgNBCQyH0g==",
|
| 1007 |
+
"license": "MIT",
|
| 1008 |
+
"dependencies": {
|
| 1009 |
+
"chokidar": "^3.5.2",
|
| 1010 |
+
"debug": "^4",
|
| 1011 |
+
"ignore-by-default": "^1.0.1",
|
| 1012 |
+
"minimatch": "^3.1.2",
|
| 1013 |
+
"pstree.remy": "^1.1.8",
|
| 1014 |
+
"semver": "^7.5.3",
|
| 1015 |
+
"simple-update-notifier": "^2.0.0",
|
| 1016 |
+
"supports-color": "^5.5.0",
|
| 1017 |
+
"touch": "^3.1.0",
|
| 1018 |
+
"undefsafe": "^2.0.5"
|
| 1019 |
+
},
|
| 1020 |
+
"bin": {
|
| 1021 |
+
"nodemon": "bin/nodemon.js"
|
| 1022 |
+
},
|
| 1023 |
+
"engines": {
|
| 1024 |
+
"node": ">=10"
|
| 1025 |
+
},
|
| 1026 |
+
"funding": {
|
| 1027 |
+
"type": "opencollective",
|
| 1028 |
+
"url": "https://opencollective.com/nodemon"
|
| 1029 |
+
}
|
| 1030 |
+
},
|
| 1031 |
+
"node_modules/normalize-path": {
|
| 1032 |
+
"version": "3.0.0",
|
| 1033 |
+
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
| 1034 |
+
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
|
| 1035 |
+
"license": "MIT",
|
| 1036 |
+
"engines": {
|
| 1037 |
+
"node": ">=0.10.0"
|
| 1038 |
+
}
|
| 1039 |
+
},
|
| 1040 |
+
"node_modules/object-assign": {
|
| 1041 |
+
"version": "4.1.1",
|
| 1042 |
+
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
| 1043 |
+
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
| 1044 |
+
"license": "MIT",
|
| 1045 |
+
"engines": {
|
| 1046 |
+
"node": ">=0.10.0"
|
| 1047 |
+
}
|
| 1048 |
+
},
|
| 1049 |
+
"node_modules/object-inspect": {
|
| 1050 |
+
"version": "1.13.4",
|
| 1051 |
+
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
| 1052 |
+
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
| 1053 |
+
"license": "MIT",
|
| 1054 |
+
"engines": {
|
| 1055 |
+
"node": ">= 0.4"
|
| 1056 |
+
},
|
| 1057 |
+
"funding": {
|
| 1058 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1059 |
+
}
|
| 1060 |
+
},
|
| 1061 |
+
"node_modules/on-finished": {
|
| 1062 |
+
"version": "2.4.1",
|
| 1063 |
+
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
| 1064 |
+
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
| 1065 |
+
"license": "MIT",
|
| 1066 |
+
"dependencies": {
|
| 1067 |
+
"ee-first": "1.1.1"
|
| 1068 |
+
},
|
| 1069 |
+
"engines": {
|
| 1070 |
+
"node": ">= 0.8"
|
| 1071 |
+
}
|
| 1072 |
+
},
|
| 1073 |
+
"node_modules/on-headers": {
|
| 1074 |
+
"version": "1.1.0",
|
| 1075 |
+
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.1.0.tgz",
|
| 1076 |
+
"integrity": "sha512-737ZY3yNnXy37FHkQxPzt4UZ2UWPWiCZWLvFZ4fu5cueciegX0zGPnrlY6bwRg4FdQOe9YU8MkmJwGhoMybl8A==",
|
| 1077 |
+
"license": "MIT",
|
| 1078 |
+
"engines": {
|
| 1079 |
+
"node": ">= 0.8"
|
| 1080 |
+
}
|
| 1081 |
+
},
|
| 1082 |
+
"node_modules/once": {
|
| 1083 |
+
"version": "1.4.0",
|
| 1084 |
+
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
| 1085 |
+
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
|
| 1086 |
+
"license": "ISC",
|
| 1087 |
+
"dependencies": {
|
| 1088 |
+
"wrappy": "1"
|
| 1089 |
+
}
|
| 1090 |
+
},
|
| 1091 |
+
"node_modules/parseurl": {
|
| 1092 |
+
"version": "1.3.3",
|
| 1093 |
+
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
| 1094 |
+
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
| 1095 |
+
"license": "MIT",
|
| 1096 |
+
"engines": {
|
| 1097 |
+
"node": ">= 0.8"
|
| 1098 |
+
}
|
| 1099 |
+
},
|
| 1100 |
+
"node_modules/path-to-regexp": {
|
| 1101 |
+
"version": "8.3.0",
|
| 1102 |
+
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz",
|
| 1103 |
+
"integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==",
|
| 1104 |
+
"license": "MIT",
|
| 1105 |
+
"funding": {
|
| 1106 |
+
"type": "opencollective",
|
| 1107 |
+
"url": "https://opencollective.com/express"
|
| 1108 |
+
}
|
| 1109 |
+
},
|
| 1110 |
+
"node_modules/picomatch": {
|
| 1111 |
+
"version": "2.3.1",
|
| 1112 |
+
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
| 1113 |
+
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
| 1114 |
+
"license": "MIT",
|
| 1115 |
+
"engines": {
|
| 1116 |
+
"node": ">=8.6"
|
| 1117 |
+
},
|
| 1118 |
+
"funding": {
|
| 1119 |
+
"url": "https://github.com/sponsors/jonschlinkert"
|
| 1120 |
+
}
|
| 1121 |
+
},
|
| 1122 |
+
"node_modules/proxy-addr": {
|
| 1123 |
+
"version": "2.0.7",
|
| 1124 |
+
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
| 1125 |
+
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
| 1126 |
+
"license": "MIT",
|
| 1127 |
+
"dependencies": {
|
| 1128 |
+
"forwarded": "0.2.0",
|
| 1129 |
+
"ipaddr.js": "1.9.1"
|
| 1130 |
+
},
|
| 1131 |
+
"engines": {
|
| 1132 |
+
"node": ">= 0.10"
|
| 1133 |
+
}
|
| 1134 |
+
},
|
| 1135 |
+
"node_modules/pstree.remy": {
|
| 1136 |
+
"version": "1.1.8",
|
| 1137 |
+
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
|
| 1138 |
+
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==",
|
| 1139 |
+
"license": "MIT"
|
| 1140 |
+
},
|
| 1141 |
+
"node_modules/punycode": {
|
| 1142 |
+
"version": "2.3.1",
|
| 1143 |
+
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
| 1144 |
+
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
| 1145 |
+
"license": "MIT",
|
| 1146 |
+
"engines": {
|
| 1147 |
+
"node": ">=6"
|
| 1148 |
+
}
|
| 1149 |
+
},
|
| 1150 |
+
"node_modules/qs": {
|
| 1151 |
+
"version": "6.14.0",
|
| 1152 |
+
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
|
| 1153 |
+
"integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==",
|
| 1154 |
+
"license": "BSD-3-Clause",
|
| 1155 |
+
"dependencies": {
|
| 1156 |
+
"side-channel": "^1.1.0"
|
| 1157 |
+
},
|
| 1158 |
+
"engines": {
|
| 1159 |
+
"node": ">=0.6"
|
| 1160 |
+
},
|
| 1161 |
+
"funding": {
|
| 1162 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1163 |
+
}
|
| 1164 |
+
},
|
| 1165 |
+
"node_modules/range-parser": {
|
| 1166 |
+
"version": "1.2.1",
|
| 1167 |
+
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
| 1168 |
+
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
| 1169 |
+
"license": "MIT",
|
| 1170 |
+
"engines": {
|
| 1171 |
+
"node": ">= 0.6"
|
| 1172 |
+
}
|
| 1173 |
+
},
|
| 1174 |
+
"node_modules/raw-body": {
|
| 1175 |
+
"version": "3.0.2",
|
| 1176 |
+
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
|
| 1177 |
+
"integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
|
| 1178 |
+
"license": "MIT",
|
| 1179 |
+
"dependencies": {
|
| 1180 |
+
"bytes": "~3.1.2",
|
| 1181 |
+
"http-errors": "~2.0.1",
|
| 1182 |
+
"iconv-lite": "~0.7.0",
|
| 1183 |
+
"unpipe": "~1.0.0"
|
| 1184 |
+
},
|
| 1185 |
+
"engines": {
|
| 1186 |
+
"node": ">= 0.10"
|
| 1187 |
+
}
|
| 1188 |
+
},
|
| 1189 |
+
"node_modules/readdirp": {
|
| 1190 |
+
"version": "3.6.0",
|
| 1191 |
+
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
|
| 1192 |
+
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
|
| 1193 |
+
"license": "MIT",
|
| 1194 |
+
"dependencies": {
|
| 1195 |
+
"picomatch": "^2.2.1"
|
| 1196 |
+
},
|
| 1197 |
+
"engines": {
|
| 1198 |
+
"node": ">=8.10.0"
|
| 1199 |
+
}
|
| 1200 |
+
},
|
| 1201 |
+
"node_modules/router": {
|
| 1202 |
+
"version": "2.2.0",
|
| 1203 |
+
"resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz",
|
| 1204 |
+
"integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==",
|
| 1205 |
+
"license": "MIT",
|
| 1206 |
+
"dependencies": {
|
| 1207 |
+
"debug": "^4.4.0",
|
| 1208 |
+
"depd": "^2.0.0",
|
| 1209 |
+
"is-promise": "^4.0.0",
|
| 1210 |
+
"parseurl": "^1.3.3",
|
| 1211 |
+
"path-to-regexp": "^8.0.0"
|
| 1212 |
+
},
|
| 1213 |
+
"engines": {
|
| 1214 |
+
"node": ">= 18"
|
| 1215 |
+
}
|
| 1216 |
+
},
|
| 1217 |
+
"node_modules/safe-buffer": {
|
| 1218 |
+
"version": "5.2.1",
|
| 1219 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
| 1220 |
+
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
| 1221 |
+
"funding": [
|
| 1222 |
+
{
|
| 1223 |
+
"type": "github",
|
| 1224 |
+
"url": "https://github.com/sponsors/feross"
|
| 1225 |
+
},
|
| 1226 |
+
{
|
| 1227 |
+
"type": "patreon",
|
| 1228 |
+
"url": "https://www.patreon.com/feross"
|
| 1229 |
+
},
|
| 1230 |
+
{
|
| 1231 |
+
"type": "consulting",
|
| 1232 |
+
"url": "https://feross.org/support"
|
| 1233 |
+
}
|
| 1234 |
+
],
|
| 1235 |
+
"license": "MIT"
|
| 1236 |
+
},
|
| 1237 |
+
"node_modules/safer-buffer": {
|
| 1238 |
+
"version": "2.1.2",
|
| 1239 |
+
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
| 1240 |
+
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
| 1241 |
+
"license": "MIT"
|
| 1242 |
+
},
|
| 1243 |
+
"node_modules/semver": {
|
| 1244 |
+
"version": "7.7.3",
|
| 1245 |
+
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz",
|
| 1246 |
+
"integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==",
|
| 1247 |
+
"license": "ISC",
|
| 1248 |
+
"bin": {
|
| 1249 |
+
"semver": "bin/semver.js"
|
| 1250 |
+
},
|
| 1251 |
+
"engines": {
|
| 1252 |
+
"node": ">=10"
|
| 1253 |
+
}
|
| 1254 |
+
},
|
| 1255 |
+
"node_modules/send": {
|
| 1256 |
+
"version": "1.2.1",
|
| 1257 |
+
"resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz",
|
| 1258 |
+
"integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==",
|
| 1259 |
+
"license": "MIT",
|
| 1260 |
+
"dependencies": {
|
| 1261 |
+
"debug": "^4.4.3",
|
| 1262 |
+
"encodeurl": "^2.0.0",
|
| 1263 |
+
"escape-html": "^1.0.3",
|
| 1264 |
+
"etag": "^1.8.1",
|
| 1265 |
+
"fresh": "^2.0.0",
|
| 1266 |
+
"http-errors": "^2.0.1",
|
| 1267 |
+
"mime-types": "^3.0.2",
|
| 1268 |
+
"ms": "^2.1.3",
|
| 1269 |
+
"on-finished": "^2.4.1",
|
| 1270 |
+
"range-parser": "^1.2.1",
|
| 1271 |
+
"statuses": "^2.0.2"
|
| 1272 |
+
},
|
| 1273 |
+
"engines": {
|
| 1274 |
+
"node": ">= 18"
|
| 1275 |
+
},
|
| 1276 |
+
"funding": {
|
| 1277 |
+
"type": "opencollective",
|
| 1278 |
+
"url": "https://opencollective.com/express"
|
| 1279 |
+
}
|
| 1280 |
+
},
|
| 1281 |
+
"node_modules/serve-static": {
|
| 1282 |
+
"version": "2.2.1",
|
| 1283 |
+
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz",
|
| 1284 |
+
"integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==",
|
| 1285 |
+
"license": "MIT",
|
| 1286 |
+
"dependencies": {
|
| 1287 |
+
"encodeurl": "^2.0.0",
|
| 1288 |
+
"escape-html": "^1.0.3",
|
| 1289 |
+
"parseurl": "^1.3.3",
|
| 1290 |
+
"send": "^1.2.0"
|
| 1291 |
+
},
|
| 1292 |
+
"engines": {
|
| 1293 |
+
"node": ">= 18"
|
| 1294 |
+
},
|
| 1295 |
+
"funding": {
|
| 1296 |
+
"type": "opencollective",
|
| 1297 |
+
"url": "https://opencollective.com/express"
|
| 1298 |
+
}
|
| 1299 |
+
},
|
| 1300 |
+
"node_modules/setprototypeof": {
|
| 1301 |
+
"version": "1.2.0",
|
| 1302 |
+
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
| 1303 |
+
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
| 1304 |
+
"license": "ISC"
|
| 1305 |
+
},
|
| 1306 |
+
"node_modules/side-channel": {
|
| 1307 |
+
"version": "1.1.0",
|
| 1308 |
+
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
|
| 1309 |
+
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
|
| 1310 |
+
"license": "MIT",
|
| 1311 |
+
"dependencies": {
|
| 1312 |
+
"es-errors": "^1.3.0",
|
| 1313 |
+
"object-inspect": "^1.13.3",
|
| 1314 |
+
"side-channel-list": "^1.0.0",
|
| 1315 |
+
"side-channel-map": "^1.0.1",
|
| 1316 |
+
"side-channel-weakmap": "^1.0.2"
|
| 1317 |
+
},
|
| 1318 |
+
"engines": {
|
| 1319 |
+
"node": ">= 0.4"
|
| 1320 |
+
},
|
| 1321 |
+
"funding": {
|
| 1322 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1323 |
+
}
|
| 1324 |
+
},
|
| 1325 |
+
"node_modules/side-channel-list": {
|
| 1326 |
+
"version": "1.0.0",
|
| 1327 |
+
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
|
| 1328 |
+
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
|
| 1329 |
+
"license": "MIT",
|
| 1330 |
+
"dependencies": {
|
| 1331 |
+
"es-errors": "^1.3.0",
|
| 1332 |
+
"object-inspect": "^1.13.3"
|
| 1333 |
+
},
|
| 1334 |
+
"engines": {
|
| 1335 |
+
"node": ">= 0.4"
|
| 1336 |
+
},
|
| 1337 |
+
"funding": {
|
| 1338 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1339 |
+
}
|
| 1340 |
+
},
|
| 1341 |
+
"node_modules/side-channel-map": {
|
| 1342 |
+
"version": "1.0.1",
|
| 1343 |
+
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
| 1344 |
+
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
| 1345 |
+
"license": "MIT",
|
| 1346 |
+
"dependencies": {
|
| 1347 |
+
"call-bound": "^1.0.2",
|
| 1348 |
+
"es-errors": "^1.3.0",
|
| 1349 |
+
"get-intrinsic": "^1.2.5",
|
| 1350 |
+
"object-inspect": "^1.13.3"
|
| 1351 |
+
},
|
| 1352 |
+
"engines": {
|
| 1353 |
+
"node": ">= 0.4"
|
| 1354 |
+
},
|
| 1355 |
+
"funding": {
|
| 1356 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1357 |
+
}
|
| 1358 |
+
},
|
| 1359 |
+
"node_modules/side-channel-weakmap": {
|
| 1360 |
+
"version": "1.0.2",
|
| 1361 |
+
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
| 1362 |
+
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
| 1363 |
+
"license": "MIT",
|
| 1364 |
+
"dependencies": {
|
| 1365 |
+
"call-bound": "^1.0.2",
|
| 1366 |
+
"es-errors": "^1.3.0",
|
| 1367 |
+
"get-intrinsic": "^1.2.5",
|
| 1368 |
+
"object-inspect": "^1.13.3",
|
| 1369 |
+
"side-channel-map": "^1.0.1"
|
| 1370 |
+
},
|
| 1371 |
+
"engines": {
|
| 1372 |
+
"node": ">= 0.4"
|
| 1373 |
+
},
|
| 1374 |
+
"funding": {
|
| 1375 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1376 |
+
}
|
| 1377 |
+
},
|
| 1378 |
+
"node_modules/sift": {
|
| 1379 |
+
"version": "17.1.3",
|
| 1380 |
+
"resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz",
|
| 1381 |
+
"integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==",
|
| 1382 |
+
"license": "MIT"
|
| 1383 |
+
},
|
| 1384 |
+
"node_modules/simple-update-notifier": {
|
| 1385 |
+
"version": "2.0.0",
|
| 1386 |
+
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
|
| 1387 |
+
"integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==",
|
| 1388 |
+
"license": "MIT",
|
| 1389 |
+
"dependencies": {
|
| 1390 |
+
"semver": "^7.5.3"
|
| 1391 |
+
},
|
| 1392 |
+
"engines": {
|
| 1393 |
+
"node": ">=10"
|
| 1394 |
+
}
|
| 1395 |
+
},
|
| 1396 |
+
"node_modules/sparse-bitfield": {
|
| 1397 |
+
"version": "3.0.3",
|
| 1398 |
+
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
|
| 1399 |
+
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
|
| 1400 |
+
"license": "MIT",
|
| 1401 |
+
"dependencies": {
|
| 1402 |
+
"memory-pager": "^1.0.2"
|
| 1403 |
+
}
|
| 1404 |
+
},
|
| 1405 |
+
"node_modules/statuses": {
|
| 1406 |
+
"version": "2.0.2",
|
| 1407 |
+
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
|
| 1408 |
+
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
|
| 1409 |
+
"license": "MIT",
|
| 1410 |
+
"engines": {
|
| 1411 |
+
"node": ">= 0.8"
|
| 1412 |
+
}
|
| 1413 |
+
},
|
| 1414 |
+
"node_modules/supports-color": {
|
| 1415 |
+
"version": "5.5.0",
|
| 1416 |
+
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
| 1417 |
+
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
| 1418 |
+
"license": "MIT",
|
| 1419 |
+
"dependencies": {
|
| 1420 |
+
"has-flag": "^3.0.0"
|
| 1421 |
+
},
|
| 1422 |
+
"engines": {
|
| 1423 |
+
"node": ">=4"
|
| 1424 |
+
}
|
| 1425 |
+
},
|
| 1426 |
+
"node_modules/to-regex-range": {
|
| 1427 |
+
"version": "5.0.1",
|
| 1428 |
+
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
| 1429 |
+
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
| 1430 |
+
"license": "MIT",
|
| 1431 |
+
"dependencies": {
|
| 1432 |
+
"is-number": "^7.0.0"
|
| 1433 |
+
},
|
| 1434 |
+
"engines": {
|
| 1435 |
+
"node": ">=8.0"
|
| 1436 |
+
}
|
| 1437 |
+
},
|
| 1438 |
+
"node_modules/toidentifier": {
|
| 1439 |
+
"version": "1.0.1",
|
| 1440 |
+
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
| 1441 |
+
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
| 1442 |
+
"license": "MIT",
|
| 1443 |
+
"engines": {
|
| 1444 |
+
"node": ">=0.6"
|
| 1445 |
+
}
|
| 1446 |
+
},
|
| 1447 |
+
"node_modules/touch": {
|
| 1448 |
+
"version": "3.1.1",
|
| 1449 |
+
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz",
|
| 1450 |
+
"integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==",
|
| 1451 |
+
"license": "ISC",
|
| 1452 |
+
"bin": {
|
| 1453 |
+
"nodetouch": "bin/nodetouch.js"
|
| 1454 |
+
}
|
| 1455 |
+
},
|
| 1456 |
+
"node_modules/tr46": {
|
| 1457 |
+
"version": "5.1.1",
|
| 1458 |
+
"resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz",
|
| 1459 |
+
"integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==",
|
| 1460 |
+
"license": "MIT",
|
| 1461 |
+
"dependencies": {
|
| 1462 |
+
"punycode": "^2.3.1"
|
| 1463 |
+
},
|
| 1464 |
+
"engines": {
|
| 1465 |
+
"node": ">=18"
|
| 1466 |
+
}
|
| 1467 |
+
},
|
| 1468 |
+
"node_modules/type-is": {
|
| 1469 |
+
"version": "2.0.1",
|
| 1470 |
+
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz",
|
| 1471 |
+
"integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==",
|
| 1472 |
+
"license": "MIT",
|
| 1473 |
+
"dependencies": {
|
| 1474 |
+
"content-type": "^1.0.5",
|
| 1475 |
+
"media-typer": "^1.1.0",
|
| 1476 |
+
"mime-types": "^3.0.0"
|
| 1477 |
+
},
|
| 1478 |
+
"engines": {
|
| 1479 |
+
"node": ">= 0.6"
|
| 1480 |
+
}
|
| 1481 |
+
},
|
| 1482 |
+
"node_modules/undefsafe": {
|
| 1483 |
+
"version": "2.0.5",
|
| 1484 |
+
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
| 1485 |
+
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
|
| 1486 |
+
"license": "MIT"
|
| 1487 |
+
},
|
| 1488 |
+
"node_modules/unpipe": {
|
| 1489 |
+
"version": "1.0.0",
|
| 1490 |
+
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
| 1491 |
+
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
| 1492 |
+
"license": "MIT",
|
| 1493 |
+
"engines": {
|
| 1494 |
+
"node": ">= 0.8"
|
| 1495 |
+
}
|
| 1496 |
+
},
|
| 1497 |
+
"node_modules/vary": {
|
| 1498 |
+
"version": "1.1.2",
|
| 1499 |
+
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
| 1500 |
+
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
| 1501 |
+
"license": "MIT",
|
| 1502 |
+
"engines": {
|
| 1503 |
+
"node": ">= 0.8"
|
| 1504 |
+
}
|
| 1505 |
+
},
|
| 1506 |
+
"node_modules/webidl-conversions": {
|
| 1507 |
+
"version": "7.0.0",
|
| 1508 |
+
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
| 1509 |
+
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
| 1510 |
+
"license": "BSD-2-Clause",
|
| 1511 |
+
"engines": {
|
| 1512 |
+
"node": ">=12"
|
| 1513 |
+
}
|
| 1514 |
+
},
|
| 1515 |
+
"node_modules/whatwg-url": {
|
| 1516 |
+
"version": "14.2.0",
|
| 1517 |
+
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz",
|
| 1518 |
+
"integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==",
|
| 1519 |
+
"license": "MIT",
|
| 1520 |
+
"dependencies": {
|
| 1521 |
+
"tr46": "^5.1.0",
|
| 1522 |
+
"webidl-conversions": "^7.0.0"
|
| 1523 |
+
},
|
| 1524 |
+
"engines": {
|
| 1525 |
+
"node": ">=18"
|
| 1526 |
+
}
|
| 1527 |
+
},
|
| 1528 |
+
"node_modules/wrappy": {
|
| 1529 |
+
"version": "1.0.2",
|
| 1530 |
+
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
| 1531 |
+
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
| 1532 |
+
"license": "ISC"
|
| 1533 |
+
}
|
| 1534 |
+
}
|
| 1535 |
+
}
|
backend/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "backend",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "",
|
| 5 |
+
"main": "index.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "nodemon index.js"
|
| 8 |
+
},
|
| 9 |
+
"keywords": [],
|
| 10 |
+
"author": "",
|
| 11 |
+
"license": "ISC",
|
| 12 |
+
"type": "module",
|
| 13 |
+
"dependencies": {
|
| 14 |
+
"compression": "^1.8.1",
|
| 15 |
+
"cors": "^2.8.5",
|
| 16 |
+
"dotenv": "^17.2.3",
|
| 17 |
+
"express": "^5.2.1",
|
| 18 |
+
"mongoose": "^9.0.2",
|
| 19 |
+
"morgan": "^1.10.1",
|
| 20 |
+
"nodemon": "^3.1.11"
|
| 21 |
+
}
|
| 22 |
+
}
|
backend/routes/authRoutes.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import {
|
| 3 |
+
setupAdmin,
|
| 4 |
+
login,
|
| 5 |
+
logout,
|
| 6 |
+
getUsers,
|
| 7 |
+
createUser,
|
| 8 |
+
deleteUser,
|
| 9 |
+
updateUser,
|
| 10 |
+
checkAdmin,
|
| 11 |
+
getCurrentUser,
|
| 12 |
+
getTenants,
|
| 13 |
+
getTenantProfile,
|
| 14 |
+
createTenantOwner,
|
| 15 |
+
updateTenantProfile,
|
| 16 |
+
updateTenantStatus,
|
| 17 |
+
} from "../controller/authController.js";
|
| 18 |
+
import { protect } from "../middleware/authMiddleware.js";
|
| 19 |
+
|
| 20 |
+
const router = Router();
|
| 21 |
+
|
| 22 |
+
router.get("/has-admin", checkAdmin);
|
| 23 |
+
router.post("/setup", setupAdmin);
|
| 24 |
+
router.post("/login", login);
|
| 25 |
+
router.post("/logout", protect, logout);
|
| 26 |
+
router.get("/me", protect, getCurrentUser);
|
| 27 |
+
router.get("/users", protect, getUsers);
|
| 28 |
+
router.post("/users", protect, createUser);
|
| 29 |
+
router.patch("/users/:id", protect, updateUser);
|
| 30 |
+
router.delete("/users/:id", protect, deleteUser);
|
| 31 |
+
router.get("/tenants", protect, getTenants);
|
| 32 |
+
router.post("/tenants", protect, createTenantOwner);
|
| 33 |
+
router.patch("/tenants/:id/status", protect, updateTenantStatus);
|
| 34 |
+
router.get("/tenant-profile", protect, getTenantProfile);
|
| 35 |
+
router.put("/tenant-profile", protect, updateTenantProfile);
|
| 36 |
+
|
| 37 |
+
export default router;
|
backend/routes/customerRoutes.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import {
|
| 3 |
+
createCustomer,
|
| 4 |
+
getCustomerById,
|
| 5 |
+
getCustomers,
|
| 6 |
+
deleteCustomer,
|
| 7 |
+
} from "../controller/customerController.js";
|
| 8 |
+
import { authorize, protect, requireTenantUser } from "../middleware/authMiddleware.js";
|
| 9 |
+
|
| 10 |
+
const router = Router();
|
| 11 |
+
|
| 12 |
+
router.use(protect, requireTenantUser);
|
| 13 |
+
|
| 14 |
+
router.post("/create", createCustomer);
|
| 15 |
+
router.get("/", getCustomers);
|
| 16 |
+
router.get("/:id", getCustomerById);
|
| 17 |
+
router.delete("/:id", authorize("owner", "admin"), deleteCustomer);
|
| 18 |
+
|
| 19 |
+
export default router;
|
backend/routes/expenseRoutes.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import { addExpense, deleteExpense } from "../controller/expenseController.js";
|
| 3 |
+
import { authorize, protect, requireTenantUser } from "../middleware/authMiddleware.js";
|
| 4 |
+
|
| 5 |
+
const router = Router();
|
| 6 |
+
|
| 7 |
+
router.use(protect, requireTenantUser, authorize("owner", "admin"));
|
| 8 |
+
|
| 9 |
+
router.post("/", addExpense);
|
| 10 |
+
router.delete("/:id", deleteExpense);
|
| 11 |
+
|
| 12 |
+
export default router;
|
backend/routes/invoiceRoutes.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import {
|
| 3 |
+
addItemToInvoice,
|
| 4 |
+
deleteInvoiceItem,
|
| 5 |
+
getInvoiceById,
|
| 6 |
+
getInvoices,
|
| 7 |
+
getInvoicesByCustomer,
|
| 8 |
+
payInvoice,
|
| 9 |
+
updateInvoiceItem,
|
| 10 |
+
} from "../controller/invoiceController.js";
|
| 11 |
+
import { protect, requireTenantUser } from "../middleware/authMiddleware.js";
|
| 12 |
+
|
| 13 |
+
const router = Router();
|
| 14 |
+
|
| 15 |
+
router.use(protect, requireTenantUser);
|
| 16 |
+
|
| 17 |
+
router.post("/:customerId/items", addItemToInvoice);
|
| 18 |
+
router.get("/", getInvoices);
|
| 19 |
+
router.get("/customer/:customerId", getInvoicesByCustomer);
|
| 20 |
+
router.get("/:id", getInvoiceById);
|
| 21 |
+
router.delete('/:invoiceId/:itemId', deleteInvoiceItem);
|
| 22 |
+
router.put("/:invoiceId/items/:itemId", updateInvoiceItem);
|
| 23 |
+
router.post("/:customerId/pay", payInvoice);
|
| 24 |
+
|
| 25 |
+
export default router;
|
backend/routes/productRoutes.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import {
|
| 3 |
+
createProduct,
|
| 4 |
+
getProducts,
|
| 5 |
+
updateProduct,
|
| 6 |
+
deleteProduct,
|
| 7 |
+
} from "../controller/productController.js";
|
| 8 |
+
import { authorize, protect, requireTenantUser } from "../middleware/authMiddleware.js";
|
| 9 |
+
|
| 10 |
+
const router = Router();
|
| 11 |
+
|
| 12 |
+
router.use(protect, requireTenantUser);
|
| 13 |
+
|
| 14 |
+
router.post("/", authorize("owner", "admin"), createProduct);
|
| 15 |
+
router.get("/", getProducts);
|
| 16 |
+
router.put("/:id", authorize("owner", "admin"), updateProduct);
|
| 17 |
+
router.delete("/:id", authorize("owner", "admin"), deleteProduct);
|
| 18 |
+
|
| 19 |
+
export default router;
|
backend/routes/reportRoutes.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import { getDailyReport, getDashboardOverview } from "../controller/reportController.js";
|
| 3 |
+
import { authorize, protect, requireTenantUser } from "../middleware/authMiddleware.js";
|
| 4 |
+
|
| 5 |
+
const router = Router();
|
| 6 |
+
|
| 7 |
+
router.use(protect, requireTenantUser, authorize("owner", "admin"));
|
| 8 |
+
|
| 9 |
+
router.get("/overview", getDashboardOverview);
|
| 10 |
+
router.get("/daily", getDailyReport);
|
| 11 |
+
|
| 12 |
+
export default router;
|
backend/routes/supplierRoutes.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router } from "express";
|
| 2 |
+
import {
|
| 3 |
+
createSupplier,
|
| 4 |
+
getSuppliers,
|
| 5 |
+
getSupplierById,
|
| 6 |
+
deleteSupplier,
|
| 7 |
+
addPurchasesToSupplier,
|
| 8 |
+
paySupplier,
|
| 9 |
+
} from "../controller/supplierController.js";
|
| 10 |
+
import { authorize, protect, requireTenantUser } from "../middleware/authMiddleware.js";
|
| 11 |
+
|
| 12 |
+
const router = Router();
|
| 13 |
+
|
| 14 |
+
router.use(protect, requireTenantUser, authorize("owner", "admin"));
|
| 15 |
+
|
| 16 |
+
router.post("/create", createSupplier);
|
| 17 |
+
router.get("/", getSuppliers);
|
| 18 |
+
router.get("/:id", getSupplierById);
|
| 19 |
+
router.delete("/:id", deleteSupplier);
|
| 20 |
+
router.post("/:id/items", addPurchasesToSupplier);
|
| 21 |
+
router.post("/:id/pay", paySupplier);
|
| 22 |
+
|
| 23 |
+
export default router;
|
backend/utils/authCookies.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import crypto from "crypto";
|
| 2 |
+
|
| 3 |
+
export const AUTH_COOKIE_NAME = "sales_system_session";
|
| 4 |
+
|
| 5 |
+
const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1000;
|
| 6 |
+
|
| 7 |
+
export const createSessionToken = () => crypto.randomBytes(32).toString("hex");
|
| 8 |
+
|
| 9 |
+
export const getAuthCookieOptions = () => ({
|
| 10 |
+
httpOnly: true,
|
| 11 |
+
sameSite: "lax",
|
| 12 |
+
secure: process.env.NODE_ENV === "production",
|
| 13 |
+
maxAge: SEVEN_DAYS_IN_MS,
|
| 14 |
+
path: "/",
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
export const getClearCookieOptions = () => ({
|
| 18 |
+
httpOnly: true,
|
| 19 |
+
sameSite: "lax",
|
| 20 |
+
secure: process.env.NODE_ENV === "production",
|
| 21 |
+
path: "/",
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
export const setAuthCookie = (res, token) => {
|
| 25 |
+
res.cookie(AUTH_COOKIE_NAME, token, getAuthCookieOptions());
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
export const clearAuthCookie = (res) => {
|
| 29 |
+
res.clearCookie(AUTH_COOKIE_NAME, getClearCookieOptions());
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
export const parseCookies = (cookieHeader = "") =>
|
| 33 |
+
cookieHeader.split(";").reduce((cookies, rawCookie) => {
|
| 34 |
+
const [name, ...valueParts] = rawCookie.trim().split("=");
|
| 35 |
+
|
| 36 |
+
if (!name) {
|
| 37 |
+
return cookies;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
cookies[name] = decodeURIComponent(valueParts.join("="));
|
| 41 |
+
return cookies;
|
| 42 |
+
}, {});
|
| 43 |
+
|
| 44 |
+
export const toSlug = (value = "") =>
|
| 45 |
+
value
|
| 46 |
+
.toString()
|
| 47 |
+
.trim()
|
| 48 |
+
.toLowerCase()
|
| 49 |
+
.replace(/[^a-z0-9]+/g, "-")
|
| 50 |
+
.replace(/^-+|-+$/g, "")
|
| 51 |
+
.replace(/-{2,}/g, "-");
|
| 52 |
+
|
| 53 |
+
export const buildTenantCredentialsWhatsApp = ({
|
| 54 |
+
companyName,
|
| 55 |
+
ownerName,
|
| 56 |
+
username,
|
| 57 |
+
temporaryPassword,
|
| 58 |
+
loginUrl,
|
| 59 |
+
}) => {
|
| 60 |
+
const message = [
|
| 61 |
+
`مرحباً ${ownerName || "صاحب النشاط"}`,
|
| 62 |
+
`تم إنشاء حساب نشاطك التجاري على منصة ${companyName}.`,
|
| 63 |
+
`اسم المستخدم: ${username}`,
|
| 64 |
+
`كلمة المرور المؤقتة: ${temporaryPassword}`,
|
| 65 |
+
`رابط الدخول: ${loginUrl}`,
|
| 66 |
+
"يرجى تسجيل الدخول وتغيير كلمة المرور بعد أول استخدام.",
|
| 67 |
+
].join("\n");
|
| 68 |
+
|
| 69 |
+
return {
|
| 70 |
+
message,
|
| 71 |
+
whatsappLink: `https://wa.me/?text=${encodeURIComponent(message)}`,
|
| 72 |
+
};
|
| 73 |
+
};
|
frontend/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
VITE_API_URL=http://localhost:5000
|
frontend/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
frontend/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# React + Vite
|
| 2 |
+
|
| 3 |
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
| 4 |
+
|
| 5 |
+
Currently, two official plugins are available:
|
| 6 |
+
|
| 7 |
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
| 8 |
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
| 9 |
+
|
| 10 |
+
## React Compiler
|
| 11 |
+
|
| 12 |
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
| 13 |
+
|
| 14 |
+
## Expanding the ESLint configuration
|
| 15 |
+
|
| 16 |
+
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
frontend/eslint.config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import js from '@eslint/js'
|
| 2 |
+
import globals from 'globals'
|
| 3 |
+
import reactHooks from 'eslint-plugin-react-hooks'
|
| 4 |
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
| 5 |
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
| 6 |
+
|
| 7 |
+
export default defineConfig([
|
| 8 |
+
globalIgnores(['dist']),
|
| 9 |
+
{
|
| 10 |
+
files: ['**/*.{js,jsx}'],
|
| 11 |
+
extends: [
|
| 12 |
+
js.configs.recommended,
|
| 13 |
+
reactHooks.configs.flat.recommended,
|
| 14 |
+
reactRefresh.configs.vite,
|
| 15 |
+
],
|
| 16 |
+
languageOptions: {
|
| 17 |
+
ecmaVersion: 2020,
|
| 18 |
+
globals: globals.browser,
|
| 19 |
+
parserOptions: {
|
| 20 |
+
ecmaVersion: 'latest',
|
| 21 |
+
ecmaFeatures: { jsx: true },
|
| 22 |
+
sourceType: 'module',
|
| 23 |
+
},
|
| 24 |
+
},
|
| 25 |
+
rules: {
|
| 26 |
+
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
| 27 |
+
},
|
| 28 |
+
},
|
| 29 |
+
])
|
frontend/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="ar">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>نظام إدارة المبيعات </title>
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div id="root" dir="rtl"></div>
|
| 11 |
+
<script type="module" src="/src/main.jsx"></script>
|
| 12 |
+
</body>
|
| 13 |
+
</html>
|
frontend/main.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* global require */
|
| 2 |
+
const { app, BrowserWindow } = require('electron');
|
| 3 |
+
|
| 4 |
+
function createWindow() {
|
| 5 |
+
const win = new BrowserWindow({
|
| 6 |
+
width: 1000,
|
| 7 |
+
height: 700,
|
| 8 |
+
});
|
| 9 |
+
|
| 10 |
+
win.loadURL('http://localhost:5173/'); // React app
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
app.whenReady().then(createWindow);
|
frontend/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "weak4",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"electron": "electron main.js",
|
| 9 |
+
"build": "vite build",
|
| 10 |
+
"dist": "electron-builder --win",
|
| 11 |
+
"lint": "eslint .",
|
| 12 |
+
"preview": "vite preview"
|
| 13 |
+
},
|
| 14 |
+
"dependencies": {
|
| 15 |
+
"@tanstack/react-query": "^5.90.12",
|
| 16 |
+
"axios": "^1.13.2",
|
| 17 |
+
"formik": "^2.4.9",
|
| 18 |
+
"lucide-react": "^0.561.0",
|
| 19 |
+
"react": "^18.2.0",
|
| 20 |
+
"react-dom": "^18.2.0",
|
| 21 |
+
"react-icons": "^5.5.0",
|
| 22 |
+
"react-router-dom": "^7.10.1",
|
| 23 |
+
"react-slick": "^0.31.0",
|
| 24 |
+
"react-toastify": "^11.0.5",
|
| 25 |
+
"slick-carousel": "^1.8.1",
|
| 26 |
+
"yup": "^1.7.1"
|
| 27 |
+
},
|
| 28 |
+
"devDependencies": {
|
| 29 |
+
"@eslint/js": "^9.39.1",
|
| 30 |
+
"@tailwindcss/vite": "^4.1.18",
|
| 31 |
+
"@types/react": "^18.2.7",
|
| 32 |
+
"@types/react-dom": "^18.2.4",
|
| 33 |
+
"@vitejs/plugin-react": "^5.1.1",
|
| 34 |
+
"electron": "^25.2.0",
|
| 35 |
+
"electron-builder": "^26.8.1",
|
| 36 |
+
"eslint": "^9.39.1",
|
| 37 |
+
"eslint-plugin-react-hooks": "^7.0.1",
|
| 38 |
+
"eslint-plugin-react-refresh": "^0.4.24",
|
| 39 |
+
"globals": "^16.5.0",
|
| 40 |
+
"tailwindcss": "^4.1.18",
|
| 41 |
+
"vite": "^7.2.7"
|
| 42 |
+
},
|
| 43 |
+
"build": {
|
| 44 |
+
"appId": "com.weak4.app",
|
| 45 |
+
"productName": "Weak4",
|
| 46 |
+
"files": [
|
| 47 |
+
"dist/**/*",
|
| 48 |
+
"main.js",
|
| 49 |
+
"package.json"
|
| 50 |
+
],
|
| 51 |
+
"directories": {
|
| 52 |
+
"buildResources": "assets"
|
| 53 |
+
},
|
| 54 |
+
"win": {
|
| 55 |
+
"target": "nsis"
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
}
|
frontend/src/App.jsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { RouterProvider } from "react-router-dom";
|
| 2 |
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
| 3 |
+
import { routes } from './routes/routes';
|
| 4 |
+
import { ToastContainer } from "react-toastify";
|
| 5 |
+
import "react-toastify/dist/ReactToastify.css";
|
| 6 |
+
import axios from "axios";
|
| 7 |
+
import { AuthProvider } from "./Context/AuthContext";
|
| 8 |
+
|
| 9 |
+
axios.defaults.withCredentials = true;
|
| 10 |
+
|
| 11 |
+
const queryClient = new QueryClient();
|
| 12 |
+
|
| 13 |
+
const App = () => {
|
| 14 |
+
return (
|
| 15 |
+
<QueryClientProvider client={queryClient}>
|
| 16 |
+
<AuthProvider>
|
| 17 |
+
<RouterProvider router={routes} />
|
| 18 |
+
<ToastContainer
|
| 19 |
+
position="top-right"
|
| 20 |
+
autoClose={3000}
|
| 21 |
+
hideProgressBar={false}
|
| 22 |
+
closeOnClick
|
| 23 |
+
pauseOnHover
|
| 24 |
+
rtl={true}
|
| 25 |
+
/>
|
| 26 |
+
</AuthProvider>
|
| 27 |
+
</QueryClientProvider>
|
| 28 |
+
);
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
export default App;
|
frontend/src/Context/AuthContext.jsx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint-disable react-refresh/only-export-components */
|
| 2 |
+
import { createContext, useContext, useEffect, useState } from "react";
|
| 3 |
+
import axios from "axios";
|
| 4 |
+
|
| 5 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 6 |
+
const AuthContext = createContext(null);
|
| 7 |
+
|
| 8 |
+
export const AuthProvider = ({ children }) => {
|
| 9 |
+
const [user, setUser] = useState(null);
|
| 10 |
+
const [isBootstrapping, setIsBootstrapping] = useState(true);
|
| 11 |
+
|
| 12 |
+
const refreshSession = async () => {
|
| 13 |
+
try {
|
| 14 |
+
const res = await axios.get(`${apiUrl}/auth/me`);
|
| 15 |
+
setUser(res.data.user || null);
|
| 16 |
+
return res.data.user || null;
|
| 17 |
+
} catch {
|
| 18 |
+
setUser(null);
|
| 19 |
+
return null;
|
| 20 |
+
} finally {
|
| 21 |
+
setIsBootstrapping(false);
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
useEffect(() => {
|
| 26 |
+
refreshSession();
|
| 27 |
+
}, []);
|
| 28 |
+
|
| 29 |
+
const login = async (credentials) => {
|
| 30 |
+
const res = await axios.post(`${apiUrl}/auth/login`, credentials);
|
| 31 |
+
setUser(res.data.user || null);
|
| 32 |
+
return res.data;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
const logout = async () => {
|
| 36 |
+
try {
|
| 37 |
+
await axios.post(`${apiUrl}/auth/logout`);
|
| 38 |
+
} finally {
|
| 39 |
+
setUser(null);
|
| 40 |
+
}
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
return (
|
| 44 |
+
<AuthContext.Provider value={{ user, setUser, login, logout, refreshSession, isBootstrapping }}>
|
| 45 |
+
{children}
|
| 46 |
+
</AuthContext.Provider>
|
| 47 |
+
);
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
export const useAuth = () => {
|
| 51 |
+
const context = useContext(AuthContext);
|
| 52 |
+
|
| 53 |
+
if (!context) {
|
| 54 |
+
throw new Error("useAuth must be used within AuthProvider");
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return context;
|
| 58 |
+
};
|
frontend/src/common/LoaderSpinner.jsx
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
const LodderSpinner = () => {
|
| 3 |
+
return (
|
| 4 |
+
<div className="flex items-center justify-center w-full min-h-dvh">
|
| 5 |
+
<div
|
| 6 |
+
className="border-4 border-gray-300 border-t-black rounded-full animate-spin"
|
| 7 |
+
style={{ width: 40, height: 40 }}
|
| 8 |
+
/>
|
| 9 |
+
</div>)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export default LodderSpinner;
|
frontend/src/common/Pagination.jsx
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* A reusable Pagination component designed with the system's premium aesthetic.
|
| 5 |
+
*
|
| 6 |
+
* @param {Object} props
|
| 7 |
+
* @param {number} props.currentPage - Current active page (1-indexed)
|
| 8 |
+
* @param {number} props.totalPages - Total number of pages
|
| 9 |
+
* @param {function} props.onPageChange - Callback when page is changed
|
| 10 |
+
* @param {number} props.totalItems - Total count of items
|
| 11 |
+
* @param {number} props.limit - Items per page
|
| 12 |
+
*/
|
| 13 |
+
const Pagination = ({ currentPage, totalPages, onPageChange, totalItems, limit }) => {
|
| 14 |
+
if (totalPages <= 1) return null;
|
| 15 |
+
|
| 16 |
+
const startItem = (currentPage - 1) * limit + 1;
|
| 17 |
+
const endItem = Math.min(currentPage * limit, totalItems);
|
| 18 |
+
|
| 19 |
+
const getPageNumbers = () => {
|
| 20 |
+
const pages = [];
|
| 21 |
+
const showPages = 5;
|
| 22 |
+
let start = Math.max(1, currentPage - Math.floor(showPages / 2));
|
| 23 |
+
let end = Math.min(totalPages, start + showPages - 1);
|
| 24 |
+
|
| 25 |
+
if (end - start + 1 < showPages) {
|
| 26 |
+
start = Math.max(1, end - showPages + 1);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
for (let i = start; i <= end; i++) {
|
| 30 |
+
pages.push(i);
|
| 31 |
+
}
|
| 32 |
+
return pages;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
return (
|
| 36 |
+
<div className="flex flex-col items-center justify-between gap-4 border-t border-slate-100 p-5 md:flex-row">
|
| 37 |
+
<div className="text-sm font-medium text-slate-500">
|
| 38 |
+
عرض <span className="font-bold text-slate-900">{startItem}-{endItem}</span> من <span className="font-bold text-slate-900">{totalItems}</span> عنصر
|
| 39 |
+
</div>
|
| 40 |
+
|
| 41 |
+
<div className="flex items-center gap-2">
|
| 42 |
+
<button
|
| 43 |
+
type="button"
|
| 44 |
+
disabled={currentPage === 1}
|
| 45 |
+
onClick={() => onPageChange(currentPage - 1)}
|
| 46 |
+
className="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white text-slate-600 transition hover:bg-slate-50 disabled:opacity-40 disabled:hover:bg-white"
|
| 47 |
+
>
|
| 48 |
+
<ChevronRight size={18} />
|
| 49 |
+
</button>
|
| 50 |
+
|
| 51 |
+
<div className="flex items-center gap-1">
|
| 52 |
+
{getPageNumbers().map((page) => (
|
| 53 |
+
<button
|
| 54 |
+
key={page}
|
| 55 |
+
type="button"
|
| 56 |
+
onClick={() => onPageChange(page)}
|
| 57 |
+
className={`flex h-10 w-10 items-center justify-center rounded-xl font-bold transition ${
|
| 58 |
+
currentPage === page
|
| 59 |
+
? "bg-emerald-600 text-white shadow-lg shadow-emerald-600/20"
|
| 60 |
+
: "border border-transparent bg-transparent text-slate-600 hover:bg-slate-100"
|
| 61 |
+
}`}
|
| 62 |
+
>
|
| 63 |
+
{page}
|
| 64 |
+
</button>
|
| 65 |
+
))}
|
| 66 |
+
|
| 67 |
+
{totalPages > 5 && getPageNumbers()[getPageNumbers().length - 1] < totalPages && (
|
| 68 |
+
<>
|
| 69 |
+
<span className="px-1 text-slate-400">...</span>
|
| 70 |
+
<button
|
| 71 |
+
type="button"
|
| 72 |
+
onClick={() => onPageChange(totalPages)}
|
| 73 |
+
className={`flex h-10 w-10 items-center justify-center rounded-xl font-bold transition border border-transparent bg-transparent text-slate-600 hover:bg-slate-100`}
|
| 74 |
+
>
|
| 75 |
+
{totalPages}
|
| 76 |
+
</button>
|
| 77 |
+
</>
|
| 78 |
+
)}
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<button
|
| 82 |
+
type="button"
|
| 83 |
+
disabled={currentPage === totalPages}
|
| 84 |
+
onClick={() => onPageChange(currentPage + 1)}
|
| 85 |
+
className="flex h-10 w-10 items-center justify-center rounded-xl border border-slate-200 bg-white text-slate-600 transition hover:bg-slate-50 disabled:opacity-40 disabled:hover:bg-white"
|
| 86 |
+
>
|
| 87 |
+
<ChevronLeft size={18} />
|
| 88 |
+
</button>
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
);
|
| 92 |
+
};
|
| 93 |
+
|
| 94 |
+
export default Pagination;
|
frontend/src/components/AddCustomer.jsx
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
| 3 |
+
import { toast } from "react-toastify";
|
| 4 |
+
import { UserPlus, User, CheckCircle, X, Loader2 } from "lucide-react";
|
| 5 |
+
import { useFormik } from "formik";
|
| 6 |
+
import * as Yup from "yup";
|
| 7 |
+
|
| 8 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 9 |
+
|
| 10 |
+
const AddCustomer = () => {
|
| 11 |
+
const queryClient = useQueryClient();
|
| 12 |
+
|
| 13 |
+
const createCustomer = async (data) => {
|
| 14 |
+
const res = await axios.post(
|
| 15 |
+
`${apiUrl}/customers/create`,
|
| 16 |
+
{ name: data.name }
|
| 17 |
+
);
|
| 18 |
+
return res.data;
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
const { mutate, isPending } = useMutation({
|
| 22 |
+
mutationFn: createCustomer,
|
| 23 |
+
onSuccess: () => {
|
| 24 |
+
formik.resetForm();
|
| 25 |
+
queryClient.invalidateQueries({ queryKey: ["customers"] });
|
| 26 |
+
toast.success("تم إضافة العميل بنجاح ✅");
|
| 27 |
+
},
|
| 28 |
+
onError: (error) => {
|
| 29 |
+
const message =
|
| 30 |
+
error.response?.data?.message ||
|
| 31 |
+
error.message ||
|
| 32 |
+
"حدث خطأ غير متوقع";
|
| 33 |
+
toast.error(message);
|
| 34 |
+
}
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
const formik = useFormik({
|
| 38 |
+
initialValues: { name: "" },
|
| 39 |
+
validationSchema: Yup.object({
|
| 40 |
+
name: Yup.string()
|
| 41 |
+
.required("يرجى إدخال اسم العميل")
|
| 42 |
+
.matches(/^[\u0600-\u06FFa-zA-Z\s]+$/, "يجب أن يحتوي الاسم على حروف فقط")
|
| 43 |
+
.min(3, "الاسم يجب أن يكون 3 حروف على الأقل")
|
| 44 |
+
}),
|
| 45 |
+
onSubmit: (values) => mutate(values)
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
return (
|
| 51 |
+
<div className="bg-white border border-slate-200 w-full mb-8 rounded-2xl p-6 shadow-sm shadow-slate-200/50 relative overflow-hidden" dir="rtl">
|
| 52 |
+
{/* Decorative top border */}
|
| 53 |
+
<div className="absolute top-0 right-0 w-full h-1.5 bg-gradient-to-l from-emerald-400 via-emerald-500 to-teal-600"></div>
|
| 54 |
+
|
| 55 |
+
<div className="flex items-center gap-3 mb-6 mt-2">
|
| 56 |
+
<div className="w-12 h-12 rounded-full bg-emerald-50 flex items-center justify-center text-emerald-600 shadow-inner">
|
| 57 |
+
<UserPlus size={26} />
|
| 58 |
+
</div>
|
| 59 |
+
<div>
|
| 60 |
+
<h3 className="text-xl md:text-2xl font-bold text-slate-800">إضافة عميل جديد</h3>
|
| 61 |
+
<p className="text-sm text-slate-500 mt-1">قم بتسجيل بيانات العميل الجديد لفتح حساب له وإصدار الفواتير.</p>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
|
| 65 |
+
<div className="flex flex-col md:flex-row gap-4 items-start md:items-start">
|
| 66 |
+
<div className="relative w-full flex-1">
|
| 67 |
+
<div className="absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 bg-slate-50/80 p-1 rounded-md">
|
| 68 |
+
<User size={20} />
|
| 69 |
+
</div>
|
| 70 |
+
<input
|
| 71 |
+
name="name"
|
| 72 |
+
type="text"
|
| 73 |
+
placeholder="أدخل اسم العميل (مثال: محمد أحمد)"
|
| 74 |
+
value={formik.values.name}
|
| 75 |
+
onChange={formik.handleChange}
|
| 76 |
+
onBlur={formik.handleBlur}
|
| 77 |
+
className={`w-full pr-14 pl-4 py-3.5 md:text-lg bg-slate-50 border ${formik.touched.name && formik.errors.name ? 'border-rose-400 focus:ring-rose-500' : 'border-slate-200 focus:ring-emerald-500'} rounded-xl focus:outline-none focus:ring-2 focus:bg-white transition-all placeholder:text-slate-400 font-medium text-slate-700`}
|
| 78 |
+
/>
|
| 79 |
+
{formik.touched.name && formik.errors.name && (
|
| 80 |
+
<p className="absolute -bottom-6 right-2 text-rose-500 text-xs font-bold">{formik.errors.name}</p>
|
| 81 |
+
)}
|
| 82 |
+
</div>
|
| 83 |
+
|
| 84 |
+
<div className="flex items-center gap-3 w-full md:w-auto mt-2 md:mt-0">
|
| 85 |
+
<button
|
| 86 |
+
onClick={formik.handleSubmit}
|
| 87 |
+
disabled={isPending}
|
| 88 |
+
className="flex-1 md:flex-none flex items-center justify-center gap-2 bg-emerald-600 text-white px-8 py-3.5 rounded-xl hover:bg-emerald-700 font-bold md:text-lg shadow-sm transition-all shadow-emerald-600/20 disabled:opacity-70 disabled:cursor-not-allowed hover:-translate-y-0.5 whitespace-nowrap"
|
| 89 |
+
>
|
| 90 |
+
{isPending ? (
|
| 91 |
+
<>
|
| 92 |
+
<Loader2 className="animate-spin" size={20} />
|
| 93 |
+
<span>جاري الحفظ...</span>
|
| 94 |
+
</>
|
| 95 |
+
) : (
|
| 96 |
+
<>
|
| 97 |
+
<CheckCircle size={20} />
|
| 98 |
+
<span>حفظ العميل</span>
|
| 99 |
+
</>
|
| 100 |
+
)}
|
| 101 |
+
</button>
|
| 102 |
+
|
| 103 |
+
<button
|
| 104 |
+
type="button"
|
| 105 |
+
className="flex-1 md:flex-none flex items-center justify-center gap-2 bg-white border border-slate-200 px-6 py-3.5 rounded-xl text-slate-600 hover:bg-slate-50 hover:text-rose-600 hover:border-rose-200 font-bold md:text-lg transition-all whitespace-nowrap shadow-sm"
|
| 106 |
+
onClick={() => formik.resetForm()}
|
| 107 |
+
>
|
| 108 |
+
<X size={20} />
|
| 109 |
+
<span>إلغاء</span>
|
| 110 |
+
</button>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
);
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
export default AddCustomer;
|
frontend/src/components/CustomerDetails/CustomerDetails.jsx
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
import { useParams, useNavigate } from "react-router-dom";
|
| 3 |
+
import { useQuery } from "@tanstack/react-query";
|
| 4 |
+
import LodderSpinner from "../../common/LoaderSpinner";
|
| 5 |
+
import {
|
| 6 |
+
ArrowLeft,
|
| 7 |
+
Calendar,
|
| 8 |
+
FileText,
|
| 9 |
+
AlertCircle,
|
| 10 |
+
CheckCircle,
|
| 11 |
+
Clock,
|
| 12 |
+
Pencil,
|
| 13 |
+
ClipboardList,
|
| 14 |
+
MessageCircle,
|
| 15 |
+
Printer,
|
| 16 |
+
Wallet,
|
| 17 |
+
} from "lucide-react";
|
| 18 |
+
import { useState } from "react";
|
| 19 |
+
import EditInvoiceItemModal from "./EditInvoiceItemModal";
|
| 20 |
+
import DeleteInvoiceItemButton from "../InvoiceItemsModal/DeleteItemAtInvoice";
|
| 21 |
+
import PayInvoiceModal from "./PayInvoiceModal";
|
| 22 |
+
import { useAuth } from "../../Context/AuthContext";
|
| 23 |
+
import { getPermissions } from "../../utils/permissions";
|
| 24 |
+
import { buildCustomerInvoiceMessage, openWhatsAppMessage } from "../../utils/whatsapp";
|
| 25 |
+
|
| 26 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 27 |
+
|
| 28 |
+
const CustomerDetails = () => {
|
| 29 |
+
const { id } = useParams();
|
| 30 |
+
const navigate = useNavigate();
|
| 31 |
+
const { user } = useAuth();
|
| 32 |
+
const permissions = getPermissions(user);
|
| 33 |
+
const companyName = user?.tenant?.name || "نظام إدارة المبيعات";
|
| 34 |
+
const [openEditModel, setOpenEditModel] = useState(false);
|
| 35 |
+
const [selectedItem, setSelectedItem] = useState(null);
|
| 36 |
+
const [openPayModal, setOpenPayModal] = useState(false);
|
| 37 |
+
|
| 38 |
+
const getCustomerDetails = () => axios.get(`${apiUrl}/customers/${id}`);
|
| 39 |
+
|
| 40 |
+
const { data, isLoading } = useQuery({
|
| 41 |
+
queryKey: ["customer", id],
|
| 42 |
+
queryFn: getCustomerDetails,
|
| 43 |
+
refetchOnWindowFocus: false,
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
if (isLoading) return <LodderSpinner />;
|
| 47 |
+
|
| 48 |
+
const customer = data?.data;
|
| 49 |
+
const customerID = customer?._id;
|
| 50 |
+
const invoice = customer?.invoice;
|
| 51 |
+
const invoiceID = customer?.invoice?._id;
|
| 52 |
+
|
| 53 |
+
const handleShareWhatsApp = () => {
|
| 54 |
+
if (!invoice) return;
|
| 55 |
+
openWhatsAppMessage(
|
| 56 |
+
buildCustomerInvoiceMessage({
|
| 57 |
+
companyName,
|
| 58 |
+
customerName: customer.name,
|
| 59 |
+
invoice,
|
| 60 |
+
})
|
| 61 |
+
);
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
const handlePrint = () => {
|
| 65 |
+
window.open(`/print/invoice/${customerID}`, "_blank", "width=800,height=800");
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
const getStatusBadge = (status) => {
|
| 69 |
+
const map = {
|
| 70 |
+
paid: {
|
| 71 |
+
label: "مدفوعة",
|
| 72 |
+
color: "bg-emerald-100 text-emerald-800 border-emerald-200",
|
| 73 |
+
icon: <CheckCircle size={16} />,
|
| 74 |
+
},
|
| 75 |
+
unpaid: {
|
| 76 |
+
label: "غير مدفوعة",
|
| 77 |
+
color: "bg-rose-100 text-rose-800 border-rose-200",
|
| 78 |
+
icon: <AlertCircle size={16} />,
|
| 79 |
+
},
|
| 80 |
+
partial: {
|
| 81 |
+
label: "مدفوعة جزئياً",
|
| 82 |
+
color: "bg-amber-100 text-amber-800 border-amber-200",
|
| 83 |
+
icon: <Clock size={16} />,
|
| 84 |
+
},
|
| 85 |
+
open: {
|
| 86 |
+
label: "مفتوحة",
|
| 87 |
+
color: "bg-rose-100 text-rose-800 border-rose-200",
|
| 88 |
+
icon: <AlertCircle size={16} />,
|
| 89 |
+
},
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
const item = map[status] || map.unpaid;
|
| 93 |
+
|
| 94 |
+
return (
|
| 95 |
+
<span className={`${item.color} border px-4 py-1.5 rounded-full text-sm font-bold flex items-center gap-2 w-fit shadow-sm`}>
|
| 96 |
+
{item.icon}
|
| 97 |
+
{item.label}
|
| 98 |
+
</span>
|
| 99 |
+
);
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
function handleOpenEditModel(item) {
|
| 103 |
+
setOpenEditModel(!openEditModel);
|
| 104 |
+
setSelectedItem(item);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
function closeEditModel() {
|
| 108 |
+
setOpenEditModel(false);
|
| 109 |
+
setSelectedItem(null);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
return (
|
| 113 |
+
<div className="min-h-screen bg-slate-50 p-4 lg:p-8" dir="rtl">
|
| 114 |
+
<div className="max-w-6xl mx-auto space-y-6">
|
| 115 |
+
<div className="bg-white rounded-2xl p-6 md:p-8 shadow-sm shadow-slate-200/50 border border-slate-200 relative overflow-hidden">
|
| 116 |
+
<div className="absolute top-0 right-0 w-2 h-full bg-gradient-to-b from-amber-400 to-amber-600"></div>
|
| 117 |
+
|
| 118 |
+
<button onClick={() => navigate(-1)} className="flex items-center gap-2 cursor-pointer text-slate-500 hover:text-slate-900 mb-6 w-fit hover:translate-x-1 transition-transform bg-slate-50 px-4 py-2 rounded-xl border border-slate-100 font-medium">
|
| 119 |
+
<ArrowLeft size={18} /> العودة للقائمة
|
| 120 |
+
</button>
|
| 121 |
+
|
| 122 |
+
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
| 123 |
+
<div>
|
| 124 |
+
<h1 className="text-3xl font-black text-slate-800 mb-2 flex items-center gap-3">
|
| 125 |
+
<div className="w-14 h-14 rounded-full bg-slate-100 flex items-center justify-center text-slate-500 text-2xl shadow-inner font-bold border border-slate-200">
|
| 126 |
+
{customer?.name?.charAt(0)}
|
| 127 |
+
</div>
|
| 128 |
+
{customer?.name}
|
| 129 |
+
</h1>
|
| 130 |
+
<div className="flex items-center gap-2 text-slate-500 mt-3 font-medium bg-slate-50 w-fit px-4 py-2 rounded-lg border border-slate-100">
|
| 131 |
+
<Calendar size={18} className="text-amber-500" />
|
| 132 |
+
<span>
|
| 133 |
+
عميل منذ <span className="text-slate-700 font-bold">{new Date(customer?.createdAt).toLocaleDateString("ar-EG")}</span>
|
| 134 |
+
</span>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
+
{!invoice ? (
|
| 141 |
+
<div className="bg-white rounded-2xl p-16 text-center shadow-sm shadow-slate-200/50 border border-slate-200 flex flex-col items-center justify-center">
|
| 142 |
+
<div className="w-24 h-24 bg-slate-50 rounded-full flex items-center justify-center mb-6">
|
| 143 |
+
<FileText size={48} className="text-slate-300" />
|
| 144 |
+
</div>
|
| 145 |
+
<h3 className="text-2xl font-bold text-slate-700 mb-2">لا توجد فاتورة نشطة</h3>
|
| 146 |
+
<p className="text-slate-500 max-w-md">هذا العميل ليس لديه أي بنود فاتورة مسجلة بعد.</p>
|
| 147 |
+
</div>
|
| 148 |
+
) : (
|
| 149 |
+
<div className="bg-white rounded-2xl p-6 md:p-8 shadow-sm shadow-slate-200/50 border border-slate-200 space-y-8">
|
| 150 |
+
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 pb-6 border-b border-slate-100">
|
| 151 |
+
<div className="flex flex-col md:flex-row items-start md:items-center gap-4">
|
| 152 |
+
<div className="flex items-center gap-4">
|
| 153 |
+
<h2 className="text-xl font-bold text-slate-800 flex items-center gap-2">
|
| 154 |
+
<FileText size={24} className="text-amber-500" /> حالة الحساب
|
| 155 |
+
</h2>
|
| 156 |
+
{getStatusBadge(invoice.status)}
|
| 157 |
+
</div>
|
| 158 |
+
|
| 159 |
+
<div className="flex items-center gap-2 border-r-0 md:border-r border-slate-200 pr-0 md:pr-4 pt-2 md:pt-0">
|
| 160 |
+
<button onClick={handleShareWhatsApp} className="flex items-center gap-2 px-4 py-2 bg-emerald-50 text-emerald-600 rounded-lg hover:bg-emerald-600 hover:text-white transition-colors font-bold text-sm border border-emerald-100 shadow-sm">
|
| 161 |
+
<MessageCircle size={18} />
|
| 162 |
+
<span className="hidden md:inline">مشاركة عبر واتساب</span>
|
| 163 |
+
</button>
|
| 164 |
+
<button onClick={handlePrint} className="flex items-center gap-2 px-4 py-2 bg-slate-50 text-slate-600 rounded-lg hover:bg-slate-800 hover:text-white transition-colors font-bold text-sm border border-slate-200 shadow-sm">
|
| 165 |
+
<Printer size={18} />
|
| 166 |
+
<span className="hidden md:inline">طباعة الفاتورة</span>
|
| 167 |
+
</button>
|
| 168 |
+
</div>
|
| 169 |
+
</div>
|
| 170 |
+
<span className="text-sm text-slate-500 font-medium flex items-center gap-2 bg-slate-50 px-4 py-2 rounded-lg border border-slate-100">
|
| 171 |
+
<Clock size={16} className="text-slate-400" /> آخر تحديث: {new Date(invoice.updatedAt).toLocaleString("ar-EG")}
|
| 172 |
+
</span>
|
| 173 |
+
</div>
|
| 174 |
+
|
| 175 |
+
<div className="bg-slate-50 rounded-2xl p-5 md:p-6 border border-slate-100 shadow-inner">
|
| 176 |
+
<h3 className="font-bold text-lg text-slate-800 mb-5 flex items-center gap-2">
|
| 177 |
+
<ClipboardList size={20} className="text-amber-500" /> بنود الفاتورة
|
| 178 |
+
</h3>
|
| 179 |
+
|
| 180 |
+
{invoice.items.length === 0 ? (
|
| 181 |
+
<p className="text-slate-500 text-center py-8 bg-white rounded-xl border border-slate-100">لا توجد بنود في هذه الفاتورة</p>
|
| 182 |
+
) : (
|
| 183 |
+
<div className="space-y-3">
|
| 184 |
+
{invoice.items.map((item) => (
|
| 185 |
+
<div key={item._id} className="flex flex-col md:flex-row justify-between items-start md:items-center bg-white border border-slate-200 rounded-xl p-4 shadow-sm hover:shadow-md transition-shadow group">
|
| 186 |
+
<div className="mb-3 md:mb-0">
|
| 187 |
+
<span className="text-lg font-bold text-slate-800 block mb-2">{item.name}</span>
|
| 188 |
+
<span className="text-sm font-medium text-slate-600 bg-slate-100 px-3 py-1.5 rounded-lg border border-slate-200 flex items-center gap-2 w-fit">
|
| 189 |
+
<span>الكمية: <b className="text-amber-600">{item.quantity}</b></span>
|
| 190 |
+
<span className="w-1 h-1 bg-slate-300 rounded-full"></span>
|
| 191 |
+
<span>السعر: <b>{item.price}</b> ج.م</span>
|
| 192 |
+
</span>
|
| 193 |
+
</div>
|
| 194 |
+
|
| 195 |
+
<div className="flex items-center gap-4 border-t md:border-t-0 border-slate-100 pt-3 md:pt-0 w-full md:w-auto justify-between md:justify-end">
|
| 196 |
+
<span className="font-black text-lg text-slate-800 bg-emerald-50 text-emerald-700 px-4 py-2 rounded-lg border border-emerald-100 shadow-sm">
|
| 197 |
+
{item.total.toFixed(2)} <span className="text-sm font-normal opacity-80">ج.م</span>
|
| 198 |
+
</span>
|
| 199 |
+
|
| 200 |
+
<div className="flex items-center gap-2">
|
| 201 |
+
{permissions.canEditInvoice ? (
|
| 202 |
+
<button onClick={() => handleOpenEditModel(item)} className="p-2.5 text-blue-600 bg-blue-50 border border-blue-100 rounded-lg hover:bg-blue-600 hover:text-white transition-colors" title="تعديل البند">
|
| 203 |
+
<Pencil size={18} />
|
| 204 |
+
</button>
|
| 205 |
+
) : null}
|
| 206 |
+
{permissions.canEditInvoice ? (
|
| 207 |
+
<DeleteInvoiceItemButton customerId={customerID} invoiceId={invoiceID} itemId={item._id} />
|
| 208 |
+
) : null}
|
| 209 |
+
</div>
|
| 210 |
+
</div>
|
| 211 |
+
</div>
|
| 212 |
+
))}
|
| 213 |
+
</div>
|
| 214 |
+
)}
|
| 215 |
+
</div>
|
| 216 |
+
|
| 217 |
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 pt-4 border-t border-slate-100 mb-6">
|
| 218 |
+
<Summary title="إجمالي الفاتورة" value={invoice.totalAmount} type="blue" />
|
| 219 |
+
<Summary title="المدفوع حتى الآن" value={invoice.paidAmount} type="green" />
|
| 220 |
+
<Summary title="الرصيد المتبقي" value={invoice.remainingAmount} type="red" />
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
{invoice.payments?.length > 0 && (
|
| 224 |
+
<div className="mt-8 bg-emerald-50/50 rounded-2xl p-5 md:p-6 border border-emerald-100 mb-6 group hover:shadow-sm transition-all">
|
| 225 |
+
<h3 className="font-bold text-lg text-emerald-800 mb-4 flex items-center gap-2">
|
| 226 |
+
<Clock size={20} className="text-emerald-500" /> سجل المدفوعات
|
| 227 |
+
</h3>
|
| 228 |
+
<div className="space-y-3">
|
| 229 |
+
{invoice.payments.map((payment) => (
|
| 230 |
+
<div key={payment._id || payment.date} className="flex justify-between items-center bg-white border border-emerald-100 rounded-xl p-3 shadow-sm hover:border-emerald-200 transition-colors">
|
| 231 |
+
<div className="flex items-center gap-3">
|
| 232 |
+
<div className="w-10 h-10 rounded-full bg-emerald-100 flex items-center justify-center text-emerald-600">
|
| 233 |
+
<CheckCircle size={18} />
|
| 234 |
+
</div>
|
| 235 |
+
<div>
|
| 236 |
+
<p className="font-bold text-slate-700 leading-tight">دفعة {payment.method || 'نقدية'}</p>
|
| 237 |
+
<p className="text-slate-500 text-sm mt-1">{new Date(payment.date).toLocaleString("ar-EG")}</p>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
<span className="font-black text-emerald-700 bg-emerald-50 px-4 py-2 rounded-xl border border-emerald-100 shadow-sm">
|
| 241 |
+
+{payment.amount.toFixed(2)} <span className="text-xs font-normal opacity-70">ج.م</span>
|
| 242 |
+
</span>
|
| 243 |
+
</div>
|
| 244 |
+
))}
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
)}
|
| 248 |
+
|
| 249 |
+
{permissions.canRecordPayments && invoice.remainingAmount > 0 && (
|
| 250 |
+
<div className="flex justify-center md:justify-start pt-6 border-t border-slate-100">
|
| 251 |
+
<button onClick={() => setOpenPayModal(true)} className="w-full md:w-auto flex items-center justify-center gap-3 bg-emerald-600 text-white px-8 py-3.5 rounded-xl hover:bg-emerald-700 font-bold shadow-sm shadow-emerald-500/20 transition-all hover:-translate-y-0.5 text-lg">
|
| 252 |
+
<Wallet size={24} /> تسجيل دفعة
|
| 253 |
+
</button>
|
| 254 |
+
</div>
|
| 255 |
+
)}
|
| 256 |
+
</div>
|
| 257 |
+
)}
|
| 258 |
+
</div>
|
| 259 |
+
{permissions.canEditInvoice && openEditModel && selectedItem ? <EditInvoiceItemModal customerId={customerID} onClose={closeEditModel} invoiceId={invoiceID} item={selectedItem} /> : null}
|
| 260 |
+
{permissions.canRecordPayments && openPayModal ? <PayInvoiceModal customerId={customerID} remainingAmount={invoice.remainingAmount} onClose={() => setOpenPayModal(false)} /> : null}
|
| 261 |
+
</div>
|
| 262 |
+
);
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
const Summary = ({ title, value, type }) => {
|
| 266 |
+
const variants = {
|
| 267 |
+
blue: "bg-blue-50 border-blue-100 text-blue-700",
|
| 268 |
+
green: "bg-emerald-50 border-emerald-100 text-emerald-700",
|
| 269 |
+
red: "bg-rose-50 border-rose-100 text-rose-700",
|
| 270 |
+
};
|
| 271 |
+
|
| 272 |
+
const valueColor = {
|
| 273 |
+
blue: "text-blue-700",
|
| 274 |
+
green: "text-emerald-700",
|
| 275 |
+
red: "text-rose-600",
|
| 276 |
+
};
|
| 277 |
+
|
| 278 |
+
return (
|
| 279 |
+
<div className={`${variants[type]} border rounded-2xl p-5 flex flex-col items-center justify-center text-center shadow-sm hover:-translate-y-1 transition-transform`}>
|
| 280 |
+
<p className="text-sm font-bold opacity-80 mb-2">{title}</p>
|
| 281 |
+
<p className={`text-2xl font-black ${valueColor[type]} drop-shadow-sm`}>
|
| 282 |
+
{value.toFixed(2)} <span className="text-sm font-normal opacity-80">ج.م</span>
|
| 283 |
+
</p>
|
| 284 |
+
</div>
|
| 285 |
+
);
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
export default CustomerDetails;
|
frontend/src/components/CustomerDetails/EditInvoiceItemModal.jsx
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { X, Save, Box, Hash, Banknote, Loader2 } from "lucide-react";
|
| 2 |
+
import { useState } from "react";
|
| 3 |
+
import axios from "axios";
|
| 4 |
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
| 5 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 6 |
+
|
| 7 |
+
const EditInvoiceItemModal = ({ customerId, invoiceId, item, onClose }) => {
|
| 8 |
+
const queryClient = useQueryClient();
|
| 9 |
+
const [form, setForm] = useState({
|
| 10 |
+
name: item.name,
|
| 11 |
+
quantity: item.quantity,
|
| 12 |
+
price: item.price
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
const updateItem = async () => {
|
| 16 |
+
const res = await axios.put(
|
| 17 |
+
`${apiUrl}/invoices/${invoiceId}/items/${item._id}`,
|
| 18 |
+
form
|
| 19 |
+
);
|
| 20 |
+
return res.data;
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
const { mutate, isPending } = useMutation({
|
| 24 |
+
mutationFn: updateItem,
|
| 25 |
+
onSuccess: () => {
|
| 26 |
+
queryClient.invalidateQueries({
|
| 27 |
+
queryKey: ["customer", customerId],
|
| 28 |
+
});
|
| 29 |
+
onClose();
|
| 30 |
+
},
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
return (
|
| 34 |
+
<div className="fixed inset-0 flex items-center justify-center z-50 bg-slate-900/40 backdrop-blur-sm p-4" >
|
| 35 |
+
<div className="bg-white w-full max-w-md rounded-2xl shadow-2xl border border-slate-200 overflow-hidden transform transition-all">
|
| 36 |
+
|
| 37 |
+
{/* Header */}
|
| 38 |
+
<div className="bg-slate-50 border-b border-slate-100 p-4 md:p-6 flex items-center justify-between relative">
|
| 39 |
+
<div className="absolute top-0 right-0 w-1.5 h-full bg-blue-500"></div>
|
| 40 |
+
<div className="flex items-center gap-3">
|
| 41 |
+
<div className="p-2 border border-blue-100 bg-white text-blue-600 rounded-lg shadow-sm">
|
| 42 |
+
<Box size={20} />
|
| 43 |
+
</div>
|
| 44 |
+
<h2 className="text-xl font-bold text-slate-800">
|
| 45 |
+
تعديل بيانات الصنف
|
| 46 |
+
</h2>
|
| 47 |
+
</div>
|
| 48 |
+
|
| 49 |
+
<button
|
| 50 |
+
onClick={onClose}
|
| 51 |
+
className="p-2 text-slate-400 hover:text-rose-500 hover:bg-rose-50 rounded-full transition-colors cursor-pointer"
|
| 52 |
+
title="إغلاق"
|
| 53 |
+
>
|
| 54 |
+
<X size={24} />
|
| 55 |
+
</button>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
{/* Body */}
|
| 59 |
+
<div className="p-4 md:p-6 space-y-5">
|
| 60 |
+
|
| 61 |
+
{/* Name */}
|
| 62 |
+
<div>
|
| 63 |
+
<label className="block text-sm font-bold text-slate-700 mb-1.5">اسم الصنف</label>
|
| 64 |
+
<div className="relative">
|
| 65 |
+
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400">
|
| 66 |
+
<Box size={18} />
|
| 67 |
+
</span>
|
| 68 |
+
<input
|
| 69 |
+
type="text"
|
| 70 |
+
value={form.name}
|
| 71 |
+
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
| 72 |
+
className="w-full bg-white border border-slate-200 rounded-xl py-3 pr-10 pl-4 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all text-slate-800 font-medium placeholder:text-slate-400"
|
| 73 |
+
placeholder="أدخل اسم البند (مثال: سلك 2 ملي)"
|
| 74 |
+
/>
|
| 75 |
+
</div>
|
| 76 |
+
</div>
|
| 77 |
+
|
| 78 |
+
{/* Quantity & Price Grid */}
|
| 79 |
+
<div className="grid grid-cols-2 gap-4">
|
| 80 |
+
{/* Quantity */}
|
| 81 |
+
<div>
|
| 82 |
+
<label className="block text-sm font-bold text-slate-700 mb-1.5">الكمية</label>
|
| 83 |
+
<div className="relative">
|
| 84 |
+
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400">
|
| 85 |
+
<Hash size={18} />
|
| 86 |
+
</span>
|
| 87 |
+
<input
|
| 88 |
+
type="number"
|
| 89 |
+
min="1"
|
| 90 |
+
value={form.quantity}
|
| 91 |
+
onChange={(e) => setForm({ ...form, quantity: Number(e.target.value) })}
|
| 92 |
+
className="w-full bg-white border border-slate-200 rounded-xl py-3 pr-10 pl-4 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all text-slate-800 font-medium placeholder:text-slate-400"
|
| 93 |
+
placeholder="الكمية"
|
| 94 |
+
/>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
{/* Price */}
|
| 99 |
+
<div>
|
| 100 |
+
<label className="block text-sm font-bold text-slate-700 mb-1.5">السعر (ج.م)</label>
|
| 101 |
+
<div className="relative">
|
| 102 |
+
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400">
|
| 103 |
+
<Banknote size={18} />
|
| 104 |
+
</span>
|
| 105 |
+
<input
|
| 106 |
+
type="number"
|
| 107 |
+
min="0"
|
| 108 |
+
value={form.price}
|
| 109 |
+
onChange={(e) => setForm({ ...form, price: Number(e.target.value) })}
|
| 110 |
+
className="w-full bg-white border border-slate-200 rounded-xl py-3 pr-10 pl-4 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all text-slate-800 font-bold text-left focus:text-right text-blue-700"
|
| 111 |
+
placeholder="0.00"
|
| 112 |
+
/>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
+
{/* Subtotal preview */}
|
| 118 |
+
<div className="flex items-center justify-between bg-blue-50 border border-blue-100 p-3 rounded-lg mx-1 mt-2">
|
| 119 |
+
<span className="text-sm font-bold text-blue-800">إجمالي الصنف:</span>
|
| 120 |
+
<span className="text-lg font-black text-blue-700">
|
| 121 |
+
{(Number(form.price || 0) * Number(form.quantity || 0)).toFixed(2)} <span className="text-sm font-normal opacity-80">ج.م</span>
|
| 122 |
+
</span>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
{/* Footer */}
|
| 127 |
+
<div className="p-4 md:p-6 bg-slate-50 border-t border-slate-100 flex gap-3">
|
| 128 |
+
<button
|
| 129 |
+
onClick={() => mutate()}
|
| 130 |
+
disabled={isPending || !form.name.trim() || form.quantity <= 0 || form.price < 0}
|
| 131 |
+
className="flex-1 flex items-center justify-center gap-2 bg-blue-600 text-white px-2 py-3 rounded-xl hover:bg-blue-700 font-bold shadow-sm shadow-blue-600/20 disabled:opacity-50 disabled:cursor-not-allowed transition-all hover:-translate-y-0.5"
|
| 132 |
+
>
|
| 133 |
+
{isPending ? (
|
| 134 |
+
<>
|
| 135 |
+
<Loader2 className="animate-spin" size={18} />
|
| 136 |
+
<span>جاري الحفظ...</span>
|
| 137 |
+
</>
|
| 138 |
+
) : (
|
| 139 |
+
<>
|
| 140 |
+
<Save size={18} />
|
| 141 |
+
<span>حفظ التعديلات</span>
|
| 142 |
+
</>
|
| 143 |
+
)}
|
| 144 |
+
</button>
|
| 145 |
+
<button
|
| 146 |
+
onClick={onClose}
|
| 147 |
+
disabled={isPending}
|
| 148 |
+
className="px-6 py-3 bg-white border border-slate-200 text-slate-600 rounded-xl hover:bg-rose-50 hover:text-rose-600 hover:border-rose-200 font-bold transition-all disabled:opacity-50"
|
| 149 |
+
>
|
| 150 |
+
إلغاء
|
| 151 |
+
</button>
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
);
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
export default EditInvoiceItemModal;
|
frontend/src/components/CustomerDetails/PayInvoiceModal.jsx
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { X, Banknote, Loader2, CheckCircle, Wallet } from "lucide-react";
|
| 2 |
+
import { useState } from "react";
|
| 3 |
+
import axios from "axios";
|
| 4 |
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
| 5 |
+
import { toast } from "react-toastify";
|
| 6 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 7 |
+
|
| 8 |
+
const PayInvoiceModal = ({ customerId, remainingAmount, onClose }) => {
|
| 9 |
+
const queryClient = useQueryClient();
|
| 10 |
+
const [amount, setAmount] = useState('');
|
| 11 |
+
|
| 12 |
+
const payInvoice = async () => {
|
| 13 |
+
const numAmount = Number(amount);
|
| 14 |
+
if (numAmount <= 0) throw new Error("يرجى إدخال مبلغ دفع صحيح أكبر من صفر");
|
| 15 |
+
if (numAmount > remainingAmount) throw new Error(`عذراً، المبلغ لا يمكن أن يتخطى إجمالي المتبقي (${remainingAmount.toFixed(2)} ج.م)`);
|
| 16 |
+
|
| 17 |
+
const res = await axios.post(`${apiUrl}/invoices/${customerId}/pay`, {
|
| 18 |
+
amount: numAmount
|
| 19 |
+
});
|
| 20 |
+
return res.data;
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
const { mutate, isPending } = useMutation({
|
| 24 |
+
mutationFn: payInvoice,
|
| 25 |
+
onSuccess: () => {
|
| 26 |
+
queryClient.invalidateQueries({ queryKey: ["customer", customerId] });
|
| 27 |
+
queryClient.invalidateQueries({ queryKey: ["customers"] });
|
| 28 |
+
toast.success("تم تسجيل وتحصيل الدفعة بنجاح 💵");
|
| 29 |
+
onClose();
|
| 30 |
+
},
|
| 31 |
+
onError: (err) => {
|
| 32 |
+
toast.error(err.message || "حدث خطأ أثناء إجراء الدفع");
|
| 33 |
+
}
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
return (
|
| 37 |
+
<div className="fixed inset-0 bg-slate-900/40 backdrop-blur-sm flex items-center justify-center z-50 p-4" dir="rtl">
|
| 38 |
+
<div className="bg-white w-full max-w-sm rounded-2xl shadow-xl border border-slate-200 overflow-hidden transform transition-all animate-in fade-in zoom-in-95">
|
| 39 |
+
|
| 40 |
+
{/* Header */}
|
| 41 |
+
<div className="bg-emerald-50 border-b border-emerald-100 p-5 flex items-center justify-between relative">
|
| 42 |
+
<div className="absolute top-0 right-0 w-1.5 h-full bg-emerald-500"></div>
|
| 43 |
+
<div className="flex items-center gap-3">
|
| 44 |
+
<div className="p-2 border border-emerald-200 bg-white text-emerald-600 rounded-lg shadow-sm">
|
| 45 |
+
<Wallet size={24} />
|
| 46 |
+
</div>
|
| 47 |
+
<h2 className="text-xl font-bold text-emerald-900">
|
| 48 |
+
تحصيل دفعة نقدية
|
| 49 |
+
</h2>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
+
<button
|
| 53 |
+
onClick={onClose}
|
| 54 |
+
className="p-2 text-slate-400 hover:text-rose-500 hover:bg-rose-50 rounded-full transition-colors cursor-pointer"
|
| 55 |
+
title="إغلاق"
|
| 56 |
+
>
|
| 57 |
+
<X size={24} />
|
| 58 |
+
</button>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
{/* Body */}
|
| 62 |
+
<div className="p-5 space-y-5 bg-white">
|
| 63 |
+
|
| 64 |
+
<div className="flex items-center justify-between bg-rose-50 p-3 rounded-lg border border-rose-100">
|
| 65 |
+
<span className="text-rose-700 font-bold text-sm">المديونية المتبقية:</span>
|
| 66 |
+
<span className="text-rose-600 font-black text-lg">{remainingAmount.toFixed(2)} <span className="font-normal text-sm">ج.م</span></span>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<div>
|
| 70 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">المبلغ المُراد تحصيله (كاش)</label>
|
| 71 |
+
<div className="relative">
|
| 72 |
+
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-emerald-500">
|
| 73 |
+
<Banknote size={20} />
|
| 74 |
+
</span>
|
| 75 |
+
<input
|
| 76 |
+
type="number"
|
| 77 |
+
min="1"
|
| 78 |
+
max={remainingAmount}
|
| 79 |
+
value={amount}
|
| 80 |
+
onChange={(e) => setAmount(e.target.value)}
|
| 81 |
+
className="w-full bg-slate-50 border border-emerald-200 rounded-xl py-3.5 pr-10 pl-4 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:bg-white transition-all text-emerald-800 font-black text-lg text-left focus:text-right placeholder:text-slate-400 placeholder:font-medium"
|
| 82 |
+
placeholder="أدخل المبلغ..."
|
| 83 |
+
/>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
{/* Quick Fill Options */}
|
| 88 |
+
<div className="flex gap-2">
|
| 89 |
+
<button onClick={() => setAmount(remainingAmount)} className="flex-1 py-2 bg-emerald-50 text-emerald-700 font-bold text-sm rounded-lg hover:bg-emerald-100 border border-emerald-200 transition-colors">
|
| 90 |
+
تصفية الحساب كامل
|
| 91 |
+
</button>
|
| 92 |
+
{remainingAmount >= 1000 && (
|
| 93 |
+
<button onClick={() => setAmount(1000)} className="flex-1 py-2 bg-slate-50 text-slate-700 font-bold text-sm rounded-lg hover:bg-slate-100 border border-slate-200 transition-colors">
|
| 94 |
+
دفع 1000 ج.م
|
| 95 |
+
</button>
|
| 96 |
+
)}
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
|
| 100 |
+
{/* Footer */}
|
| 101 |
+
<div className="p-5 bg-slate-50 border-t border-slate-100 flex gap-3">
|
| 102 |
+
<button
|
| 103 |
+
onClick={() => mutate()}
|
| 104 |
+
disabled={isPending || !amount || Number(amount) <= 0 || Number(amount) > remainingAmount}
|
| 105 |
+
className="flex-1 flex items-center justify-center gap-2 bg-emerald-600 text-white py-3.5 rounded-xl hover:bg-emerald-700 font-bold shadow-sm shadow-emerald-600/20 disabled:opacity-50 disabled:cursor-not-allowed transition-all hover:-translate-y-0.5"
|
| 106 |
+
>
|
| 107 |
+
{isPending ? (
|
| 108 |
+
<>
|
| 109 |
+
<Loader2 className="animate-spin" size={20} />
|
| 110 |
+
<span>جاري التحصيل...</span>
|
| 111 |
+
</>
|
| 112 |
+
) : (
|
| 113 |
+
<>
|
| 114 |
+
<CheckCircle size={20} />
|
| 115 |
+
<span>تأكيد تسجيل الدفعة</span>
|
| 116 |
+
</>
|
| 117 |
+
)}
|
| 118 |
+
</button>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
);
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
export default PayInvoiceModal;
|
frontend/src/components/CustomerDetails/PrintInvoice.jsx
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect } from "react";
|
| 2 |
+
import { useParams } from "react-router-dom";
|
| 3 |
+
import { useQuery } from "@tanstack/react-query";
|
| 4 |
+
import axios from "axios";
|
| 5 |
+
import LodderSpinner from "../../common/LoaderSpinner";
|
| 6 |
+
import { useAuth } from "../../Context/AuthContext";
|
| 7 |
+
|
| 8 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 9 |
+
|
| 10 |
+
const PrintInvoice = () => {
|
| 11 |
+
const { id } = useParams();
|
| 12 |
+
const { user } = useAuth();
|
| 13 |
+
const companyName = user?.tenant?.name || "نظام إدارة المبيعات";
|
| 14 |
+
const companyDescription = user?.tenant?.address || "نظام محاسبة وفوترة متعدد المستأجرين";
|
| 15 |
+
|
| 16 |
+
const { data, isLoading } = useQuery({
|
| 17 |
+
queryKey: ["customer", id],
|
| 18 |
+
queryFn: () => axios.get(`${apiUrl}/customers/${id}`),
|
| 19 |
+
refetchOnWindowFocus: false,
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
useEffect(() => {
|
| 23 |
+
if (data) {
|
| 24 |
+
setTimeout(() => {
|
| 25 |
+
window.print();
|
| 26 |
+
}, 500);
|
| 27 |
+
}
|
| 28 |
+
}, [data]);
|
| 29 |
+
|
| 30 |
+
if (isLoading) return <LodderSpinner />;
|
| 31 |
+
|
| 32 |
+
const customer = data?.data;
|
| 33 |
+
const invoice = customer?.invoice;
|
| 34 |
+
|
| 35 |
+
if (!invoice) return <div className="p-10 text-center">لا توجد فاتورة لهذا العميل</div>;
|
| 36 |
+
|
| 37 |
+
return (
|
| 38 |
+
<div className="bg-white p-8 max-w-4xl mx-auto text-black font-sans min-h-screen" dir="rtl">
|
| 39 |
+
<style>{`
|
| 40 |
+
@media print {
|
| 41 |
+
@page { margin: 0; size: auto; }
|
| 42 |
+
body { background: white; margin: 1cm; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
| 43 |
+
}
|
| 44 |
+
`}</style>
|
| 45 |
+
|
| 46 |
+
<div className="text-center border-b-2 border-slate-800 pb-6 mb-6">
|
| 47 |
+
<h1 className="text-4xl font-black mb-2">{companyName}</h1>
|
| 48 |
+
<p className="text-xl font-bold">{companyDescription}</p>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<div className="flex justify-between mb-10 pt-2">
|
| 52 |
+
<div>
|
| 53 |
+
<p className="font-bold text-gray-500 mb-1">العميل</p>
|
| 54 |
+
<h2 className="text-3xl font-bold">{customer.name}</h2>
|
| 55 |
+
</div>
|
| 56 |
+
<div className="text-left bg-gray-50 p-4 rounded-xl border border-gray-200">
|
| 57 |
+
<p className="font-bold text-gray-500 mb-1">رقم الفاتورة</p>
|
| 58 |
+
<p className="text-xl font-black"># {invoice.invoiceNumber || invoice._id.slice(-6).toUpperCase()}</p>
|
| 59 |
+
<p className="font-bold text-gray-500 mt-2 mb-1">تاريخ الطباعة</p>
|
| 60 |
+
<p className="text-lg font-bold">{new Date().toLocaleString("ar-EG")}</p>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
|
| 64 |
+
<table className="w-full text-right border-collapse mb-10">
|
| 65 |
+
<thead>
|
| 66 |
+
<tr className="bg-gray-100 border-y-2 border-gray-300">
|
| 67 |
+
<th className="p-4 font-bold text-lg">#</th>
|
| 68 |
+
<th className="p-4 font-bold text-lg">الصنف</th>
|
| 69 |
+
<th className="p-4 font-bold text-lg text-center">الكمية</th>
|
| 70 |
+
<th className="p-4 font-bold text-lg text-center">سعر الوحدة</th>
|
| 71 |
+
<th className="p-4 font-bold text-lg text-right">الإجمالي</th>
|
| 72 |
+
</tr>
|
| 73 |
+
</thead>
|
| 74 |
+
<tbody>
|
| 75 |
+
{invoice.items.map((item, index) => (
|
| 76 |
+
<tr key={index} className="border-b border-gray-200">
|
| 77 |
+
<td className="p-4">{index + 1}</td>
|
| 78 |
+
<td className="p-4 font-black">{item.name}</td>
|
| 79 |
+
<td className="p-4 font-bold text-center">{item.quantity}</td>
|
| 80 |
+
<td className="p-4 text-center">{item.price} ج.م</td>
|
| 81 |
+
<td className="p-4 font-black text-right">{item.total.toFixed(2)} ج.م</td>
|
| 82 |
+
</tr>
|
| 83 |
+
))}
|
| 84 |
+
</tbody>
|
| 85 |
+
</table>
|
| 86 |
+
|
| 87 |
+
<div className="flex justify-start mt-4">
|
| 88 |
+
<div className="w-1/2 p-6 rounded-xl border-4 border-gray-800">
|
| 89 |
+
<div className="flex justify-between mb-4 text-xl">
|
| 90 |
+
<span className="font-bold text-gray-600">إجمالي الفاتورة</span>
|
| 91 |
+
<span className="font-black">{invoice.totalAmount.toFixed(2)} ج.م</span>
|
| 92 |
+
</div>
|
| 93 |
+
<div className="flex justify-between mb-4 text-xl border-b-2 border-gray-300 pb-4">
|
| 94 |
+
<span className="font-bold text-gray-600">المدفوعات المستلمة</span>
|
| 95 |
+
<span className="font-bold text-gray-800">{invoice.paidAmount.toFixed(2)} ج.م</span>
|
| 96 |
+
</div>
|
| 97 |
+
<div className="flex justify-between mt-4 text-2xl">
|
| 98 |
+
<span className="font-black text-black">الرصيد المتبقي</span>
|
| 99 |
+
<span className="font-black text-black">{invoice.remainingAmount.toFixed(2)} ج.م</span>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<div className="text-center mt-16 pt-8 border-t-2 border-dashed border-gray-300">
|
| 105 |
+
<p className="font-black text-2xl mb-2">شكراً لاختياركم {companyName}</p>
|
| 106 |
+
<p className="text-lg text-gray-600 font-bold">هذه النسخة جاهزة للطباعة ويمكن حفظها كملف PDF</p>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
);
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
export default PrintInvoice;
|
frontend/src/components/Customers/Customer.jsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Taps from "../Taps"
|
| 2 |
+
import CustomerBoxView from "./CustomerBoxView"
|
| 3 |
+
import { useQuery } from '@tanstack/react-query';
|
| 4 |
+
import axios from 'axios';
|
| 5 |
+
import LodderSpinner from '../../common/LoaderSpinner';
|
| 6 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
const Customer = () => {
|
| 10 |
+
|
| 11 |
+
function getAllCustomers() {
|
| 12 |
+
return axios.get(`${apiUrl}/customers`)
|
| 13 |
+
}
|
| 14 |
+
const { data, isLoading } = useQuery({
|
| 15 |
+
queryKey: ['customers'],
|
| 16 |
+
queryFn: getAllCustomers,
|
| 17 |
+
refetchOnWindowFocus: false
|
| 18 |
+
})
|
| 19 |
+
if (isLoading) return <LodderSpinner />
|
| 20 |
+
const customerData = data?.data;
|
| 21 |
+
|
| 22 |
+
return (
|
| 23 |
+
<div className="bg-white shadow rounded-2xl py-4">
|
| 24 |
+
<Taps customerData={customerData} />
|
| 25 |
+
</div>
|
| 26 |
+
)
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export default Customer
|
frontend/src/components/Customers/CustomerBoxView.jsx
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Eye, Search, PlusCircle, Inbox } from "lucide-react";
|
| 2 |
+
import { useState } from "react";
|
| 3 |
+
import { Link } from "react-router-dom";
|
| 4 |
+
import InvoiceItemsModal from "../InvoiceItemsModal/InvoiceItemsModal";
|
| 5 |
+
import DeleteCustomerButton from "./DeleteCustomerButton";
|
| 6 |
+
|
| 7 |
+
const CustomerBoxView = ({ customerData }) => {
|
| 8 |
+
const [searchTerm, setSearchTerm] = useState("");
|
| 9 |
+
const [showModal, setShowModal] = useState(false);
|
| 10 |
+
const [activeCustomerId, setActiveCustomerId] = useState(null);
|
| 11 |
+
|
| 12 |
+
const filteredCustomers = customerData?.filter((c) =>
|
| 13 |
+
c.name.toLowerCase().includes(searchTerm.toLowerCase())
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
const openModal = (customerId) => {
|
| 17 |
+
setActiveCustomerId(customerId);
|
| 18 |
+
setShowModal(true);
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
const closeModal = () => {
|
| 22 |
+
setShowModal(false);
|
| 23 |
+
setActiveCustomerId(null);
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
return (
|
| 27 |
+
<div className="m-4">
|
| 28 |
+
{/* Search Input Section */}
|
| 29 |
+
<div className="relative flex-1 max-w-full mb-6">
|
| 30 |
+
<div className="absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 bg-slate-100 p-1.5 rounded-md">
|
| 31 |
+
<Search size={20} />
|
| 32 |
+
</div>
|
| 33 |
+
<input
|
| 34 |
+
type="text"
|
| 35 |
+
placeholder="ابحث عن اسم العميل..."
|
| 36 |
+
value={searchTerm}
|
| 37 |
+
onChange={(e) => setSearchTerm(e.target.value)}
|
| 38 |
+
className="w-full pr-14 pl-4 py-3.5 text-lg bg-white border border-slate-200 rounded-xl shadow-sm focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent transition-all placeholder:text-slate-400"
|
| 39 |
+
dir="rtl"
|
| 40 |
+
/>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
{/* Table Container */}
|
| 44 |
+
<div className="max-h-[500px] overflow-y-auto custom-scroll rounded-2xl bg-white shadow-lg shadow-slate-200/50 border border-slate-100 scroll-smooth">
|
| 45 |
+
<table className="w-full border-collapse text-right" dir="rtl">
|
| 46 |
+
{/* Table Head */}
|
| 47 |
+
<thead className="sticky top-0 bg-slate-50 border-b-2 border-slate-200 z-10">
|
| 48 |
+
<tr className="text-slate-600">
|
| 49 |
+
<th className="p-5 font-bold text-base whitespace-nowrap">اسم العميل</th>
|
| 50 |
+
<th className="p-5 font-bold text-base text-center whitespace-nowrap">تاريخ الإنشاء</th>
|
| 51 |
+
<th className="p-5 font-bold text-base text-center whitespace-nowrap">إجمالي الديون</th>
|
| 52 |
+
<th className="p-5 font-bold text-base text-center whitespace-nowrap">عدد الفواتير</th>
|
| 53 |
+
<th className="p-5 font-bold text-base text-center whitespace-nowrap">الإجراءات</th>
|
| 54 |
+
</tr>
|
| 55 |
+
</thead>
|
| 56 |
+
|
| 57 |
+
{/* Table Body */}
|
| 58 |
+
<tbody className="divide-y divide-slate-100">
|
| 59 |
+
{filteredCustomers?.length > 0 &&
|
| 60 |
+
filteredCustomers.map((customer) => (
|
| 61 |
+
<tr
|
| 62 |
+
key={customer._id}
|
| 63 |
+
className="hover:bg-amber-50/50 transition-colors group"
|
| 64 |
+
>
|
| 65 |
+
<td className="p-5 text-lg font-bold text-slate-800">
|
| 66 |
+
<div className="flex items-center gap-3">
|
| 67 |
+
<div className="w-10 h-10 rounded-full bg-slate-100 flex items-center justify-center text-slate-500 font-bold group-hover:bg-amber-100 group-hover:text-amber-600 transition-colors flex-shrink-0">
|
| 68 |
+
{customer.name.charAt(0)}
|
| 69 |
+
</div>
|
| 70 |
+
<span className="truncate max-w-[200px] block" title={customer.name}>
|
| 71 |
+
{customer.name}
|
| 72 |
+
</span>
|
| 73 |
+
</div>
|
| 74 |
+
</td>
|
| 75 |
+
|
| 76 |
+
<td className="p-5 text-slate-500 font-medium text-center">
|
| 77 |
+
<span className="bg-slate-100 px-3 py-1.5 rounded-full text-sm">
|
| 78 |
+
{new Date(customer.createdAt).toLocaleDateString('ar-EG')}
|
| 79 |
+
</span>
|
| 80 |
+
</td>
|
| 81 |
+
|
| 82 |
+
<td className="p-5 font-bold text-rose-600 text-center text-lg">
|
| 83 |
+
<span className="bg-rose-50 px-3 py-1.5 rounded-lg border border-rose-100 inline-block">
|
| 84 |
+
{Number(customer.totalDebt || 0).toFixed(2)} <span className="text-sm font-normal text-rose-400">ج.م</span>
|
| 85 |
+
</span>
|
| 86 |
+
</td>
|
| 87 |
+
|
| 88 |
+
<td className="p-5 text-center">
|
| 89 |
+
<span className="inline-flex items-center justify-center min-w-[32px] h-8 px-2 rounded-full bg-blue-50 text-blue-700 font-bold text-lg border border-blue-100">
|
| 90 |
+
{customer.invoices?.length || 0}
|
| 91 |
+
</span>
|
| 92 |
+
</td>
|
| 93 |
+
<td className="p-5">
|
| 94 |
+
<div className="flex justify-center gap-2 lg:gap-3 flex-wrap md:flex-nowrap">
|
| 95 |
+
<Link
|
| 96 |
+
to={`/customers/${customer._id}`}
|
| 97 |
+
className="bg-slate-800 text-white px-3 lg:px-4 py-2 rounded-lg hover:bg-slate-900 flex items-center gap-1 lg:gap-2 shadow-sm transition-all hover:shadow-md hover:-translate-y-0.5 whitespace-nowrap"
|
| 98 |
+
>
|
| 99 |
+
<Eye size={18} className="text-amber-400" />
|
| 100 |
+
<span>التفاصيل</span>
|
| 101 |
+
</Link>
|
| 102 |
+
|
| 103 |
+
<button
|
| 104 |
+
onClick={() => openModal(customer._id)}
|
| 105 |
+
className="bg-amber-500 text-white/90 font-bold px-3 lg:px-4 py-2 rounded-lg hover:bg-amber-600 flex items-center justify-center gap-1 lg:gap-2 shadow-sm transition-all hover:shadow-md hover:-translate-y-0.5 whitespace-nowrap"
|
| 106 |
+
>
|
| 107 |
+
<PlusCircle size={18} />
|
| 108 |
+
<span>إضافة بنود</span>
|
| 109 |
+
</button>
|
| 110 |
+
<DeleteCustomerButton customerId={customer._id} customerName={customer.name} />
|
| 111 |
+
</div>
|
| 112 |
+
</td>
|
| 113 |
+
</tr>
|
| 114 |
+
))}
|
| 115 |
+
</tbody>
|
| 116 |
+
</table>
|
| 117 |
+
|
| 118 |
+
{/* Empty State when no characters match search */}
|
| 119 |
+
{filteredCustomers?.length === 0 && customerData?.length > 0 && (
|
| 120 |
+
<div className="flex flex-col items-center justify-center py-16 text-slate-400">
|
| 121 |
+
<Search size={48} className="mb-4 text-slate-300 opacity-50" />
|
| 122 |
+
<p className="text-xl font-medium">عذراً، لم يتم العثور على عميل بهذا الاسم</p>
|
| 123 |
+
</div>
|
| 124 |
+
)}
|
| 125 |
+
|
| 126 |
+
{showModal && activeCustomerId && (
|
| 127 |
+
<InvoiceItemsModal
|
| 128 |
+
customerId={activeCustomerId}
|
| 129 |
+
onClose={closeModal}
|
| 130 |
+
/>
|
| 131 |
+
)}
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
{/* Empty State overall */}
|
| 135 |
+
{(!customerData || customerData.length === 0) && (
|
| 136 |
+
<div className="flex flex-col items-center justify-center p-16 bg-white rounded-2xl shadow-sm border border-slate-100 mt-4">
|
| 137 |
+
<div className="w-24 h-24 bg-slate-50 rounded-full flex items-center justify-center mb-4">
|
| 138 |
+
<Inbox size={48} className="text-slate-300" />
|
| 139 |
+
</div>
|
| 140 |
+
<p className="text-2xl font-bold text-slate-500 mb-2">لا يوجد عملاء مسجلين بعد</p>
|
| 141 |
+
<p className="text-slate-400">قم بإضافة عميل جديد للبدء في إدارة الفواتير والديون</p>
|
| 142 |
+
</div>
|
| 143 |
+
)}
|
| 144 |
+
</div>
|
| 145 |
+
);
|
| 146 |
+
};
|
| 147 |
+
|
| 148 |
+
export default CustomerBoxView;
|
frontend/src/components/Customers/CustomersWorkspace.jsx
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from "react";
|
| 2 |
+
import axios from "axios";
|
| 3 |
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
| 4 |
+
import { Link } from "react-router-dom";
|
| 5 |
+
import { Eye, Loader2, PlusCircle, Search, Trash2, UserRound } from "lucide-react";
|
| 6 |
+
import { useFormik } from "formik";
|
| 7 |
+
import * as Yup from "yup";
|
| 8 |
+
import { toast } from "react-toastify";
|
| 9 |
+
import LodderSpinner from "../../common/LoaderSpinner";
|
| 10 |
+
import InvoiceItemsModal from "../InvoiceItemsModal/InvoiceItemsModal";
|
| 11 |
+
import { useAuth } from "../../Context/AuthContext";
|
| 12 |
+
import { getPermissions } from "../../utils/permissions";
|
| 13 |
+
import { formatCurrency, formatDate, formatNumber } from "../../utils/formatters";
|
| 14 |
+
import Pagination from "../../common/Pagination";
|
| 15 |
+
|
| 16 |
+
const apiUrl = import.meta.env.VITE_API_URL;
|
| 17 |
+
const EMPTY_LIST = [];
|
| 18 |
+
|
| 19 |
+
const CustomersWorkspace = () => {
|
| 20 |
+
const { user } = useAuth();
|
| 21 |
+
const permissions = getPermissions(user);
|
| 22 |
+
const currency = user?.tenant?.settings?.currency || "EGP";
|
| 23 |
+
const queryClient = useQueryClient();
|
| 24 |
+
const [searchTerm, setSearchTerm] = useState("");
|
| 25 |
+
const [page, setPage] = useState(1);
|
| 26 |
+
const [activeCustomerId, setActiveCustomerId] = useState(null);
|
| 27 |
+
const [pendingDeleteId, setPendingDeleteId] = useState(null);
|
| 28 |
+
|
| 29 |
+
const { data: response, isLoading } = useQuery({
|
| 30 |
+
queryKey: ["customers", page, searchTerm],
|
| 31 |
+
queryFn: () => axios.get(`${apiUrl}/customers`, {
|
| 32 |
+
params: {
|
| 33 |
+
page,
|
| 34 |
+
limit: 5,
|
| 35 |
+
search: searchTerm
|
| 36 |
+
}
|
| 37 |
+
}),
|
| 38 |
+
refetchOnWindowFocus: false,
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
const createCustomerMutation = useMutation({
|
| 42 |
+
mutationFn: (values) => axios.post(`${apiUrl}/customers/create`, values),
|
| 43 |
+
onSuccess: () => {
|
| 44 |
+
formik.resetForm();
|
| 45 |
+
queryClient.invalidateQueries({ queryKey: ["customers"] });
|
| 46 |
+
queryClient.invalidateQueries({ queryKey: ["reports", "overview"] });
|
| 47 |
+
toast.success("تم إنشاء حساب العميل");
|
| 48 |
+
},
|
| 49 |
+
onError: (error) => {
|
| 50 |
+
toast.error(error.response?.data?.message || "تعذر إنشاء العميل");
|
| 51 |
+
},
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
const deleteCustomerMutation = useMutation({
|
| 55 |
+
mutationFn: (customerId) => axios.delete(`${apiUrl}/customers/${customerId}`),
|
| 56 |
+
onSuccess: () => {
|
| 57 |
+
queryClient.invalidateQueries({ queryKey: ["customers"] });
|
| 58 |
+
queryClient.invalidateQueries({ queryKey: ["reports", "overview"] });
|
| 59 |
+
toast.success("تم حذف العميل");
|
| 60 |
+
setPendingDeleteId(null);
|
| 61 |
+
},
|
| 62 |
+
onError: (error) => {
|
| 63 |
+
toast.error(error.response?.data?.message || "تعذر حذف العميل");
|
| 64 |
+
setPendingDeleteId(null);
|
| 65 |
+
},
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
const formik = useFormik({
|
| 69 |
+
initialValues: {
|
| 70 |
+
name: "",
|
| 71 |
+
phone: "",
|
| 72 |
+
},
|
| 73 |
+
validationSchema: Yup.object({
|
| 74 |
+
name: Yup.string().required("اسم العميل مطلوب").min(3, "3 أحرف على الأقل"),
|
| 75 |
+
}),
|
| 76 |
+
onSubmit: (values) => createCustomerMutation.mutate(values),
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
const customers = response?.data?.data ?? EMPTY_LIST;
|
| 80 |
+
const pagination = response?.data?.pagination || { total: 0, totalPages: 0 };
|
| 81 |
+
|
| 82 |
+
const handleSearchChange = (e) => {
|
| 83 |
+
setSearchTerm(e.target.value);
|
| 84 |
+
setPage(1); // Reset to page 1 when searching
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
if (isLoading) {
|
| 88 |
+
return <LodderSpinner />;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return (
|
| 92 |
+
<div className="space-y-6">
|
| 93 |
+
{permissions.canCreateCustomers ? (
|
| 94 |
+
<section className="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm">
|
| 95 |
+
<div className="mb-5 flex items-center gap-3">
|
| 96 |
+
<div className="flex h-12 w-12 items-center justify-center rounded-2xl border border-emerald-100 bg-emerald-50 text-emerald-700">
|
| 97 |
+
<UserRound size={22} />
|
| 98 |
+
</div>
|
| 99 |
+
<div>
|
| 100 |
+
<h3 className="text-lg font-black text-slate-900">تسجيل عميل</h3>
|
| 101 |
+
<p className="text-sm text-slate-500">أنشئ حساب عميل قبل إصدار الفواتير وتتبع المدفوعات.</p>
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<form onSubmit={formik.handleSubmit} className="grid gap-4 md:grid-cols-[1.2fr_1fr_auto]">
|
| 106 |
+
<Field label="اسم العميل" name="name" formik={formik} placeholder="الاسم الكامل للعميل" />
|
| 107 |
+
<Field label="الهاتف" name="phone" formik={formik} placeholder="+20..." />
|
| 108 |
+
<button
|
| 109 |
+
type="submit"
|
| 110 |
+
disabled={createCustomerMutation.isPending}
|
| 111 |
+
className="mt-[22px] flex h-12 items-center justify-center gap-2 rounded-2xl bg-emerald-600 px-5 font-bold text-white transition hover:bg-emerald-700 disabled:opacity-60"
|
| 112 |
+
>
|
| 113 |
+
{createCustomerMutation.isPending ? <Loader2 size={18} className="animate-spin" /> : <PlusCircle size={18} />}
|
| 114 |
+
إضافة عميل
|
| 115 |
+
</button>
|
| 116 |
+
</form>
|
| 117 |
+
</section>
|
| 118 |
+
) : null}
|
| 119 |
+
|
| 120 |
+
<section className="rounded-3xl border border-slate-200 bg-white shadow-sm">
|
| 121 |
+
<div className="flex flex-col gap-4 border-b border-slate-100 p-5 md:flex-row md:items-center md:justify-between">
|
| 122 |
+
<div>
|
| 123 |
+
<h3 className="text-lg font-black text-slate-900">حسابات العملاء</h3>
|
| 124 |
+
<p className="text-sm text-slate-500">فتح التفاصيل، إصدار الفواتير، وتتبع الأرصدة المعلقة.</p>
|
| 125 |
+
</div>
|
| 126 |
+
<div className="relative w-full md:max-w-sm">
|
| 127 |
+
<Search size={18} className="absolute right-4 top-1/2 -translate-y-1/2 text-slate-400" />
|
| 128 |
+
<input
|
| 129 |
+
type="text"
|
| 130 |
+
value={searchTerm}
|
| 131 |
+
onChange={handleSearchChange}
|
| 132 |
+
placeholder="البحث في العملاء..."
|
| 133 |
+
className="h-11 w-full rounded-2xl border border-slate-200 bg-slate-50 pr-11 pl-4 font-medium text-slate-800 outline-none transition focus:bg-white focus:ring-2 focus:ring-amber-500"
|
| 134 |
+
/>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
<div className="overflow-x-auto">
|
| 139 |
+
<table className="min-w-full border-collapse">
|
| 140 |
+
<thead>
|
| 141 |
+
<tr className="border-b border-slate-200 text-right text-sm font-bold text-slate-500">
|
| 142 |
+
<th className="px-4 py-3">العميل</th>
|
| 143 |
+
<th className="px-4 py-3">تاريخ الإنشاء</th>
|
| 144 |
+
<th className="px-4 py-3">الفواتير</th>
|
| 145 |
+
<th className="px-4 py-3">المستحقات</th>
|
| 146 |
+
<th className="px-4 py-3">الإجراءات</th>
|
| 147 |
+
</tr>
|
| 148 |
+
</thead>
|
| 149 |
+
<tbody>
|
| 150 |
+
{customers.length ? (
|
| 151 |
+
customers.map((customer) => (
|
| 152 |
+
<tr key={customer._id} className="border-b border-slate-100 text-sm text-slate-700">
|
| 153 |
+
<td className="px-4 py-4">
|
| 154 |
+
<div className="flex items-center gap-3">
|
| 155 |
+
<div className="flex h-10 w-10 items-center justify-center rounded-2xl bg-slate-100 font-black text-slate-700">
|
| 156 |
+
{customer.name.charAt(0)}
|
| 157 |
+
</div>
|
| 158 |
+
<div>
|
| 159 |
+
<p className="font-bold text-slate-900">{customer.name}</p>
|
| 160 |
+
<p className="text-xs text-slate-500">{customer.phone || "لا يوجد رقم هاتف"}</p>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
</td>
|
| 164 |
+
<td className="px-4 py-4">{formatDate(customer.createdAt)}</td>
|
| 165 |
+
<td className="px-4 py-4 font-bold">{formatNumber(customer.invoicesCount || customer.invoices?.length || 0)}</td>
|
| 166 |
+
<td className="px-4 py-4 font-bold text-rose-600">
|
| 167 |
+
{formatCurrency(customer.totalDebt || 0, currency)}
|
| 168 |
+
</td>
|
| 169 |
+
<td className="px-4 py-4">
|
| 170 |
+
<div className="flex flex-wrap items-center gap-2">
|
| 171 |
+
<Link
|
| 172 |
+
to={`/customers/${customer._id}`}
|
| 173 |
+
className="flex h-10 items-center justify-center gap-2 rounded-2xl bg-slate-900 px-4 font-bold text-white transition hover:bg-slate-800"
|
| 174 |
+
>
|
| 175 |
+
<Eye size={16} />
|
| 176 |
+
التفاصيل
|
| 177 |
+
</Link>
|
| 178 |
+
{permissions.canCreateInvoices ? (
|
| 179 |
+
<button
|
| 180 |
+
type="button"
|
| 181 |
+
onClick={() => setActiveCustomerId(customer._id)}
|
| 182 |
+
className="flex h-10 items-center justify-center gap-2 rounded-2xl bg-amber-500 px-4 font-bold text-slate-900 transition hover:bg-amber-400"
|
| 183 |
+
>
|
| 184 |
+
<PlusCircle size={16} />
|
| 185 |
+
فاتورة جديدة
|
| 186 |
+
</button>
|
| 187 |
+
) : null}
|
| 188 |
+
{permissions.canDeleteCustomers ? (
|
| 189 |
+
pendingDeleteId === customer._id ? (
|
| 190 |
+
<div className="flex items-center gap-2 rounded-2xl border border-rose-200 bg-rose-50 px-3 py-2">
|
| 191 |
+
<span className="text-xs font-bold text-rose-700">حذف الحساب؟</span>
|
| 192 |
+
<button
|
| 193 |
+
type="button"
|
| 194 |
+
onClick={() => deleteCustomerMutation.mutate(customer._id)}
|
| 195 |
+
disabled={deleteCustomerMutation.isPending}
|
| 196 |
+
className="rounded-xl bg-rose-600 px-3 py-1.5 text-xs font-bold text-white transition hover:bg-rose-700 disabled:opacity-60"
|
| 197 |
+
>
|
| 198 |
+
{deleteCustomerMutation.isPending ? <Loader2 size={14} className="animate-spin" /> : "تأكيد"}
|
| 199 |
+
</button>
|
| 200 |
+
<button
|
| 201 |
+
type="button"
|
| 202 |
+
onClick={() => setPendingDeleteId(null)}
|
| 203 |
+
disabled={deleteCustomerMutation.isPending}
|
| 204 |
+
className="rounded-xl border border-slate-200 bg-white px-3 py-1.5 text-xs font-bold text-slate-600 transition hover:bg-slate-50"
|
| 205 |
+
>
|
| 206 |
+
إلغاء
|
| 207 |
+
</button>
|
| 208 |
+
</div>
|
| 209 |
+
) : (
|
| 210 |
+
<button
|
| 211 |
+
type="button"
|
| 212 |
+
onClick={() => setPendingDeleteId(customer._id)}
|
| 213 |
+
className="flex h-10 items-center justify-center gap-2 rounded-2xl border border-rose-100 bg-rose-50 px-3 font-bold text-rose-600 transition hover:bg-rose-600 hover:text-white"
|
| 214 |
+
>
|
| 215 |
+
<Trash2 size={16} />
|
| 216 |
+
حذف
|
| 217 |
+
</button>
|
| 218 |
+
)
|
| 219 |
+
) : null}
|
| 220 |
+
</div>
|
| 221 |
+
</td>
|
| 222 |
+
</tr>
|
| 223 |
+
))
|
| 224 |
+
) : (
|
| 225 |
+
<tr>
|
| 226 |
+
<td colSpan="5" className="px-4 py-12 text-center text-sm font-medium text-slate-500">
|
| 227 |
+
لا يوجد عملاء مطابقون لهذا البحث.
|
| 228 |
+
</td>
|
| 229 |
+
</tr>
|
| 230 |
+
)}
|
| 231 |
+
</tbody>
|
| 232 |
+
</table>
|
| 233 |
+
</div>
|
| 234 |
+
|
| 235 |
+
<Pagination
|
| 236 |
+
currentPage={page}
|
| 237 |
+
totalPages={pagination.totalPages}
|
| 238 |
+
onPageChange={setPage}
|
| 239 |
+
totalItems={pagination.total}
|
| 240 |
+
limit={5}
|
| 241 |
+
/>
|
| 242 |
+
</section>
|
| 243 |
+
|
| 244 |
+
{activeCustomerId ? (
|
| 245 |
+
<InvoiceItemsModal customerId={activeCustomerId} onClose={() => setActiveCustomerId(null)} />
|
| 246 |
+
) : null}
|
| 247 |
+
</div>
|
| 248 |
+
);
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
const Field = ({ label, name, formik, placeholder }) => (
|
| 252 |
+
<div>
|
| 253 |
+
<label className="mb-1 block text-xs font-bold uppercase tracking-wide text-slate-500">{label}</label>
|
| 254 |
+
<input
|
| 255 |
+
name={name}
|
| 256 |
+
type="text"
|
| 257 |
+
value={formik.values[name]}
|
| 258 |
+
onChange={formik.handleChange}
|
| 259 |
+
onBlur={formik.handleBlur}
|
| 260 |
+
placeholder={placeholder}
|
| 261 |
+
className={`h-12 w-full rounded-2xl border bg-slate-50 px-4 font-medium text-slate-800 outline-none transition focus:bg-white focus:ring-2 focus:ring-emerald-500 ${
|
| 262 |
+
formik.touched[name] && formik.errors[name] ? "border-rose-400" : "border-slate-200"
|
| 263 |
+
}`}
|
| 264 |
+
/>
|
| 265 |
+
{formik.touched[name] && formik.errors[name] ? (
|
| 266 |
+
<p className="mt-1 text-xs font-bold text-rose-500">{formik.errors[name]}</p>
|
| 267 |
+
) : null}
|
| 268 |
+
</div>
|
| 269 |
+
);
|
| 270 |
+
|
| 271 |
+
export default CustomersWorkspace;
|