2023-11-07 20:53:31 +01:00
|
|
|
package catering.order;
|
|
|
|
|
2023-11-26 12:10:28 +01:00
|
|
|
import catering.staff.Staff;
|
2023-11-26 16:59:50 +01:00
|
|
|
import org.javamoney.moneta.Money;
|
2023-11-19 13:00:21 +01:00
|
|
|
import org.salespointframework.order.Cart;
|
|
|
|
|
2023-11-26 16:59:50 +01:00
|
|
|
import javax.money.MonetaryAmount;
|
2023-11-26 12:10:28 +01:00
|
|
|
import java.time.Duration;
|
2023-11-19 13:00:21 +01:00
|
|
|
import java.time.LocalDateTime;
|
2023-11-26 12:10:28 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2023-11-19 13:00:21 +01:00
|
|
|
|
|
|
|
public class CustomCart extends Cart {
|
2023-11-26 16:59:50 +01:00
|
|
|
private final Set<Staff> staff;
|
2023-11-19 13:00:21 +01:00
|
|
|
private OrderType orderType;
|
|
|
|
private LocalDateTime start;
|
|
|
|
private LocalDateTime finish;
|
|
|
|
private final String formatterPattern;
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public CustomCart(OrderType orderType, LocalDateTime start, LocalDateTime finish) {
|
|
|
|
super();
|
2023-11-26 12:10:28 +01:00
|
|
|
this.staff = new HashSet<>();
|
2023-11-19 13:00:21 +01:00
|
|
|
this.orderType = orderType;
|
|
|
|
this.start = start;
|
|
|
|
this.finish = finish;
|
2023-11-26 12:10:28 +01:00
|
|
|
this.formatterPattern = "dd.MM.yyyy, HH:mm 'Uhr'";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an employee to the cart
|
|
|
|
*/
|
|
|
|
public boolean addStaff(Staff staff) {
|
2023-11-26 16:59:50 +01:00
|
|
|
for (Staff myStaff : this.staff) {
|
|
|
|
if (myStaff.equals(staff)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-11-26 12:10:28 +01:00
|
|
|
return this.staff.add(staff);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<Staff> getStaff() {
|
|
|
|
return staff;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean removeStaff(Staff staff) {
|
2023-11-26 16:59:50 +01:00
|
|
|
for (Staff myStaff : this.staff) {
|
|
|
|
if (myStaff.equals(staff)) {
|
|
|
|
return this.staff.remove(myStaff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2023-11-26 12:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add staff to order (analogous to cart.addItemsTo(order))
|
|
|
|
*/
|
|
|
|
public CustomOrder addStaffTo(CustomOrder order) {
|
|
|
|
for (Staff staff : this.staff) {
|
|
|
|
order.addStaff(staff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return order;
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public OrderType getOrderType() {
|
2023-11-07 20:53:31 +01:00
|
|
|
return orderType;
|
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public void setOrderType(OrderType orderType) {
|
|
|
|
this.orderType = orderType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocalDateTime getStart() {
|
|
|
|
return start;
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public void setStart(LocalDateTime start) {
|
|
|
|
this.start = start;
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-26 12:10:28 +01:00
|
|
|
/**
|
2023-11-26 16:59:50 +01:00
|
|
|
* @return hours between start and finish multiplied with a rate
|
2023-11-26 12:10:28 +01:00
|
|
|
*/
|
2023-11-26 16:59:50 +01:00
|
|
|
public double getDurationInHoursTimesRate(double rate) {
|
|
|
|
return (float) Duration.between(start, finish).getSeconds() / 3600 * rate;
|
2023-11-26 12:10:28 +01:00
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public LocalDateTime getFinish() {
|
|
|
|
return finish;
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public void setFinish(LocalDateTime finish) {
|
|
|
|
this.finish = finish;
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|
2023-11-07 22:23:48 +01:00
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public String getFormatterPattern() {
|
|
|
|
return formatterPattern;
|
2023-11-07 22:23:48 +01:00
|
|
|
}
|
2023-11-26 16:59:50 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public MonetaryAmount getPrice() {
|
|
|
|
MonetaryAmount total = super.getPrice();
|
|
|
|
|
|
|
|
for (int i = 0; i < staff.size(); i++) { // TODO: get this from staff itself
|
|
|
|
total = total.add(Money.of(getDurationInHoursTimesRate(12.0), "EUR"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear() {
|
|
|
|
super.clear();
|
|
|
|
staff.forEach(staff::remove);
|
|
|
|
}
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|