Search in sources :

Example 1 with OfxExport

use of jgnash.convert.exportantur.ofx.OfxExport in project jgnash by ccavanaugh.

the class OfxExportText method testExport.

@Test
void testExport() throws Exception {
    Transaction transaction = TransactionFactory.generateDoubleEntryTransaction(checkingAccount, usdBankAccount, BigDecimal.TEN, LocalDate.now(), "Transfer Test", "Transfer", "");
    assertTrue(e.addTransaction(transaction));
    Path path = Files.createTempFile("j", ".ofx");
    OfxExport ofxExport = new OfxExport(usdBankAccount, LocalDate.now().minusDays(1), LocalDate.now().plusDays(1), path.toFile());
    ofxExport.exportAccount();
    assertTrue(Files.exists(path));
    OfxBank ofxBank = OfxV2Parser.parse(path);
    assertNotNull(ofxBank);
    assertEquals(0, ofxBank.statusCode);
    assertEquals("INFO", ofxBank.statusSeverity);
    assertEquals(1, ofxBank.getTransactions().size());
    ImportTransaction importTransaction = ofxBank.getTransactions().get(0);
    assertEquals("10001-C01", importTransaction.getAccountTo());
    Files.delete(path);
}
Also used : Path(java.nio.file.Path) ImportTransaction(jgnash.convert.importat.ImportTransaction) Transaction(jgnash.engine.Transaction) OfxExport(jgnash.convert.exportantur.ofx.OfxExport) ImportTransaction(jgnash.convert.importat.ImportTransaction) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.jupiter.api.Test)

Example 2 with OfxExport

use of jgnash.convert.exportantur.ofx.OfxExport in project jgnash by ccavanaugh.

the class RegisterActions method exportTransactions.

static void exportTransactions(final Account account, final LocalDate startDate, final LocalDate endDate) {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final Preferences pref = Preferences.userNodeForPackage(RegisterActions.class);
    final FileChooser fileChooser = new FileChooser();
    final File initialDirectory = new File(pref.get(EXPORT_DIR, System.getProperty("user.home")));
    // Protect against an IllegalArgumentException
    if (initialDirectory.isDirectory()) {
        fileChooser.setInitialDirectory(initialDirectory);
    }
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.CsvFiles") + " (*.csv)", "*.csv"), new FileChooser.ExtensionFilter(resources.getString("Label.OfxFiles") + " (*.ofx)", "*.ofx"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls)", "*.xls"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xlsx)", "*.xlsx"));
    final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
    final File exportFile;
    if (file != null) {
        if (!FileUtils.fileHasExtension(file.getName())) {
            // fix up the file name if the user did not specify it
            final String fileExtension = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).substring(1);
            exportFile = new File(FileUtils.stripFileExtension(file.getAbsolutePath()) + fileExtension);
        } else {
            exportFile = file;
        }
        pref.put(EXPORT_DIR, exportFile.getParentFile().getAbsolutePath());
        final Task<Void> exportTask = new Task<>() {

            @Override
            protected Void call() {
                updateMessage(resources.getString("Message.PleaseWait"));
                updateProgress(-1, Long.MAX_VALUE);
                if (OFX.equals(FileUtils.getFileExtension(exportFile.getName()))) {
                    final OfxExport export = new OfxExport(account, startDate, endDate, exportFile);
                    export.exportAccount();
                } else if (FileUtils.getFileExtension(exportFile.getName()).contains(XLS)) {
                    final AbstractReportTableModel reportTableModel = AccountRegisterReport.createReportModel(account, startDate, endDate, false, "", "", true);
                    Workbook.export(reportTableModel, exportFile);
                } else {
                    CsvExport.exportAccount(account, startDate, endDate, exportFile.toPath());
                }
                return null;
            }
        };
        new Thread(exportTask).start();
        StaticUIMethods.displayTaskProgress(exportTask);
    }
}
Also used : Task(javafx.concurrent.Task) FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) OfxExport(jgnash.convert.exportantur.ofx.OfxExport) Preferences(java.util.prefs.Preferences) File(java.io.File) AbstractReportTableModel(jgnash.report.table.AbstractReportTableModel)

Aggregations

OfxExport (jgnash.convert.exportantur.ofx.OfxExport)2 File (java.io.File)1 Path (java.nio.file.Path)1 ResourceBundle (java.util.ResourceBundle)1 Preferences (java.util.prefs.Preferences)1 Task (javafx.concurrent.Task)1 FileChooser (javafx.stage.FileChooser)1 ImportTransaction (jgnash.convert.importat.ImportTransaction)1 AbstractEngineTest (jgnash.engine.AbstractEngineTest)1 Transaction (jgnash.engine.Transaction)1 AbstractReportTableModel (jgnash.report.table.AbstractReportTableModel)1 Test (org.junit.jupiter.api.Test)1