add: export invoice to txt
This commit is contained in:
parent
745eddea31
commit
4c9a3343d2
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,3 +38,4 @@ build/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
/database.db
|
/database.db
|
||||||
|
/Rechnungen
|
@ -9,6 +9,10 @@ import javafx.scene.control.Spinner;
|
|||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -30,7 +34,8 @@ public class InvoiceController {
|
|||||||
jahrSpinner.getValueFactory().setValue(Calendar.getInstance().get(Calendar.YEAR));
|
jahrSpinner.getValueFactory().setValue(Calendar.getInstance().get(Calendar.YEAR));
|
||||||
|
|
||||||
List<Child> childList = AccountMgr.getAllChildren();
|
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]));
|
ObservableList<Object> childOptions = FXCollections.observableArrayList(childList.stream()
|
||||||
|
.map(c -> c.getId() + ": " + c.getFirstname() + " " + c.getName()).toList().toArray(new String[0]));
|
||||||
childChoiceBox.setItems(childOptions);
|
childChoiceBox.setItems(childOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +49,8 @@ public class InvoiceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String childId = childChoiceBox.getValue().toString().split(":")[0];
|
String childId = childChoiceBox.getValue().toString().split(":")[0];
|
||||||
String date = String.format("%d-%02d", Integer.parseInt(jahrSpinner.getValue().toString()), monthToInt(monatChoiceBox.getValue().toString()));
|
String date = String.format("%d-%02d", Integer.parseInt(jahrSpinner.getValue().toString()),
|
||||||
|
monthToInt(monatChoiceBox.getValue().toString()));
|
||||||
|
|
||||||
System.out.println("Invoice (" + date + ") from child: " + childId);
|
System.out.println("Invoice (" + date + ") from child: " + childId);
|
||||||
|
|
||||||
@ -53,7 +59,8 @@ public class InvoiceController {
|
|||||||
responseText.setText(invoice.get(invoice.size() - 1));
|
responseText.setText(invoice.get(invoice.size() - 1));
|
||||||
|
|
||||||
// TODO: show invoice
|
// TODO: show invoice
|
||||||
//TODO: export invoice as word or pdf
|
Child child = AccountMgr.getChildById(Long.parseLong(childId));
|
||||||
|
exportInvoice("Rechnung_" + date + "_" + childId + "_" + child.getName() +"_" + child.getFirstname(), invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int monthToInt(String month) {
|
private int monthToInt(String month) {
|
||||||
@ -91,4 +98,21 @@ public class InvoiceController {
|
|||||||
default -> "";
|
default -> "";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void exportInvoice(String filename, List<String> invoice) {
|
||||||
|
try {
|
||||||
|
Files.createDirectories(Path.of(Path.of("").toAbsolutePath() + "/Rechnungen"));
|
||||||
|
|
||||||
|
// TODO: save invoice to pdf or word
|
||||||
|
File file = new File(Path.of("").toAbsolutePath() + "/Rechnungen/" + filename + ".txt");
|
||||||
|
if (file.createNewFile()) {
|
||||||
|
System.out.println("File created: " + file.getName());
|
||||||
|
} else {
|
||||||
|
System.out.println("File already exists.");
|
||||||
|
}
|
||||||
|
Files.write(Path.of(file.getAbsolutePath()), invoice);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user