create-myexam-app 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/projects/SMS-/frontend-project/src/pages/Reports.jsx +179 -23
- package/projects/SCMS/backend/.env +0 -5
- package/projects/SCMS/backend/config/db.js +0 -12
- package/projects/SCMS/backend/controllers/authController.js +0 -90
- package/projects/SCMS/backend/controllers/deliveryController.js +0 -79
- package/projects/SCMS/backend/controllers/productController.js +0 -74
- package/projects/SCMS/backend/controllers/reportsController.js +0 -77
- package/projects/SCMS/backend/controllers/shipmentController.js +0 -80
- package/projects/SCMS/backend/controllers/supplierController.js +0 -58
- package/projects/SCMS/backend/middleware/auth.js +0 -32
- package/projects/SCMS/backend/models/User.js +0 -28
- package/projects/SCMS/backend/models/delivery.js +0 -33
- package/projects/SCMS/backend/models/product.js +0 -43
- package/projects/SCMS/backend/models/shipment.js +0 -34
- package/projects/SCMS/backend/models/supplier.js +0 -36
- package/projects/SCMS/backend/package-lock.json +0 -2190
- package/projects/SCMS/backend/package.json +0 -23
- package/projects/SCMS/backend/routes/SupplierRoutes.js +0 -15
- package/projects/SCMS/backend/routes/authRoutes.js +0 -11
- package/projects/SCMS/backend/routes/deliveryRoutes.js +0 -18
- package/projects/SCMS/backend/routes/productRoutes.js +0 -15
- package/projects/SCMS/backend/routes/protectedRoutes.js +0 -10
- package/projects/SCMS/backend/routes/reportsRoutes.js +0 -8
- package/projects/SCMS/backend/routes/shipmentRoutes.js +0 -18
- package/projects/SCMS/backend/server.js +0 -35
- package/projects/SCMS/frontend/README.md +0 -16
- package/projects/SCMS/frontend/eslint.config.js +0 -21
- package/projects/SCMS/frontend/index.html +0 -13
- package/projects/SCMS/frontend/node_modules/.bin/acorn +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/acorn.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/acorn.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/baseline-browser-mapping +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/baseline-browser-mapping.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/baseline-browser-mapping.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/browserslist +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/browserslist.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/browserslist.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/eslint +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/eslint.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/eslint.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/jiti +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/jiti.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/jiti.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/jsesc +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/jsesc.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/jsesc.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/json5 +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/json5.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/json5.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/nanoid +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/nanoid.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/nanoid.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/node-which +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/node-which.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/node-which.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/parser +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/parser.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/parser.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/rolldown +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/rolldown.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/rolldown.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/semver +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/semver.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/semver.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/update-browserslist-db +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/update-browserslist-db.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/update-browserslist-db.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.bin/vite +0 -16
- package/projects/SCMS/frontend/node_modules/.bin/vite.cmd +0 -17
- package/projects/SCMS/frontend/node_modules/.bin/vite.ps1 +0 -28
- package/projects/SCMS/frontend/node_modules/.package-lock.json +0 -2401
- package/projects/SCMS/frontend/node_modules/.vite/deps/_metadata.json +0 -56
- package/projects/SCMS/frontend/node_modules/.vite/deps/axios.js +0 -3184
- package/projects/SCMS/frontend/node_modules/.vite/deps/axios.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/.vite/deps/chunk-B-1-B7_t.js +0 -33
- package/projects/SCMS/frontend/node_modules/.vite/deps/package.json +0 -3
- package/projects/SCMS/frontend/node_modules/.vite/deps/react-dom.js +0 -186
- package/projects/SCMS/frontend/node_modules/.vite/deps/react-dom.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/.vite/deps/react-dom_client.js +0 -14385
- package/projects/SCMS/frontend/node_modules/.vite/deps/react-dom_client.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/.vite/deps/react-router-dom.js +0 -10177
- package/projects/SCMS/frontend/node_modules/.vite/deps/react-router-dom.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/.vite/deps/react.js +0 -769
- package/projects/SCMS/frontend/node_modules/.vite/deps/react.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/.vite/deps/react_jsx-dev-runtime.js +0 -205
- package/projects/SCMS/frontend/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/.vite/deps/react_jsx-runtime.js +0 -209
- package/projects/SCMS/frontend/node_modules/.vite/deps/react_jsx-runtime.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/code-frame/LICENSE +0 -22
- package/projects/SCMS/frontend/node_modules/@babel/code-frame/README.md +0 -19
- package/projects/SCMS/frontend/node_modules/@babel/code-frame/lib/index.js +0 -217
- package/projects/SCMS/frontend/node_modules/@babel/code-frame/lib/index.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/code-frame/package.json +0 -32
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/LICENSE +0 -22
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/README.md +0 -19
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/corejs2-built-ins.js +0 -2
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/corejs3-shipped-proposals.js +0 -2
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/data/corejs2-built-ins.json +0 -2120
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/data/corejs3-shipped-proposals.json +0 -5
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/data/native-modules.json +0 -18
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/data/overlapping-plugins.json +0 -38
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/data/plugin-bugfixes.json +0 -231
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/data/plugins.json +0 -843
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/native-modules.js +0 -2
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/overlapping-plugins.js +0 -2
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/package.json +0 -40
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/plugin-bugfixes.js +0 -2
- package/projects/SCMS/frontend/node_modules/@babel/compat-data/plugins.js +0 -2
- package/projects/SCMS/frontend/node_modules/@babel/core/LICENSE +0 -22
- package/projects/SCMS/frontend/node_modules/@babel/core/README.md +0 -19
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/cache-contexts.js +0 -5
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/cache-contexts.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/caching.js +0 -261
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/caching.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/config-chain.js +0 -469
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/config-chain.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/config-descriptors.js +0 -190
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/config-descriptors.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/configuration.js +0 -290
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/configuration.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/import.cjs +0 -6
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/import.cjs.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/index-browser.js +0 -58
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/index-browser.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/index.js +0 -78
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/files/index.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/full.js +0 -312
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/full.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/index.js +0 -87
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/index.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/item.js +0 -67
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/item.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/partial.js +0 -158
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/partial.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/pattern-to-regex.js +0 -38
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/pattern-to-regex.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/plugin.js +0 -33
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/plugin.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/printer.js +0 -113
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/printer.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/resolve-targets-browser.js +0 -41
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/resolve-targets-browser.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/resolve-targets.js +0 -61
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/resolve-targets.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/util.js +0 -31
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/config/util.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/index.js +0 -230
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/index.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/parse.js +0 -45
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/parse.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform-ast.js +0 -48
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform-ast.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform-file-browser.js +0 -23
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform-file-browser.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform-file.js +0 -40
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform-file.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform.js +0 -47
- package/projects/SCMS/frontend/node_modules/@babel/core/lib/transform.js.map +0 -1
- package/projects/SCMS/frontend/node_modules/@babel/core/package.json +0 -84
- package/projects/SCMS/frontend/package-lock.json +0 -3053
- package/projects/SCMS/frontend/package.json +0 -31
- package/projects/SCMS/frontend/public/favicon.svg +0 -1
- package/projects/SCMS/frontend/src/App.jsx +0 -35
- package/projects/SCMS/frontend/src/components/DashboardLayout.jsx +0 -103
- package/projects/SCMS/frontend/src/components/ProtectedRoute.jsx +0 -30
- package/projects/SCMS/frontend/src/index.css +0 -114
- package/projects/SCMS/frontend/src/main.jsx +0 -10
- package/projects/SCMS/frontend/src/pages/DashboardHome.jsx +0 -34
- package/projects/SCMS/frontend/src/pages/Delivery.jsx +0 -183
- package/projects/SCMS/frontend/src/pages/Login.jsx +0 -81
- package/projects/SCMS/frontend/src/pages/Profile.jsx +0 -62
- package/projects/SCMS/frontend/src/pages/Register.jsx +0 -110
- package/projects/SCMS/frontend/src/pages/Reports.jsx +0 -94
- package/projects/SCMS/frontend/src/pages/Shipment.jsx +0 -182
- package/projects/SCMS/frontend/src/pages/Supplier.jsx +0 -165
- package/projects/SCMS/frontend/vite.config.js +0 -7
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
2
|
import axios from '../axiosInstance';
|
|
3
3
|
|
|
4
|
-
function Reports
|
|
4
|
+
function Reports() {
|
|
5
|
+
|
|
5
6
|
const [products, setProducts] = useState([]);
|
|
6
7
|
const [warehouses, setWarehouses] = useState([]);
|
|
7
8
|
const [stockTransaction, setStockTransaction] = useState([]);
|
|
@@ -17,7 +18,7 @@ function Reports () {
|
|
|
17
18
|
|
|
18
19
|
const txRes = await axios.get('http://localhost:5000/api/stockTransaction');
|
|
19
20
|
setStockTransaction(txRes.data);
|
|
20
|
-
} catch(error) {
|
|
21
|
+
} catch (error) {
|
|
21
22
|
setError("Failed to generate report summaries.");
|
|
22
23
|
}
|
|
23
24
|
};
|
|
@@ -26,38 +27,150 @@ function Reports () {
|
|
|
26
27
|
fetchAllReports();
|
|
27
28
|
}, []);
|
|
28
29
|
|
|
30
|
+
const today = new Date();
|
|
31
|
+
|
|
32
|
+
const dailyTransactions = stockTransaction.filter((tx) => {
|
|
33
|
+
if (!tx.transactionDate) return false;
|
|
34
|
+
const txDate = new Date(tx.transactionDate);
|
|
35
|
+
return txDate.toDateString() === today.toDateString();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const weeklyTransactions = stockTransaction.filter((tx) => {
|
|
39
|
+
if (!tx.transactionDate) return false;
|
|
40
|
+
|
|
41
|
+
const txDate = new Date(tx.transactionDate);
|
|
42
|
+
|
|
43
|
+
const startOfWeek = new Date(today);
|
|
44
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
45
|
+
startOfWeek.setDate(today.getDate() - today.getDay());
|
|
46
|
+
|
|
47
|
+
const endOfWeek = new Date(startOfWeek);
|
|
48
|
+
endOfWeek.setDate(startOfWeek.getDate() + 6);
|
|
49
|
+
endOfWeek.setHours(23, 59, 59, 999);
|
|
50
|
+
|
|
51
|
+
return txDate >= startOfWeek && txDate <= endOfWeek;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const monthlyTransactions = stockTransaction.filter((tx) => {
|
|
55
|
+
if (!tx.transactionDate) return false;
|
|
56
|
+
|
|
57
|
+
const txDate = new Date(tx.transactionDate);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
txDate.getMonth() === today.getMonth() &&
|
|
61
|
+
txDate.getFullYear() === today.getFullYear()
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const dailyQuantity = dailyTransactions.reduce(
|
|
66
|
+
(sum, tx) => sum + Number(tx.quantityMoved || 0),
|
|
67
|
+
0
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const weeklyQuantity = weeklyTransactions.reduce(
|
|
71
|
+
(sum, tx) => sum + Number(tx.quantityMoved || 0),
|
|
72
|
+
0
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const monthlyQuantity = monthlyTransactions.reduce(
|
|
76
|
+
(sum, tx) => sum + Number(tx.quantityMoved || 0),
|
|
77
|
+
0
|
|
78
|
+
);
|
|
79
|
+
|
|
29
80
|
return (
|
|
30
81
|
<div className="p-6 bg-slate-50 min-h-screen flex flex-col gap-8">
|
|
82
|
+
|
|
31
83
|
<div>
|
|
32
84
|
<h2 className="text-2xl font-bold text-slate-800">System Summary Reports</h2>
|
|
33
85
|
<p className="text-sm text-slate-500">Live summary data across your inventory portal.</p>
|
|
34
86
|
</div>
|
|
35
87
|
|
|
36
88
|
{error && (
|
|
37
|
-
<p className="text-red-500 bg-red-100 p-2 rounded text-sm font-semibold text-center">
|
|
89
|
+
<p className="text-red-500 bg-red-100 p-2 rounded text-sm font-semibold text-center">
|
|
90
|
+
{error}
|
|
91
|
+
</p>
|
|
38
92
|
)}
|
|
39
93
|
|
|
40
|
-
{/* Quick Stats Grid Cards */}
|
|
41
94
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
95
|
+
|
|
96
|
+
<div className="bg-white p-4 rounded shadow-sm border border-slate-200">
|
|
97
|
+
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
98
|
+
Total Items
|
|
99
|
+
</span>
|
|
100
|
+
<h4 className="text-2xl font-extrabold text-blue-600">
|
|
101
|
+
{products.length} Products
|
|
102
|
+
</h4>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div className="bg-white p-4 rounded shadow-sm border border-slate-200">
|
|
106
|
+
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
107
|
+
Active Spots
|
|
108
|
+
</span>
|
|
109
|
+
<h4 className="text-2xl font-extrabold text-green-600">
|
|
110
|
+
{warehouses.length} Warehouses
|
|
111
|
+
</h4>
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div className="bg-white p-4 rounded shadow-sm border border-slate-200">
|
|
115
|
+
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
116
|
+
Logged Activity
|
|
117
|
+
</span>
|
|
118
|
+
<h4 className="text-2xl font-extrabold text-purple-600">
|
|
119
|
+
{stockTransaction.length} Logs
|
|
120
|
+
</h4>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
126
|
+
|
|
42
127
|
<div className="bg-white p-4 rounded shadow-sm border border-slate-200">
|
|
43
|
-
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
44
|
-
|
|
128
|
+
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
129
|
+
Daily Report
|
|
130
|
+
</span>
|
|
131
|
+
<h4 className="text-2xl font-extrabold text-blue-600">
|
|
132
|
+
{dailyTransactions.length} Transactions
|
|
133
|
+
</h4>
|
|
134
|
+
<p className="text-sm text-slate-500">
|
|
135
|
+
{dailyQuantity} Units Moved Today
|
|
136
|
+
</p>
|
|
45
137
|
</div>
|
|
138
|
+
|
|
46
139
|
<div className="bg-white p-4 rounded shadow-sm border border-slate-200">
|
|
47
|
-
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
48
|
-
|
|
140
|
+
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
141
|
+
Weekly Report
|
|
142
|
+
</span>
|
|
143
|
+
<h4 className="text-2xl font-extrabold text-green-600">
|
|
144
|
+
{weeklyTransactions.length} Transactions
|
|
145
|
+
</h4>
|
|
146
|
+
<p className="text-sm text-slate-500">
|
|
147
|
+
{weeklyQuantity} Units Moved This Week
|
|
148
|
+
</p>
|
|
49
149
|
</div>
|
|
150
|
+
|
|
50
151
|
<div className="bg-white p-4 rounded shadow-sm border border-slate-200">
|
|
51
|
-
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
52
|
-
|
|
152
|
+
<span className="text-xs font-bold text-slate-400 uppercase">
|
|
153
|
+
Monthly Report
|
|
154
|
+
</span>
|
|
155
|
+
<h4 className="text-2xl font-extrabold text-purple-600">
|
|
156
|
+
{monthlyTransactions.length} Transactions
|
|
157
|
+
</h4>
|
|
158
|
+
<p className="text-sm text-slate-500">
|
|
159
|
+
{monthlyQuantity} Units Moved This Month
|
|
160
|
+
</p>
|
|
53
161
|
</div>
|
|
162
|
+
|
|
54
163
|
</div>
|
|
55
164
|
|
|
56
|
-
{/* Products Table */}
|
|
57
165
|
<div className="bg-white rounded shadow-sm border border-slate-200 flex flex-col gap-2 p-4">
|
|
58
|
-
|
|
166
|
+
|
|
167
|
+
<h3 className="text-lg font-bold text-slate-700">
|
|
168
|
+
Available Products Summary
|
|
169
|
+
</h3>
|
|
170
|
+
|
|
59
171
|
<div className="overflow-x-auto">
|
|
60
172
|
<table className="w-full text-left border-collapse">
|
|
173
|
+
|
|
61
174
|
<thead>
|
|
62
175
|
<tr className="bg-slate-100 border-b border-slate-200 text-slate-700 text-sm font-bold">
|
|
63
176
|
<th className="p-3">Product Code</th>
|
|
@@ -69,28 +182,43 @@ function Reports () {
|
|
|
69
182
|
<th className="p-3">Date</th>
|
|
70
183
|
</tr>
|
|
71
184
|
</thead>
|
|
185
|
+
|
|
72
186
|
<tbody className="text-slate-600 text-sm divide-y divide-slate-100">
|
|
73
187
|
{Array.isArray(products) && products.map((prod) => (
|
|
74
188
|
<tr key={prod._id} className="hover:bg-slate-50">
|
|
75
|
-
<td className="p-3 font-semibold text-slate-700">
|
|
189
|
+
<td className="p-3 font-semibold text-slate-700">
|
|
190
|
+
{prod.productCode}
|
|
191
|
+
</td>
|
|
76
192
|
<td className="p-3">{prod.productName}</td>
|
|
77
193
|
<td className="p-3">{prod.category}</td>
|
|
78
194
|
<td className="p-3">{prod.quantityInStock}</td>
|
|
79
195
|
<td className="p-3">${prod.unitPrice}</td>
|
|
80
196
|
<td className="p-3">{prod.supplierName}</td>
|
|
81
|
-
<td className="p-3">
|
|
197
|
+
<td className="p-3">
|
|
198
|
+
{prod.date
|
|
199
|
+
? prod.date.substring(0, 10)
|
|
200
|
+
: (prod.dateReceived
|
|
201
|
+
? prod.dateReceived.substring(0, 10)
|
|
202
|
+
: "")}
|
|
203
|
+
</td>
|
|
82
204
|
</tr>
|
|
83
205
|
))}
|
|
84
206
|
</tbody>
|
|
207
|
+
|
|
85
208
|
</table>
|
|
86
209
|
</div>
|
|
210
|
+
|
|
87
211
|
</div>
|
|
88
212
|
|
|
89
|
-
{/* Warehouse Table */}
|
|
90
213
|
<div className="bg-white rounded shadow-sm border border-slate-200 flex flex-col gap-2 p-4">
|
|
91
|
-
|
|
214
|
+
|
|
215
|
+
<h3 className="text-lg font-bold text-slate-700">
|
|
216
|
+
Warehouse Setup Summary
|
|
217
|
+
</h3>
|
|
218
|
+
|
|
92
219
|
<div className="overflow-x-auto">
|
|
93
220
|
<table className="w-full text-left border-collapse">
|
|
221
|
+
|
|
94
222
|
<thead>
|
|
95
223
|
<tr className="bg-slate-100 border-b border-slate-200 text-slate-700 text-sm font-bold">
|
|
96
224
|
<th className="p-3">Warehouse Code</th>
|
|
@@ -98,24 +226,33 @@ function Reports () {
|
|
|
98
226
|
<th className="p-3">Warehouse Location</th>
|
|
99
227
|
</tr>
|
|
100
228
|
</thead>
|
|
229
|
+
|
|
101
230
|
<tbody className="text-slate-600 text-sm divide-y divide-slate-100">
|
|
102
231
|
{Array.isArray(warehouses) && warehouses.map((wh) => (
|
|
103
232
|
<tr key={wh._id} className="hover:bg-slate-50">
|
|
104
|
-
<td className="p-3 font-semibold text-slate-700">
|
|
233
|
+
<td className="p-3 font-semibold text-slate-700">
|
|
234
|
+
{wh.warehouseCode}
|
|
235
|
+
</td>
|
|
105
236
|
<td className="p-3">{wh.warehouseName}</td>
|
|
106
237
|
<td className="p-3">{wh.warehouseLocation}</td>
|
|
107
238
|
</tr>
|
|
108
239
|
))}
|
|
109
240
|
</tbody>
|
|
241
|
+
|
|
110
242
|
</table>
|
|
111
243
|
</div>
|
|
244
|
+
|
|
112
245
|
</div>
|
|
113
246
|
|
|
114
|
-
{/* Transactions Table */}
|
|
115
247
|
<div className="bg-white rounded shadow-sm border border-slate-200 flex flex-col gap-2 p-4">
|
|
116
|
-
|
|
248
|
+
|
|
249
|
+
<h3 className="text-lg font-bold text-slate-700">
|
|
250
|
+
Stock Activity Logs
|
|
251
|
+
</h3>
|
|
252
|
+
|
|
117
253
|
<div className="overflow-x-auto">
|
|
118
254
|
<table className="w-full text-left border-collapse">
|
|
255
|
+
|
|
119
256
|
<thead>
|
|
120
257
|
<tr className="bg-slate-100 border-b border-slate-200 text-slate-700 text-sm font-bold">
|
|
121
258
|
<th className="p-3">Transaction Date</th>
|
|
@@ -123,24 +260,43 @@ function Reports () {
|
|
|
123
260
|
<th className="p-3">Transaction Type</th>
|
|
124
261
|
</tr>
|
|
125
262
|
</thead>
|
|
263
|
+
|
|
126
264
|
<tbody className="text-slate-600 text-sm divide-y divide-slate-100">
|
|
127
265
|
{Array.isArray(stockTransaction) && stockTransaction.map((tx) => (
|
|
128
266
|
<tr key={tx._id} className="hover:bg-slate-50">
|
|
129
|
-
<td className="p-3">{tx.transactionDate ? tx.transactionDate.substring(0, 10) : ""}</td>
|
|
130
|
-
<td className="p-3 font-semibold">{tx.quantityMoved}</td>
|
|
131
267
|
<td className="p-3">
|
|
132
|
-
|
|
268
|
+
{tx.transactionDate
|
|
269
|
+
? tx.transactionDate.substring(0, 10)
|
|
270
|
+
: ""}
|
|
271
|
+
</td>
|
|
272
|
+
|
|
273
|
+
<td className="p-3 font-semibold">
|
|
274
|
+
{tx.quantityMoved}
|
|
275
|
+
</td>
|
|
276
|
+
|
|
277
|
+
<td className="p-3">
|
|
278
|
+
<span
|
|
279
|
+
className={`px-2 py-0.5 rounded text-xs font-bold ${
|
|
280
|
+
tx.transactionType?.toLowerCase().includes('in')
|
|
281
|
+
? 'bg-green-100 text-green-700'
|
|
282
|
+
: 'bg-amber-100 text-amber-700'
|
|
283
|
+
}`}
|
|
284
|
+
>
|
|
133
285
|
{tx.transactionType}
|
|
134
286
|
</span>
|
|
135
287
|
</td>
|
|
288
|
+
|
|
136
289
|
</tr>
|
|
137
290
|
))}
|
|
138
291
|
</tbody>
|
|
292
|
+
|
|
139
293
|
</table>
|
|
140
294
|
</div>
|
|
295
|
+
|
|
141
296
|
</div>
|
|
142
297
|
|
|
143
298
|
</div>
|
|
144
299
|
);
|
|
145
300
|
}
|
|
146
|
-
|
|
301
|
+
|
|
302
|
+
export default Reports;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const mongoose = require('mongoose');
|
|
2
|
-
|
|
3
|
-
const connectDB = async () => {
|
|
4
|
-
try {
|
|
5
|
-
await mongoose.connect('mongodb://localhost:27017/SCMS');
|
|
6
|
-
console.log('MongoDB connected');
|
|
7
|
-
} catch (error) {
|
|
8
|
-
console.error('MongoDB connection error:', error);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
module.exports = connectDB;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const bcrypt = require('bcrypt');
|
|
2
|
-
const jwt = require('jsonwebtoken');
|
|
3
|
-
const User = require('../models/User');
|
|
4
|
-
const JWT_SECRET = 'change_this_to_a_long_random_secret';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function createToken(userId) {
|
|
9
|
-
return jwt.sign({ userId },JWT_SECRET, { expiresIn: '7d' });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function formatUser(user) {
|
|
13
|
-
return {
|
|
14
|
-
id: user._id,
|
|
15
|
-
name: user.name,
|
|
16
|
-
email: user.email,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.register = async (req, res) => {
|
|
21
|
-
try {
|
|
22
|
-
const { name, email, password } = req.body;
|
|
23
|
-
|
|
24
|
-
if (!name || !email || !password) {
|
|
25
|
-
return res.status(400).json({ message: 'Name, email, and password are required' });
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (password.length < 6) {
|
|
29
|
-
return res.status(400).json({ message: 'Password must be at least 6 characters' });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const existing = await User.findOne({ email: email.toLowerCase() });
|
|
33
|
-
if (existing) {
|
|
34
|
-
return res.status(409).json({ message: 'Email already registered' });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const hashedPassword = await bcrypt.hash(password, 10);
|
|
38
|
-
const user = await User.create({
|
|
39
|
-
name,
|
|
40
|
-
email: email.toLowerCase(),//to ensure the email is always lowercase
|
|
41
|
-
password: hashedPassword,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const token = createToken(user._id);
|
|
45
|
-
|
|
46
|
-
res.status(201).json({
|
|
47
|
-
token,
|
|
48
|
-
user: formatUser(user),
|
|
49
|
-
});
|
|
50
|
-
} catch (err) {
|
|
51
|
-
res.status(500).json({ message: err.message });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exports.login = async (req, res) => {
|
|
56
|
-
try {
|
|
57
|
-
const { email, password } = req.body;
|
|
58
|
-
|
|
59
|
-
if (!email || !password) {
|
|
60
|
-
return res.status(400).json({ message: 'Email and password are required' });
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const user = await User.findOne({ email: email.toLowerCase() });
|
|
64
|
-
if (!user) {
|
|
65
|
-
return res.status(401).json({ message: 'Invalid email or password' });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const match = await bcrypt.compare(password, user.password);
|
|
69
|
-
if (!match) {
|
|
70
|
-
return res.status(401).json({ message: 'Invalid email or password' });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const token = createToken(user._id);
|
|
74
|
-
|
|
75
|
-
res.json({
|
|
76
|
-
token,
|
|
77
|
-
user: formatUser(user),
|
|
78
|
-
});
|
|
79
|
-
} catch (err) {
|
|
80
|
-
res.status(500).json({ message: err.message });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.getMe = async (req, res) => {
|
|
85
|
-
try {
|
|
86
|
-
res.json({ user: formatUser(req.user) });
|
|
87
|
-
} catch (err) {
|
|
88
|
-
res.status(500).json({ message: err.message });
|
|
89
|
-
}
|
|
90
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const Delivery = require('../models/delivery');
|
|
2
|
-
const Shipment = require('../models/shipment');
|
|
3
|
-
|
|
4
|
-
exports.addDelivery = async (req, res) => {
|
|
5
|
-
try {
|
|
6
|
-
const { deliveryCode, deliveryDate, quantityDelivered, deliveryStatus, shipmentId } = req.body;
|
|
7
|
-
|
|
8
|
-
if (shipmentId) {
|
|
9
|
-
const shipment = await Shipment.findById(shipmentId);
|
|
10
|
-
if (!shipment) return res.status(404).json({ msg: 'Shipment not found' });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const newDelivery = await Delivery.create({
|
|
14
|
-
deliveryCode,
|
|
15
|
-
deliveryDate,
|
|
16
|
-
quantityDelivered,
|
|
17
|
-
deliveryStatus,
|
|
18
|
-
shipment: shipmentId || null,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
res.status(201).json(newDelivery);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
res.status(500).json({ msg: 'Failed to add delivery', error: error.message });
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
exports.getDeliveries = async (req, res) => {
|
|
28
|
-
try {
|
|
29
|
-
const deliveries = await Delivery.find().populate({ path: 'shipment', populate: 'supplier' });
|
|
30
|
-
res.status(200).json(deliveries);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
res.status(500).json({ msg: 'Failed to fetch deliveries', error: error.message });
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
exports.getDeliveryById = async (req, res) => {
|
|
37
|
-
try {
|
|
38
|
-
const delivery = await Delivery.findById(req.params.id).populate({ path: 'shipment', populate: 'supplier' });
|
|
39
|
-
if (!delivery) return res.status(404).json({ msg: 'Delivery not found' });
|
|
40
|
-
res.status(200).json(delivery);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
res.status(500).json({ msg: 'Failed to fetch delivery', error: error.message });
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
exports.updateDelivery = async (req, res) => {
|
|
47
|
-
try {
|
|
48
|
-
const { shipmentId } = req.body;
|
|
49
|
-
|
|
50
|
-
if (shipmentId) {
|
|
51
|
-
const shipment = await Shipment.findById(shipmentId);
|
|
52
|
-
if (!shipment) return res.status(404).json({ msg: 'Shipment not found' });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const updatedDelivery = await Delivery.findByIdAndUpdate(
|
|
56
|
-
req.params.id,
|
|
57
|
-
{
|
|
58
|
-
...req.body,
|
|
59
|
-
shipment: shipmentId || null,
|
|
60
|
-
},
|
|
61
|
-
{ new: true }
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if (!updatedDelivery) return res.status(404).json({ msg: 'Delivery not found' });
|
|
65
|
-
res.status(200).json(updatedDelivery);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
res.status(500).json({ msg: 'Failed to update delivery', error: error.message });
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
exports.deleteDelivery = async (req, res) => {
|
|
72
|
-
try {
|
|
73
|
-
const deletedDelivery = await Delivery.findByIdAndDelete(req.params.id);
|
|
74
|
-
if (!deletedDelivery) return res.status(404).json({ msg: 'Delivery not found' });
|
|
75
|
-
res.status(200).json({ msg: 'Delivery deleted successfully' });
|
|
76
|
-
} catch (error) {
|
|
77
|
-
res.status(500).json({ msg: 'Failed to delete delivery', error: error.message });
|
|
78
|
-
}
|
|
79
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const Product = require('../models/Product');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getproduct = async (req, res) => {
|
|
5
|
-
try {
|
|
6
|
-
const products = await Product.find().populate('Supplier');
|
|
7
|
-
if (!products) {
|
|
8
|
-
return res.status(404).json({ message: 'Products not found' });
|
|
9
|
-
}
|
|
10
|
-
res.json(products);
|
|
11
|
-
} catch (err) {
|
|
12
|
-
res.status(500).json({ message: err.message });
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.getproductbyid = async (req, res) => {
|
|
17
|
-
try {
|
|
18
|
-
const productById = await Product.findById(req.params.id).populate('Supplier');
|
|
19
|
-
if (!productById) {
|
|
20
|
-
return res.status(404).json({ message: 'Product not found' });
|
|
21
|
-
}
|
|
22
|
-
res.json(productById);
|
|
23
|
-
} catch (err) {
|
|
24
|
-
res.status(500).json({ message: err.message });
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
exports.addproduct = async (req, res) => {
|
|
29
|
-
try {
|
|
30
|
-
const { productCode, productName, category, unitPrice, quantity, expiryDate } = req.body
|
|
31
|
-
const newproduct = await Product.create({
|
|
32
|
-
productCode,
|
|
33
|
-
productName,
|
|
34
|
-
category,
|
|
35
|
-
unitPrice,
|
|
36
|
-
quantity,
|
|
37
|
-
expiryDate,
|
|
38
|
-
Supplier: req.user._id
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
res.status(201).json(newproduct);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
res.status(500).json({ message: err.message });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
exports.updateproduct = async (req, res) => {
|
|
48
|
-
try {
|
|
49
|
-
const updateproducts = await Product.findByIdAndUpdate(
|
|
50
|
-
req.params.id,
|
|
51
|
-
req.body,
|
|
52
|
-
{ new: true }
|
|
53
|
-
);
|
|
54
|
-
if (!updateproducts) return res.status(404).json({ msg: " product not found" })
|
|
55
|
-
|
|
56
|
-
res.json({ msg: "Products updated Syccessfully", data: updateproducts });
|
|
57
|
-
} catch (err) {
|
|
58
|
-
res.status(500).json({ message: err.message });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
exports.deleteproduct = async (req, res) => {
|
|
63
|
-
try {
|
|
64
|
-
const deleteproduct = await Product.findByIdAndDelete(
|
|
65
|
-
req.params.id
|
|
66
|
-
);
|
|
67
|
-
if (!deleteproduct) {
|
|
68
|
-
return res.status(404).json({ message: 'product not found' });
|
|
69
|
-
}
|
|
70
|
-
res.json({ message: 'Product deleted successfully' });
|
|
71
|
-
} catch (err) {
|
|
72
|
-
res.status(500).json({ message: err.message });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const Supplier = require('../models/Supplier');
|
|
2
|
-
const Shipment = require('../models/shipment');
|
|
3
|
-
const Delivery = require('../models/delivery');
|
|
4
|
-
|
|
5
|
-
function getStartDate(days) {
|
|
6
|
-
const date = new Date();
|
|
7
|
-
date.setHours(0, 0, 0, 0);
|
|
8
|
-
date.setDate(date.getDate() - days);
|
|
9
|
-
return date;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
exports.getReportSummary = async (req, res) => {
|
|
13
|
-
try {
|
|
14
|
-
const now = new Date();
|
|
15
|
-
const dailyStart = getStartDate(1);
|
|
16
|
-
const weeklyStart = getStartDate(7);
|
|
17
|
-
const monthlyStart = getStartDate(30);
|
|
18
|
-
|
|
19
|
-
const [
|
|
20
|
-
totalSuppliers,
|
|
21
|
-
dailySuppliers,
|
|
22
|
-
weeklySuppliers,
|
|
23
|
-
monthlySuppliers,
|
|
24
|
-
totalShipments,
|
|
25
|
-
dailyShipments,
|
|
26
|
-
weeklyShipments,
|
|
27
|
-
monthlyShipments,
|
|
28
|
-
totalDeliveries,
|
|
29
|
-
dailyDeliveries,
|
|
30
|
-
weeklyDeliveries,
|
|
31
|
-
monthlyDeliveries,
|
|
32
|
-
recentShipments,
|
|
33
|
-
recentDeliveries,
|
|
34
|
-
] = await Promise.all([
|
|
35
|
-
Supplier.countDocuments(),
|
|
36
|
-
Supplier.countDocuments({ createdAt: { $gte: dailyStart } }),
|
|
37
|
-
Supplier.countDocuments({ createdAt: { $gte: weeklyStart } }),
|
|
38
|
-
Supplier.countDocuments({ createdAt: { $gte: monthlyStart } }),
|
|
39
|
-
Shipment.countDocuments(),
|
|
40
|
-
Shipment.countDocuments({ createdAt: { $gte: dailyStart } }),
|
|
41
|
-
Shipment.countDocuments({ createdAt: { $gte: weeklyStart } }),
|
|
42
|
-
Shipment.countDocuments({ createdAt: { $gte: monthlyStart } }),
|
|
43
|
-
Delivery.countDocuments(),
|
|
44
|
-
Delivery.countDocuments({ createdAt: { $gte: dailyStart } }),
|
|
45
|
-
Delivery.countDocuments({ createdAt: { $gte: weeklyStart } }),
|
|
46
|
-
Delivery.countDocuments({ createdAt: { $gte: monthlyStart } }),
|
|
47
|
-
Shipment.find().sort({ createdAt: -1 }).limit(5).populate('supplier'),
|
|
48
|
-
Delivery.find().sort({ createdAt: -1 }).limit(5).populate({ path: 'shipment', populate: 'supplier' }),
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
res.status(200).json({
|
|
52
|
-
suppliers: {
|
|
53
|
-
total: totalSuppliers,
|
|
54
|
-
daily: dailySuppliers,
|
|
55
|
-
weekly: weeklySuppliers,
|
|
56
|
-
monthly: monthlySuppliers,
|
|
57
|
-
},
|
|
58
|
-
shipments: {
|
|
59
|
-
total: totalShipments,
|
|
60
|
-
daily: dailyShipments,
|
|
61
|
-
weekly: weeklyShipments,
|
|
62
|
-
monthly: monthlyShipments,
|
|
63
|
-
},
|
|
64
|
-
deliveries: {
|
|
65
|
-
total: totalDeliveries,
|
|
66
|
-
daily: dailyDeliveries,
|
|
67
|
-
weekly: weeklyDeliveries,
|
|
68
|
-
monthly: monthlyDeliveries,
|
|
69
|
-
},
|
|
70
|
-
recentShipments,
|
|
71
|
-
recentDeliveries,
|
|
72
|
-
generatedAt: now,
|
|
73
|
-
});
|
|
74
|
-
} catch (error) {
|
|
75
|
-
res.status(500).json({ msg: 'Failed to generate report', error: error.message });
|
|
76
|
-
}
|
|
77
|
-
};
|