From 38eda35e6cf65f997805e45c507a857aabae7643 Mon Sep 17 00:00:00 2001 From: Theo Reichert Date: Mon, 13 Nov 2023 16:49:35 +0100 Subject: [PATCH] Add calender to OrderController calender displays `order.id`s per day --- .../order/CustomOrderDataInitializer.java | 14 ++++++++++ .../java/catering/order/OrderController.java | 28 +++++++++++++++++-- .../resources/templates/orders_calender.html | 4 ++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/main/java/catering/order/CustomOrderDataInitializer.java b/src/main/java/catering/order/CustomOrderDataInitializer.java index 224b479..29e33b2 100644 --- a/src/main/java/catering/order/CustomOrderDataInitializer.java +++ b/src/main/java/catering/order/CustomOrderDataInitializer.java @@ -58,5 +58,19 @@ public class CustomOrderDataInitializer implements DataInitializer { true, 4000.0 )); + + products = new HashMap<>(); + products.put("Koch", Quantity.of(3)); + products.put("Wasser (still)", Quantity.of(101)); + products.put("Käseplatte", Quantity.of(1000)); + products.put("Wiener Würstchen", Quantity.of(150)); + orderRepository.addOrder(new CustomOrder( + CustomOrder.OrderType.EVENT_CATERING, + LocalDateTime.of(2023, 11, 20, 11, 0), + LocalDateTime.of(2023, 11, 21, 8, 0), + products, + true, + 1001.0 + )); } } diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index f6f3de8..e8fbffd 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -1,5 +1,6 @@ package catering.order; +import org.springframework.data.util.Streamable; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -7,6 +8,7 @@ import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Comparator; import java.util.Optional; @@ -106,14 +108,36 @@ public class OrderController { for (LocalDate date : datesOfTheWeek) { ArrayList x = new ArrayList(2); x.add(Integer.toString(date.getDayOfMonth())); - x.add("#OrdersToday"); week_to_add_to_month.add(x); } //datesOfTheWeek.clear(); weeksOfMonth.add(week_to_add_to_month); } - // calender header with names of week + LocalDate endDate = startDate.plusDays(27); + + // get orders_in_next_month (in future sorted by endDate) + Iterable orders_in_next_month = this.orderRepository.getOrders().stream().filter(e -> + !e.getFinish().toLocalDate().isBefore(startDate) && // end is not before today + !e.getStart().toLocalDate().isAfter(endDate)).toList(); + + + for (CustomOrder order : orders_in_next_month) { + int start_index_inclusive = Math.max(order.getStart().toLocalDate().compareTo(startDate),0); + int end_index_exclusive = Math.min(order.getFinish().toLocalDate().compareTo(startDate), 27) + 1; + for (int i = start_index_inclusive; i < end_index_exclusive; i++) { + weeksOfMonth.get((int) i/7).get(Math.floorMod(i,7)).add(Integer.toString(order.getId())); + } + } +// for (List> orders_in_next_week : orders_in_next_month) { +// orders_in_next_weeks.stream().filter(e -> +// e.start.toLocalDate().isEqual(calender_day) || // start day +// e.end.toLocalDate().isEqual(calender_day) || // end day +// e.start.toLocalDate().isBefore(calender_day) && end.toLocalDate().isAfter(calender_day) // day in between start and end +// ).toList().count(); +// } + + // calendar header with names of week LocalDate endOfWeekDate = startDate.plusDays(6); ArrayList dayNames = new ArrayList(7); for (LocalDate date = startDate; !date.isAfter(endOfWeekDate); date = date.plusDays(1)) { diff --git a/src/main/resources/templates/orders_calender.html b/src/main/resources/templates/orders_calender.html index 2169407..72608cf 100644 --- a/src/main/resources/templates/orders_calender.html +++ b/src/main/resources/templates/orders_calender.html @@ -71,8 +71,10 @@