Search in sources :

Example 16 with CurrencyNode

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

the class CurrencyModifyDialog method buildCommodityNode.

private CurrencyNode buildCommodityNode() {
    CurrencyNode node = new CurrencyNode();
    node.setDescription(descriptionField.getText());
    node.setPrefix(prefixField.getText());
    node.setScale(Byte.parseByte(scaleField.getText()));
    node.setSuffix(suffixField.getText());
    if (currentCurrency != null) {
        node.setSymbol(currentCurrency.getSymbol());
    } else {
        node.setSymbol(symbolField.getText());
    }
    return node;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode)

Example 17 with CurrencyNode

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

the class CurrenciesPanel method customAction.

private void customAction() {
    if (!customField.getText().isEmpty()) {
        if (engine.getCurrency(customField.getText()) != null) {
            ValidationFactory.showValidationError(rb.getString("Message.Error.Duplicate"), customField);
        } else {
            CurrencyNode node = DefaultCurrencies.buildCustomNode(customField.getText());
            // the add could fail if the commodity symbol is a duplicate
            if (engine.addCurrency(node)) {
                cList.addElement(new CurrencyElement(node, true));
                customField.setText(null);
                return;
            }
        }
    }
    ValidationFactory.showValidationError(rb.getString("Message.Error.MissingSymbol"), customField);
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode)

Example 18 with CurrencyNode

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

the class CurrenciesPanel method buildLists.

private void buildLists() {
    Set<CurrencyNode> defaultNodes = DefaultCurrencies.generateCurrencies();
    Set<CurrencyNode> activeNodes = engine.getActiveCurrencies();
    List<CurrencyNode> availNodes = engine.getCurrencies();
    availNodes.forEach(defaultNodes::remove);
    aList = new SortedListModel<>(defaultNodes);
    aJList = new JList<>(aList);
    ArrayList<CurrencyElement> list = new ArrayList<>();
    for (CurrencyNode node : availNodes) {
        if (activeNodes.contains(node)) {
            list.add(new CurrencyElement(node, false));
        } else {
            list.add(new CurrencyElement(node, true));
        }
    }
    cList = new SortedListModel<>(list);
    cJList = new JList<>(cList);
    cJList.setCellRenderer(new CurrencyRenderer(cJList.getCellRenderer()));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ArrayList(java.util.ArrayList)

Example 19 with CurrencyNode

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

the class GenericImport method importSecurities.

public static void importSecurities(final List<ImportSecurity> importSecurities, final CurrencyNode currencyNode) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final ImportSecurity importSecurity : importSecurities) {
        if (ImportUtils.matchSecurity(importSecurity).isEmpty()) {
            // Import only if a match is not found
            final SecurityNode securityNode = ImportUtils.createSecurityNode(importSecurity, currencyNode);
            // link the security node
            importSecurity.setSecurityNode(securityNode);
            engine.addSecurity(securityNode);
            // if the ImportSecurity has pricing information, import it as well
            importSecurity.getLocalDate().ifPresent(localDate -> importSecurity.getUnitPrice().ifPresent(price -> {
                SecurityHistoryNode securityHistoryNode = new SecurityHistoryNode(localDate, price, 0, price, price);
                engine.addSecurityHistory(securityNode, securityHistoryNode);
            }));
        } else {
            // check to see if the cuspid needs to be updated
            // link the security node
            ImportUtils.matchSecurity(importSecurity).ifPresent(importSecurity::setSecurityNode);
            ImportUtils.matchSecurity(importSecurity).ifPresent(securityNode -> importSecurity.getId().ifPresent(securityId -> {
                if (securityNode.getISIN() == null || securityNode.getISIN().isEmpty()) {
                    try {
                        final SecurityNode clone = (SecurityNode) securityNode.clone();
                        clone.setISIN(securityId);
                        engine.updateCommodity(securityNode, clone);
                        Logger.getLogger(GenericImport.class.getName()).info("Assigning CUSPID");
                    } catch (final CloneNotSupportedException e) {
                        Logger.getLogger(GenericImport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
                    }
                }
            }));
        }
    }
}
Also used : Engine(jgnash.engine.Engine) DateUtils(jgnash.time.DateUtils) NotNull(jgnash.util.NotNull) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) Logger(java.util.logging.Logger) SecurityNode(jgnash.engine.SecurityNode) Level(java.util.logging.Level) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) List(java.util.List) LocalDate(java.time.LocalDate) Account(jgnash.engine.Account) CurrencyNode(jgnash.engine.CurrencyNode) TransactionFactory(jgnash.engine.TransactionFactory) SecurityNode(jgnash.engine.SecurityNode) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Engine(jgnash.engine.Engine)

Example 20 with CurrencyNode

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

the class OfxImport method matchAccount.

public static Account matchAccount(final OfxBank bank) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final String number = bank.accountId;
    final CurrencyNode node = engine.getCurrency(bank.currency);
    Account account = null;
    if (node != null) {
        for (Account a : engine.getAccountList()) {
            if (a.getAccountNumber() != null && a.getAccountNumber().equals(number) && a.getCurrencyNode().equals(node)) {
                account = a;
                break;
            }
        }
    } else if (number != null) {
        for (Account a : engine.getAccountList()) {
            if (a.getAccountNumber().equals(number)) {
                account = a;
                break;
            }
        }
    }
    return account;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Engine(jgnash.engine.Engine)

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