コード例 #1
0
  @FXML
  @Override
  public void handleEnterAction() {
    if (validateForm()) {
      if (modTrans == null) { // new transaction
        Transaction newTrans = buildTransaction();

        ReconcileManager.reconcileTransaction(
            accountProperty.get(), newTrans, getReconciledState());

        newTrans = attachmentPane.buildTransaction(newTrans); // chain the transaction build

        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

        if (engine != null) {
          engine.addTransaction(newTrans);
        }
      } else {
        Transaction newTrans = buildTransaction();

        newTrans.setDateEntered(modTrans.getDateEntered());

        // restore the reconciled state of the previous old transaction
        for (final Account a : modTrans.getAccounts()) {
          if (!a.equals(accountProperty.get())) {
            ReconcileManager.reconcileTransaction(a, newTrans, modTrans.getReconciled(a));
          }
        }

        /*
         * Reconcile the modified transaction for this account.
         * This must be performed last to ensure consistent results per the ReconcileManager rules
         */
        ReconcileManager.reconcileTransaction(
            accountProperty.get(), newTrans, getReconciledState());

        newTrans = attachmentPane.buildTransaction(newTrans); // chain the transaction build

        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

        if (engine != null && engine.removeTransaction(modTrans)) {
          engine.addTransaction(newTrans);
        }
      }
      clearForm();

      if (payeeTextField != null) {
        payeeTextField.requestFocus();
      } else {
        memoTextField.requestFocus();
      }
    }
  }
コード例 #2
0
  @FXML
  private void convertAction() {
    final Optional<Account> accountOptional =
        StaticAccountsMethods.selectAccount(null, accountProperty.get());
    if (accountOptional.isPresent()) {
      final Account opp = accountOptional.get();

      final Transaction t = new Transaction();

      t.setDate(datePicker.getValue());
      t.setNumber(numberComboBox.getValue());
      t.setPayee(payeeTextField.getText());

      final TransactionEntry entry = new TransactionEntry();
      entry.setMemo(memoTextField.getText());

      if (amountField.getDecimal().signum() >= 0) {
        entry.setCreditAccount(accountProperty.get());
        entry.setDebitAccount(opp);
      } else {
        entry.setDebitAccount(accountProperty.get());
        entry.setCreditAccount(opp);
      }

      entry.setCreditAmount(amountField.getDecimal().abs());
      entry.setDebitAmount(amountField.getDecimal().abs().negate());

      t.addTransactionEntry(entry);

      ReconcileManager.reconcileTransaction(accountProperty.get(), t, getReconciledState());

      TransactionDialog.showAndWait(
          accountProperty.get(),
          t,
          optional -> {
            if (optional.isPresent()) {
              final Transaction tran = optional.get();
              final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
              Objects.requireNonNull(engine);

              if (engine.removeTransaction(modTrans)) {
                engine.addTransaction(tran);
              }
              clearForm();
            }
          });
    }
  }
コード例 #3
0
  /**
   * Changes and transaction number to the next available in the account and returns the resultant
   *
   * @param transaction transaction to change the check number
   * @return the resultant transaction
   */
  private static Transaction changeTransNum(final Transaction transaction) {
    Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

    try {
      Transaction clone = (Transaction) transaction.clone();

      clone.setNumber(getNextTransactionNum(transaction));

      if (engine.removeTransaction(transaction)) {
        engine.addTransaction(clone);
        return clone;
      }
    } catch (CloneNotSupportedException e) {
      Logger.getLogger(PrintCheckFactory.class.getName()).log(Level.SEVERE, null, e);
    }

    return transaction;
  }