]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/db/TransactionAccount.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / TransactionAccount.java
1 /*
2  * Copyright © 2021 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.db;
19
20 import androidx.annotation.NonNull;
21 import androidx.room.ColumnInfo;
22 import androidx.room.Entity;
23 import androidx.room.ForeignKey;
24 import androidx.room.Index;
25 import androidx.room.PrimaryKey;
26
27 import net.ktnx.mobileledger.utils.Misc;
28
29 @Entity(tableName = "transaction_accounts", foreignKeys = {
30         @ForeignKey(entity = Transaction.class, parentColumns = {"id"},
31                     childColumns = {"transaction_id"}, onDelete = ForeignKey.CASCADE,
32                     onUpdate = ForeignKey.RESTRICT)
33 }, indices = {@Index(name = "fk_trans_acc_trans", value = {"transaction_id"}),
34               @Index(name = "un_transaction_accounts", unique = true,
35                      value = {"transaction_id", "order_no"})
36 })
37 public class TransactionAccount {
38     @ColumnInfo
39     @PrimaryKey(autoGenerate = true)
40     private long id;
41     @ColumnInfo(name = "transaction_id")
42     private long transactionId;
43     @ColumnInfo(name = "order_no")
44     private int orderNo;
45     @ColumnInfo(name = "account_name")
46     @NonNull
47     private String accountName;
48     @ColumnInfo(defaultValue = "")
49     @NonNull
50     private String currency = "";
51     @ColumnInfo
52     private float amount;
53     @ColumnInfo
54     private String comment;
55     @ColumnInfo(defaultValue = "0")
56     private long generation = 0;
57     public long getId() {
58         return id;
59     }
60     public void setId(long id) {
61         this.id = id;
62     }
63     @NonNull
64     public long getTransactionId() {
65         return transactionId;
66     }
67     public void setTransactionId(long transactionId) {
68         this.transactionId = transactionId;
69     }
70     public int getOrderNo() {
71         return orderNo;
72     }
73     public void setOrderNo(int orderNo) {
74         this.orderNo = orderNo;
75     }
76     @NonNull
77     public String getAccountName() {
78         return accountName;
79     }
80     public void setAccountName(@NonNull String accountName) {
81         this.accountName = accountName;
82     }
83     @NonNull
84     public String getCurrency() {
85         return currency;
86     }
87     public void setCurrency(@NonNull String currency) {
88         this.currency = currency;
89     }
90     public float getAmount() {
91         return amount;
92     }
93     public void setAmount(float amount) {
94         this.amount = amount;
95     }
96     public String getComment() {
97         return comment;
98     }
99     public void setComment(String comment) {
100         this.comment = comment;
101     }
102     public long getGeneration() {
103         return generation;
104     }
105     public void setGeneration(long generation) {
106         this.generation = generation;
107     }
108
109     public void copyDataFrom(TransactionAccount o) {
110         // id = o.id
111         transactionId = o.transactionId;
112         orderNo = o.orderNo;
113         accountName = o.accountName;
114         currency = Misc.nullIsEmpty(o.currency);
115         amount = o.amount;
116         comment = o.comment;
117         generation = o.generation;
118     }
119 }