-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOrderManagementSystem.java
More file actions
441 lines (342 loc) · 13.6 KB
/
Copy pathOrderManagementSystem.java
File metadata and controls
441 lines (342 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
import java.util.Scanner;
import java.time.LocalDate;
/**
* Main controller class for the Dough Jamaica Order Management System (DJOMS).
*
* Responsibilities:
* - Initialize managers and load data from files
* - Display menus and handle user navigation
* - Coordinate between modules (Order, Customer, Payment managers)
* - Trigger alerts for deadlines (startup + on demand)
* - Save data back to CSV files via DataStore
*/
public class OrderManagementSystem {
private final OrderManager orderManager;
private final CustomerManager customerManager;
private final PaymentManager paymentManager;
private final DataStore datastore;
private final Scanner scanner;
/**
* Constructor: loads all data and checks for alerts.
*/
public OrderManagementSystem() {
datastore = new DataStore();
// Load stored CSV data into managers
orderManager = datastore.loadOrders();
customerManager = datastore.loadCustomers();
paymentManager = datastore.loadPayments();
scanner = new Scanner(System.in);
System.out.println("\n=== Checking for Upcoming Order Deadlines... ===");
orderManager.showUpcomingAlerts(); // startup alerts
}
/**
* Main program loop. This displays menus until the user exits.
*/
public void run() {
boolean running = true;
while (running) {
printMainMenu();
int choice = readInt("Enter your choice: ");
switch (choice) {
case 1 -> manageOrders();
case 2 -> manageCustomers();
case 3 -> managePayments();
case 4 -> showAlerts(); // manual alert check
case 5 -> saveAll();
case 6 -> {
saveAll();
System.out.println("Goodbye! Exiting system...");
running = false;
}
default -> System.out.println("Invalid choice. Please try again.");
}
}
}
// --------------------------------------------------------------
// MAIN MENU
// --------------------------------------------------------------
private void printMainMenu() {
System.out.println("\n====== DOUGH JAMAICA ORDER MANAGEMENT SYSTEM ======");
System.out.println("1. Order Management");
System.out.println("2. Customer Management");
System.out.println("3. Payment Management");
System.out.println("4. Upcoming Alerts");
System.out.println("5. Save All Changes");
System.out.println("6. Exit System");
System.out.println("====================================================");
}
// --------------------------------------------------------------
// ORDER MENU
// --------------------------------------------------------------
private void manageOrders() {
System.out.println("\n--- Order Menu ---");
System.out.println("1. Add New Order");
System.out.println("2. View All Orders");
System.out.println("3. Update Order Status");
System.out.println("4. Archive Completed Orders");
System.out.println("5. Edit Customer Order");
System.out.println("6. Delete Customer Order");
System.out.println("7. Return to Main Menu");
int choice = readInt("Enter your choice: ");
switch (choice) {
case 1 -> addOrderFlow();
case 2 -> orderManager.viewOrders();
case 3 -> updateOrderStatus();
case 4 -> orderManager.archiveCompleted();
case 5 -> editOrderFlow();
case 6 -> deleteOrderFlow();
default -> System.out.println("Invalid choice.");
}
}
/**
* Flow for adding an order (simplified; can be expanded).
*/
private void addOrderFlow() {
System.out.println("\n--- Add New Order ---");
System.out.print("Enter Customer ID: ");
String id = scanner.nextLine().trim();
Customer c = customerManager.findCustomer(id);
if (c == null) {
System.out.println("Customer not found. Add customer first.");
return;
}
System.out.print("Enter delivery date (YYYY-MM-DD): ");
String date = scanner.nextLine();
System.out.print("Enter order type: ");
String type = scanner.nextLine();
System.out.print("Enter order method (Please type: \"Pickup\" or \"Delivery\"): ");
String order_method = scanner.nextLine();
order_method.trim().toLowerCase();
String address = "12 Fairway Avenue"; //Company Address
if (order_method == "delivery"){
System.out.print("Enter delivery/pickup address: ");
address = scanner.nextLine();
}
//System.out.print("Enter delivery/pickup address: ");
//String address = scanner.nextLine();
System.out.print("Enter payment method (POS/Transfer): ");
String method = scanner.nextLine();
System.out.print("Enter total amount: ");
double amt = readDouble("");
Order o = new Order(orderManager.getNextOrderID(), c,
java.time.LocalDate.parse(date), type,
address, method, amt);
orderManager.addOrder(o);
System.out.println("Order added successfully!");
}
private void editOrderFlow(){
System.out.println("\n--- Edit Order ---");
System.out.print("Enter Order ID to edit: ");
int orderID = Integer.parseInt(scanner.nextLine());
Order ordertoEdit = null;
for (Order o: orderManager.getOrdersList()){
if (o.getOrderID() == orderID){
ordertoEdit = o;
break;
}
}
if (ordertoEdit == null){
System.out.print("Order ID not found");
return;
}
System.out.print("Enter new delivery date: ");
String newDate = scanner.nextLine();
if(!newDate.isEmpty()){
try{
ordertoEdit.deliveryDate = LocalDate.parse(newDate);
} catch(Exception e){
System.out.print("Invalid Date Entered");
}
}
System.out.print("Enter new order type: ");
String newType = scanner.nextLine();
if(!newType.isEmpty()){
ordertoEdit.orderType = newType;
}
System.out.print("Enter new order method: ");
String orderMethod = scanner.nextLine();
if(!orderMethod.isEmpty()){
ordertoEdit.method = orderMethod;
}
if(ordertoEdit.method.equalsIgnoreCase("Delivery")){
System.out.print("Enter new delivery address: ");
String newAddress = scanner.nextLine();
if (!newAddress.isEmpty()){
ordertoEdit.address = newAddress;
}
} else{
ordertoEdit.address = "12 Fairway Avenue";
}
System.out.print("Enter new status method: ");
String newStatus = scanner.nextLine();
if(!orderMethod.isEmpty()){
ordertoEdit.setStatus(newStatus);
} else{
System.out.print("Invalid Status");
}
System.out.print("Order edited sucessfully");
}
private void deleteOrderFlow(){
System.out.print("Enter order ID to delete: ");
int orderID = Integer.parseInt(scanner.nextLine());
Order orderToDelete = null;
for (Order o : orderManager.getOrdersList()) {
if (o.getOrderID() == orderID) {
orderToDelete = o;
break;
}
}
if (orderToDelete == null) {
System.out.println("Error: Order not found.");
return;
}
orderManager.getOrdersList().remove(orderToDelete);
}
private void updateOrderStatus() {
int id = readInt("Enter Order ID to update: ");
orderManager.updateStatus(id, scanner);
}
// --------------------------------------------------------------
// CUSTOMER MENU
// --------------------------------------------------------------
private void manageCustomers() {
System.out.println("\n--- Customer Menu ---");
System.out.println("1. Add Customer");
System.out.println("2. View Customers");
System.out.println("3. Edit Customers");
System.out.println("4. Delete Customers");
System.out.println("5. Return to Main Menu");
int choice = readInt("Enter choice: ");
switch (choice) {
case 1 -> addCustomerFlow();
case 2 -> customerManager.viewCustomers();
case 3 -> editCustomerFlow();
case 4 -> deleteCustomerFlow();
default -> System.out.println("Invalid choice.");
}
}
private void addCustomerFlow() {
System.out.println("\n--- Add Customer ---");
String id;
while (true) { // loop until a unique ID is entered
System.out.print("Enter Customer ID: ");
id = scanner.nextLine().trim();
if (customerManager.findCustomer(id) != null) {
System.out.println("Customer ID already exists. Please enter a unique ID.");
} else {
break; // unique ID, exit loop
}
}
//System.out.print("Enter Customer ID: ");
//String id = scanner.nextLine().trim();
System.out.print("Enter name: ");
String name = scanner.nextLine();
System.out.print("Enter phone number: ");
String phone = scanner.nextLine();
System.out.print("Enter email: ");
String email = scanner.nextLine();
System.out.print("Enter address: ");
String address = scanner.nextLine();
Customer c = new Customer(id, name, phone, email, address);
customerManager.addCustomer(c);
}
private void editCustomerFlow() {
System.out.print("Enter Customer ID to edit: ");
String id = scanner.nextLine();
Customer c = customerManager.findCustomer(id);
if (c == null) {
System.out.println("Customer not found.");
return;
}
System.out.print("Enter new name: ");
String name = scanner.nextLine();
System.out.print("Enter new phone: ");
String phone = scanner.nextLine();
System.out.print("Enter new email: ");
String email = scanner.nextLine();
System.out.print("Enter new address: ");
String address = scanner.nextLine();
customerManager.editCustomer(id, name, phone, email, address);
}
private void deleteCustomerFlow() {
System.out.print("Enter Customer ID to delete: ");
String id = scanner.nextLine().trim();
Customer c = customerManager.findCustomer(id);
if (c == null){
System.out.print("Customer ID not found");
return;
}
customerManager.deleteCustomer(id);
}
// --------------------------------------------------------------
// PAYMENT MENU
// --------------------------------------------------------------
private void managePayments() {
System.out.println("\n--- Payment Menu ---");
System.out.println("1. Record Payment");
System.out.println("2. View Payments");
System.out.println("3. Update Payment Status");
System.out.println("4. Return to Main Menu");
int choice = readInt("Enter choice: ");
switch (choice) {
case 1 -> recordPaymentFlow();
case 2 -> paymentManager.viewPayments();
case 3 -> updatePaymentStatus();
case 4 -> {}
default -> System.out.println("Invalid choice.");
}
}
private void recordPaymentFlow() {
System.out.println("\n--- Record Payment ---");
int id = readInt("Enter Order ID: ");
System.out.print("Enter payment method: ");
String method = scanner.nextLine();
double amount = readDouble("Enter amount: ");
Payment p = new Payment(paymentManager.getNextPaymentID(), id, method, amount);
paymentManager.addPayment(p);
System.out.println("Payment recorded!");
}
private void updatePaymentStatus() {
int id = readInt("Payment ID to update: ");
paymentManager.updateStatus(id, scanner);
}
// --------------------------------------------------------------
// ALERTS + SAVE
// --------------------------------------------------------------
private void showAlerts() {
System.out.println("\n--- Alerts ---");
orderManager.showUpcomingAlerts();
}
private void saveAll() {
System.out.println("\nSaving data...");
datastore.saveOrders(orderManager);
datastore.saveCustomers(customerManager);
datastore.savePayments(paymentManager);
System.out.println("All data saved successfully.");
}
// --------------------------------------------------------------
// INPUT HELPERS
// --------------------------------------------------------------
private int readInt(String msg) {
while (true) {
try {
System.out.print(msg);
String s = scanner.nextLine();
return Integer.parseInt(s.trim());
} catch (NumberFormatException e) {
System.out.println("Please enter a valid number.");
}
}
}
private double readDouble(String msg) {
while (true) {
try {
System.out.print(msg);
String s = scanner.nextLine();
return Double.parseDouble(s.trim());
} catch (Exception e) {
System.out.println("Enter a valid number.");
}
}
}
}