Search in sources :

Example 11 with NotNull

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;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) DoughnutChart(jgnash.uifx.control.DoughnutChart) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) TextInputControl(javafx.scene.control.TextInputControl) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) Side(javafx.geometry.Side) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) EncodeDecode(jgnash.util.EncodeDecode) BigDecimal(java.math.BigDecimal) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) CurrencyNode(jgnash.engine.CurrencyNode) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) InjectFXML(jgnash.uifx.util.InjectFXML) TitledPane(javafx.scene.control.TitledPane) NotNull(jgnash.util.NotNull) Comparators(jgnash.engine.Comparators) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) List(java.util.List) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) Account(jgnash.engine.Account) ObservableList(javafx.collections.ObservableList) PayeePredicate(jgnash.util.function.PayeePredicate) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) DatePickerEx(jgnash.uifx.control.DatePickerEx) CollectionUtils(jgnash.util.CollectionUtils) Options(jgnash.uifx.Options) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal) Predicate(java.util.function.Predicate) PayeePredicate(jgnash.util.function.PayeePredicate) PieChart(javafx.scene.chart.PieChart) Transaction(jgnash.engine.Transaction) ObservableList(javafx.collections.ObservableList) PayeePredicate(jgnash.util.function.PayeePredicate) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with NotNull

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;
}
Also used : Transaction(jgnash.engine.Transaction) NotNull(jgnash.util.NotNull)

Example 13 with NotNull

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);
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) NotNull(jgnash.util.NotNull)

Example 14 with NotNull

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;
}
Also used : Transaction(jgnash.engine.Transaction) BigDecimal(java.math.BigDecimal) NotNull(jgnash.util.NotNull)

Example 15 with NotNull

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);
}
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)

Aggregations

NotNull (jgnash.util.NotNull)17 Transaction (jgnash.engine.Transaction)13 BigDecimal (java.math.BigDecimal)10 InvestmentTransaction (jgnash.engine.InvestmentTransaction)9 List (java.util.List)6 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)6 TransactionEntry (jgnash.engine.TransactionEntry)6 ChangeListener (javafx.beans.value.ChangeListener)4 FXML (javafx.fxml.FXML)4 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 TransactionFactory (jgnash.engine.TransactionFactory)3 TransactionType (jgnash.engine.TransactionType)3 Collections (java.util.Collections)2 Objects (java.util.Objects)2 ResourceBundle (java.util.ResourceBundle)2 ExecutionException (java.util.concurrent.ExecutionException)2 Logger (java.util.logging.Logger)2 Preferences (java.util.prefs.Preferences)2 Collectors (java.util.stream.Collectors)2