Esempio n. 1
0
    private void saveGoalTransaction(GoalTransactionUIModel goalTransactionUIModel) {
      try {
        TransactionUIModel transactionUIModel = goalTransactionUIModel.getTransaction();
        Transaction transaction = transactionDao.queryForId(transactionUIModel.getId());

        GoalTransaction goalTransaction = new GoalTransaction(transaction);
        goalTransactionDao.create(goalTransaction);

        transaction.setGoalTransaction(goalTransaction);
        transaction.setAmount(transactionUIModel.getAmount());
        transactionDao.update(transaction);

        transactionsUpdateListener.onTransactionsUpdated(transactionUIModel);
      } catch (SQLException e) {
        Log.e(TAG, "Error updating goal transaction", e);
      }
    }
Esempio n. 2
0
    private void splitTransaction(
        TransactionUIModel transaction, GoalTransactionUIModel goalTransaction) {
      try {
        TransactionUIModel parentTransaction = goalTransaction.getTransaction();
        Double rest =
            new BigDecimal(transaction.getAmount())
                .add(new BigDecimal(parentTransaction.getAmount()).negate())
                .doubleValue();

        saveGoalTransaction(goalTransaction);

        Transaction clone = transactionDao.queryForId(transaction.getId()).getClone();
        clone.setAmount(rest);
        transactionDao.create(clone);
        transactionsUpdateListener.onTransactionAdded(
            ConvertUtil.convertToUIModel(clone), parentTransaction);
      } catch (SQLException e) {
        Log.e(TAG, "Error splitting transaction", e);
      }
    }