From: Damyan Ivanov Date: Sun, 5 Jan 2020 21:08:24 +0000 (+0200) Subject: fu: DB support for comments X-Git-Tag: v0.12.0~103 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=86a3a3652dd2a8e6b2a403cbc816214348eaaea3;p=mobile-ledger.git fu: DB support for comments --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 807e4375..44e916c5 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -371,7 +371,7 @@ public class RetrieveTransactionsTask if (currency == null) currency = ""; amount = amount.replace(',', '.'); transaction.addAccount(new LedgerTransactionAccount(acc_name, - Float.valueOf(amount), currency)); + Float.valueOf(amount), currency, null)); L(String.format(Locale.ENGLISH, "%d: %s = %s", transaction.getId(), acc_name, amount)); } diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java index f1a6e1ff..a3667a23 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_14/ParsedPosting.java @@ -135,7 +135,8 @@ public class ParsedPosting { public LedgerTransactionAccount asLedgerAccount() { ParsedAmount amt = pamount.get(0); return new LedgerTransactionAccount(paccount, amt.getAquantity() - .asFloat(), amt.getAcommodity()); + .asFloat(), amt.getAcommodity(), + getPcomment()); } } diff --git a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java index 0789f0d9..a0607512 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/v1_15/ParsedPosting.java @@ -31,26 +31,53 @@ public class ParsedPosting { private String paccount; private List pamount; private String pdate = null; - public String getPdate2() { - return pdate2; - } - public void setPdate2(String pdate2) { - this.pdate2 = pdate2; - } private String pdate2 = null; private String ptype = "RegularPosting"; private String pcomment = ""; private List> ptags = new ArrayList<>(); private String poriginal = null; private int ptransaction_; + public ParsedPosting() { + } + public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) { + ParsedPosting result = new ParsedPosting(); + result.setPaccount(acc.getAccountName()); + + String comment = acc.getComment(); + if (comment == null) + comment = ""; + result.setPcomment(comment); + + ArrayList amounts = new ArrayList<>(); + ParsedAmount amt = new ParsedAmount(); + amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency()); + amt.setAismultiplier(false); + ParsedQuantity qty = new ParsedQuantity(); + qty.setDecimalPlaces(2); + qty.setDecimalMantissa(Math.round(acc.getAmount() * 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; + } + public String getPdate2() { + return pdate2; + } + public void setPdate2(String pdate2) { + this.pdate2 = pdate2; + } public int getPtransaction_() { return ptransaction_; } public void setPtransaction_(int ptransaction_) { this.ptransaction_ = ptransaction_; } - public ParsedPosting() { - } public String getPdate() { return pdate; } @@ -107,35 +134,9 @@ public class ParsedPosting { } public LedgerTransactionAccount asLedgerAccount() { ParsedAmount amt = pamount.get(0); - return new LedgerTransactionAccount(paccount, amt.getAquantity().asFloat(), - amt.getAcommodity()); - } - public static ParsedPosting fromLedgerAccount(LedgerTransactionAccount acc) { - ParsedPosting result = new ParsedPosting(); - result.setPaccount(acc.getAccountName()); - - String comment = acc.getComment(); - if (comment == null) - comment = ""; - result.setPcomment(comment); - - ArrayList amounts = new ArrayList<>(); - ParsedAmount amt = new ParsedAmount(); - amt.setAcommodity((acc.getCurrency() == null) ? "" : acc.getCurrency()); - amt.setAismultiplier(false); - ParsedQuantity qty = new ParsedQuantity(); - qty.setDecimalPlaces(2); - qty.setDecimalMantissa(Math.round(acc.getAmount() * 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; + return new LedgerTransactionAccount(paccount, amt.getAquantity() + .asFloat(), amt.getAcommodity(), + getPcomment()); } }