Search in sources :

Example 1 with PayeePredicate

use of jgnash.util.function.PayeePredicate in project jgnash by ccavanaugh.

the class RegisterTableController method handleFilterChange.

private void handleFilterChange() {
    Predicate<Transaction> predicate = new ReconciledPredicate(account.get(), reconciledStateFilterComboBox.valueProperty().get().getReconciledState()).and(new TransactionAgePredicate(transactionAgeFilterComboBox.valueProperty().get().getChronoUnit(), transactionAgeFilterComboBox.valueProperty().get().getAge()));
    if (memoFilterTextField != null) {
        predicate = predicate.and(new MemoPredicate(memoFilterTextField.getText(), Options.regexForFiltersProperty().get()));
    }
    if (payeeFilterTextField != null) {
        predicate = predicate.and(new PayeePredicate(payeeFilterTextField.getText(), Options.regexForFiltersProperty().get()));
    }
    predicate = predicate.and(new TagPredicate(tagPane.getSelectedTags()));
    filteredTransactionList.setPredicate(predicate);
}
Also used : ReconciledPredicate(jgnash.util.function.ReconciledPredicate) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionAgePredicate(jgnash.util.function.TransactionAgePredicate) PayeePredicate(jgnash.util.function.PayeePredicate) TagPredicate(jgnash.util.function.TagPredicate) MemoPredicate(jgnash.util.function.MemoPredicate)

Example 2 with PayeePredicate

use of jgnash.util.function.PayeePredicate 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 = 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) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) List(java.util.List) 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) NumericFormats(jgnash.text.NumericFormats) 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)

Aggregations

Transaction (jgnash.engine.Transaction)2 PayeePredicate (jgnash.util.function.PayeePredicate)2 BigDecimal (java.math.BigDecimal)1 NumberFormat (java.text.NumberFormat)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 ResourceBundle (java.util.ResourceBundle)1 UUID (java.util.UUID)1 Predicate (java.util.function.Predicate)1 Preferences (java.util.prefs.Preferences)1 Collectors (java.util.stream.Collectors)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 FXCollections (javafx.collections.FXCollections)1