Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
codinguser committed May 27, 2014
2 parents 1902ec2 + 3b99114 commit 4a9cdd4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change Log
===============================================================================
Version 1.3.3 *(2014-05-26)*
* Reversed changes in the computation of balances, back to pre-v1.3.2 mode (will be re-instated in the future)

Version 1.3.2 *(2014-05-23)*
----------------------------
* Fixed: Editing account modifies the transaction type of transfer transactions
Expand Down
2 changes: 1 addition & 1 deletion app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.gnucash.android"
android:versionCode="28"
android:versionCode="29"
android:versionName="@string/app_version_name" >

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
Expand Down
2 changes: 1 addition & 1 deletion app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">GnuCash</string>
<string name="app_version_name">1.3.2</string>
<string name="app_version_name">1.3.3</string>
<string name="title_add_account">Create Account</string>
<string name="title_edit_account">Edit Account</string>
<string name="info_details">Info</string>
Expand Down
14 changes: 14 additions & 0 deletions app/src/org/gnucash/android/app/GnuCashApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.gnucash.android.R;

/**
* An {@link Application} subclass for retrieving static context
Expand All @@ -39,4 +42,15 @@ public void onCreate(){
public static Context getAppContext() {
return GnuCashApplication.context;
}

/**
* Returns <code>true</code> if double entry is enabled in the app settings, <code>false</code> otherwise.
* If the value is not set, the default value can be specified in the parameters.
* @param defaultValue Default value to return if double entry is not explicitly set
* @return <code>true</code> if double entry is enabled, <code>false</code> otherwise
*/
public static boolean isDoubleEntryEnabled(boolean defaultValue){
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPrefs.getBoolean(context.getString(R.string.key_use_double_entry), defaultValue);
}
}
8 changes: 7 additions & 1 deletion app/src/org/gnucash/android/db/AccountsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,13 @@ public Money getAccountBalance(long accountId){
balance = balance.add(subBalance);
}
}
return balance.add(getAccount(accountId).getBalance());

return balance.add(mTransactionsAdapter.getTransactionsSum(accountId));

// properly compute the account balance taking double entry into account
// TODO: re-enable this when splits are added
// return balance.add(getAccount(accountId).getBalance());

}

/**
Expand Down
24 changes: 18 additions & 6 deletions app/src/org/gnucash/android/db/TransactionsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Transaction;
Expand Down Expand Up @@ -186,14 +187,25 @@ public List<Transaction> getAllTransactionsForAccount(String accountUID){
while (c.moveToNext()) {
Transaction transaction = buildTransactionInstance(c);
String doubleEntryAccountUID = transaction.getDoubleEntryAccountUID();
// Negate double entry transactions for the transfer account

//one transaction in this case represents both sides of the split
if (doubleEntryAccountUID != null && doubleEntryAccountUID.equals(accountUID)){
if (transaction.getType() == TransactionType.DEBIT) {
transaction.setType(TransactionType.CREDIT);
} else {
transaction.setType(TransactionType.DEBIT);
}
transaction.setAmount(transaction.getAmount().negate());
/*
//use this to properly compute the account balance
if (GnuCashApplication.isDoubleEntryEnabled(false)) {
if (transaction.getType() == TransactionType.DEBIT) {
transaction.setType(TransactionType.CREDIT);
} else {
transaction.setType(TransactionType.DEBIT);
}
} else {
// Negate double entry transactions for the transfer account
transaction.setAmount(transaction.getAmount().negate());
}
*/
}

transactionsList.add(transaction);
}
c.close();
Expand Down
39 changes: 24 additions & 15 deletions app/src/org/gnucash/android/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,30 @@ public boolean hasUnexportedTransactions(){
public Money getBalance(){
Money balance = new Money(new BigDecimal(0), this.mCurrency);
for (Transaction transaction : mTransactionsList) {
boolean isDebitAccount = getAccountType().hasDebitNormalBalance();
boolean isDebitTransaction = transaction.getType() == TransactionType.DEBIT;
if (isDebitAccount) {
if (isDebitTransaction) {
balance = balance.add(transaction.getAmount());
} else {
balance = balance.subtract(transaction.getAmount());
}
} else {
if (isDebitTransaction) {
balance = balance.subtract(transaction.getAmount());
} else {
balance = balance.add(transaction.getAmount());
}
}
balance = balance.add(transaction.getAmount());

/*
//TODO: Re-enable proper computation of balance for double-entries in the future
if (GnuCashApplication.isDoubleEntryEnabled(false)) {
boolean isDebitAccount = getAccountType().hasDebitNormalBalance();
boolean isDebitTransaction = transaction.getType() == TransactionType.DEBIT;
if (isDebitAccount) {
if (isDebitTransaction) {
balance = balance.add(transaction.getAmount());
} else {
balance = balance.subtract(transaction.getAmount());
}
} else {
if (isDebitTransaction) {
balance = balance.subtract(transaction.getAmount());
} else {
balance = balance.add(transaction.getAmount());
}
}
} else { //not using double entry
balance = balance.add(transaction.getAmount());
}
*/
}
return balance;
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/org/gnucash/android/ui/account/AccountsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ private void init() {
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
if (firstRun){
createDefaultAccounts();
//default to using double entry and save the preference explicitly
prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).commit();
}

if (hasNewFeatures()){
Expand Down

0 comments on commit 4a9cdd4

Please sign in to comment.