]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
treat null currency as "" when storing transaction accounts
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / MobileLedgerProfile.java
index 7dc4bbfcecc79fabf6e86a6883f9e1041993e442..7cadf8eb06f2d6154203fcafe0a06c36559e5d41 100644 (file)
@@ -32,6 +32,7 @@ import net.ktnx.mobileledger.async.SendTransactionTask;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
+import net.ktnx.mobileledger.utils.Misc;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -243,7 +244,7 @@ public final class MobileLedgerProfile {
     public void storeAccountValue(SQLiteDatabase db, String name, String currency, Float amount) {
         db.execSQL("replace into account_values(profile, account, " +
                    "currency, value, keep) values(?, ?, ?, ?, 1);",
-                new Object[]{uuid, name, currency, amount});
+                new Object[]{uuid, name, Misc.emptyIsNull(currency), amount});
     }
     public void storeTransaction(SQLiteDatabase db, LedgerTransaction tr) {
         tr.fillDataHash();
@@ -262,7 +263,7 @@ public final class MobileLedgerProfile {
             db.execSQL("INSERT INTO transaction_accounts(profile, transaction_id, " +
                        "account_name, amount, currency, comment) values(?, ?, ?, ?, ?, ?)",
                     new Object[]{uuid, tr.getId(), item.getAccountName(), item.getAmount(),
-                                 item.getCurrency(), item.getComment()
+                                 Misc.nullIsEmpty(item.getCurrency()), item.getComment()
                     });
         }
 //        debug("profile", String.format("Transaction %d stored", tr.getId()));
@@ -488,6 +489,23 @@ public final class MobileLedgerProfile {
             db.endTransaction();
         }
     }
+    public List<Currency> getCurrencies() {
+        SQLiteDatabase db = App.getDatabase();
+
+        ArrayList<Currency> result = new ArrayList<>();
+
+        try (Cursor c = db.rawQuery("SELECT c.id, c.name, c.position, c.has_gap FROM currencies c",
+                new String[]{}))
+        {
+            while (c.moveToNext()) {
+                Currency currency = new Currency(c.getInt(0), c.getString(1),
+                        Currency.Position.valueOf(c.getInt(2)), c.getInt(3) == 1);
+                result.add(currency);
+            }
+        }
+
+        return result;
+    }
     public enum FutureDates {
         None(0), OneWeek(7), TwoWeeks(14), OneMonth(30), TwoMonths(60), ThreeMonths(90),
         SixMonths(180), OneYear(365), All(-1);