use of jgnash.util.NotNull in project jgnash by ccavanaugh.
the class IncomeExpensePayeePieChartDialogController method createPieDataSet.
private ObservableList<PieChart.Data>[] createPieDataSet(@NotNull final Account account) {
@SuppressWarnings("unchecked") final ObservableList<PieChart.Data>[] chartData = (ObservableList<PieChart.Data>[]) new ObservableList[2];
chartData[CREDIT] = FXCollections.observableArrayList();
chartData[DEBIT] = FXCollections.observableArrayList();
final Map<String, BigDecimal> names = new HashMap<>();
final List<TranTuple> list = getTransactions(account, new ArrayList<>(), startDatePicker.getValue(), endDatePicker.getValue());
final CurrencyNode currency = account.getCurrencyNode();
// Create a list of predicates
final List<Predicate<Transaction>> predicates = getPayeeTextFields().stream().filter(textField -> !textField.getText().isEmpty()).map(textField -> new PayeePredicate(textField.getText(), Options.regexForFiltersProperty().get())).collect(Collectors.toList());
// Iterate through the list and add up filtered payees
for (final TranTuple tranTuple : list) {
final String payee = tranTuple.transaction.getPayee();
BigDecimal sum = tranTuple.transaction.getAmount(tranTuple.account);
sum = sum.multiply(tranTuple.account.getCurrencyNode().getExchangeRate(currency));
boolean keep = false;
if (predicates.isEmpty()) {
keep = true;
} else {
for (final Predicate<Transaction> predicate : predicates) {
if (predicate.test(tranTuple.transaction)) {
keep = true;
break;
}
}
}
if (keep) {
if (names.containsKey(payee)) {
sum = sum.add(names.get(payee));
}
names.put(payee, sum);
}
}
final Map<String, BigDecimal> sortedNames = CollectionUtils.sortMapByValue(names);
for (final Map.Entry<String, BigDecimal> entry : sortedNames.entrySet()) {
final PieChart.Data data = new PieChart.Data(truncateString(entry.getKey()), entry.getValue().abs().doubleValue());
// nodes are created lazily. Set the user data (Account) after the node is created
data.nodeProperty().addListener((observable, oldValue, newValue) -> newValue.setUserData(entry.getKey()));
if (entry.getValue().signum() == -1) {
chartData[DEBIT].add(data);
} else {
chartData[CREDIT].add(data);
}
}
return chartData;
}
use of jgnash.util.NotNull in project jgnash by ccavanaugh.
the class TransferSlipController method buildTransaction.
@NotNull
@Override
public Transaction buildTransaction() {
String number = numberComboBox.getValue();
String payee = resources.getString("Tab.Transfer");
Transaction transaction;
final int signum = amountField.getDecimal().signum();
if (signum >= 0) {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(accountExchangePane.getSelectedAccount(), accountProperty().get(), amountField.getDecimal().abs(), datePicker.getValue(), memoTextField.getText(), payee, number);
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(accountExchangePane.getSelectedAccount(), accountProperty().get(), accountExchangePane.exchangeAmountProperty().get().abs(), amountField.getDecimal().abs().negate(), datePicker.getValue(), memoTextField.getText(), payee, number);
}
} else {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(accountProperty().get(), accountExchangePane.getSelectedAccount(), amountField.getDecimal().abs(), datePicker.getValue(), memoTextField.getText(), payee, number);
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(accountProperty().get(), accountExchangePane.getSelectedAccount(), amountField.getDecimal().abs(), accountExchangePane.exchangeAmountProperty().get().abs().negate(), datePicker.getValue(), memoTextField.getText(), payee, number);
}
}
ReconcileManager.reconcileTransaction(accountProperty().get(), transaction, getReconciledState());
return transaction;
}
use of jgnash.util.NotNull in project jgnash by ccavanaugh.
the class ReinvestDividendSlipController method buildTransaction.
@NotNull
@Override
public Transaction buildTransaction() {
final List<TransactionEntry> gains = gainLossPane.getTransactions();
final List<TransactionEntry> fees = feePane.getTransactions();
final Transaction transaction = TransactionFactory.generateReinvestDividendXTransaction(accountProperty().get(), securityComboBox.getValue(), priceField.getDecimal(), quantityField.getDecimal(), datePicker.getValue(), memoTextField.getText(), fees, gains);
transaction.setNumber(numberComboBox.getValue());
return attachmentPane.buildTransaction(transaction);
}
use of jgnash.util.NotNull in project jgnash by ccavanaugh.
the class ReturnOfCapitalSlipController method buildTransaction.
@NotNull
@Override
public Transaction buildTransaction() {
BigDecimal incomeExchangedAmount = decimalTextField.getDecimal().negate();
BigDecimal accountExchangedAmount = decimalTextField.getDecimal();
if (!incomeExchangePane.getSelectedAccount().getCurrencyNode().equals(accountProperty().get().getCurrencyNode())) {
incomeExchangedAmount = incomeExchangePane.exchangeAmountProperty().get().negate();
}
if (!accountExchangePane.getSelectedAccount().getCurrencyNode().equals(accountProperty().get().getCurrencyNode())) {
accountExchangedAmount = accountExchangePane.exchangeAmountProperty().get();
}
final Transaction transaction = TransactionFactory.generateRocXTransaction(incomeExchangePane.getSelectedAccount(), accountProperty().get(), accountExchangePane.getSelectedAccount(), securityComboBox.getValue(), decimalTextField.getDecimal(), incomeExchangedAmount, accountExchangedAmount, datePicker.getValue(), memoTextField.getText());
transaction.setNumber(numberComboBox.getValue());
return transaction;
}
use of jgnash.util.NotNull 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());
return attachmentPane.buildTransaction(transaction);
}
Aggregations