-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoice.java
104 lines (88 loc) · 4.21 KB
/
Invoice.java
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
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.UUID;
public class Invoice {
private final String invoiceNumber;
private Customer invoiceCustomer;
private Restaurant invoiceRestaurant;
private ArrayList <MenuItem> invoiceItemsArray;
private ArrayList<Integer> invoiceQuantitiesArray;
private DeliveryDriver invoiceDriver;
private String invoiceSpecialInstructions;
// Constructor used in createInvoice() method in Main
public Invoice() {
this.invoiceNumber = (UUID.randomUUID()).toString();
this.invoiceCustomer = new Customer();
this.invoiceRestaurant = new Restaurant();
this.invoiceItemsArray = new ArrayList<>();
this.invoiceQuantitiesArray = new ArrayList<>();
this.invoiceDriver = new DeliveryDriver();
this.invoiceSpecialInstructions = "N/A";
}
public String getInvoiceNumber() {
return invoiceNumber;
}
public Customer getInvoiceCustomer() {
return invoiceCustomer;
}
public void setInvoiceCustomer(Customer invoiceCustomer) {
this.invoiceCustomer = invoiceCustomer;
}
public Restaurant getInvoiceRestaurant() {
return invoiceRestaurant;
}
public void setInvoiceRestaurant(Restaurant invoiceRestaurant) {
this.invoiceRestaurant = invoiceRestaurant;
}
public void setInvoiceItemsArray(ArrayList<MenuItem> invoiceItemsArray) {
this.invoiceItemsArray = invoiceItemsArray;
}
public void setInvoiceQuantitiesArray(ArrayList<Integer> invoiceQuantitiesArray) {
this.invoiceQuantitiesArray = invoiceQuantitiesArray;
}
public DeliveryDriver getInvoiceDriver() {
return invoiceDriver;
}
public void setInvoiceDriver(DeliveryDriver invoiceDriver) {
this.invoiceDriver = invoiceDriver;
}
public void setInvoiceSpecialInstructions(String invoiceSpecialInstructions) {
this.invoiceSpecialInstructions = invoiceSpecialInstructions;
}
// Getting the invoice total for toString() method
private double getInvoiceTotal() {
double invoiceTotal = 0d;
for(int i =0; i<invoiceQuantitiesArray.size(); i++) {
invoiceTotal += (invoiceItemsArray.get(i).mealPrice()) * (invoiceQuantitiesArray.get(i)) ;
}
return invoiceTotal;
}
// Creating invoice items list for toString() Method
private String invoiceItemQuantityPriceString() {
StringBuilder invoiceItemQuantityPriceString = new StringBuilder();
for (int i = 0; i < this.invoiceItemsArray.size(); i++) {
invoiceItemQuantityPriceString.append(this.invoiceQuantitiesArray.get(i)).append(" x ").append(invoiceItemsArray.get(i).getMenuItemString()).append('\n');
}
return invoiceItemQuantityPriceString.toString();
}
@Override
// Method to create the invoice string for invoice.txt file
public String toString() {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
LocalDateTime now = LocalDateTime.now();
return "Order No: " + this.invoiceNumber + "\n" +
"Date: " + dtf.format(now) + "\n" +
"Customer: " + this.invoiceCustomer.getCustomerName() + "\n" +
"Email: " + this.invoiceCustomer.getCustomerEmail() + "\n" +
"Cell: " + this.invoiceCustomer.getCustomerPhone() + "\n" +
"Location: " + this.invoiceCustomer.getCustomerLocation() + "\n" +
"You have ordered the following from " + this.invoiceRestaurant.getRestaurantName() + " in " + invoiceRestaurant.getRestaurantLocation() + ": \n" +
this.invoiceItemQuantityPriceString() +
"Special instructions: " + this.invoiceSpecialInstructions + '\n' +
"Total: R" + String.format("%.2f", this.getInvoiceTotal()) + '\n' +
this.invoiceDriver.getDriverName() + " is the nearest to the restaurant, so they will be delivering your order to you at: \n " + this.invoiceCustomer.getCustomerAddress() + "\n" +
"If you need to contact the restaurant, their number is " + this.invoiceRestaurant.getRestaurantPhone() + ". "
;
}
}