create-cedro-app 1.0.2 → 1.0.3
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/bin/index.js +32 -18
- package/package.json +1 -1
- package/templates/invoice-service-management-system/client/README.md +16 -0
- package/templates/invoice-service-management-system/client/eslint.config.js +21 -0
- package/templates/invoice-service-management-system/client/index.html +13 -0
- package/templates/invoice-service-management-system/client/package.json +35 -0
- package/templates/invoice-service-management-system/client/public/favicon.svg +1 -0
- package/templates/invoice-service-management-system/client/public/icons.svg +24 -0
- package/templates/invoice-service-management-system/client/src/App.jsx +15 -0
- package/templates/invoice-service-management-system/client/src/assets/hero.png +0 -0
- package/templates/invoice-service-management-system/client/src/assets/react.svg +1 -0
- package/templates/invoice-service-management-system/client/src/assets/vite.svg +1 -0
- package/templates/invoice-service-management-system/client/src/components/AppRoutes.jsx +39 -0
- package/templates/invoice-service-management-system/client/src/components/Customer.jsx +326 -0
- package/templates/invoice-service-management-system/client/src/components/Dashboard.jsx +512 -0
- package/templates/invoice-service-management-system/client/src/components/Invoice.jsx +523 -0
- package/templates/invoice-service-management-system/client/src/components/Login.jsx +170 -0
- package/templates/invoice-service-management-system/client/src/components/PageNotFound.jsx +11 -0
- package/templates/invoice-service-management-system/client/src/components/Register.jsx +171 -0
- package/templates/invoice-service-management-system/client/src/components/Report.jsx +383 -0
- package/templates/invoice-service-management-system/client/src/components/Service.jsx +390 -0
- package/templates/invoice-service-management-system/client/src/index.css +1 -0
- package/templates/invoice-service-management-system/client/src/main.jsx +13 -0
- package/templates/invoice-service-management-system/client/vite.config.js +9 -0
- package/templates/invoice-service-management-system/server/.env +8 -0
- package/templates/invoice-service-management-system/server/Functions/Customer.js +79 -0
- package/templates/invoice-service-management-system/server/Functions/Invoice.js +192 -0
- package/templates/invoice-service-management-system/server/Functions/Service.js +86 -0
- package/templates/invoice-service-management-system/server/Functions/dashboard.js +33 -0
- package/templates/invoice-service-management-system/server/Functions/report.js +50 -0
- package/templates/invoice-service-management-system/server/Functions/users.js +101 -0
- package/templates/invoice-service-management-system/server/db.js +22 -0
- package/templates/invoice-service-management-system/server/package.json +23 -0
- package/templates/invoice-service-management-system/server/server.js +294 -0
- package/templates/slot-car-management-system/client/README.md +16 -0
- package/templates/slot-car-management-system/client/eslint.config.js +21 -0
- package/templates/slot-car-management-system/client/index.html +13 -0
- package/templates/slot-car-management-system/client/package.json +35 -0
- package/templates/slot-car-management-system/client/public/favicon.svg +1 -0
- package/templates/slot-car-management-system/client/public/icons.svg +24 -0
- package/templates/slot-car-management-system/client/src/App.css +184 -0
- package/templates/slot-car-management-system/client/src/App.jsx +49 -0
- package/templates/slot-car-management-system/client/src/assets/hero.png +0 -0
- package/templates/slot-car-management-system/client/src/assets/react.svg +1 -0
- package/templates/slot-car-management-system/client/src/assets/vite.svg +1 -0
- package/templates/slot-car-management-system/client/src/components/Cars.jsx +246 -0
- package/templates/slot-car-management-system/client/src/components/Dashboard.jsx +629 -0
- package/templates/slot-car-management-system/client/src/components/Login.jsx +170 -0
- package/templates/slot-car-management-system/client/src/components/PageNotFound.jsx +11 -0
- package/templates/slot-car-management-system/client/src/components/ParkingRecord.jsx +553 -0
- package/templates/slot-car-management-system/client/src/components/ParkingSlot.jsx +268 -0
- package/templates/slot-car-management-system/client/src/components/Payment.jsx +464 -0
- package/templates/slot-car-management-system/client/src/components/Register.jsx +171 -0
- package/templates/slot-car-management-system/client/src/components/Report.jsx +407 -0
- package/templates/slot-car-management-system/client/src/index.css +1 -0
- package/templates/slot-car-management-system/client/src/main.jsx +10 -0
- package/templates/slot-car-management-system/client/vite.config.js +9 -0
- package/templates/slot-car-management-system/parking_slot.sql +218 -0
- package/templates/slot-car-management-system/server/.env +8 -0
- package/templates/slot-car-management-system/server/Functions/Payment.js +107 -0
- package/templates/slot-car-management-system/server/Functions/car.js +93 -0
- package/templates/slot-car-management-system/server/Functions/dashboard.js +64 -0
- package/templates/slot-car-management-system/server/Functions/parkingRecord.js +220 -0
- package/templates/slot-car-management-system/server/Functions/parkingslot.js +58 -0
- package/templates/slot-car-management-system/server/Functions/report.js +48 -0
- package/templates/slot-car-management-system/server/Functions/users.js +101 -0
- package/templates/slot-car-management-system/server/db.js +22 -0
- package/templates/slot-car-management-system/server/package.json +23 -0
- package/templates/slot-car-management-system/server/server.js +192 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
-- phpMyAdmin SQL Dump
|
|
2
|
+
-- version 5.2.1
|
|
3
|
+
-- https://www.phpmyadmin.net/
|
|
4
|
+
--
|
|
5
|
+
-- Host: 127.0.0.1
|
|
6
|
+
-- Generation Time: May 25, 2026 at 12:59 PM
|
|
7
|
+
-- Server version: 10.4.32-MariaDB
|
|
8
|
+
-- PHP Version: 8.0.30
|
|
9
|
+
|
|
10
|
+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
|
11
|
+
START TRANSACTION;
|
|
12
|
+
SET time_zone = "+00:00";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
|
17
|
+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
|
18
|
+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
|
19
|
+
/*!40101 SET NAMES utf8mb4 */;
|
|
20
|
+
|
|
21
|
+
--
|
|
22
|
+
-- Database: `parking_slot`
|
|
23
|
+
--
|
|
24
|
+
|
|
25
|
+
-- --------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
--
|
|
28
|
+
-- Table structure for table `car`
|
|
29
|
+
--
|
|
30
|
+
|
|
31
|
+
CREATE TABLE `car` (
|
|
32
|
+
`PlateNumber` int(11) NOT NULL,
|
|
33
|
+
`DriverName` varchar(255) NOT NULL,
|
|
34
|
+
`PhoneNumber` varchar(255) NOT NULL
|
|
35
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
36
|
+
|
|
37
|
+
--
|
|
38
|
+
-- Dumping data for table `car`
|
|
39
|
+
--
|
|
40
|
+
|
|
41
|
+
INSERT INTO `car` (`PlateNumber`, `DriverName`, `PhoneNumber`) VALUES
|
|
42
|
+
(1, 'cedrick', '0780353135'),
|
|
43
|
+
(2, '07893653', 'ceos nd');
|
|
44
|
+
|
|
45
|
+
-- --------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
--
|
|
48
|
+
-- Table structure for table `parkingrecord`
|
|
49
|
+
--
|
|
50
|
+
|
|
51
|
+
CREATE TABLE `parkingrecord` (
|
|
52
|
+
`recordNumber` int(11) NOT NULL,
|
|
53
|
+
`EntryTime` datetime NOT NULL,
|
|
54
|
+
`ExitTime` datetime NOT NULL,
|
|
55
|
+
`Duration` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
|
56
|
+
`PlateNumber` int(11) NOT NULL,
|
|
57
|
+
`SlotNumber` int(11) NOT NULL
|
|
58
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
59
|
+
|
|
60
|
+
--
|
|
61
|
+
-- Dumping data for table `parkingrecord`
|
|
62
|
+
--
|
|
63
|
+
|
|
64
|
+
INSERT INTO `parkingrecord` (`recordNumber`, `EntryTime`, `ExitTime`, `Duration`, `PlateNumber`, `SlotNumber`) VALUES
|
|
65
|
+
(1, '2026-05-02 08:46:00', '2026-05-07 10:46:00', '2000-01-21 22:00:00', 1, 1);
|
|
66
|
+
|
|
67
|
+
-- --------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
--
|
|
70
|
+
-- Table structure for table `parkingslot`
|
|
71
|
+
--
|
|
72
|
+
|
|
73
|
+
CREATE TABLE `parkingslot` (
|
|
74
|
+
`SlotNumber` int(11) NOT NULL,
|
|
75
|
+
`SlotStatus` varchar(255) NOT NULL
|
|
76
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
77
|
+
|
|
78
|
+
--
|
|
79
|
+
-- Dumping data for table `parkingslot`
|
|
80
|
+
--
|
|
81
|
+
|
|
82
|
+
INSERT INTO `parkingslot` (`SlotNumber`, `SlotStatus`) VALUES
|
|
83
|
+
(1, 'active'),
|
|
84
|
+
(2, 'Available');
|
|
85
|
+
|
|
86
|
+
-- --------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
--
|
|
89
|
+
-- Table structure for table `payment`
|
|
90
|
+
--
|
|
91
|
+
|
|
92
|
+
CREATE TABLE `payment` (
|
|
93
|
+
`PaymentNumber` int(11) NOT NULL,
|
|
94
|
+
`AmountPaid` varchar(255) NOT NULL,
|
|
95
|
+
`PaymentDate` datetime NOT NULL,
|
|
96
|
+
`recordNumber` int(11) NOT NULL
|
|
97
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
98
|
+
|
|
99
|
+
--
|
|
100
|
+
-- Dumping data for table `payment`
|
|
101
|
+
--
|
|
102
|
+
|
|
103
|
+
INSERT INTO `payment` (`PaymentNumber`, `AmountPaid`, `PaymentDate`, `recordNumber`) VALUES
|
|
104
|
+
(1, '300000', '2026-05-25 05:51:53', 1);
|
|
105
|
+
|
|
106
|
+
-- --------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
--
|
|
109
|
+
-- Table structure for table `users`
|
|
110
|
+
--
|
|
111
|
+
|
|
112
|
+
CREATE TABLE `users` (
|
|
113
|
+
`id` int(11) NOT NULL,
|
|
114
|
+
`Name` varchar(255) NOT NULL,
|
|
115
|
+
`Email` varchar(255) NOT NULL,
|
|
116
|
+
`Password` text NOT NULL
|
|
117
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
118
|
+
|
|
119
|
+
--
|
|
120
|
+
-- Dumping data for table `users`
|
|
121
|
+
--
|
|
122
|
+
|
|
123
|
+
INSERT INTO `users` (`id`, `Name`, `Email`, `Password`) VALUES
|
|
124
|
+
(1, 'cedrick', 'cedrick@gmail.com', '$2b$10$824YceNKmQfWerPGTHfl.OgOoIz6LC4nMCVPptkkOKY1vKfhNzAhW');
|
|
125
|
+
|
|
126
|
+
--
|
|
127
|
+
-- Indexes for dumped tables
|
|
128
|
+
--
|
|
129
|
+
|
|
130
|
+
--
|
|
131
|
+
-- Indexes for table `car`
|
|
132
|
+
--
|
|
133
|
+
ALTER TABLE `car`
|
|
134
|
+
ADD PRIMARY KEY (`PlateNumber`);
|
|
135
|
+
|
|
136
|
+
--
|
|
137
|
+
-- Indexes for table `parkingrecord`
|
|
138
|
+
--
|
|
139
|
+
ALTER TABLE `parkingrecord`
|
|
140
|
+
ADD PRIMARY KEY (`recordNumber`),
|
|
141
|
+
ADD KEY `PlateNumber` (`PlateNumber`),
|
|
142
|
+
ADD KEY `SlotNumber` (`SlotNumber`);
|
|
143
|
+
|
|
144
|
+
--
|
|
145
|
+
-- Indexes for table `parkingslot`
|
|
146
|
+
--
|
|
147
|
+
ALTER TABLE `parkingslot`
|
|
148
|
+
ADD PRIMARY KEY (`SlotNumber`);
|
|
149
|
+
|
|
150
|
+
--
|
|
151
|
+
-- Indexes for table `payment`
|
|
152
|
+
--
|
|
153
|
+
ALTER TABLE `payment`
|
|
154
|
+
ADD PRIMARY KEY (`PaymentNumber`),
|
|
155
|
+
ADD KEY `recordNumber` (`recordNumber`);
|
|
156
|
+
|
|
157
|
+
--
|
|
158
|
+
-- Indexes for table `users`
|
|
159
|
+
--
|
|
160
|
+
ALTER TABLE `users`
|
|
161
|
+
ADD PRIMARY KEY (`id`),
|
|
162
|
+
ADD UNIQUE KEY `1` (`Email`);
|
|
163
|
+
|
|
164
|
+
--
|
|
165
|
+
-- AUTO_INCREMENT for dumped tables
|
|
166
|
+
--
|
|
167
|
+
|
|
168
|
+
--
|
|
169
|
+
-- AUTO_INCREMENT for table `car`
|
|
170
|
+
--
|
|
171
|
+
ALTER TABLE `car`
|
|
172
|
+
MODIFY `PlateNumber` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
|
|
173
|
+
|
|
174
|
+
--
|
|
175
|
+
-- AUTO_INCREMENT for table `parkingrecord`
|
|
176
|
+
--
|
|
177
|
+
ALTER TABLE `parkingrecord`
|
|
178
|
+
MODIFY `recordNumber` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
|
|
179
|
+
|
|
180
|
+
--
|
|
181
|
+
-- AUTO_INCREMENT for table `parkingslot`
|
|
182
|
+
--
|
|
183
|
+
ALTER TABLE `parkingslot`
|
|
184
|
+
MODIFY `SlotNumber` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
|
|
185
|
+
|
|
186
|
+
--
|
|
187
|
+
-- AUTO_INCREMENT for table `payment`
|
|
188
|
+
--
|
|
189
|
+
ALTER TABLE `payment`
|
|
190
|
+
MODIFY `PaymentNumber` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
|
|
191
|
+
|
|
192
|
+
--
|
|
193
|
+
-- AUTO_INCREMENT for table `users`
|
|
194
|
+
--
|
|
195
|
+
ALTER TABLE `users`
|
|
196
|
+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
|
|
197
|
+
|
|
198
|
+
--
|
|
199
|
+
-- Constraints for dumped tables
|
|
200
|
+
--
|
|
201
|
+
|
|
202
|
+
--
|
|
203
|
+
-- Constraints for table `parkingrecord`
|
|
204
|
+
--
|
|
205
|
+
ALTER TABLE `parkingrecord`
|
|
206
|
+
ADD CONSTRAINT `parkingrecord_ibfk_1` FOREIGN KEY (`PlateNumber`) REFERENCES `car` (`PlateNumber`),
|
|
207
|
+
ADD CONSTRAINT `parkingrecord_ibfk_2` FOREIGN KEY (`SlotNumber`) REFERENCES `parkingslot` (`SlotNumber`);
|
|
208
|
+
|
|
209
|
+
--
|
|
210
|
+
-- Constraints for table `payment`
|
|
211
|
+
--
|
|
212
|
+
ALTER TABLE `payment`
|
|
213
|
+
ADD CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`recordNumber`) REFERENCES `parkingrecord` (`recordNumber`);
|
|
214
|
+
COMMIT;
|
|
215
|
+
|
|
216
|
+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
|
217
|
+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
|
218
|
+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import db from "../db.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// ============================
|
|
6
|
+
// CREATE PAYMENT
|
|
7
|
+
// ============================
|
|
8
|
+
export const createPayment = (req, res) => {
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
AmountPaid,
|
|
12
|
+
PaymentDate,
|
|
13
|
+
recordNumber
|
|
14
|
+
} = req.body;
|
|
15
|
+
|
|
16
|
+
// VALIDATION
|
|
17
|
+
if (
|
|
18
|
+
!AmountPaid ||
|
|
19
|
+
!PaymentDate ||
|
|
20
|
+
!recordNumber
|
|
21
|
+
) {
|
|
22
|
+
return res.status(400).json({
|
|
23
|
+
Error: "All fields are required"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const sql = `
|
|
28
|
+
INSERT INTO payment
|
|
29
|
+
(
|
|
30
|
+
AmountPaid,
|
|
31
|
+
PaymentDate,
|
|
32
|
+
recordNumber
|
|
33
|
+
)
|
|
34
|
+
VALUES (?, ?, ?)
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
db.query(
|
|
38
|
+
sql,
|
|
39
|
+
[
|
|
40
|
+
AmountPaid,
|
|
41
|
+
PaymentDate,
|
|
42
|
+
recordNumber
|
|
43
|
+
],
|
|
44
|
+
(err, result) => {
|
|
45
|
+
|
|
46
|
+
if (err) {
|
|
47
|
+
|
|
48
|
+
return res.status(500).json({
|
|
49
|
+
Error: err.message
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return res.status(201).json({
|
|
54
|
+
Message: "Payment inserted successfully"
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// ============================
|
|
63
|
+
// GET ALL PAYMENTS
|
|
64
|
+
// ============================
|
|
65
|
+
export const getPayments = (req, res) => {
|
|
66
|
+
|
|
67
|
+
const sql = `
|
|
68
|
+
SELECT
|
|
69
|
+
payment.PaymentNumber,
|
|
70
|
+
payment.AmountPaid,
|
|
71
|
+
payment.PaymentDate,
|
|
72
|
+
|
|
73
|
+
parkingrecord.recordNumber,
|
|
74
|
+
|
|
75
|
+
car.PlateNumber,
|
|
76
|
+
|
|
77
|
+
parkingslot.SlotNumber
|
|
78
|
+
|
|
79
|
+
FROM payment
|
|
80
|
+
|
|
81
|
+
JOIN parkingrecord
|
|
82
|
+
ON payment.recordNumber =
|
|
83
|
+
parkingrecord.recordNumber
|
|
84
|
+
|
|
85
|
+
JOIN car
|
|
86
|
+
ON parkingrecord.PlateNumber =
|
|
87
|
+
car.PlateNumber
|
|
88
|
+
|
|
89
|
+
JOIN parkingslot
|
|
90
|
+
ON parkingrecord.SlotNumber =
|
|
91
|
+
parkingslot.SlotNumber
|
|
92
|
+
|
|
93
|
+
ORDER BY payment.PaymentDate DESC
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
db.query(sql, (err, result) => {
|
|
97
|
+
|
|
98
|
+
if (err) {
|
|
99
|
+
|
|
100
|
+
return res.status(500).json({
|
|
101
|
+
Error: err.message
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return res.status(200).json(result);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import db from "../db.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// ============================
|
|
7
|
+
// INSERT CAR
|
|
8
|
+
// ============================
|
|
9
|
+
export const InsertCar = (req, res) => {
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
PlateNumber,
|
|
13
|
+
DriverName,
|
|
14
|
+
PhoneNumber
|
|
15
|
+
} = req.body;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// VALIDATION
|
|
19
|
+
if (
|
|
20
|
+
!PlateNumber ||
|
|
21
|
+
!DriverName ||
|
|
22
|
+
!PhoneNumber
|
|
23
|
+
) {
|
|
24
|
+
return res.status(400).json({
|
|
25
|
+
Error: "All fields are required"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const sql = `
|
|
31
|
+
INSERT INTO Car
|
|
32
|
+
(
|
|
33
|
+
PlateNumber,
|
|
34
|
+
DriverName,
|
|
35
|
+
PhoneNumber
|
|
36
|
+
)
|
|
37
|
+
VALUES (?, ?,?)
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
db.query(
|
|
42
|
+
sql,
|
|
43
|
+
[
|
|
44
|
+
PlateNumber,
|
|
45
|
+
DriverName,
|
|
46
|
+
PhoneNumber
|
|
47
|
+
],
|
|
48
|
+
(err, result) => {
|
|
49
|
+
|
|
50
|
+
if (err) {
|
|
51
|
+
|
|
52
|
+
return res.status(500).json({
|
|
53
|
+
Error: `Failed to insert car: ${err.message}`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return res.status(201).json({
|
|
58
|
+
Message: "Car inserted successfully"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// ============================
|
|
70
|
+
// SELECT ALL CARS
|
|
71
|
+
// ============================
|
|
72
|
+
export const SelectCar = (req, res) => {
|
|
73
|
+
|
|
74
|
+
const sql = `
|
|
75
|
+
SELECT * FROM Car
|
|
76
|
+
ORDER BY PlateNumber DESC
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
db.query(sql, (err, result) => {
|
|
81
|
+
|
|
82
|
+
if (err) {
|
|
83
|
+
|
|
84
|
+
console.log(err);
|
|
85
|
+
|
|
86
|
+
return res.status(500).json({
|
|
87
|
+
Error: "Failed to fetch cars"
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return res.status(200).json(result);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import db from "../db.js";
|
|
2
|
+
|
|
3
|
+
export const dashboardStats = (req, res) => {
|
|
4
|
+
|
|
5
|
+
const sqlCars =
|
|
6
|
+
"SELECT COUNT(*) AS totalCars FROM car";
|
|
7
|
+
|
|
8
|
+
const sqlSlots =
|
|
9
|
+
"SELECT COUNT(*) AS totalSlots FROM parkingslot";
|
|
10
|
+
|
|
11
|
+
const sqlRecords =
|
|
12
|
+
"SELECT COUNT(*) AS totalRecords FROM parkingrecord";
|
|
13
|
+
|
|
14
|
+
const sqlPayments =
|
|
15
|
+
"SELECT COUNT(*) AS totalPayments FROM payment";
|
|
16
|
+
|
|
17
|
+
db.query(sqlCars, (err, carsResult) => {
|
|
18
|
+
|
|
19
|
+
if (err) {
|
|
20
|
+
return res.status(500).json({
|
|
21
|
+
Error: err.message
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
db.query(sqlSlots, (err, slotsResult) => {
|
|
26
|
+
|
|
27
|
+
if (err) {
|
|
28
|
+
return res.status(500).json({
|
|
29
|
+
Error: err.message
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
db.query(sqlRecords, (err, recordsResult) => {
|
|
34
|
+
|
|
35
|
+
if (err) {
|
|
36
|
+
return res.status(500).json({
|
|
37
|
+
Error: err.message
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
db.query(sqlPayments, (err, paymentsResult) => {
|
|
42
|
+
|
|
43
|
+
if (err) {
|
|
44
|
+
return res.status(500).json({
|
|
45
|
+
Error: err.message
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return res.status(200).json({
|
|
50
|
+
cars: carsResult[0].totalCars,
|
|
51
|
+
slots: slotsResult[0].totalSlots,
|
|
52
|
+
records: recordsResult[0].totalRecords,
|
|
53
|
+
payments: paymentsResult[0].totalPayments
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import db from "../db.js";
|
|
2
|
+
|
|
3
|
+
// ============================
|
|
4
|
+
// CREATE PARKING RECORD
|
|
5
|
+
// ============================
|
|
6
|
+
export const createParkingRecord = (req, res) => {
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
EntryTime,
|
|
10
|
+
ExitTime,
|
|
11
|
+
PlateNumber,
|
|
12
|
+
SlotNumber
|
|
13
|
+
} = req.body;
|
|
14
|
+
|
|
15
|
+
// VALIDATION
|
|
16
|
+
if (
|
|
17
|
+
!EntryTime ||
|
|
18
|
+
!ExitTime ||
|
|
19
|
+
!PlateNumber ||
|
|
20
|
+
!SlotNumber
|
|
21
|
+
) {
|
|
22
|
+
return res.status(400).json({
|
|
23
|
+
Error: "All fields are required"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// CALCULATE DURATION IN HOURS
|
|
28
|
+
const entry = new Date(EntryTime);
|
|
29
|
+
const exit = new Date(ExitTime);
|
|
30
|
+
|
|
31
|
+
const durationMs = exit - entry;
|
|
32
|
+
|
|
33
|
+
const durationHours = Math.ceil(
|
|
34
|
+
durationMs / (1000 * 60 * 60)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const sql = `
|
|
38
|
+
INSERT INTO parkingrecord
|
|
39
|
+
(
|
|
40
|
+
EntryTime,
|
|
41
|
+
ExitTime,
|
|
42
|
+
Duration,
|
|
43
|
+
PlateNumber,
|
|
44
|
+
SlotNumber
|
|
45
|
+
)
|
|
46
|
+
VALUES (?, ?, ?, ?, ?)
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
db.query(
|
|
50
|
+
sql,
|
|
51
|
+
[
|
|
52
|
+
EntryTime,
|
|
53
|
+
ExitTime,
|
|
54
|
+
durationHours,
|
|
55
|
+
PlateNumber,
|
|
56
|
+
SlotNumber
|
|
57
|
+
],
|
|
58
|
+
(err, result) => {
|
|
59
|
+
|
|
60
|
+
if (err) {
|
|
61
|
+
|
|
62
|
+
console.log(err);
|
|
63
|
+
|
|
64
|
+
return res.status(500).json({
|
|
65
|
+
Error: err.message
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return res.status(201).json({
|
|
70
|
+
message: "Parking record inserted successfully"
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// ============================
|
|
80
|
+
// GET ALL PARKING RECORDS
|
|
81
|
+
// ============================
|
|
82
|
+
export const getAllParkingRecords = (req, res) => {
|
|
83
|
+
|
|
84
|
+
const sql = `
|
|
85
|
+
SELECT
|
|
86
|
+
parkingrecord.*,
|
|
87
|
+
car.DriverName,
|
|
88
|
+
parkingslot.SlotStatus
|
|
89
|
+
FROM parkingrecord
|
|
90
|
+
JOIN car
|
|
91
|
+
ON parkingrecord.PlateNumber = car.PlateNumber
|
|
92
|
+
JOIN parkingslot
|
|
93
|
+
ON parkingrecord.SlotNumber = parkingslot.SlotNumber
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
db.query(sql, (err, result) => {
|
|
97
|
+
|
|
98
|
+
if (err) {
|
|
99
|
+
return res.status(500).json(err);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
res.json(result);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
// ============================
|
|
109
|
+
// GET SINGLE PARKING RECORD
|
|
110
|
+
// ============================
|
|
111
|
+
export const getSingleParkingRecord = (req, res) => {
|
|
112
|
+
|
|
113
|
+
const id = req.params.id;
|
|
114
|
+
|
|
115
|
+
const sql = `
|
|
116
|
+
SELECT * FROM parkingrecord
|
|
117
|
+
WHERE recordNumber = ?
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
db.query(sql, [id], (err, result) => {
|
|
121
|
+
|
|
122
|
+
if (err) {
|
|
123
|
+
return res.status(500).json(err);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
res.json(result[0]);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
// ============================
|
|
133
|
+
// UPDATE PARKING RECORD
|
|
134
|
+
// ============================
|
|
135
|
+
export const updateParkingRecord = (req, res) => {
|
|
136
|
+
|
|
137
|
+
const id = req.params.id;
|
|
138
|
+
|
|
139
|
+
const {
|
|
140
|
+
EntryTime,
|
|
141
|
+
ExitTime,
|
|
142
|
+
PlateNumber,
|
|
143
|
+
SlotNumber
|
|
144
|
+
} = req.body;
|
|
145
|
+
|
|
146
|
+
// CALCULATE DURATION
|
|
147
|
+
const entry = new Date(EntryTime);
|
|
148
|
+
|
|
149
|
+
const exit = new Date(ExitTime);
|
|
150
|
+
|
|
151
|
+
const durationMs = exit - entry;
|
|
152
|
+
|
|
153
|
+
const durationHours = Math.ceil(
|
|
154
|
+
durationMs / (1000 * 60 * 60)
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const sql = `
|
|
158
|
+
UPDATE parkingrecord
|
|
159
|
+
SET
|
|
160
|
+
EntryTime = ?,
|
|
161
|
+
ExitTime = ?,
|
|
162
|
+
Duration = ?,
|
|
163
|
+
PlateNumber = ?,
|
|
164
|
+
SlotNumber = ?
|
|
165
|
+
WHERE recordNumber = ?
|
|
166
|
+
`;
|
|
167
|
+
|
|
168
|
+
db.query(
|
|
169
|
+
sql,
|
|
170
|
+
[
|
|
171
|
+
EntryTime,
|
|
172
|
+
ExitTime,
|
|
173
|
+
durationHours,
|
|
174
|
+
PlateNumber,
|
|
175
|
+
SlotNumber,
|
|
176
|
+
id
|
|
177
|
+
],
|
|
178
|
+
(err, result) => {
|
|
179
|
+
|
|
180
|
+
if (err) {
|
|
181
|
+
return res.status(500).json(err);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
res.json({
|
|
185
|
+
message: "Parking record updated successfully"
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
// ============================
|
|
194
|
+
// DELETE PARKING RECORD
|
|
195
|
+
// ============================
|
|
196
|
+
export const deleteParkingRecord = (req, res) => {
|
|
197
|
+
|
|
198
|
+
const id = req.params.id;
|
|
199
|
+
|
|
200
|
+
const sql = `
|
|
201
|
+
DELETE FROM parkingrecord
|
|
202
|
+
WHERE recordNumber = ?
|
|
203
|
+
`;
|
|
204
|
+
|
|
205
|
+
db.query(sql, [id], (err, result) => {
|
|
206
|
+
|
|
207
|
+
if (err) {
|
|
208
|
+
|
|
209
|
+
return res.status(500).json({
|
|
210
|
+
Error: err.message
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return res.status(200).json({
|
|
215
|
+
message: "Parking record deleted successfully"
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
};
|