]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/json/ParsedLedgerTransaction.java
methods for converting of run-time data structures to json-serializable ones
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / json / ParsedLedgerTransaction.java
1 /*
2  * Copyright © 2019 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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.ktnx.mobileledger.json;
19
20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
21
22 import net.ktnx.mobileledger.model.LedgerTransaction;
23 import net.ktnx.mobileledger.utils.Globals;
24
25 import java.text.ParseException;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.List;
29
30 @JsonIgnoreProperties(ignoreUnknown = true)
31 public class ParsedLedgerTransaction {
32     private String tdate;
33     private String tdate2;
34     private String tdescription;
35     private String tcomment;
36     private String tcode = "";
37     private String tstatus = "Unmarked";
38     private String tprecedingcomment;
39     private int tindex;
40     private List<ParsedPosting> tpostings;
41     private List<String> ttags = new ArrayList<>();
42     private ParsedSourcePos tsourcepos = new ParsedSourcePos();
43     public ParsedLedgerTransaction() {
44     }
45     public String getTcode() {
46         return tcode;
47     }
48     public void setTcode(String tcode) {
49         this.tcode = tcode;
50     }
51     public String getTstatus() {
52         return tstatus;
53     }
54     public void setTstatus(String tstatus) {
55         this.tstatus = tstatus;
56     }
57     public List<String> getTtags() {
58         return ttags;
59     }
60     public void setTtags(List<String> ttags) {
61         this.ttags = ttags;
62     }
63     public ParsedSourcePos getTsourcepos() {
64         return tsourcepos;
65     }
66     public void setTsourcepos(ParsedSourcePos tsourcepos) {
67         this.tsourcepos = tsourcepos;
68     }
69     public String getTprecedingcomment() {
70         return tprecedingcomment;
71     }
72     public void setTprecedingcomment(String tprecedingcomment) {
73         this.tprecedingcomment = tprecedingcomment;
74     }
75     public String getTdate() {
76         return tdate;
77     }
78     public void setTdate(String tdate) {
79         this.tdate = tdate;
80     }
81     public String getTdate2() {
82         return tdate2;
83     }
84     public void setTdate2(String tdate2) {
85         this.tdate2 = tdate2;
86     }
87     public String getTdescription() {
88         return tdescription;
89     }
90     public void setTdescription(String tdescription) {
91         this.tdescription = tdescription;
92     }
93     public String getTcomment() {
94         return tcomment;
95     }
96     public void setTcomment(String tcomment) {
97         this.tcomment = tcomment;
98     }
99     public int getTindex() {
100         return tindex;
101     }
102     public void setTindex(int tindex) {
103         this.tindex = tindex;
104     }
105     public List<ParsedPosting> getTpostings() {
106         return tpostings;
107     }
108     public void setTpostings(List<ParsedPosting> tpostings) {
109         this.tpostings = tpostings;
110     }
111     public LedgerTransaction asLedgerTransaction() throws ParseException {
112         Date date = Globals.parseIsoDate(tdate);
113         LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
114
115         List<ParsedPosting> postings = tpostings;
116
117         if (postings != null) {
118             for (ParsedPosting p : postings) {
119                 tr.addAccount(p.asLedgerAccount());
120             }
121         }
122         return tr;
123     }
124 }