-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
199 lines (184 loc) · 7.37 KB
/
Copy pathOrder.java
File metadata and controls
199 lines (184 loc) · 7.37 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
package javalibrary;
import java.io.*;
import java.util.*;
public class Order implements Serializable {
private int orderId;
private int supplierId;
private int supplierContact;
private String orderDate;
private boolean status;
private double totalAmount;
static HashMap<Integer, Order> orderMap = new HashMap<>();
private static Scanner input = new Scanner(System.in);
public Order(int orderId, int supplierId, int supplierContact, String orderDate, boolean status, double totalAmount) {
this.orderId = orderId;
this.supplierId = supplierId;
this.supplierContact = supplierContact;
this.orderDate = orderDate;
this.status = status;
this.totalAmount = totalAmount;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public int getSupplierId() {
return supplierId;
}
public void setSupplierId(int supplierId) {
this.supplierId = supplierId;
}
public int getSupplierContact() {
return supplierContact;
}
public void setSupplierContact(int supplierContact) {
this.supplierContact = supplierContact;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(double totalAmount) {
this.totalAmount = totalAmount;
}
public static void savefile() {
try (ObjectOutputStream writing = new ObjectOutputStream(new FileOutputStream("order.bin"))) {
writing.writeObject(orderMap);
System.out.println("Order data saved to file successfully.");
} catch (IOException e) {
System.out.println("Error while saving Order: " + e.getMessage());
}
}
public static void readfile() {
try (ObjectInputStream loading = new ObjectInputStream(new FileInputStream("order.bin"))) {
orderMap = (HashMap<Integer, Order>) loading.readObject();
System.out.println("Orders loaded from file successfully.");
} catch (IOException | ClassNotFoundException e) {
System.err.println("Error while loading Order: " + e.getMessage());
}
}
public static void createOrder()
{
readfile();
Supplier.readfile();
System.out.println("Enter Supplier ID:");
int supplierId = input.nextInt();
if (!Supplier.suppmap.containsKey(supplierId))
{
System.out.println("Supplier ID " + supplierId + " not Found");
return;
}
System.out.println("Enter Supplier Contact Number:");
int supplierContact = input.nextInt();
System.out.println("Enter Order ID:");
int orderId = input.nextInt();
// Check if the order ID already exists
if (orderMap.containsKey(orderId)) {
System.out.println("Order ID " + orderId + " already exists.");
return;
}
System.out.println("Enter Order Date: ");
String orderDateString = input.nextLine();
System.out.println("Enter Total Amount:");
double totalAmount = input.nextFloat();
Order newOrder = new Order(orderId, supplierId, supplierContact, orderDateString, false, totalAmount);
orderMap.put(orderId, newOrder);
Order order = Order.orderMap.get(orderId);
double amountorder = order.getTotalAmount();
Supplier supplier = Supplier.suppmap.get(supplierId);
supplier.setOrdercount(supplier.getOrdercount()+1);
supplier.setRevenue(supplier.getRevenue()+amountorder);
Supplier.savefile();
savefile();
System.out.println("Order created successfully.");
}
public static void updateOrder(int orderId) {
readfile();
Supplier.readfile();
// Check if the order exists
if (!orderMap.containsKey(orderId)) {
System.out.println("Order ID " + orderId + " not found.");
return;
}
System.out.println("Enter Supplier ID to update: ");
int supplierId = input.nextInt();
if (!Supplier.suppmap.containsKey(supplierId))
{
System.out.println("Supplier ID " + supplierId + " not Found");
return;
}
Order order = orderMap.get(orderId);
System.out.println("Enter new Supplier Contact Number:");
int supplierContact = input.nextInt();
order.setSupplierContact(supplierContact);
System.out.println("Enter new Order Date: ");
String orderDateString = input.nextLine();
order.setOrderDate(orderDateString);
System.out.println("Enter new Total Amount:");
double totalAmount = input.nextFloat();
order.setTotalAmount(totalAmount);
Supplier supplier = Supplier.suppmap.get(supplierId);
supplier.setRevenue(supplier.getRevenue() + totalAmount);
Supplier.savefile();
savefile();
System.out.println("Order updated successfully.");
}
public static void cancelOrder(int orderId) {
readfile();
if (!orderMap.containsKey(orderId)) {
System.out.println("Order ID " + orderId + " not found.");
return;
}
Order order = orderMap.get(orderId);
order.setStatus(true);
savefile();
System.out.println("Order ID " + orderId + " has been canceled successfully.");
}
public static void viewOrderDetails(int orderId) {
readfile();
if (!orderMap.containsKey(orderId)) {
System.out.println("Order ID " + orderId + " not found.");
return;
}
Order order = orderMap.get(orderId);
System.out.println("Order Details:");
System.out.println("Supplier ID: " + order.getSupplierId());
System.out.println("Order ID: " + order.getOrderId());
System.out.println("Supplier ID: " + order.getSupplierId());
System.out.println("Supplier Contact: " + order.getSupplierContact());
System.out.println("Order Date: " + order.getOrderDate());
System.out.println("Total Amount: " + order.getTotalAmount());
}
public static void Supplierhistory(int SupplierId)
{
readfile();
boolean found = false;
System.out.println("Supplier History for Supplier ID: " + SupplierId);
for (Order order : orderMap.values()) {
if (order.getSupplierId() == SupplierId) {
found = true;
System.out.println("Order ID: " + order.getOrderId());
System.out.println("Order Date: " + order.getOrderDate());
System.out.println("Supplier Contact: " + order.getSupplierContact());
System.out.println("Total Amount: " + order.getTotalAmount());
System.out.println("Order Status: " + (order.getStatus() ? "Canceled" : "Active"));
}
}
if (!found) {
System.out.println("No Supplier history found for Supplier ID: " + SupplierId);
}
}
}