diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/OrderHistoryController.java b/src/main/java/com/bib/essensbestellungsverwaltung/OrderHistoryController.java new file mode 100644 index 0000000..46944aa --- /dev/null +++ b/src/main/java/com/bib/essensbestellungsverwaltung/OrderHistoryController.java @@ -0,0 +1,37 @@ +package com.bib.essensbestellungsverwaltung; + +import javafx.fxml.FXML; +import javafx.scene.control.ListView; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class OrderHistoryController { + public ListView listView; + + @FXML + public void initialize() { + List children = AccountMgr.getAllChildrenFromParentWithId(AccountMgr.currentUser.getId()); + + List orders = new ArrayList<>(); + + for (Child child : children) { + System.out.println(child.getId()); + List selections = Database.select("food_selection", new String[] { "childid" }, new String[] { String.valueOf(child.getId()) }); + for (String selection : selections) { + String[] selectionParts = selection.split(":"); + String foodplanid = selectionParts[2]; + String foodid = selectionParts[3]; + String foodName = FoodMgr.getFoodById(Long.parseLong(foodid)).getName(); + String date = FoodMgr.getFoodPlanById(Long.parseLong(foodplanid)).getDate(); + orders.add(String.format("%s\t %s \t %s", date, child.getFirstname(), foodName)); + } + } + + Collections.sort(orders); + for(String order : orders){ + listView.getItems().add(order); + } + } +} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java b/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java index 4f21d1b..81e6051 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java @@ -44,7 +44,7 @@ public class ParentMenuController { @FXML public void onBestellungClick(MouseEvent mouseEvent) { setButtonActive(bestellungButton); - changePage("dailyOrder-view.fxml"); + changePage("orderHistory-view.fxml"); } @FXML diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/orderHistory-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/orderHistory-view.fxml new file mode 100644 index 0000000..e45b51e --- /dev/null +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/orderHistory-view.fxml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + +