X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=65dd11084fbf007bd2dea1ad15c182781f234ff4;hb=d8d945a86bdc934e98dda81ac566ef238b7821d2;hp=2de99c8f3b30f8880a250d0b628df52985004faa;hpb=2c14b80572cc9199f7ed0171786a04931075b50d;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 2de99c8f..65dd1108 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -83,10 +83,12 @@ public final class MobileLedgerProfile { futureDates = origin.futureDates; apiVersion = origin.apiVersion; defaultCommodity = origin.defaultCommodity; + firstTransactionDate = origin.firstTransactionDate; + lastTransactionDate = origin.lastTransactionDate; } // loads all profiles into Data.profiles // returns the profile with the given UUID - public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) { + public static MobileLedgerProfile loadAllFromDB(@Nullable String currentProfileUUID) { MobileLedgerProfile result = null; ArrayList list = new ArrayList<>(); SQLiteDatabase db = App.getDatabase(); @@ -269,15 +271,14 @@ public final class MobileLedgerProfile { public void storeAccount(SQLiteDatabase db, LedgerAccount acc) { // replace into is a bad idea because it would reset hidden to its default value // we like the default, but for new accounts only - db.execSQL("update accounts set level = ?, keep = 1, hidden=?, expanded=? " + + db.execSQL("update accounts set level = ?, keep = 1, expanded=? " + "where profile=? and name = ?", - new Object[]{acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded(), uuid, - acc.getName() + new Object[]{acc.getLevel(), acc.isExpanded(), uuid, acc.getName() }); - db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, hidden, " + - "expanded, keep) " + "select ?,?,?,?,?,?,?,1 where (select changes() = 0)", + db.execSQL("insert into accounts(profile, name, name_upper, parent_name, level, " + + "expanded, keep) " + "select ?,?,?,?,?,?,1 where (select changes() = 0)", new Object[]{uuid, acc.getName(), acc.getName().toUpperCase(), acc.getParentName(), - acc.getLevel(), acc.isHiddenByStar(), acc.isExpanded() + acc.getLevel(), acc.isExpanded() }); // debug("accounts", String.format("Stored account '%s' in DB [%s]", acc.getName(), uuid)); } @@ -293,13 +294,11 @@ public final class MobileLedgerProfile { db.execSQL("DELETE from transaction_accounts WHERE profile = ? and transaction_id=?", new Object[]{uuid, tr.getId()}); - db.execSQL( - "INSERT INTO transactions(profile, id, year, month, day, description, "+ - "comment, data_hash, keep) " + - "values(?,?,?,?,?,?,?,?,1)", + db.execSQL("INSERT INTO transactions(profile, id, year, month, day, description, " + + "comment, data_hash, keep) values(?,?,?,?,?,?,?,?,1)", new Object[]{uuid, tr.getId(), tr.getDate().year, tr.getDate().month, - tr.getDate().day, tr.getDescription(), - tr.getComment(), tr.getDataHash() + tr.getDate().day, tr.getDescription(), tr.getComment(), + tr.getDataHash() }); for (LedgerTransactionAccount item : tr.getAccounts()) { @@ -403,16 +402,16 @@ public final class MobileLedgerProfile { } @Nullable public LedgerAccount tryLoadAccount(SQLiteDatabase db, String accName) { - try (Cursor cursor = db.rawQuery( - "SELECT a.hidden, a.expanded, (select 1 from accounts a2 " + - "where a2.profile = a.profile and a2.name like a.name||':%' limit 1) " + - "FROM accounts a WHERE a.profile = ? and a.name=?", new String[]{uuid, accName})) + try (Cursor cursor = db.rawQuery("SELECT a.expanded, (select 1 from accounts a2 " + + "where a2.profile = a.profile and a2.name like a" + + ".name||':%' limit 1) " + + "FROM accounts a WHERE a.profile = ? and a.name=?", + new String[]{uuid, accName})) { if (cursor.moveToFirst()) { LedgerAccount acc = new LedgerAccount(accName); - acc.setHiddenByStar(cursor.getInt(0) == 1); - acc.setExpanded(cursor.getInt(1) == 1); - acc.setHasSubAccounts(cursor.getInt(2) == 1); + acc.setExpanded(cursor.getInt(0) == 1); + acc.setHasSubAccounts(cursor.getInt(1) == 1); try (Cursor c2 = db.rawQuery( "SELECT value, currency FROM account_values WHERE profile = ? " +