Search in sources :

Example 51 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class ReportActions method exportProfitLossReport.

public static void exportProfitLossReport() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final CurrencyNode baseCommodity = engine.getDefaultCurrency();
    final FXMLUtils.Pair<DateRangeDialogController> pair = FXMLUtils.load(DateRangeDialogController.class.getResource("DateRangeDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
    pair.getStage().setResizable(false);
    pair.getStage().showAndWait();
    final Optional<LocalDate[]> optional = pair.getController().getDates();
    optional.ifPresent(localDates -> {
        final Preferences pref = Preferences.userNodeForPackage(ReportActions.class);
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
        final File initialDirectory = new File(pref.get(LAST_DIR, System.getProperty("user.home")));
        // Protect against an IllegalArgumentException
        if (initialDirectory.isDirectory()) {
            fileChooser.setInitialDirectory(initialDirectory);
        }
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("TXT", "*.txt"));
        final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
        if (file != null) {
            pref.put(LAST_DIR, file.getParent());
            final ProfitLossTextReport report = new ProfitLossTextReport(file.getAbsolutePath(), localDates[0], localDates[1], baseCommodity, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
            report.run();
        }
    });
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) FXMLUtils(jgnash.uifx.util.FXMLUtils) ProfitLossTextReport(jgnash.report.ProfitLossTextReport) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine) DateRangeDialogController(jgnash.uifx.control.DateRangeDialogController) AccountBalanceDisplayManager(jgnash.uifx.views.AccountBalanceDisplayManager)

Example 52 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class ImportPageTwoController method getSettings.

@Override
public void getSettings(final Map<ImportWizard.Settings, Object> map) {
    @SuppressWarnings("unchecked") final ImportBank<ImportTransaction> bank = (ImportBank<ImportTransaction>) map.get(ImportWizard.Settings.BANK);
    if (bank != null) {
        final List<ImportTransaction> list = bank.getTransactions();
        baseAccount = (Account) map.get(ImportWizard.Settings.ACCOUNT);
        final CurrencyNode currencyNode = baseAccount.getCurrencyNode();
        // rescale for consistency
        numberFormat.setMinimumFractionDigits(currencyNode.getScale());
        numberFormat.setMaximumFractionDigits(currencyNode.getScale());
        // List of enabled import filters
        final List<ImportFilter> importFilterList = ImportFilter.getEnabledImportFilters();
        // set to sane account assuming it's going to be a single entry
        for (final ImportTransaction t : list) {
            // Process transactions with the import filter
            for (final ImportFilter importFilter : importFilterList) {
                // pass the import transaction for manipulation by the script
                importFilter.acceptTransaction(t);
                t.setMemo(importFilter.processMemo(t.getMemo()));
                t.setPayee(importFilter.processPayee(t.getPayee()));
            }
            if (t.getTransactionType() != TransactionType.REINVESTDIV) {
                t.setAccount(baseAccount);
            }
            if (t.isInvestmentTransaction()) {
                switch(t.getTransactionType()) {
                    case BUYSHARE:
                        t.setFeesAccount(baseAccount);
                        break;
                    case SELLSHARE:
                    case REINVESTDIV:
                        t.setFeesAccount(baseAccount);
                        t.setGainsAccount(baseAccount);
                        break;
                    case DIVIDEND:
                        t.setGainsAccount(baseAccount);
                        break;
                    default:
                }
            }
            // force reset
            t.setState(ImportState.NEW);
        }
        incomeAccountColumn.setVisible(bank.isInvestmentAccount());
        expenseAccountColumn.setVisible(bank.isInvestmentAccount());
        typeColumn.setVisible(bank.isInvestmentAccount());
        // match up any pre-existing transactions
        GenericImport.matchTransactions(list, baseAccount);
        // classify the transactions
        if (Options.globalBayesProperty().get()) {
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            Objects.requireNonNull(engine);
            final List<Transaction> transactions = engine.getTransactions();
            transactions.sort(null);
            BayesImportClassifier.classifyTransactions(list, transactions, baseAccount);
        } else {
            BayesImportClassifier.classifyTransactions(list, baseAccount.getSortedTransactionList(), baseAccount);
        }
        // override the classifier if an account has been specified already
        for (final ImportTransaction importTransaction : list) {
            final Account account = ImportUtils.matchAccount(importTransaction);
            if (account != null) {
                importTransaction.setAccount(account);
            }
        }
        tableView.getItems().setAll(list);
        FXCollections.sort(tableView.getItems());
        tableViewManager.restoreLayout();
    }
    JavaFXUtils.runLater(tableViewManager::packTable);
    updateDescriptor();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ImportFilter(jgnash.convert.importat.ImportFilter) Account(jgnash.engine.Account) ImportTransaction(jgnash.convert.importat.ImportTransaction) ImportTransaction(jgnash.convert.importat.ImportTransaction) Transaction(jgnash.engine.Transaction) ImportBank(jgnash.convert.importat.ImportBank) Engine(jgnash.engine.Engine)

Example 53 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class ApiTest method testAccountAttributes.

@Test
void testAccountAttributes() {
    CurrencyNode node = e.getDefaultCurrency();
    Account a = new Account(AccountType.BANK, node);
    a.setName("AccountAttributes");
    e.addAccount(e.getRootAccount(), a);
    e.setAccountAttribute(a, "myStuff", "gobbleDeGook");
    e.setAccountAttribute(a, "myKey", "myValue");
    e.setAccountAttribute(a, "myNumber", BigDecimal.TEN.toString());
    Account b = e.getAccountByUuid(a.getUuid());
    assertEquals("gobbleDeGook", Engine.getAccountAttribute(b, "myStuff"));
    // close and reopen to force check for persistence
    closeEngine();
    e = EngineFactory.bootLocalEngine(database, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD);
    b = e.getAccountByUuid(a.getUuid());
    assertEquals("gobbleDeGook", Engine.getAccountAttribute(b, "myStuff"));
    assertEquals("myValue", Engine.getAccountAttribute(b, "myKey"));
    String attribute = Engine.getAccountAttribute(b, "myNumber");
    assertNotNull(attribute);
    assertEquals(BigDecimal.TEN, new BigDecimal(attribute));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) BigDecimal(java.math.BigDecimal) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.jupiter.api.Test)

