Search in sources :

Example 51 with TransactionEntry

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

the class SellShareSlipController method buildTransaction.

@NotNull
@Override
public Transaction buildTransaction() {
    final BigDecimal exchangeRate = accountExchangePane.getExchangeRate();
    final List<TransactionEntry> gains = gainLossPane.getTransactions();
    final List<TransactionEntry> fees = feePane.getTransactions();
    final Transaction transaction = TransactionFactory.generateSellXTransaction(accountExchangePane.getSelectedAccount(), accountProperty().get(), securityComboBox.getValue(), priceField.getDecimal(), quantityField.getDecimal(), exchangeRate, datePicker.getValue(), memoTextField.getText(), fees, gains);
    transaction.setNumber(numberComboBox.getValue());
    transaction.setTags(TransactionEntrySellX.class, tagPane.getSelectedTags());
    return attachmentPane.buildTransaction(transaction);
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) BigDecimal(java.math.BigDecimal) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) NotNull(jgnash.util.NotNull)

Example 52 with TransactionEntry

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

the class SlipController method modifyTransaction.

@Override
public void modifyTransaction(@NotNull final Transaction transaction) {
    if (transaction.areAccountsLocked()) {
        clearForm();
        StaticUIMethods.displayError(resources.getString("Message.TransactionModifyLocked"));
        return;
    }
    // load the form
    newTransaction(transaction);
    // save reference to old transaction
    modTrans = transaction;
    modTrans = attachmentPane.modifyTransaction(modTrans);
    tagPane.setSelectedTags(transaction.getTags(account.get()));
    // Set state of memo concatenation
    concatenated.setValue(modTrans.isMemoConcatenated());
    if (!canModifyTransaction(transaction) && transaction.getTransactionType() == TransactionType.SPLITENTRY) {
        for (final TransactionEntry entry : transaction.getTransactionEntries()) {
            if (entry.getCreditAccount().equals(accountProperty().get()) || entry.getDebitAccount().equals(accountProperty().get())) {
                modEntry.setValue(entry);
                // override to allow editing the entry
                concatenated.setValue(false);
                break;
            }
        }
        if (modEntry.get() == null) {
            Logger logger = Logger.getLogger(SlipController.class.getName());
            logger.warning("Was not able to modify the transaction");
        }
    }
}
Also used : Logger(java.util.logging.Logger) TransactionEntry(jgnash.engine.TransactionEntry)

Example 53 with TransactionEntry

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

the class SplitTransactionDialog method deleteAction.

@Override
void deleteAction() {
    final TransactionEntry entry = tableView.getSelectionModel().getSelectedItem();
    if (entry != null) {
        tableView.getSelectionModel().clearSelection();
        ((SplitTransactionSlipController) tabPane.getSelectionModel().getSelectedItem().getUserData()).clearForm();
        getTransactionEntries().remove(entry);
    }
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

Example 54 with TransactionEntry

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

the class SplitTransactionSlipController method buildTransactionEntry.

@Override
TransactionEntry buildTransactionEntry() {
    TransactionEntry entry = new TransactionEntry();
    entry.setMemo(memoField.getText());
    int signum = amountField.getDecimal().signum();
    if ((slipType == SlipType.DECREASE && signum >= 0) || (slipType == SlipType.INCREASE && signum < 0)) {
        entry.setCreditAccount(accountExchangePane.getSelectedAccount());
        entry.setDebitAccount(account.get());
        if (hasEqualCurrencies()) {
            entry.setAmount(amountField.getDecimal().abs());
        } else {
            entry.setDebitAmount(amountField.getDecimal().abs().negate());
            entry.setCreditAmount(accountExchangePane.exchangeAmountProperty().get().abs());
        }
    } else {
        entry.setCreditAccount(account.get());
        entry.setDebitAccount(accountExchangePane.getSelectedAccount());
        if (hasEqualCurrencies()) {
            entry.setAmount(amountField.getDecimal().abs());
        } else {
            entry.setCreditAmount(amountField.getDecimal().abs());
            entry.setDebitAmount(accountExchangePane.exchangeAmountProperty().get().abs().negate());
        }
    }
    entry.setReconciled(account.get(), getReconciledState());
    entry.setTags(tagPane.getSelectedTags());
    return entry;
}
Also used : TransactionEntry(jgnash.engine.TransactionEntry)

Example 55 with TransactionEntry

use of jgnash.engine.TransactionEntry 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());
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) TransactionEntry(jgnash.engine.TransactionEntry) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionEntry (jgnash.engine.TransactionEntry)55 Account (jgnash.engine.Account)16 InvestmentTransaction (jgnash.engine.InvestmentTransaction)16 Transaction (jgnash.engine.Transaction)16 BigDecimal (java.math.BigDecimal)13 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)11 Logger (java.util.logging.Logger)4 FXML (javafx.fxml.FXML)4 NotNull (jgnash.util.NotNull)4 CellConstraints (com.jgoodies.forms.layout.CellConstraints)3 FormLayout (com.jgoodies.forms.layout.FormLayout)3 FocusAdapter (java.awt.event.FocusAdapter)3 FocusEvent (java.awt.event.FocusEvent)3 FocusListener (java.awt.event.FocusListener)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JPanel (javax.swing.JPanel)3 Engine (jgnash.engine.Engine)3 TransactionFactory (jgnash.engine.TransactionFactory)3