Search in sources :

Example 96 with Account

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

the class AccountTools method modifyAccount.

static void modifyAccount(final Account account) {
    if (account == null) {
        return;
    }
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final ResourceBundle rb = ResourceUtils.getBundle();
    final Account parentAccount = account.getParent();
    if (parentAccount == null) {
        if (engine.getRootAccount() == null) {
            // no root account at all, file was closed
            return;
        }
        account.setParent(engine.getRootAccount());
    }
    AccountDialog dlg = new AccountDialog();
    dlg.setTitle(rb.getString("Title.ModifyAccount"));
    dlg.setModifyingAccount(account);
    dlg.setParentAccount(account.getParent());
    dlg.setAccountName(account.getName());
    dlg.setAccountDescription(account.getDescription());
    dlg.setAccountCode(account.getAccountCode());
    dlg.setAccountNumber(account.getAccountNumber());
    dlg.setBankId(account.getBankId());
    dlg.setCurrency(account.getCurrencyNode());
    dlg.setAccountNotes(account.getNotes());
    dlg.setAccountLocked(account.isLocked());
    dlg.setAccountVisible(account.isVisible());
    dlg.setExcludedFromBudget(account.isExcludedFromBudget());
    if (account.getAccountType().getAccountGroup() == AccountGroup.INVEST) {
        dlg.setAccountSecurities(account.getSecurities());
    }
    dlg.setAccountType(account.getAccountType());
    dlg.disableAccountType(account.getAccountType());
    if (account.getTransactionCount() > 0) {
        dlg.disableAccountCurrency();
    }
    if (account.getTransactionCount() > 0) {
        dlg.setPlaceholderEnabled(false);
    } else {
        dlg.setAccountPlaceholder(account.isPlaceHolder());
    }
    dlg.setVisible(true);
    if (dlg.returnStatus()) {
        Account tAccount = new Account(dlg.getAccountType(), dlg.getCurrency());
        // set the data
        tAccount.setAccountCode(dlg.getAccountCode());
        tAccount.setAccountNumber(dlg.getAccountNumber());
        tAccount.setBankId(dlg.getBankId());
        tAccount.setName(dlg.getAccountName());
        tAccount.setDescription(dlg.getAccountDescription());
        tAccount.setNotes(dlg.getAccountNotes());
        tAccount.setLocked(dlg.isAccountLocked());
        tAccount.setPlaceHolder(dlg.isAccountPlaceholder());
        if (dlg.getParentAccount() == account) {
            tAccount.setParent(account.getParent());
            Logger.getLogger(AccountTools.class.getName()).warning("Prevented an attempt to assign accounts parent to itself");
        } else {
            tAccount.setParent(dlg.getParentAccount());
        }
        tAccount.setVisible(dlg.isAccountVisible());
        tAccount.setExcludedFromBudget(dlg.isExcludedFromBudget());
        if (!engine.modifyAccount(tAccount, account)) {
            StaticUIMethods.displayError(rb.getString("Message.Error.AccountUpdate"));
        }
        if (account.getAccountType().getAccountGroup() == AccountGroup.INVEST) {
            if (!engine.updateAccountSecurities(account, dlg.getAccountSecurities())) {
                StaticUIMethods.displayError(rb.getString("Message.Error.SecurityAccountUpdate"));
            }
        }
    }
}
Also used : Account(jgnash.engine.Account) ResourceBundle(java.util.ResourceBundle) Engine(jgnash.engine.Engine)

Example 97 with Account

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

the class AmortizeDialog method fillForm.

private void fillForm() {
    interestField.setDecimal(ao.getRate());
    loanAmountField.setDecimal(ao.getPrincipal());
    loanTermField.setIntValue(ao.getLength());
    payPeriodsField.setIntValue(ao.getPaymentPeriods());
    intPeriodsField.setIntValue(ao.getInterestPeriods());
    feesField.setDecimal(ao.getFees());
    memoField.setText(ao.getMemo());
    payeeField.setText(ao.getPayee());
    dateField.setDate(ao.getDate());
    daysField.setDecimal(ao.getDaysPerYear());
    useDaysButton.setSelected(ao.getUseDailyRate());
    daysField.setEnabled(ao.getUseDailyRate());
    Account a = ao.getBankAccount();
    if (a != null) {
        bankAccount = a;
        bankAccButton.setText(a.getName());
    }
    a = ao.getInterestAccount();
    if (a != null) {
        interestAccount = a;
        interestAccButton.setText(a.getName());
    }
    a = ao.getFeesAccount();
    if (a != null) {
        feesAccount = a;
        feesAccButton.setText(a.getName());
    }
}
Also used : Account(jgnash.engine.Account)

