From 301b3c61d29d5bfb27a5ed4b98f6d24f4d2fcfc6 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Sat, 29 Feb 2020 17:35:39 +0100 Subject: [PATCH] Fixes #876 - Take into account only splitTypeSwitch to compute Split Balance --- .../ui/transaction/SplitEditorFragment.java | 57 ++++++++++++++----- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java index 1494b16c7..b56daf566 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java @@ -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)); } }