]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java
methods for converting of run-time data structures to json-serializable ones
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerTransaction.java
index fd2a8407dfca79910216bc3191ed692d3661f956..689d619a694d2d15ae0d5ea6a110aa1e8fcf3b30 100644 (file)
@@ -21,6 +21,8 @@ import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.util.Log;
 
+import net.ktnx.mobileledger.json.ParsedLedgerTransaction;
+import net.ktnx.mobileledger.json.ParsedPosting;
 import net.ktnx.mobileledger.utils.Digest;
 import net.ktnx.mobileledger.utils.Globals;
 
@@ -186,4 +188,21 @@ public class LedgerTransaction {
     public void finishLoading() {
         dataLoaded = true;
     }
+    public ParsedLedgerTransaction toParsedLedgerTransaction() {
+        ParsedLedgerTransaction result = new ParsedLedgerTransaction();
+        result.setTcomment("");
+        result.setTprecedingcomment("");
+
+        ArrayList<ParsedPosting> postings = new ArrayList<>();
+        for (LedgerTransactionAccount acc : accounts) {
+            if (!acc.getAccountName().isEmpty()) postings.add(acc.asParsedPosting());
+        }
+
+        result.setTpostings(postings);
+        result.setTdate(Globals.formatIsoDate(date));
+        result.setTdate2(null);
+        result.setTindex(1);
+        result.setTdescription(description);
+        return result;
+    }
 }