2023-11-05 10:39:39 +01:00
|
|
|
package catering.order;
|
|
|
|
|
2023-11-23 16:57:44 +01:00
|
|
|
import catering.staff.Employee;
|
2023-11-26 16:59:50 +01:00
|
|
|
import jakarta.persistence.*;
|
2023-11-26 12:10:28 +01:00
|
|
|
import org.javamoney.moneta.Money;
|
2023-11-19 13:00:21 +01:00
|
|
|
import org.salespointframework.order.Order;
|
|
|
|
import org.salespointframework.payment.Cash;
|
|
|
|
import org.salespointframework.useraccount.UserAccount;
|
2023-11-26 12:10:28 +01:00
|
|
|
import org.springframework.data.annotation.Id;
|
2023-11-05 10:39:39 +01:00
|
|
|
|
2023-11-26 12:10:28 +01:00
|
|
|
import javax.money.MonetaryAmount;
|
|
|
|
import java.time.Duration;
|
2023-11-05 11:36:39 +01:00
|
|
|
import java.time.LocalDateTime;
|
2023-11-05 15:36:46 +01:00
|
|
|
import java.time.format.DateTimeFormatter;
|
2023-11-26 12:10:28 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2023-11-05 10:39:39 +01:00
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
@Entity
|
|
|
|
public class CustomOrder extends Order {
|
2023-11-26 12:10:28 +01:00
|
|
|
@Id
|
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
|
private Long id;
|
2023-11-26 16:59:50 +01:00
|
|
|
@ManyToMany
|
2023-11-23 16:57:44 +01:00
|
|
|
private Set<Employee> staff;
|
2023-11-19 13:00:21 +01:00
|
|
|
private OrderType orderType = OrderType.SOMETHING_ELSE;
|
2023-11-05 11:36:39 +01:00
|
|
|
private LocalDateTime start;
|
|
|
|
private LocalDateTime finish;
|
2023-11-19 13:00:21 +01:00
|
|
|
private boolean invoiceAvailable = false;
|
2023-11-26 12:10:28 +01:00
|
|
|
private String formatterPattern = "dd.MM.yyyy, HH:mm 'Uhr'";
|
2023-11-19 13:00:21 +01:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public CustomOrder(UserAccount.UserAccountIdentifier identifier, CustomCart cart) {
|
|
|
|
super(identifier, Cash.CASH);
|
2023-11-26 12:10:28 +01:00
|
|
|
this.staff = new HashSet<>();
|
2023-11-19 13:00:21 +01:00
|
|
|
this.orderType = cart.getOrderType();
|
|
|
|
this.start = cart.getStart();
|
|
|
|
this.finish = cart.getFinish();
|
|
|
|
this.formatterPattern = cart.getFormatterPattern();
|
2023-11-05 10:39:39 +01:00
|
|
|
}
|
|
|
|
|
2023-11-26 12:10:28 +01:00
|
|
|
public CustomOrder() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get the amount of hours in between start and finish (analogous to CustomCart)
|
|
|
|
* @return hours between start and finish
|
|
|
|
*/
|
|
|
|
private long getDurationInHours(LocalDateTime start, LocalDateTime finish) {
|
|
|
|
return Duration.between(start, finish).getSeconds() / 3600;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an employee to the order and adds a new {@Link ChangeLine} containing the costs
|
|
|
|
*/
|
2023-11-23 16:57:44 +01:00
|
|
|
public boolean addEmployee(Employee employee) {
|
2023-11-26 12:10:28 +01:00
|
|
|
MonetaryAmount cost = Money.of(12.0, "EUR")
|
2023-11-23 16:57:44 +01:00
|
|
|
.multiply(getDurationInHours(this.start, this.finish)); // TODO: Get salary from employee
|
2023-11-26 12:10:28 +01:00
|
|
|
|
2023-11-23 16:57:44 +01:00
|
|
|
if (this.staff.add(employee)) {
|
|
|
|
super.addChargeLine(cost, employee.getId().toString());
|
2023-11-26 12:10:28 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-23 16:57:44 +01:00
|
|
|
public Set<Employee> getStaff() {
|
2023-11-26 12:10:28 +01:00
|
|
|
return staff;
|
|
|
|
}
|
2023-11-05 16:41:22 +01:00
|
|
|
|
2023-11-05 10:39:39 +01:00
|
|
|
public OrderType getOrderType() {
|
|
|
|
return orderType;
|
|
|
|
}
|
|
|
|
|
2023-11-05 11:36:39 +01:00
|
|
|
public LocalDateTime getStart() {
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2023-11-26 12:10:28 +01:00
|
|
|
/**
|
|
|
|
* @return start DateTime in a formatted manner
|
|
|
|
*/
|
2023-11-05 15:36:46 +01:00
|
|
|
public String getFormattedStart() {
|
2023-11-19 13:00:21 +01:00
|
|
|
return start.format(DateTimeFormatter.ofPattern(formatterPattern));
|
|
|
|
}
|
|
|
|
|
2023-11-05 11:36:39 +01:00
|
|
|
public LocalDateTime getFinish() {
|
|
|
|
return finish;
|
|
|
|
}
|
|
|
|
|
2023-11-26 12:10:28 +01:00
|
|
|
/**
|
|
|
|
* @return finish DateTime in a formatted manner
|
|
|
|
*/
|
2023-11-05 15:36:46 +01:00
|
|
|
public String getFormattedFinish() {
|
2023-11-19 13:00:21 +01:00
|
|
|
return finish.format(DateTimeFormatter.ofPattern(formatterPattern));
|
2023-11-05 10:39:39 +01:00
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public boolean isInvoiceAvailable() {
|
2023-11-05 10:39:39 +01:00
|
|
|
return invoiceAvailable;
|
|
|
|
}
|
|
|
|
|
2023-11-19 13:00:21 +01:00
|
|
|
public void setInvoiceAvailable(boolean available) {
|
|
|
|
this.invoiceAvailable = available;
|
2023-11-05 10:39:39 +01:00
|
|
|
}
|
|
|
|
}
|