Search in sources :

Example 11 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class RecurringViewController method handleNewAction.

@FXML
private void handleNewAction() {
    final Optional<Reminder> optional = RecurringEntryDialog.showAndWait(null);
    optional.ifPresent(reminder -> {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        if (!engine.addReminder(reminder)) {
            StaticUIMethods.displayError(resources.getString("Message.Error.ReminderAdd"));
        }
    });
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) Reminder(jgnash.engine.recurring.Reminder) Engine(jgnash.engine.Engine) FXML(javafx.fxml.FXML)

Example 12 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class RecurringViewController method initialize.

@FXML
private void initialize() {
    tableView.setTableMenuButtonVisible(true);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    // hide the horizontal scrollbar and prevent ghosting
    tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
    final TableColumn<Reminder, String> descriptionColumn = new TableColumn<>(resources.getString("Column.Description"));
    descriptionColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
    tableView.getColumns().add(descriptionColumn);
    final TableColumn<Reminder, String> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount().toString());
        }
        return null;
    });
    tableView.getColumns().add(accountColumn);
    final TableColumn<Reminder, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> {
        if (param.getValue().getTransaction() != null) {
            return new SimpleObjectProperty<>(param.getValue().getTransaction().getAmount(param.getValue().getAccount()));
        }
        return null;
    });
    amountColumn.setCellFactory(new Callback<TableColumn<Reminder, BigDecimal>, TableCell<Reminder, BigDecimal>>() {

        @Override
        public TableCell<Reminder, BigDecimal> call(TableColumn<Reminder, BigDecimal> param) {
            return new TableCell<Reminder, BigDecimal>() {

                {
                    setStyle("-fx-alignment: center-right;");
                }

                @Override
                protected void updateItem(final BigDecimal amount, final boolean empty) {
                    super.updateItem(amount, empty);
                    if (!empty && getTableRow() != null && getTableRow().getItem() != null) {
                        final Reminder reminder = (Reminder) getTableRow().getItem();
                        if (reminder.getTransaction() != null) {
                            setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(amount));
                            if (amount != null && amount.signum() < 0) {
                                setId(StyleClass.NORMAL_NEGATIVE_CELL_ID);
                            } else {
                                setId(StyleClass.NORMAL_CELL_ID);
                            }
                        } else {
                            setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(BigDecimal.ZERO));
                        }
                    }
                }
            };
        }
    });
    tableView.getColumns().add(amountColumn);
    final TableColumn<Reminder, String> frequencyColumn = new TableColumn<>(resources.getString("Column.Freq"));
    frequencyColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getReminderType().toString()));
    tableView.getColumns().add(frequencyColumn);
    final TableColumn<Reminder, Boolean> enabledColumn = new TableColumn<>(resources.getString("Column.Enabled"));
    enabledColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isEnabled()));
    enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn));
    tableView.getColumns().add(enabledColumn);
    final TableColumn<Reminder, LocalDate> lastPosted = new TableColumn<>(resources.getString("Column.LastPosted"));
    lastPosted.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLastDate()));
    lastPosted.setCellFactory(cell -> new ShortDateTableCell<>());
    tableView.getColumns().add(lastPosted);
    final TableColumn<Reminder, LocalDate> due = new TableColumn<>(resources.getString("Column.Due"));
    due.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getIterator().next()));
    due.setCellFactory(cell -> new ShortDateTableCell<>());
    tableView.getColumns().add(due);
    sortedReminderList.comparatorProperty().bind(tableView.comparatorProperty());
    tableView.setItems(sortedReminderList);
    selectedReminder.bind(tableView.getSelectionModel().selectedItemProperty());
    // bind enabled state of the buttons to the selected reminder property
    deleteButton.disableProperty().bind(Bindings.isNull(selectedReminder));
    modifyButton.disableProperty().bind(Bindings.isNull(selectedReminder));
    MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM, MessageChannel.REMINDER);
    JavaFXUtils.runLater(this::loadTable);
    startTimer();
    // Update the period when the snooze value changes
    Options.reminderSnoozePeriodProperty().addListener((observable, oldValue, newValue) -> {
        stopTimer();
        startTimer();
    });
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) PendingReminder(jgnash.engine.recurring.PendingReminder) Reminder(jgnash.engine.recurring.Reminder) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXML(javafx.fxml.FXML)

Example 13 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class Engine method createDefaultReminder.

/**
     * Creates a default reminder given a transaction and the primary account.  The Reminder will need to persisted.
     *
     * @param transaction Transaction for the reminder.  The transaction wil be cloned
     * @param account     primary account
     * @return new default {@code MonthlyReminder}
     */
public Reminder createDefaultReminder(final Transaction transaction, final Account account) {
    final Reminder reminder = new MonthlyReminder();
    try {
        reminder.setAccount(account);
        reminder.setStartDate(transaction.getLocalDate().plusMonths(1));
        reminder.setTransaction((Transaction) transaction.clone());
        reminder.setDescription(transaction.getPayee());
        reminder.setNotes(transaction.getMemo());
    } catch (final CloneNotSupportedException e) {
        logSevere(e.getLocalizedMessage());
    }
    return reminder;
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) MonthlyReminder(jgnash.engine.recurring.MonthlyReminder) Reminder(jgnash.engine.recurring.Reminder) MonthlyReminder(jgnash.engine.recurring.MonthlyReminder)

Example 14 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class Engine method processPendingReminders.

public void processPendingReminders(final Collection<PendingReminder> pendingReminders) {
    pendingReminders.stream().filter(PendingReminder::isApproved).forEach(pending -> {
        final Reminder reminder = pending.getReminder();
        if (reminder.getTransaction() != null) {
            final Transaction t = reminder.getTransaction();
            t.setDate(pending.getCommitDate());
            addTransaction(t);
        }
        reminder.setLastDate();
        if (!updateReminder(reminder)) {
            logSevere(rb.getString("Message.Error.ReminderUpdate"));
        }
    });
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) MonthlyReminder(jgnash.engine.recurring.MonthlyReminder) Reminder(jgnash.engine.recurring.Reminder)

Aggregations

Reminder (jgnash.engine.recurring.Reminder)14 PendingReminder (jgnash.engine.recurring.PendingReminder)8 Engine (jgnash.engine.Engine)7 MonthlyReminder (jgnash.engine.recurring.MonthlyReminder)4 FXML (javafx.fxml.FXML)3 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 DailyReminder (jgnash.engine.recurring.DailyReminder)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 TableCell (javafx.scene.control.TableCell)1 TableColumn (javafx.scene.control.TableColumn)1 CheckBoxTableCell (javafx.scene.control.cell.CheckBoxTableCell)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Account (jgnash.engine.Account)1