]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java
whitespace
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerTransactionAccount.java
index 2e5e9c4990163e81fe0e2719adb098e3df573725..f759114954532b50b32d5baddfa9a2cb058e9774 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -19,6 +19,13 @@ package net.ktnx.mobileledger.model;
 
 import androidx.annotation.NonNull;
 
+import net.ktnx.mobileledger.json.ParsedAmount;
+import net.ktnx.mobileledger.json.ParsedPosting;
+import net.ktnx.mobileledger.json.ParsedQuantity;
+import net.ktnx.mobileledger.json.ParsedStyle;
+
+import java.util.ArrayList;
+
 public class LedgerTransactionAccount {
     private String accountName;
     private String shortAccountName;
@@ -85,4 +92,25 @@ public class LedgerTransactionAccount {
 
         return sb.toString();
     }
+    public ParsedPosting asParsedPosting() {
+        ParsedPosting result = new ParsedPosting();
+        result.setPaccount(accountName);
+        ArrayList<ParsedAmount> amounts = new ArrayList<>();
+        ParsedAmount amt = new ParsedAmount();
+        amt.setAcommodity((currency == null) ? "" : currency);
+        amt.setAismultiplier(false);
+        ParsedQuantity qty = new ParsedQuantity();
+        qty.setDecimalPlaces(2);
+        qty.setDecimalMantissa(Math.round(amount * 100));
+        amt.setAquantity(qty);
+        ParsedStyle style = new ParsedStyle();
+        style.setAscommodityside('L');
+        style.setAscommodityspaced(false);
+        style.setAsprecision(2);
+        style.setAsdecimalpoint('.');
+        amt.setAstyle(style);
+        amounts.add(amt);
+        result.setPamount(amounts);
+        return result;
+    }
 }