use of jgnash.report.BalanceByMonthCSVReport in project jgnash by ccavanaugh.
the class ReportActions method exportBalanceByMonthCSVReport.
public static void exportBalanceByMonthCSVReport() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final Preferences preferences = Preferences.userNodeForPackage(ReportActions.class);
final FXMLUtils.Pair<BalanceByMonthOptionsDialogController> pair = FXMLUtils.load(BalanceByMonthOptionsDialogController.class.getResource("BalanceByMonthOptionsDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
pair.getController().forceDefaultCurrencyProperty().set(preferences.getBoolean(FORCE_CURRENCY, false));
pair.getStage().setResizable(false);
pair.getStage().showAndWait();
final boolean vertical = pair.getController().isVertical();
final boolean forceCurrency = pair.getController().forceDefaultCurrencyProperty().get();
final Optional<LocalDate[]> optional = pair.getController().getDates();
optional.ifPresent(localDates -> {
final String lastDir = preferences.get(LAST_DIR, null);
preferences.putBoolean(FORCE_CURRENCY, forceCurrency);
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
if (lastDir != null) {
fileChooser.setInitialDirectory(new File(lastDir));
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("CSV", "*.csv"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
preferences.put(LAST_DIR, file.getParent());
final BalanceByMonthCSVReport report;
if (forceCurrency) {
report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], engine.getDefaultCurrency(), vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
} else {
report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], null, vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
}
report.run();
}
});
}
Aggregations