Skip to content

Commit

Permalink
codinguser#876 - Enhance Code Quality
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanGarf committed Mar 3, 2020
1 parent 4c84125 commit 9e1951f
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public Cursor fetchAccountsOrderedByFavoriteAndFullName(String where, String[] w
* @return Account Balance of an account including sub-accounts
*/
public Money getAccountBalance(String accountUID){
return computeBalance(accountUID, -1, -1);
return getAccountBalance(accountUID, -1, -1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,15 @@ public Split buildModelInstance(@NonNull final Cursor cursor){
* @param hasDebitNormalBalance Does the final balance has normal debit credit meaning
* @return Balance of the splits for this account
*/
public Money computeSplitBalance(List<String> accountUIDList, String currencyCode, boolean hasDebitNormalBalance){
return calculateSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance, -1, -1);
public Money computeSplitBalance(List<String> accountUIDList,
String currencyCode,
boolean hasDebitNormalBalance) {

return computeSplitBalance(accountUIDList,
currencyCode,
hasDebitNormalBalance,
-1,
-1);
}

/**
Expand All @@ -173,9 +180,17 @@ public Money computeSplitBalance(List<String> accountUIDList, String currencyCod
* @param endTimestamp the end timestamp of the time range
* @return Balance of the splits for this account within the specified time range
*/
public Money computeSplitBalance(List<String> accountUIDList, String currencyCode, boolean hasDebitNormalBalance,
long startTimestamp, long endTimestamp){
return calculateSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance, startTimestamp, endTimestamp);
public Money computeSplitBalance(List<String> accountUIDList,
String currencyCode,
boolean hasDebitNormalBalance,
long startTimestamp,
long endTimestamp) {

return calculateSplitBalance(accountUIDList,
currencyCode,
hasDebitNormalBalance,
startTimestamp,
endTimestamp);
}


Expand Down Expand Up @@ -260,23 +275,30 @@ private Money calculateSplitBalance(List<String> accountUIDList,

// #876
// if (!hasDebitNormalBalance) {
// // The account has usually DEBIT < CREDIT
//
// // Invert signum to get a positive amount
// amount_num = -amount_num;
// }

if (commodityCode.equals(currencyCode)) {
// currency matches

total = total.add(new Money(amount_num,
amount_denom,
currencyCode));
//Log.d(getClass().getName(), "currency " + commodity + " sub - total " + total);

} else {
// there is a second currency involved

if (commoditiesDbAdapter == null) {
commoditiesDbAdapter = new CommoditiesDbAdapter(mDb);
pricesDbAdapter = new PricesDbAdapter(mDb);
commodity = commoditiesDbAdapter.getCommodity(currencyCode);
currencyUID = commoditiesDbAdapter.getCommodityUID(currencyCode);
}

// get price
String commodityUID = commoditiesDbAdapter.getCommodityUID(commodityCode);
Pair<Long, Long> price = pricesDbAdapter.getPrice(commodityUID,
Expand All @@ -296,7 +318,9 @@ private Money calculateSplitBalance(List<String> accountUIDList,
//Log.d(getClass().getName(), "currency " + commodity + " sub - total " + total);
}
} // while

return total;

} finally {
cursor.close();
}
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/org/gnucash/android/model/AccountType.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,24 @@ public enum AccountType {
//nothing to see here, move along
}

public boolean hasDebitNormalBalance(){
public boolean hasDebitNormalBalance() {

return mNormalBalance == TransactionType.DEBIT;
}

/**
* Returns the type of normal balance this account possesses
* @return TransactionType balance of the account type
*/
public TransactionType getNormalBalanceType(){
public TransactionType getNormalBalanceType() {

return mNormalBalance;
}

// TODO TW C 2020-03-03 : A renommer en anglais
public boolean isResultAccount() {

return EXPENSE.equals(this) || INCOME.equals(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @author Ngewi Fet <[email protected]>
* @author Jesse Shieh <[email protected]>
*/
// TODO TW C 2020-03-03 : A renommer SplitType (AC)
public enum TransactionType {
DEBIT, CREDIT;

Expand Down
Loading

0 comments on commit 9e1951f

Please sign in to comment.