Search in sources :

Example 11 with CurrencyNode

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

the class ProfitLossTXT method run.

public void run() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final CurrencyNode baseCommodity = engine.getDefaultCurrency();
    final LocalDate[] dates = getDates();
    if (dates != null) {
        final String fileName = getFileName();
        ProfitLossTextReport report = new ProfitLossTextReport(fileName, dates[0], dates[1], baseCommodity, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
        report.run();
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ProfitLossTextReport(jgnash.report.ProfitLossTextReport) LocalDate(java.time.LocalDate) Engine(jgnash.engine.Engine) AccountBalanceDisplayManager(jgnash.ui.register.AccountBalanceDisplayManager)

Example 12 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).isPresent()) {
            // 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 13 with CurrencyNode

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

the class CurrencyExchangeDialog method addExchangeRate.

private void addExchangeRate() {
    if (validateForm()) {
        CurrencyNode src = baseCurrencyCombo.getSelectedNode();
        CurrencyNode dst = exchangeCurrencyCombo.getSelectedNode();
        getEngine().setExchangeRate(src, dst, rateField.getDecimal(), dateField.getLocalDate());
        clearForm();
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode)

Example 14 with CurrencyNode

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

the class CurrencyExchangeDialog method getSelectedExchangeRate.

private ExchangeRate getSelectedExchangeRate() {
    CurrencyNode src = baseCurrencyCombo.getSelectedNode();
    CurrencyNode dst = exchangeCurrencyCombo.getSelectedNode();
    return getEngine().getExchangeRate(src, dst);
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode)

Example 15 with CurrencyNode

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

the class CurrencyModifyDialog method messagePosted.

@Override
public void messagePosted(final Message event) {
    final CommodityNode node = event.getObject(MessageProperty.COMMODITY);
    if (node instanceof CurrencyNode) {
        EventQueue.invokeLater(() -> {
            switch(event.getEvent()) {
                case CURRENCY_REMOVE:
                    model.removeElement((CurrencyNode) node);
                    if (currentCurrency.equals(node)) {
                        clearForm();
                    }
                    break;
                case CURRENCY_REMOVE_FAILED:
                    JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Warn.CurrencyInUse"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
                    break;
                case CURRENCY_ADD:
                    clearForm();
                    model.addElement((CurrencyNode) node);
                    break;
                case CURRENCY_ADD_FAILED:
                    JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Error.AddCurrency"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
                    break;
                case CURRENCY_MODIFY:
                    // node will be stale
                    model.removeElement((CurrencyNode) node);
                    model.addElement(getEngine().getCurrency(node.getSymbol()));
                    if (currentCurrency.equals(node)) {
                        updateForm();
                    }
                    break;
                case CURRENCY_MODIFY_FAILED:
                    JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Error.ModifyCurrency"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
                    break;
                default:
                    break;
            }
        });
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) CommodityNode(jgnash.engine.CommodityNode)

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