Search in sources :

Example 1 with BalanceByMonthCSVReport

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();
        }
    });
}
Also used : FXMLUtils(jgnash.uifx.util.FXMLUtils) BalanceByMonthCSVReport(jgnash.report.BalanceByMonthCSVReport) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine)

Aggregations

File (java.io.File)1 Preferences (java.util.prefs.Preferences)1 FileChooser (javafx.stage.FileChooser)1 Engine (jgnash.engine.Engine)1 BalanceByMonthCSVReport (jgnash.report.BalanceByMonthCSVReport)1 FXMLUtils (jgnash.uifx.util.FXMLUtils)1