diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java b/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java index aebd7ba..58af018 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java @@ -1,12 +1,16 @@ package com.bib.essensbestellungsverwaltung; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Spinner; import javafx.scene.input.MouseEvent; import javafx.scene.text.Text; import java.util.Calendar; +import java.util.List; public class InvoiceController { @FXML @@ -14,6 +18,9 @@ public class InvoiceController { @FXML ChoiceBox monatChoiceBox; + @FXML + ChoiceBox childChoiceBox; + @FXML Spinner jahrSpinner; @@ -21,12 +28,32 @@ public class InvoiceController { public void initialize() { monatChoiceBox.setValue(intToMonth(Calendar.getInstance().get(Calendar.MONTH) + 1)); jahrSpinner.getValueFactory().setValue(Calendar.getInstance().get(Calendar.YEAR)); + + List childList = AccountMgr.getAllChildren(); + ObservableList childOptions = FXCollections.observableArrayList(childList.stream().map(c -> c.getId() + ": " + c.getFirstname() + " " + c.getName()).toList().toArray(new String[0])); + childChoiceBox.setItems(childOptions); } @FXML void onRechnungErstellenClick(MouseEvent mouseEvent) { - responseText.setText(monatChoiceBox.getValue().toString() + jahrSpinner.getValue()); - // hier rechnung erstellen + if(childChoiceBox.getValue() == null){ + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Es wurde kein Kind ausgewählt"); + alert.setHeaderText("Bitte wählen sie ein Kind aus"); + alert.showAndWait(); + } + + String childId = childChoiceBox.getValue().toString().split(":")[0]; + String date = String.format("%d-%02d", Integer.parseInt(jahrSpinner.getValue().toString()), monthToInt(monatChoiceBox.getValue().toString())); + + System.out.println("Invoice (" + date + ") from child: " + childId); + + List invoice = AccountMgr.getInvoice(date, childId); + + responseText.setText(invoice.get(invoice.size() - 1)); + + //TODO: show invoice + //TODO: export invoice as word or pdf } private int monthToInt(String month) { diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/invoice-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/invoice-view.fxml index 5b2a05c..99c1d22 100644 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/invoice-view.fxml +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/invoice-view.fxml @@ -17,14 +17,10 @@ - + - @@ -50,6 +46,16 @@ + + + +