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();
}
});
}
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();
}
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));
}
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());
}
}
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();
}
Aggregations