Skip to content

Commit

Permalink
Fixes codinguser#876 - Take into account only splitTypeSwitch to comp…
Browse files Browse the repository at this point in the history
…ute Split Balance
  • Loading branch information
JeanGarf committed Feb 29, 2020
1 parent 85704b4 commit 301b3c6
Showing 1 changed file with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,30 +422,61 @@ public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

@Override
public void afterTextChanged(Editable editable) {

//
// Compute Split balance
//

BigDecimal imbalance = BigDecimal.ZERO;

for (View splitItem : mSplitItemViewList) {
SplitViewHolder viewHolder = (SplitViewHolder) splitItem.getTag();
BigDecimal amount = viewHolder.getAmountValue().abs();

// Get the absolute value of the amount
BigDecimal absAmount = viewHolder.getAmountValue()
.abs();

long accountId = viewHolder.accountsSpinner.getSelectedItemId();
boolean hasDebitNormalBalance = AccountsDbAdapter.getInstance()
.getAccountType(accountId).hasDebitNormalBalance();

// #876 May be usefull for debug
// String accountFullName = AccountsDbAdapter.getInstance()
// .getAccountFullName(AccountsDbAdapter.getInstance()
// .getUID(accountId));

// #876
// boolean hasDebitNormalBalance = AccountsDbAdapter.getInstance()
// .getAccountType(accountId)
// .hasDebitNormalBalance();

if (viewHolder.splitTypeSwitch.isChecked()) {
if (hasDebitNormalBalance)
imbalance = imbalance.add(amount);
else
imbalance = imbalance.subtract(amount);
// Switch is CREDIT

// #876
// if (hasDebitNormalBalance) {
// imbalance = imbalance.add(absAmount);
// } else {
// imbalance = imbalance.subtract(absAmount);
// }
imbalance = imbalance.add(absAmount);

} else {
if (hasDebitNormalBalance)
imbalance = imbalance.subtract(amount);
else
imbalance = imbalance.add(amount);
// Switch is DEBIT

// #876
// if (hasDebitNormalBalance) {
// imbalance = imbalance.subtract(absAmount);
// } else {
// imbalance = imbalance.add(absAmount);
// }
imbalance = imbalance.subtract(absAmount);

}

}
} // for

TransactionsActivity.displayBalance(mImbalanceTextView, new Money(imbalance, mCommodity));
TransactionsActivity.displayBalance(mImbalanceTextView,
new Money(imbalance,
mCommodity));
}
}

Expand Down

0 comments on commit 301b3c6

Please sign in to comment.