add: select child for invoice and show total
This commit is contained in:
		| @@ -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<Child> childList = AccountMgr.getAllChildren(); | ||||
|         ObservableList<Object> 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<String> 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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Johannes Kantz
					Johannes Kantz