From 745eddea319add6b52092439478962d8e2454430 Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Sat, 4 Feb 2023 19:07:14 +0100 Subject: [PATCH] add: select child for invoice and show total --- .../InvoiceController.java | 31 +++++++++++++++++-- .../invoice-view.fxml | 20 +++++++----- 2 files changed, 42 insertions(+), 9 deletions(-) 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 @@ + + + +