swt23w23/src/main/java/catering/order/CustomCart.java

89 lines
1.8 KiB
Java
Raw Normal View History

package catering.order;
import catering.staff.Staff;
import org.salespointframework.order.Cart;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
public class CustomCart extends Cart {
private Set<Staff> staff;
private OrderType orderType;
private LocalDateTime start;
private LocalDateTime finish;
private final String formatterPattern;
// Constructor
public CustomCart(OrderType orderType, LocalDateTime start, LocalDateTime finish) {
super();
this.staff = new HashSet<>();
this.orderType = orderType;
this.start = start;
this.finish = finish;
this.formatterPattern = "dd.MM.yyyy, HH:mm 'Uhr'";
}
/**
* Adds an employee to the cart
*/
public boolean addStaff(Staff staff) {
return this.staff.add(staff);
}
public Set<Staff> getStaff() {
return staff;
}
public boolean removeStaff(Staff staff) {
return this.staff.remove(staff);
}
/**
* Add staff to order (analogous to cart.addItemsTo(order))
*/
public CustomOrder addStaffTo(CustomOrder order) {
for (Staff staff : this.staff) {
order.addStaff(staff);
}
return order;
}
public OrderType getOrderType() {
return orderType;
}
public void setOrderType(OrderType orderType) {
this.orderType = orderType;
}
public LocalDateTime getStart() {
return start;
}
public void setStart(LocalDateTime start) {
this.start = start;
}
/**
* @return hours between start and finish
*/
public long getDurationInHours(LocalDateTime start, LocalDateTime finish) {
return Duration.between(start, finish).getSeconds() / 3600;
}
public LocalDateTime getFinish() {
return finish;
}
public void setFinish(LocalDateTime finish) {
this.finish = finish;
}
2023-11-07 22:23:48 +01:00
public String getFormatterPattern() {
return formatterPattern;
2023-11-07 22:23:48 +01:00
}
}