create-cedro-app 1.0.2 → 1.0.4
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/inventory-management-system/client/README.md +16 -0
- package/templates/inventory-management-system/client/eslint.config.js +21 -0
- package/templates/inventory-management-system/client/index.html +13 -0
- package/templates/inventory-management-system/client/package.json +35 -0
- package/templates/inventory-management-system/client/public/favicon.svg +1 -0
- package/templates/inventory-management-system/client/public/icons.svg +24 -0
- package/templates/inventory-management-system/client/src/App.jsx +15 -0
- package/templates/inventory-management-system/client/src/assets/hero.png +0 -0
- package/templates/inventory-management-system/client/src/assets/react.svg +1 -0
- package/templates/inventory-management-system/client/src/assets/vite.svg +1 -0
- package/templates/inventory-management-system/client/src/components/AppRoutes.jsx +39 -0
- package/templates/inventory-management-system/client/src/components/Customer.jsx +326 -0
- package/templates/inventory-management-system/client/src/components/Dashboard.jsx +512 -0
- package/templates/inventory-management-system/client/src/components/Invoice.jsx +523 -0
- package/templates/inventory-management-system/client/src/components/Login.jsx +170 -0
- package/templates/inventory-management-system/client/src/components/PageNotFound.jsx +11 -0
- package/templates/inventory-management-system/client/src/components/Register.jsx +171 -0
- package/templates/inventory-management-system/client/src/components/Report.jsx +383 -0
- package/templates/inventory-management-system/client/src/components/Service.jsx +390 -0
- package/templates/inventory-management-system/client/src/index.css +1 -0
- package/templates/inventory-management-system/client/src/main.jsx +13 -0
- package/templates/inventory-management-system/client/vite.config.js +9 -0
- package/templates/inventory-management-system/server/.env +8 -0
- package/templates/inventory-management-system/server/Functions/Customer.js +79 -0
- package/templates/inventory-management-system/server/Functions/Invoice.js +192 -0
- package/templates/inventory-management-system/server/Functions/Service.js +86 -0
- package/templates/inventory-management-system/server/Functions/dashboard.js +33 -0
- package/templates/inventory-management-system/server/Functions/report.js +50 -0
- package/templates/inventory-management-system/server/Functions/users.js +101 -0
- package/templates/inventory-management-system/server/db.js +22 -0
- package/templates/inventory-management-system/server/package.json +23 -0
- package/templates/inventory-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,390 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { toast } from "react-toastify";
|
|
4
|
+
import {
|
|
5
|
+
Trash2,
|
|
6
|
+
Pencil,
|
|
7
|
+
Wrench
|
|
8
|
+
} from "lucide-react";
|
|
9
|
+
import { useNavigate } from "react-router-dom";
|
|
10
|
+
|
|
11
|
+
function Services() {
|
|
12
|
+
|
|
13
|
+
const token = localStorage.getItem("token");
|
|
14
|
+
|
|
15
|
+
const navigate = useNavigate();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
|
|
19
|
+
const token = localStorage.getItem("token");
|
|
20
|
+
|
|
21
|
+
if (!token) {
|
|
22
|
+
navigate("/");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}, [navigate]);
|
|
26
|
+
|
|
27
|
+
const [services, setServices] = useState([]);
|
|
28
|
+
|
|
29
|
+
const [editId, setEditId] = useState(null);
|
|
30
|
+
|
|
31
|
+
const [values, setValues] = useState({
|
|
32
|
+
ServiceCode: "",
|
|
33
|
+
ServiceName: "",
|
|
34
|
+
ServiceCost: "",
|
|
35
|
+
TotalDeduction: ""
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const fetchServices = async () => {
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
|
|
42
|
+
const res = await axios.get(
|
|
43
|
+
"http://localhost:3000/selectservices",
|
|
44
|
+
{
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Bearer ${token}`
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
setServices(res.data || []);
|
|
52
|
+
|
|
53
|
+
} catch (error) {
|
|
54
|
+
|
|
55
|
+
toast.error("Failed to load services");
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
|
|
61
|
+
fetchServices();
|
|
62
|
+
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
const handleSubmit = async (e) => {
|
|
66
|
+
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
|
|
71
|
+
if (editId) {
|
|
72
|
+
|
|
73
|
+
await axios.put(
|
|
74
|
+
`http://localhost:3000/updateservice/${editId}`,
|
|
75
|
+
values,
|
|
76
|
+
{
|
|
77
|
+
headers: {
|
|
78
|
+
Authorization: `Bearer ${token}`
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
toast.success("Service updated");
|
|
84
|
+
|
|
85
|
+
setEditId(null);
|
|
86
|
+
|
|
87
|
+
} else {
|
|
88
|
+
|
|
89
|
+
await axios.post(
|
|
90
|
+
"http://localhost:3000/insertservice",
|
|
91
|
+
values,
|
|
92
|
+
{
|
|
93
|
+
headers: {
|
|
94
|
+
Authorization: `Bearer ${token}`
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
toast.success("Service created");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setValues({
|
|
103
|
+
ServiceCode: "",
|
|
104
|
+
ServiceName: "",
|
|
105
|
+
ServiceCost: "",
|
|
106
|
+
TotalDeduction: ""
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
fetchServices();
|
|
110
|
+
|
|
111
|
+
} catch (error) {
|
|
112
|
+
|
|
113
|
+
toast.error(
|
|
114
|
+
error.response?.data?.Error ||
|
|
115
|
+
"Error saving service"
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const deleteService = async (code) => {
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
|
|
124
|
+
await axios.delete(
|
|
125
|
+
`http://localhost:3000/deleteservice/${code}`,
|
|
126
|
+
{
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: `Bearer ${token}`
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
toast.success("Service deleted");
|
|
134
|
+
|
|
135
|
+
fetchServices();
|
|
136
|
+
|
|
137
|
+
} catch (error) {
|
|
138
|
+
|
|
139
|
+
toast.error("Delete failed");
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const editService = (service) => {
|
|
144
|
+
|
|
145
|
+
setValues({
|
|
146
|
+
ServiceCode: service.ServiceCode,
|
|
147
|
+
ServiceName: service.ServiceName,
|
|
148
|
+
ServiceCost: service.ServiceCost,
|
|
149
|
+
TotalDeduction: service.TotalDeduction
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
setEditId(service.ServiceCode);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
|
|
157
|
+
<div className="p-6">
|
|
158
|
+
|
|
159
|
+
<div className="mb-6">
|
|
160
|
+
|
|
161
|
+
<h1 className="text-3xl font-bold text-gray-800">
|
|
162
|
+
Services
|
|
163
|
+
</h1>
|
|
164
|
+
|
|
165
|
+
<p className="text-gray-500 mt-1">
|
|
166
|
+
Manage vehicle services
|
|
167
|
+
</p>
|
|
168
|
+
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div className="bg-white p-8 rounded-2xl shadow-lg mb-8 border">
|
|
172
|
+
|
|
173
|
+
<div className="flex items-center gap-3 mb-6">
|
|
174
|
+
|
|
175
|
+
<Wrench
|
|
176
|
+
className="text-indigo-600"
|
|
177
|
+
size={30}
|
|
178
|
+
/>
|
|
179
|
+
|
|
180
|
+
<h2 className="text-2xl font-bold text-indigo-600">
|
|
181
|
+
|
|
182
|
+
{editId
|
|
183
|
+
? "Update Service"
|
|
184
|
+
: "Add Service"}
|
|
185
|
+
|
|
186
|
+
</h2>
|
|
187
|
+
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<form
|
|
191
|
+
onSubmit={handleSubmit}
|
|
192
|
+
className="grid grid-cols-1 md:grid-cols-2 gap-5"
|
|
193
|
+
>
|
|
194
|
+
|
|
195
|
+
<input
|
|
196
|
+
type="text"
|
|
197
|
+
placeholder="Service Code"
|
|
198
|
+
className="border p-3 rounded-xl"
|
|
199
|
+
value={values.ServiceCode}
|
|
200
|
+
onChange={(e) =>
|
|
201
|
+
setValues({
|
|
202
|
+
...values,
|
|
203
|
+
ServiceCode: e.target.value
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
required
|
|
207
|
+
disabled={editId}
|
|
208
|
+
/>
|
|
209
|
+
|
|
210
|
+
<input
|
|
211
|
+
type="text"
|
|
212
|
+
placeholder="Service Name"
|
|
213
|
+
className="border p-3 rounded-xl"
|
|
214
|
+
value={values.ServiceName}
|
|
215
|
+
onChange={(e) =>
|
|
216
|
+
setValues({
|
|
217
|
+
...values,
|
|
218
|
+
ServiceName: e.target.value
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
required
|
|
222
|
+
/>
|
|
223
|
+
|
|
224
|
+
<input
|
|
225
|
+
type="text"
|
|
226
|
+
placeholder="Service Cost"
|
|
227
|
+
className="border p-3 rounded-xl"
|
|
228
|
+
value={values.ServiceCost}
|
|
229
|
+
onChange={(e) =>
|
|
230
|
+
setValues({
|
|
231
|
+
...values,
|
|
232
|
+
ServiceCost: e.target.value
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
required
|
|
236
|
+
/>
|
|
237
|
+
|
|
238
|
+
<input
|
|
239
|
+
type="text"
|
|
240
|
+
placeholder="Total Deduction"
|
|
241
|
+
className="border p-3 rounded-xl"
|
|
242
|
+
value={values.TotalDeduction}
|
|
243
|
+
onChange={(e) =>
|
|
244
|
+
setValues({
|
|
245
|
+
...values,
|
|
246
|
+
TotalDeduction: e.target.value
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
required
|
|
250
|
+
/>
|
|
251
|
+
|
|
252
|
+
<button
|
|
253
|
+
className={`text-white p-3 rounded-xl font-semibold ${
|
|
254
|
+
editId
|
|
255
|
+
? "bg-green-600 hover:bg-green-700"
|
|
256
|
+
: "bg-indigo-600 hover:bg-indigo-700"
|
|
257
|
+
}`}
|
|
258
|
+
>
|
|
259
|
+
|
|
260
|
+
{editId
|
|
261
|
+
? "Update Service"
|
|
262
|
+
: "Save Service"}
|
|
263
|
+
|
|
264
|
+
</button>
|
|
265
|
+
|
|
266
|
+
</form>
|
|
267
|
+
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
<div className="bg-white rounded-2xl shadow-lg overflow-hidden border">
|
|
271
|
+
|
|
272
|
+
<div className="p-6 border-b">
|
|
273
|
+
|
|
274
|
+
<h2 className="text-2xl font-bold">
|
|
275
|
+
Services List
|
|
276
|
+
</h2>
|
|
277
|
+
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<table className="w-full">
|
|
281
|
+
|
|
282
|
+
<thead className="bg-gray-100">
|
|
283
|
+
|
|
284
|
+
<tr>
|
|
285
|
+
|
|
286
|
+
<th className="p-3">
|
|
287
|
+
Service Code
|
|
288
|
+
</th>
|
|
289
|
+
|
|
290
|
+
<th className="p-3">
|
|
291
|
+
Service Name
|
|
292
|
+
</th>
|
|
293
|
+
|
|
294
|
+
<th className="p-3">
|
|
295
|
+
Service Cost
|
|
296
|
+
</th>
|
|
297
|
+
|
|
298
|
+
<th className="p-3">
|
|
299
|
+
Total Deduction
|
|
300
|
+
</th>
|
|
301
|
+
|
|
302
|
+
<th className="p-3 text-center">
|
|
303
|
+
Actions
|
|
304
|
+
</th>
|
|
305
|
+
|
|
306
|
+
</tr>
|
|
307
|
+
|
|
308
|
+
</thead>
|
|
309
|
+
|
|
310
|
+
<tbody>
|
|
311
|
+
|
|
312
|
+
{services.length > 0 ? (
|
|
313
|
+
|
|
314
|
+
services.map((service) => (
|
|
315
|
+
|
|
316
|
+
<tr
|
|
317
|
+
key={service.ServiceCode}
|
|
318
|
+
className="text-center border-t"
|
|
319
|
+
>
|
|
320
|
+
|
|
321
|
+
<td className="p-3">
|
|
322
|
+
{service.ServiceCode}
|
|
323
|
+
</td>
|
|
324
|
+
|
|
325
|
+
<td className="p-3">
|
|
326
|
+
{service.ServiceName}
|
|
327
|
+
</td>
|
|
328
|
+
|
|
329
|
+
<td className="p-3">
|
|
330
|
+
{service.ServiceCost}
|
|
331
|
+
</td>
|
|
332
|
+
|
|
333
|
+
<td className="p-3">
|
|
334
|
+
{service.TotalDeduction}
|
|
335
|
+
</td>
|
|
336
|
+
|
|
337
|
+
<td className="p-3">
|
|
338
|
+
|
|
339
|
+
<div className="flex justify-center gap-3">
|
|
340
|
+
|
|
341
|
+
<button
|
|
342
|
+
onClick={() => editService(service)}
|
|
343
|
+
className="bg-blue-500 text-white p-2 rounded"
|
|
344
|
+
>
|
|
345
|
+
<Pencil size={18} />
|
|
346
|
+
</button>
|
|
347
|
+
|
|
348
|
+
<button
|
|
349
|
+
onClick={() =>
|
|
350
|
+
deleteService(service.ServiceCode)
|
|
351
|
+
}
|
|
352
|
+
className="bg-red-500 text-white p-2 rounded"
|
|
353
|
+
>
|
|
354
|
+
<Trash2 size={18} />
|
|
355
|
+
</button>
|
|
356
|
+
|
|
357
|
+
</div>
|
|
358
|
+
|
|
359
|
+
</td>
|
|
360
|
+
|
|
361
|
+
</tr>
|
|
362
|
+
|
|
363
|
+
))
|
|
364
|
+
|
|
365
|
+
) : (
|
|
366
|
+
|
|
367
|
+
<tr>
|
|
368
|
+
|
|
369
|
+
<td
|
|
370
|
+
colSpan="5"
|
|
371
|
+
className="text-center p-4 text-gray-500"
|
|
372
|
+
>
|
|
373
|
+
No services found
|
|
374
|
+
</td>
|
|
375
|
+
|
|
376
|
+
</tr>
|
|
377
|
+
|
|
378
|
+
)}
|
|
379
|
+
|
|
380
|
+
</tbody>
|
|
381
|
+
|
|
382
|
+
</table>
|
|
383
|
+
|
|
384
|
+
</div>
|
|
385
|
+
|
|
386
|
+
</div>
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export default Services;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StrictMode } from 'react'
|
|
2
|
+
import { createRoot } from 'react-dom/client'
|
|
3
|
+
import './index.css'
|
|
4
|
+
import App from './App.jsx'
|
|
5
|
+
import {BrowserRouter as Router} from 'react-router-dom'
|
|
6
|
+
|
|
7
|
+
createRoot(document.getElementById('root')).render(
|
|
8
|
+
<StrictMode>
|
|
9
|
+
<Router>
|
|
10
|
+
<App />
|
|
11
|
+
</Router>
|
|
12
|
+
</StrictMode>,
|
|
13
|
+
)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import db from "../db.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const InsertCustomer = (req, res) => {
|
|
8
|
+
|
|
9
|
+
const { FirstName,LastName,Address,Telephone,VehiclePlateNumber,VehicleType,ServiceDate}= req.body;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// VALIDATION
|
|
13
|
+
if (
|
|
14
|
+
!FirstName || !LastName || !Address || !Telephone || !VehiclePlateNumber || !VehicleType || !ServiceDate
|
|
15
|
+
) {
|
|
16
|
+
return res.status(400).json({
|
|
17
|
+
Error: "All fields are required"
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const sql = `
|
|
23
|
+
INSERT INTO Customer
|
|
24
|
+
(
|
|
25
|
+
FirstName,LastName,Address,Telephone,VehiclePlateNumber,VehicleType,ServiceDate
|
|
26
|
+
)
|
|
27
|
+
VALUES (?, ?,?,?,?,?,?)
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
db.query(
|
|
32
|
+
sql,
|
|
33
|
+
[
|
|
34
|
+
FirstName,LastName,Address,Telephone,VehiclePlateNumber,VehicleType,ServiceDate
|
|
35
|
+
],
|
|
36
|
+
(err, result) => {
|
|
37
|
+
|
|
38
|
+
if (err) {
|
|
39
|
+
|
|
40
|
+
return res.status(500).json({
|
|
41
|
+
Error: `Failed to insert car: ${err.message}`
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return res.status(201).json({
|
|
46
|
+
Message: "Customer inserted successfully"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export const SelectCustomers = (req, res) => {
|
|
59
|
+
|
|
60
|
+
const sql = `
|
|
61
|
+
SELECT * FROM Customer
|
|
62
|
+
ORDER BY CustomerId DESC
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
db.query(sql, (err, result) => {
|
|
67
|
+
|
|
68
|
+
if (err) {
|
|
69
|
+
|
|
70
|
+
console.log(err);
|
|
71
|
+
|
|
72
|
+
return res.status(500).json({
|
|
73
|
+
Error: "Failed to fetch cars"
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return res.status(200).json(result);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import db from "../db.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const createInvoice = (req, res) => {
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
TotalCost,
|
|
8
|
+
PaidAmount,
|
|
9
|
+
Balance,
|
|
10
|
+
PaymentMonth,
|
|
11
|
+
CustomerId,
|
|
12
|
+
ServiceCode
|
|
13
|
+
} = req.body;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if (
|
|
17
|
+
!TotalCost ||
|
|
18
|
+
!PaidAmount ||
|
|
19
|
+
!Balance ||
|
|
20
|
+
!PaymentMonth ||
|
|
21
|
+
!CustomerId ||
|
|
22
|
+
!ServiceCode
|
|
23
|
+
) {
|
|
24
|
+
return res.status(400).json({
|
|
25
|
+
Error: "All fields are required"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const sql = `
|
|
30
|
+
INSERT INTO invoice
|
|
31
|
+
(
|
|
32
|
+
TotalCost,
|
|
33
|
+
PaidAmount,
|
|
34
|
+
Balance,
|
|
35
|
+
PaymentMonth,
|
|
36
|
+
CustomerId,
|
|
37
|
+
ServiceCode
|
|
38
|
+
)
|
|
39
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
db.query(
|
|
43
|
+
sql,
|
|
44
|
+
[
|
|
45
|
+
TotalCost,
|
|
46
|
+
PaidAmount,
|
|
47
|
+
Balance,
|
|
48
|
+
PaymentMonth,
|
|
49
|
+
CustomerId,
|
|
50
|
+
ServiceCode
|
|
51
|
+
],
|
|
52
|
+
(err, result) => {
|
|
53
|
+
|
|
54
|
+
if (err) {
|
|
55
|
+
|
|
56
|
+
console.log(err);
|
|
57
|
+
|
|
58
|
+
return res.status(500).json({
|
|
59
|
+
Error: err.message
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return res.status(201).json({
|
|
64
|
+
message: "Invoice inserted successfully"
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export const getAllInvoices = (req, res) => {
|
|
73
|
+
|
|
74
|
+
const sql = `
|
|
75
|
+
SELECT
|
|
76
|
+
invoice.*,
|
|
77
|
+
customer.FirstName,
|
|
78
|
+
customer.LastName,
|
|
79
|
+
service.ServiceName
|
|
80
|
+
FROM invoice
|
|
81
|
+
JOIN customer
|
|
82
|
+
ON invoice.CustomerId = customer.CustomerId
|
|
83
|
+
JOIN service
|
|
84
|
+
ON invoice.ServiceCode = service.ServiceCode
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
db.query(sql, (err, result) => {
|
|
88
|
+
|
|
89
|
+
if (err) {
|
|
90
|
+
return res.status(500).json(err);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
res.json(result);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
export const getSingleInvoice = (req, res) => {
|
|
99
|
+
|
|
100
|
+
const id = req.params.id;
|
|
101
|
+
|
|
102
|
+
const sql = `
|
|
103
|
+
SELECT * FROM invoice
|
|
104
|
+
WHERE InvoiceId = ?
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
db.query(sql, [id], (err, result) => {
|
|
108
|
+
|
|
109
|
+
if (err) {
|
|
110
|
+
return res.status(500).json(err);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
res.json(result[0]);
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
export const updateInvoice = (req, res) => {
|
|
119
|
+
|
|
120
|
+
const id = req.params.id;
|
|
121
|
+
|
|
122
|
+
const {
|
|
123
|
+
TotalCost,
|
|
124
|
+
PaidAmount,
|
|
125
|
+
Balance,
|
|
126
|
+
PaymentMonth,
|
|
127
|
+
CustomerId,
|
|
128
|
+
ServiceCode
|
|
129
|
+
} = req.body;
|
|
130
|
+
|
|
131
|
+
const sql = `
|
|
132
|
+
UPDATE invoice
|
|
133
|
+
SET
|
|
134
|
+
TotalCost = ?,
|
|
135
|
+
PaidAmount = ?,
|
|
136
|
+
Balance = ?,
|
|
137
|
+
PaymentMonth = ?,
|
|
138
|
+
CustomerId = ?,
|
|
139
|
+
ServiceCode = ?
|
|
140
|
+
WHERE InvoiceId = ?
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
db.query(
|
|
144
|
+
sql,
|
|
145
|
+
[
|
|
146
|
+
TotalCost,
|
|
147
|
+
PaidAmount,
|
|
148
|
+
Balance,
|
|
149
|
+
PaymentMonth,
|
|
150
|
+
CustomerId,
|
|
151
|
+
ServiceCode,
|
|
152
|
+
id
|
|
153
|
+
],
|
|
154
|
+
(err, result) => {
|
|
155
|
+
|
|
156
|
+
if (err) {
|
|
157
|
+
return res.status(500).json(err);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
res.json({
|
|
161
|
+
message: "Invoice updated successfully"
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
export const deleteInvoice = (req, res) => {
|
|
169
|
+
|
|
170
|
+
const id = req.params.id;
|
|
171
|
+
|
|
172
|
+
const sql = `
|
|
173
|
+
DELETE FROM invoice
|
|
174
|
+
WHERE InvoiceId = ?
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
db.query(sql, [id], (err, result) => {
|
|
178
|
+
|
|
179
|
+
if (err) {
|
|
180
|
+
|
|
181
|
+
return res.status(500).json({
|
|
182
|
+
Error: err.message
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return res.status(200).json({
|
|
187
|
+
message: "Invoice deleted successfully"
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
};
|