2 * Copyright © 2020 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.json.v1_14;
20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
22 import net.ktnx.mobileledger.model.LedgerTransaction;
23 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
24 import net.ktnx.mobileledger.utils.Globals;
25 import net.ktnx.mobileledger.utils.Misc;
26 import net.ktnx.mobileledger.utils.SimpleDate;
28 import java.text.ParseException;
29 import java.util.ArrayList;
30 import java.util.List;
32 @JsonIgnoreProperties(ignoreUnknown = true)
33 public class ParsedLedgerTransaction implements net.ktnx.mobileledger.json.ParsedLedgerTransaction {
35 private String tdate2 = null;
36 private String tdescription;
37 private String tcomment;
38 private String tcode = "";
39 private String tstatus = "Unmarked";
40 private String tprecedingcomment = "";
42 private List<ParsedPosting> tpostings;
43 private List<List<String>> ttags = new ArrayList<>();
44 private ParsedSourcePos
45 tsourcepos = new ParsedSourcePos();
46 public ParsedLedgerTransaction() {
48 public static ParsedLedgerTransaction fromLedgerTransaction(LedgerTransaction tr) {
49 ParsedLedgerTransaction
50 result = new ParsedLedgerTransaction();
51 result.setTcomment(tr.getComment());
52 result.setTprecedingcomment("");
54 ArrayList<ParsedPosting> postings = new ArrayList<>();
55 for (LedgerTransactionAccount acc : tr.getAccounts()) {
56 if (!acc.getAccountName()
58 postings.add(ParsedPosting.fromLedgerAccount(acc));
61 result.setTpostings(postings);
62 SimpleDate transactionDate = tr.getDateIfAny();
63 if (transactionDate == null) {
64 transactionDate = SimpleDate.today();
66 result.setTdate(Globals.formatIsoDate(transactionDate));
67 result.setTdate2(null);
69 result.setTdescription(tr.getDescription());
72 public String getTcode() {
75 public void setTcode(String tcode) {
78 public String getTstatus() {
81 public void setTstatus(String tstatus) {
82 this.tstatus = tstatus;
84 public List<List<String>> getTtags() {
87 public void setTtags(List<List<String>> ttags) {
90 public ParsedSourcePos getTsourcepos() {
93 public void setTsourcepos(ParsedSourcePos tsourcepos) {
94 this.tsourcepos = tsourcepos;
96 public String getTprecedingcomment() {
97 return tprecedingcomment;
99 public void setTprecedingcomment(String tprecedingcomment) {
100 this.tprecedingcomment = tprecedingcomment;
102 public String getTdate() {
105 public void setTdate(String tdate) {
108 public String getTdate2() {
111 public void setTdate2(String tdate2) {
112 this.tdate2 = tdate2;
114 public String getTdescription() {
117 public void setTdescription(String tdescription) {
118 this.tdescription = tdescription;
120 public String getTcomment() {
123 public void setTcomment(String tcomment) {
124 this.tcomment = tcomment;
126 public int getTindex() {
129 public void setTindex(int tindex) {
130 this.tindex = tindex;
131 if (tpostings != null)
132 for (ParsedPosting p : tpostings) {
133 p.setPtransaction_(tindex);
136 public List<ParsedPosting> getTpostings() {
139 public void setTpostings(List<ParsedPosting> tpostings) {
140 this.tpostings = tpostings;
142 public void addPosting(ParsedPosting posting) {
143 posting.setPtransaction_(tindex);
144 tpostings.add(posting);
146 public LedgerTransaction asLedgerTransaction() throws ParseException {
147 SimpleDate date = Globals.parseIsoDate(tdate);
148 LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
149 tr.setComment(Misc.trim(Misc.emptyIsNull(tcomment)));
151 List<ParsedPosting> postings = tpostings;
153 if (postings != null) {
154 for (ParsedPosting p : postings) {
155 tr.addAccount(p.asLedgerAccount());