]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/json/ParsedLedgerTransaction.java
62cf1d0a83fa0b662cb14f774461e413b4d6fe9b
[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.Date;
27 import java.util.List;
28
29 @JsonIgnoreProperties(ignoreUnknown = true)
30 public class ParsedLedgerTransaction {
31     private String tdate, tdate2, tdescription, tcomment;
32     private int tindex;
33     private List<ParsedPosting> tpostings;
34     public ParsedLedgerTransaction() {
35     }
36     public String getTdate() {
37         return tdate;
38     }
39     public void setTdate(String tdate) {
40         this.tdate = tdate;
41     }
42     public String getTdate2() {
43         return tdate2;
44     }
45     public void setTdate2(String tdate2) {
46         this.tdate2 = tdate2;
47     }
48     public String getTdescription() {
49         return tdescription;
50     }
51     public void setTdescription(String tdescription) {
52         this.tdescription = tdescription;
53     }
54     public String getTcomment() {
55         return tcomment;
56     }
57     public void setTcomment(String tcomment) {
58         this.tcomment = tcomment;
59     }
60     public int getTindex() {
61         return tindex;
62     }
63     public void setTindex(int tindex) {
64         this.tindex = tindex;
65     }
66     public List<ParsedPosting> getTpostings() {
67         return tpostings;
68     }
69     public void setTpostings(List<ParsedPosting> tpostings) {
70         this.tpostings = tpostings;
71     }
72     public LedgerTransaction asLedgerTransaction() throws ParseException {
73         Date date = Globals.parseIsoDate(tdate);
74         LedgerTransaction tr = new LedgerTransaction(tindex, date, tdescription);
75
76         List<ParsedPosting> postings = tpostings;
77
78         if (postings != null) {
79             for (ParsedPosting p : postings) {
80                 tr.addAccount(p.asLedgerAccount());
81             }
82         }
83         return tr;
84     }
85 }