Example 98 with Account

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

the class AmortizeDialog method actionPerformed.

/**
     * Invoked when an action occurs.
     */
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == cancelButton) {
        closeDialog();
    } else if (e.getSource() == okButton) {
        result = true;
        closeDialog();
    } else if (e.getSource() == bankAccButton) {
        Account a = showAccountListDialog(bankAccount);
        if (a != null) {
            bankAccount = a;
            bankAccButton.setText(a.getName());
        } else {
            bankAccButton.setText(rb.getString("Word.None"));
        }
    } else if (e.getSource() == interestAccButton) {
        Account a = showAccountListDialog(interestAccount);
        if (a != null) {
            interestAccount = a;
            interestAccButton.setText(a.getName());
        } else {
            interestAccButton.setText(rb.getString("Word.None"));
        }
    } else if (e.getSource() == feesAccButton) {
        Account a = showAccountListDialog(feesAccount);
        if (a != null) {
            feesAccount = a;
            feesAccButton.setText(a.getName());
        } else {
            feesAccButton.setText(rb.getString("Word.None"));
        }
    } else if (e.getSource() == useDaysButton) {
        daysField.setEnabled(useDaysButton.isSelected());
    }
}
Also used : Account(jgnash.engine.Account)

Example 99 with Account

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

the class AccountListTreePane method messagePosted.

@Override
public void messagePosted(final Message event) {
    if (event.getEvent() == ChannelEvent.FILE_CLOSING) {
        EventQueue.invokeLater(AccountListTreePane.this::close);
        return;
    }
    if (EngineFactory.getEngine(EngineFactory.DEFAULT) == null) {
        return;
    }
    final Account a = event.getObject(MessageProperty.ACCOUNT);
    EventQueue.invokeLater(() -> {
        switch(event.getEvent()) {
            case ACCOUNT_ADD:
                model.reload();
                expand();
                break;
            case ACCOUNT_MODIFY:
                model.reload();
                expand();
                break;
            case ACCOUNT_REMOVE:
                if (a != null && selectedAccount != null) {
                    if (selectedAccount.equals(a)) {
                        selectedAccount = null;
                    }
                    model.removeAccount(a);
                } else {
                    model.reload();
                    expand();
                }
                break;
            case ACCOUNT_VISIBILITY_CHANGE:
                model.reload();
                expand();
                break;
            case FILE_LOAD_SUCCESS:
                refresh();
                expand();
                break;
            default:
                // ignore any other messages that don't belong to us
                break;
        }
    });
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account)

Example 100 with Account

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

the class BuySharePanel method modifyTransaction.

@Override
public void modifyTransaction(final Transaction tran) {
    if (!(tran instanceof InvestmentTransaction)) {
        throw new IllegalArgumentException("bad tranType");
    }
    clearForm();
    datePanel.setDate(tran.getLocalDate());
    List<TransactionEntry> entries = tran.getTransactionEntries();
    feePanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentFeeEntries());
    entries.stream().filter(e -> e instanceof TransactionEntryBuyX).forEach(e -> {
        AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
        memoField.setText(e.getMemo());
        priceField.setDecimal(entry.getPrice());
        quantityField.setDecimal(entry.getQuantity());
        securityCombo.setSelectedNode(entry.getSecurityNode());
        if (entry.getCreditAccount().equals(account)) {
            accountExchangePanel.setSelectedAccount(entry.getDebitAccount());
            accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
        } else {
            accountExchangePanel.setSelectedAccount(entry.getCreditAccount());
            accountExchangePanel.setExchangedAmount(entry.getCreditAmount());
        }
    });
    updateTotalField();
    modTrans = tran;
    setReconciledState(tran.getReconciled(getAccount()));
}
Also used : FocusListener(java.awt.event.FocusListener) Transaction(jgnash.engine.Transaction) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX) ValidationFactory(jgnash.ui.util.ValidationFactory) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) BigDecimal(java.math.BigDecimal) FocusAdapter(java.awt.event.FocusAdapter) List(java.util.List) FormLayout(com.jgoodies.forms.layout.FormLayout) FocusEvent(java.awt.event.FocusEvent) CellConstraints(com.jgoodies.forms.layout.CellConstraints) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) AccountExchangePanel(jgnash.ui.register.AccountExchangePanel) JPanel(javax.swing.JPanel) TransactionFactory(jgnash.engine.TransactionFactory) InvestmentTransaction(jgnash.engine.InvestmentTransaction) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9