Search in sources :

Example 11 with Transaction

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

the class AbstractRegisterPanel method deleteAction.

protected void deleteAction() {
    Transaction[] trans = getSelectedTransactions();
    if (RegisterFactory.isConfirmTransactionDeleteEnabled()) {
        if (!confirmTransactionRemoval(trans.length)) {
            return;
        }
    }
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    // walk through the array and delete each transaction
    for (Transaction tran : trans) {
        if (engine.removeTransaction(tran)) {
            if (tran.getAttachment() != null) {
                if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(rb.getString("Question.DeleteAttachment")), rb.getString("Title.DeleteAttachment"))) {
                    if (!engine.removeAttachment(tran.getAttachment())) {
                        StaticUIMethods.displayError(ResourceUtils.getString("Message.Error.DeleteAttachment", tran.getAttachment()));
                    }
                }
            }
        }
    }
    // Request focus as it may have been lost
    requestFocusInWindow();
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) JLabel(javax.swing.JLabel) Engine(jgnash.engine.Engine)

Example 12 with Transaction

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

the class RegisterPanel method modifyTransaction.

@Override
protected void modifyTransaction(final int index) {
    if (index >= model.getRowCount()) {
        throw new IllegalArgumentException("RegisterPanel: should not have exceeded model size");
    }
    Transaction t = model.getTransactionAt(index);
    if (t instanceof InvestmentTransaction) {
        ((AbstractEntryFormPanel) tabbedPane.getSelectedComponent()).clearForm();
        InvestmentTransactionDialog.showDialog((InvestmentTransaction) t);
        return;
    }
    if (t.getTransactionType() == TransactionType.SINGLENTRY) {
        tabbedPane.setSelectedComponent(adjustPanel);
        adjustPanel.modifyTransaction(t);
    } else if (t.getAmount(account).signum() >= 0) {
        tabbedPane.setSelectedComponent(creditPanel);
        creditPanel.modifyTransaction(t);
    } else {
        tabbedPane.setSelectedComponent(debitPanel);
        debitPanel.modifyTransaction(t);
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 13 with Transaction

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

the class PayeePieChart method createPieDataSet.

private PieDataset[] createPieDataSet(final Account a) {
    final DefaultPieDataset[] returnValue = new DefaultPieDataset[2];
    returnValue[CREDIT] = new DefaultPieDataset();
    returnValue[DEBIT] = new DefaultPieDataset();
    if (a != null) {
        //System.out.print("Account = "); System.out.println(a);
        Map<String, BigDecimal> names = new HashMap<>();
        List<TranTuple> list = getTransactions(a, new ArrayList<>(), startField.getLocalDate(), endField.getLocalDate());
        CurrencyNode currency = a.getCurrencyNode();
        for (final TranTuple tranTuple : list) {
            Transaction tran = tranTuple.transaction;
            Account account = tranTuple.account;
            String payee = tran.getPayee();
            BigDecimal sum = tran.getAmount(account);
            sum = sum.multiply(account.getCurrencyNode().getExchangeRate(currency));
            if (useFilters.isSelected()) {
                for (String aFilterList : filterList) {
                    PayeeMatcher pm = new PayeeMatcher(aFilterList, false);
                    if (pm.matches(tran)) {
                        payee = aFilterList;
                        //System.out.println(filterList.get(i));
                        break;
                    }
                }
            }
            if (names.containsKey(payee)) {
                sum = sum.add(names.get(payee));
            }
            names.put(payee, sum);
        }
        for (final Map.Entry<String, BigDecimal> entry : names.entrySet()) {
            BigDecimal value = entry.getValue();
            if (value.compareTo(BigDecimal.ZERO) == -1) {
                value = value.negate();
                returnValue[DEBIT].setValue(entry.getKey(), value);
            } else {
                returnValue[CREDIT].setValue(entry.getKey(), value);
            }
        }
    }
    return returnValue;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) HashMap(java.util.HashMap) PayeeMatcher(jgnash.engine.search.PayeeMatcher) BigDecimal(java.math.BigDecimal) Transaction(jgnash.engine.Transaction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Transaction

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

the class InvestmentRegisterTableModel method getInternalValueAt.

@Override
public Object getInternalValueAt(int row, int col) {
    InvestmentTransaction _t = null;
    Transaction t = getTransactionAt(row);
    if (t instanceof InvestmentTransaction) {
        _t = (InvestmentTransaction) t;
    }
    switch(col) {
        case 0:
            return t.getLocalDate();
        case 1:
            if (_t != null) {
                return _t.getTransactionType().toString();
            } else if (t.getAmount(account).signum() > 0) {
                return rb.getString("Item.CashDeposit");
            }
            return rb.getString("Item.CashWithdrawal");
        case 2:
            if (_t != null) {
                return _t.getSecurityNode().getSymbol();
            }
            return t.getMemo();
        case 3:
            return t.getReconciled(account).toString();
        case // quantity
        4:
            if (_t != null) {
                BigDecimal quantity = _t.getQuantity();
                if (quantity.compareTo(BigDecimal.ZERO) != 0) {
                    return quantity;
                }
            }
            return null;
        case // price
        5:
            if (_t != null) {
                BigDecimal price = _t.getPrice();
                if (price.compareTo(BigDecimal.ZERO) != 0) {
                    return price;
                }
            }
            return null;
        case // net cash amount
        6:
            if (_t != null) {
                return _t.getNetCashValue();
            }
            return t.getAmount(account);
        default:
            return ERROR;
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal)

Example 15 with Transaction

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

the class RegisterTableModel method getInternalValueAt.

@Override
protected Object getInternalValueAt(int row, int col) {
    Transaction t = getTransactionAt(row);
    BigDecimal amount = t.getAmount(account);
    int signum = amount.signum();
    switch(col) {
        case 0:
            return t.getLocalDate();
        case 1:
            return t.getNumber();
        case 2:
            return t.getPayee();
        case 3:
            return t.getMemo();
        case 4:
            if (t instanceof InvestmentTransaction) {
                return ((InvestmentTransaction) t).getInvestmentAccount().getName();
            }
            int count = t.size();
            if (count > 1) {
                return "[ " + count + " " + split + " ]";
            }
            Account creditAccount = t.getTransactionEntries().get(0).getCreditAccount();
            if (creditAccount != account) {
                return creditAccount.getName();
            }
            return t.getTransactionEntries().get(0).getDebitAccount().getName();
        case 5:
            return t.getReconciled(account).toString();
        case 6:
            if (signum >= 0) {
                return amount;
            }
            return null;
        case 7:
            if (signum < 0) {
                return amount.abs();
            }
            return null;
        case 8:
            return getBalanceAt(row);
        default:
            return ERROR;
    }
}
Also used : Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal)

Aggregations

Transaction (jgnash.engine.Transaction)81 InvestmentTransaction (jgnash.engine.InvestmentTransaction)39 Account (jgnash.engine.Account)27 BigDecimal (java.math.BigDecimal)24 Engine (jgnash.engine.Engine)22 TransactionEntry (jgnash.engine.TransactionEntry)18 NotNull (jgnash.util.NotNull)13 List (java.util.List)10 LocalDate (java.time.LocalDate)9 FXML (javafx.fxml.FXML)9 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)9 ArrayList (java.util.ArrayList)7 TransactionType (jgnash.engine.TransactionType)7 ResourceBundle (java.util.ResourceBundle)6 TransactionFactory (jgnash.engine.TransactionFactory)6 NumberFormat (java.text.NumberFormat)5 Objects (java.util.Objects)5 ChangeListener (javafx.beans.value.ChangeListener)5 EngineFactory (jgnash.engine.EngineFactory)5 Message (jgnash.engine.message.Message)5