Example 54 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class ApiTest method testTransactionAPI.

@Test
void testTransactionAPI() {
    final String ACCOUNT_NAME = "testAccount";
    final CurrencyNode node = e.getDefaultCurrency();
    final Account a = new Account(AccountType.BANK, node);
    a.setName(ACCOUNT_NAME);
    e.addAccount(e.getRootAccount(), a);
    // Test single entry transaction
    final Transaction transaction = TransactionFactory.generateSingleEntryTransaction(a, BigDecimal.TEN, LocalDate.now(), "memo", "payee", "1");
    e.addTransaction(transaction);
    assertTrue(a.contains(transaction));
    assertEquals(0, a.indexOf(transaction));
    assertEquals(TransactionType.SINGLENTRY, transaction.getTransactionType());
    for (final TransactionEntry transactionEntry : transaction.getTransactionEntries()) {
        assertFalse(transactionEntry.isMultiCurrency());
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) TransactionEntry(jgnash.engine.TransactionEntry) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.jupiter.api.Test)

Example 55 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class EditExchangeRatesController method handleUpdateAction.

@FXML
private void handleUpdateAction() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    updateOnlineButton.disableProperty().set(true);
    updateTask = new Task<>() {

        @Override
        protected Void call() {
            final List<CurrencyNode> list = engine.getCurrencies();
            // need to track the total processed count
            long processedHistory = 0;
            for (final CurrencyNode source : list) {
                for (final CurrencyNode target : list) {
                    if (!source.equals(target) && source.getSymbol().compareToIgnoreCase(target.getSymbol()) > 0 && !requestCancel) {
                        final Optional<BigDecimal> rate = CurrencyUpdateFactory.getExchangeRate(source, target);
                        if (rate.isPresent()) {
                            engine.setExchangeRate(source, target, rate.get());
                            updateProgress(++processedHistory, list.size() - 1);
                        }
                    }
                }
            }
            return null;
        }
    };
    updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, event -> taskComplete());
    updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_CANCELLED, event -> taskComplete());
    updateTask.addEventHandler(WorkerStateEvent.WORKER_STATE_FAILED, event -> taskComplete());
    progressBar.progressProperty().bind(updateTask.progressProperty());
    final Thread thread = new Thread(updateTask);
    thread.setDaemon(true);
    thread.start();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Optional(java.util.Optional) ArrayList(java.util.ArrayList) List(java.util.List) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Aggregations

CurrencyNode (jgnash.engine.CurrencyNode)58 Account (jgnash.engine.Account)28 Engine (jgnash.engine.Engine)28 BigDecimal (java.math.BigDecimal)10 ArrayList (java.util.ArrayList)10 LocalDate (java.time.LocalDate)8 NumberFormat (java.text.NumberFormat)7 List (java.util.List)7 FXML (javafx.fxml.FXML)7 AccountGroup (jgnash.engine.AccountGroup)7 Transaction (jgnash.engine.Transaction)6 ResourceBundle (java.util.ResourceBundle)5 SecurityNode (jgnash.engine.SecurityNode)5 InjectFXML (jgnash.uifx.util.InjectFXML)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 ExecutionException (java.util.concurrent.ExecutionException)3