Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#876 Major contribution to gnucash-android #882

Open
wants to merge 77 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
301b3c6
Fixes #876 - Take into account only splitTypeSwitch to compute Split …
JeanGarf Feb 29, 2020
fdea65b
#110 - Formatting and Comments
JeanGarf Mar 2, 2020
931bde4
#876 - French Translation
JeanGarf Mar 2, 2020
5367a26
#876 - Correct errors in debit/credit labels vs GnuCash Windows. isCh…
JeanGarf Mar 2, 2020
b2ea8a0
#876 - Computing Balance : Debit => +, Credit => -
JeanGarf Mar 2, 2020
6615458
#876 - hasDebitNormalBalance should not invert amount signum
JeanGarf Mar 2, 2020
4c84125
#876 - Create AccountUtils
JeanGarf Mar 3, 2020
9e1951f
#876 - Enhance Code Quality
JeanGarf Mar 3, 2020
c329455
#876 - Set red/green color according to decrease/increase balance (an…
JeanGarf Mar 3, 2020
02e6a02
#876 - Move attributes from ColorizeOnTransactionTypeChangeListener t…
JeanGarf Mar 3, 2020
e7f8d6f
#876 - Create setViewsToColorize(...) to initialize views to colorize…
JeanGarf Mar 3, 2020
f507e59
#876 - Use setViewsToColorize(...) to initialize views to colorize in…
JeanGarf Mar 3, 2020
6ed4930
#876 - In transaction form, put the split button to the right, like f…
JeanGarf Mar 3, 2020
b44c207
#876 - Renamings and TODO
JeanGarf Mar 3, 2020
b7c042f
#876 - Add AccountType parameter in displayBalance(...)
JeanGarf Mar 6, 2020
e178e3a
#876 - use displayBalance(...) with AccountType
JeanGarf Mar 6, 2020
2f82436
#876 - Correct balance amount computation and factorize into getAmoun…
JeanGarf Mar 6, 2020
52f59ef
#876 - Explain that balance in DetailTransactionActivity is computed …
JeanGarf Mar 6, 2020
b31daad
#876 - Enhance Code Quality
JeanGarf Mar 6, 2020
bf49482
#876 - Replace mAssetAccountTypes with ASSET_ACCOUNT_TYPES from Accou…
JeanGarf Mar 7, 2020
8e04ba5
#876 - Code quality
JeanGarf Mar 7, 2020
535e3d5
#876 - Transfer displayBalance(...) into AccountType and make methods…
JeanGarf Mar 7, 2020
8844002
#876 - Use AccountType.displayBalance(...)
JeanGarf Mar 7, 2020
cd0916b
#876 - Enhance Code Quality
JeanGarf Mar 7, 2020
e9ab836
#876 - Rename mValue to mAmountAbsValue and use setter to ensure stor…
JeanGarf Mar 7, 2020
23790c8
#876 - Add shallDisplayAbsValue parameter in displayBalance(...)
JeanGarf Mar 7, 2020
c0bf48d
#876 - TransactionTypeSwitch does not change amount signum anymore
JeanGarf Mar 7, 2020
6821ba7
#876 - Display amount absolute value when TransactionTypeSwitch is vi…
JeanGarf Mar 7, 2020
bc27e47
#876 - Add preference key_display_negative_signum_in_splits
JeanGarf Mar 7, 2020
362377c
#876 - Use preference key_display_negative_signum_in_splits
JeanGarf Mar 7, 2020
6db2f62
#876 - Restore General Preferences after Test
JeanGarf Mar 8, 2020
b1c83ce
#876 - Use a Switch for Debit/Credit Preference instead of a ListPref…
JeanGarf Mar 8, 2020
6754ced
#876 - Create AccountTypeUtils
JeanGarf Mar 8, 2020
26b9b97
#876 - Use AccountTypeUtils
JeanGarf Mar 8, 2020
143dbe0
#876 - Trying to display customized debit/credit labels in Transactio…
JeanGarf Mar 8, 2020
a21d2e2
#876 - Enhance Code Quality
JeanGarf Mar 8, 2020
393cc69
#876 - Correct Transaction Detail Balance translation
JeanGarf Mar 8, 2020
05c7c70
#876 - Add a separator before Balance in Transaction Detail
JeanGarf Mar 8, 2020
aad6e6a
#876 - Fix error on title_default_transaction_type in fragment_transa…
JeanGarf Mar 8, 2020
b449bcf
#876 - Correct ASSET toggle switch button labels
JeanGarf Mar 11, 2020
b9d5aee
#876 - Compute DefaultTransactionType for new Transactions, according…
JeanGarf Mar 11, 2020
0ef72cf
#876 - Preference for new Default Transaction Type computing mode
JeanGarf Mar 11, 2020
d396cd4
#876 - Enhance Code Quality
JeanGarf Mar 11, 2020
6ec5b17
#876 - Use different colors for balance, according to Account Type : …
JeanGarf Apr 5, 2020
391d0b5
#876 - Balance colors more close
JeanGarf Apr 5, 2020
de30be2
#876 - Add AccountType.getBalanceWithSignumForDisplay()
JeanGarf Apr 5, 2020
04f958f
#876 - Add colors for Equity
JeanGarf Apr 7, 2020
183696f
#876 - Invert Memo and Account Spinner
JeanGarf May 23, 2020
5bcf4d6
#876 - Update Transaction and Split Amount when changing TransactionT…
JeanGarf May 23, 2020
529860e
#876 - Cleaning code
JeanGarf May 23, 2020
000a42e
#876 - Factorize calls to AccountType.displayBalance() + add shallDis…
JeanGarf May 23, 2020
c1a40f3
#876 - Create AccountType.displayBalanceWithoutCurrency()
JeanGarf May 23, 2020
07497fe
#876 - Use AccountType.displayBalanceWithoutCurrency() for Splits and…
JeanGarf May 23, 2020
15bcce9
#876 - Add param to TransactionFormFragment.updateAmountEditText(fina…
JeanGarf May 23, 2020
0509066
#876 - Remove shallDisplayNegativeSignumInSplits parameter from Accou…
JeanGarf May 24, 2020
07cf91e
#876 - For Transaction Details, use unsigned balanced in debit/credit…
JeanGarf May 24, 2020
b59e69b
#876 - In Splits Editor, display imbalance as if account is an asset
JeanGarf May 24, 2020
eb0f00d
#876 - Fix NPE when type switching on a new transaction
JeanGarf May 28, 2020
7fc3485
#876 - Set amount to 0 if text field is empty
JeanGarf Jun 10, 2020
a1626c1
#876 - Rename mTransactionsAdapter into mTransactionsDbAdapter
JeanGarf Jun 13, 2020
5db92fb
#876 - Invert finish() and BookUtils.loadBook
JeanGarf Jun 13, 2020
453252e
#876 - Logs and comments
JeanGarf Jun 13, 2020
3e333ec
#876 - ** Allow null to enter SplitEditor + Transfert if from Transac…
JeanGarf Jun 14, 2020
03225b1
#876 - * Check split not null in Listener onCheckedChanged
JeanGarf Jun 14, 2020
8f1767e
#876 - ** Add shallDisplayZero in displayBalance(...) to avoid displa…
JeanGarf Jun 14, 2020
978a5eb
#876 - ** Add shallDisplayZero in displayBalanceWithoutCurrency(...) …
JeanGarf Jun 14, 2020
b8d58a7
#876 - Renaming toggleAmountInputEntryMode() to setAllowAmountEdit
JeanGarf Jun 14, 2020
d92391b
#876 - Remove black color for 0 balance, to be homogeneous with Trans…
JeanGarf Jun 14, 2020
1f41df3
#876 - Use updateAmountEditText(...) to factorize code
JeanGarf Jun 14, 2020
511f889
#876 - Code formatting
JeanGarf Jun 14, 2020
849bc2a
#876 - ** Must be on the Account Page to change Book
JeanGarf Jun 15, 2020
5d36c85
#876 - Code formatting
JeanGarf Jun 15, 2020
1e2d83a
#876 - Remove #586
JeanGarf Jun 15, 2020
1ee83dd
#876 - Toast message internationalization
JeanGarf Jun 16, 2020
56bb0a0
Remove TODO
JeanGarf Jun 16, 2020
13b3baf
#876 - Add another test to reduce probability of not being able to ch…
JeanGarf Jun 16, 2020
8cca2e3
#876 - ** when editing transaction, display 2 decimals but not curren…
JeanGarf Jun 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class AccountsDbAdapter extends DatabaseAdapter<Account> {
/**
* Transactions database adapter for manipulating transactions associated with accounts
*/
private final TransactionsDbAdapter mTransactionsAdapter;
private final TransactionsDbAdapter mTransactionsDbAdapter;

/**
* Commodities database adapter for commodity manipulation
Expand All @@ -101,7 +101,7 @@ public AccountsDbAdapter(SQLiteDatabase db, TransactionsDbAdapter transactionsDb
AccountEntry.COLUMN_PARENT_ACCOUNT_UID,
AccountEntry.COLUMN_DEFAULT_TRANSFER_ACCOUNT_UID
});
mTransactionsAdapter = transactionsDbAdapter;
mTransactionsDbAdapter = transactionsDbAdapter;
mCommoditiesDbAdapter = new CommoditiesDbAdapter(db);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public AccountsDbAdapter(SQLiteDatabase db){
AccountEntry.COLUMN_DEFAULT_TRANSFER_ACCOUNT_UID
});

mTransactionsAdapter = new TransactionsDbAdapter(db, new SplitsDbAdapter(db));
mTransactionsDbAdapter = new TransactionsDbAdapter(db, new SplitsDbAdapter(db));
mCommoditiesDbAdapter = new CommoditiesDbAdapter(db);
}

Expand All @@ -150,7 +150,7 @@ public static AccountsDbAdapter getInstance(){
public void addRecord(@NonNull Account account, UpdateMethod updateMethod){
Log.d(LOG_TAG, "Replace account to db");
//in-case the account already existed, we want to update the templates based on it as well
List<Transaction> templateTransactions = mTransactionsAdapter.getScheduledTransactionsForAccount(account.getUID());
List<Transaction> templateTransactions = mTransactionsDbAdapter.getScheduledTransactionsForAccount(account.getUID());
super.addRecord(account, updateMethod);
String accountUID = account.getUID();
//now add transactions if there are any
Expand All @@ -159,10 +159,10 @@ public void addRecord(@NonNull Account account, UpdateMethod updateMethod){
updateRecord(accountUID, AccountEntry.COLUMN_FULL_NAME, getFullyQualifiedAccountName(accountUID));
for (Transaction t : account.getTransactions()) {
t.setCommodity(account.getCommodity());
mTransactionsAdapter.addRecord(t, updateMethod);
mTransactionsDbAdapter.addRecord(t, updateMethod);
}
for (Transaction transaction : templateTransactions) {
mTransactionsAdapter.addRecord(transaction, UpdateMethod.update);
mTransactionsDbAdapter.addRecord(transaction, UpdateMethod.update);
}
}
}
Expand All @@ -187,12 +187,12 @@ public long bulkAddRecords(@NonNull List<Account> accountList, UpdateMethod upda
List<Transaction> transactionList = new ArrayList<>(accountList.size()*2);
for (Account account : accountList) {
transactionList.addAll(account.getTransactions());
transactionList.addAll(mTransactionsAdapter.getScheduledTransactionsForAccount(account.getUID()));
transactionList.addAll(mTransactionsDbAdapter.getScheduledTransactionsForAccount(account.getUID()));
}
long nRow = super.bulkAddRecords(accountList, updateMethod);

if (nRow > 0 && !transactionList.isEmpty()){
mTransactionsAdapter.bulkAddRecords(transactionList, updateMethod);
mTransactionsDbAdapter.bulkAddRecords(transactionList, updateMethod);
}
return nRow;
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public boolean recursiveDeleteAccount(long accountId){
try {
descendantAccountUIDs.add(accountUID); //add account to descendants list just for convenience
for (String descendantAccountUID : descendantAccountUIDs) {
mTransactionsAdapter.deleteTransactionsForAccount(descendantAccountUID);
mTransactionsDbAdapter.deleteTransactionsForAccount(descendantAccountUID);
}

String accountUIDList = "'" + TextUtils.join("','", descendantAccountUIDs) + "'";
Expand Down Expand Up @@ -413,7 +413,7 @@ public boolean recursiveDeleteAccount(long accountId){
@Override
public Account buildModelInstance(@NonNull final Cursor c){
Account account = buildSimpleAccountInstance(c);
account.setTransactions(mTransactionsAdapter.getAllTransactionsForAccount(account.getUID()));
account.setTransactions(mTransactionsDbAdapter.getAllTransactionsForAccount(account.getUID()));

return account;
}
Expand Down 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 Expand Up @@ -801,7 +801,7 @@ public Money getAccountBalance(AccountType accountType, long startTimestamp, lon
String currencyCode = GnuCashApplication.getDefaultCurrencyCode();

Log.d(LOG_TAG, "all account list : " + accountUidList.size());
SplitsDbAdapter splitsDbAdapter = mTransactionsAdapter.getSplitDbAdapter();
SplitsDbAdapter splitsDbAdapter = mTransactionsDbAdapter.getSplitDbAdapter();

return (startTimestamp == -1 && endTimestamp == -1)
? splitsDbAdapter.computeSplitBalance(accountUidList, currencyCode, hasDebitNormalBalance)
Expand All @@ -825,7 +825,7 @@ public Money getAccountBalance(List<AccountType> accountTypes, long start, long

private Money computeBalance(String accountUID, long startTimestamp, long endTimestamp) {
Log.d(LOG_TAG, "Computing account balance for account ID " + accountUID);
String currencyCode = mTransactionsAdapter.getAccountCurrencyCode(accountUID);
String currencyCode = mTransactionsDbAdapter.getAccountCurrencyCode(accountUID);
boolean hasDebitNormalBalance = getAccountType(accountUID).hasDebitNormalBalance();

List<String> accountsList = getDescendantAccountUIDs(accountUID,
Expand All @@ -834,7 +834,7 @@ private Money computeBalance(String accountUID, long startTimestamp, long endTim
accountsList.add(0, accountUID);

Log.d(LOG_TAG, "all account list : " + accountsList.size());
SplitsDbAdapter splitsDbAdapter = mTransactionsAdapter.getSplitDbAdapter();
SplitsDbAdapter splitsDbAdapter = mTransactionsDbAdapter.getSplitDbAdapter();
return (startTimestamp == -1 && endTimestamp == -1)
? splitsDbAdapter.computeSplitBalance(accountsList, currencyCode, hasDebitNormalBalance)
: splitsDbAdapter.computeSplitBalance(accountsList, currencyCode, hasDebitNormalBalance, startTimestamp, endTimestamp);
Expand All @@ -858,7 +858,7 @@ public Money getAccountsBalance(@NonNull List<String> accountUIDList, long star

boolean hasDebitNormalBalance = getAccountType(accountUIDList.get(0)).hasDebitNormalBalance();

SplitsDbAdapter splitsDbAdapter = mTransactionsAdapter.getSplitDbAdapter();
SplitsDbAdapter splitsDbAdapter = mTransactionsDbAdapter.getSplitDbAdapter();
Money splitSum = (startTimestamp == -1 && endTimestamp == -1)
? splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance)
: splitsDbAdapter.computeSplitBalance(accountUIDList, currencyCode, hasDebitNormalBalance, startTimestamp, endTimestamp);
Expand Down Expand Up @@ -1145,7 +1145,7 @@ public List<Transaction> getAllOpeningBalanceTransactions(){
Cursor cursor = fetchAccounts(null, null, null);
List<Transaction> openingTransactions = new ArrayList<>();
try {
SplitsDbAdapter splitsDbAdapter = mTransactionsAdapter.getSplitDbAdapter();
SplitsDbAdapter splitsDbAdapter = mTransactionsDbAdapter.getSplitDbAdapter();
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(AccountEntry._ID));
String accountUID = getUID(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,17 +531,26 @@ public int deleteAllRecords(){
* @throws IllegalArgumentException if the GUID does not exist in the database
*/
public long getID(@NonNull String uid){

Cursor cursor = mDb.query(mTableName,
new String[] {DatabaseSchema.CommonColumns._ID},
DatabaseSchema.CommonColumns.COLUMN_UID + " = ?",
new String[]{uid},
null, null, null);
new String[]{DatabaseSchema.CommonColumns._ID},
DatabaseSchema.CommonColumns.COLUMN_UID + " = ?",
new String[]{uid},
null, null, null);

long result = -1;

try{
if (cursor.moveToFirst()) {
result = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseSchema.CommonColumns._ID));
} else {
throw new IllegalArgumentException(mTableName + " with GUID " + uid + " does not exist in the db");
throw new IllegalArgumentException("UID ("
+ uid
+ ") does not exist in Table ("
+ mTableName
+ ") of db ("
+ mDb.getPath()
+ ")");
}
} finally {
cursor.close();
Expand Down
Loading