X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdao%2FTransactionDAO.java;h=9d7fdeae4813171c7a697065c59ce2016435f843;hb=64413271ef4ed943ae29e9cf9115c1bb77053278;hp=8e0156b77cf1993e29abbedabe2c9f79e14a1c94;hpb=916547239190f7daf921f2066593637cfca877fc;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java b/app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java index 8e0156b7..9d7fdeae 100644 --- a/app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java +++ b/app/src/main/java/net/ktnx/mobileledger/dao/TransactionDAO.java @@ -79,12 +79,11 @@ public abstract class TransactionDAO extends BaseDAO { @Query("SELECT * FROM transactions WHERE id = :transactionId") public abstract TransactionWithAccounts getByIdWithAccountsSync(long transactionId); - @Query("SELECT DISTINCT description, CASE WHEN description_upper LIKE :term||'%%' THEN 1 " + - " WHEN description_upper LIKE '%%:'||:term||'%%' THEN 2 " + - " WHEN description_upper LIKE '%% '||:term||'%%' THEN 3 " + - " ELSE 9 END AS ordering " + "FROM description_history " + - "WHERE description_upper LIKE '%%'||:term||'%%' " + - "ORDER BY ordering, description_upper, rowid ") + @Query("SELECT DISTINCT description, CASE WHEN description LIKE :term||'%%' THEN 1 " + + " WHEN description LIKE '%%:'||:term||'%%' THEN 2 " + + " WHEN description LIKE '%% '||:term||'%%' THEN 3 " + + " ELSE 9 END AS ordering FROM transactions " + + "WHERE description LIKE '%%'||:term||'%%' " + "ORDER BY ordering, description, rowid ") public abstract List lookupDescriptionSync(@NonNull String term); @androidx.room.Transaction @@ -109,12 +108,7 @@ public abstract class TransactionDAO extends BaseDAO { @androidx.room.Transaction @Query("SELECT * FROM transactions WHERE profile_id = :profileId ORDER BY year " + - " desc, month desc, day desc, ledger_id desc") - public abstract List getAllWithAccountsSync(long profileId); - - @androidx.room.Transaction - @Query("SELECT * FROM transactions WHERE profile_id = :profileId ORDER BY year " + - " desc, month desc, day desc, ledger_id desc") + " asc, month asc, day asc, ledger_id asc") public abstract LiveData> getAllWithAccounts(long profileId); @androidx.room.Transaction @@ -122,16 +116,7 @@ public abstract class TransactionDAO extends BaseDAO { " tr.day, tr.description, tr.comment, tr.generation FROM transactions tr JOIN " + "transaction_accounts ta ON ta.transaction_id=tr.id WHERE ta.account_name LIKE " + ":accountName||'%' AND ta.amount <> 0 AND tr.profile_id = :profileId ORDER BY tr.year " + - "desc, tr.month desc, tr.day desc, tr.ledger_id desc") - public abstract List getAllWithAccountsFilteredSync(long profileId, - String accountName); - - @androidx.room.Transaction - @Query("SELECT distinct(tr.id), tr.ledger_id, tr.profile_id, tr.data_hash, tr.year, tr.month," + - " tr.day, tr.description, tr.comment, tr.generation FROM transactions tr JOIN " + - "transaction_accounts ta ON ta.transaction_id=tr.id WHERE ta.account_name LIKE " + - ":accountName||'%' AND ta.amount <> 0 AND tr.profile_id = :profileId ORDER BY tr.year " + - "desc, tr.month desc, tr.day desc, tr.ledger_id desc") + "asc, tr.month asc, tr.day asc, tr.ledger_id asc") public abstract LiveData> getAllWithAccountsFiltered( long profileId, String accountName); @@ -254,32 +239,36 @@ public abstract class TransactionDAO extends BaseDAO { trAcc.setGeneration(transaction.getGeneration()); trAcc.setId(trAccDao.insertSync(trAcc)); - Account acc = accDao.getByNameSync(profileId, trAcc.getAccountName()); - if (acc == null) { - acc = new Account(); - acc.setProfileId(profileId); - acc.setName(trAcc.getAccountName()); - acc.setNameUpper(acc.getName() - .toUpperCase()); - acc.setParentName(LedgerAccount.extractParentName(acc.getName())); - acc.setLevel(LedgerAccount.determineLevel(acc.getName())); - acc.setGeneration(trAcc.getGeneration()); - - acc.setId(accDao.insertSync(acc)); - } - - AccountValue accVal = accValDao.getByCurrencySync(acc.getId(), trAcc.getCurrency()); - if (accVal == null) { - accVal = new AccountValue(); - accVal.setAccountId(acc.getId()); - accVal.setGeneration(trAcc.getGeneration()); - accVal.setCurrency(trAcc.getCurrency()); - accVal.setValue(trAcc.getAmount()); - accVal.setId(accValDao.insertSync(accVal)); - } - else { - accVal.setValue(accVal.getValue() + trAcc.getAmount()); - accValDao.updateSync(accVal); + String accName = trAcc.getAccountName(); + while (accName != null) { + Account acc = accDao.getByNameSync(profileId, accName); + if (acc == null) { + acc = new Account(); + acc.setProfileId(profileId); + acc.setName(accName); + acc.setNameUpper(accName.toUpperCase()); + acc.setParentName(LedgerAccount.extractParentName(accName)); + acc.setLevel(LedgerAccount.determineLevel(acc.getName())); + acc.setGeneration(trAcc.getGeneration()); + + acc.setId(accDao.insertSync(acc)); + } + + AccountValue accVal = accValDao.getByCurrencySync(acc.getId(), trAcc.getCurrency()); + if (accVal == null) { + accVal = new AccountValue(); + accVal.setAccountId(acc.getId()); + accVal.setGeneration(trAcc.getGeneration()); + accVal.setCurrency(trAcc.getCurrency()); + accVal.setValue(trAcc.getAmount()); + accVal.setId(accValDao.insertSync(accVal)); + } + else { + accVal.setValue(accVal.getValue() + trAcc.getAmount()); + accValDao.updateSync(accVal); + } + + accName = LedgerAccount.extractParentName(accName); } } }