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.
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.db;
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;
27 import org.jetbrains.annotations.NotNull;
29 @Entity(tableName = "template_accounts",
30 indices = {@Index(name = "fk_template_accounts_template", value = "template_id"),
31 @Index(name = "fk_template_accounts_currency", value = "currency")
32 }, foreignKeys = {@ForeignKey(childColumns = "template_id", parentColumns = "id",
33 entity = TemplateHeader.class, onDelete = ForeignKey.CASCADE,
34 onUpdate = ForeignKey.RESTRICT),
35 @ForeignKey(childColumns = "currency", parentColumns = "id",
36 entity = Currency.class, onDelete = ForeignKey.RESTRICT,
37 onUpdate = ForeignKey.RESTRICT)
39 public class TemplateAccount extends TemplateBase {
40 @PrimaryKey(autoGenerate = true)
44 @ColumnInfo(name = "template_id")
45 private Long templateId;
46 @ColumnInfo(name = "acc")
47 private String accountName;
48 @ColumnInfo(name = "position")
50 private Long position;
51 @ColumnInfo(name = "acc_match_group")
52 private Integer accountNameMatchGroup;
53 @ColumnInfo(name = "currency")
54 private Integer currency;
55 @ColumnInfo(name = "currency_match_group")
56 private Integer currencyMatchGroup;
57 @ColumnInfo(name = "amount")
59 @ColumnInfo(name = "amount_match_group")
60 private Integer amountMatchGroup;
61 @ColumnInfo(name = "comment")
62 private String accountComment;
63 @ColumnInfo(name = "comment_match_group")
64 private Integer accountCommentMatchGroup;
65 @ColumnInfo(name = "negate_amount")
66 private Boolean negateAmount;
67 public TemplateAccount(@NotNull Long id, @NonNull Long templateId, @NonNull Long position) {
69 this.templateId = templateId;
70 this.position = position;
72 public TemplateAccount(TemplateAccount o) {
74 templateId = o.templateId;
75 accountName = o.accountName;
76 position = o.position;
77 accountNameMatchGroup = o.accountNameMatchGroup;
78 currency = o.currency;
79 currencyMatchGroup = o.currencyMatchGroup;
81 amountMatchGroup = o.amountMatchGroup;
82 accountComment = o.accountComment;
83 accountCommentMatchGroup = o.accountCommentMatchGroup;
84 negateAmount = o.negateAmount;
89 public void setId(Long id) {
92 public Boolean getNegateAmount() {
95 public void setNegateAmount(Boolean negateAmount) {
96 this.negateAmount = negateAmount;
98 public @NotNull Long getTemplateId() {
101 public void setTemplateId(@NonNull Long templateId) {
102 this.templateId = templateId;
105 public String getAccountName() {
108 public void setAccountName(@NonNull String accountName) {
109 this.accountName = accountName;
112 public Long getPosition() {
115 public void setPosition(@NonNull Long position) {
116 this.position = position;
118 public void setPosition(int position) {
119 this.position = (long) position;
121 public Integer getAccountNameMatchGroup() {
122 return accountNameMatchGroup;
124 public void setAccountNameMatchGroup(Integer accountNameMatchGroup) {
125 this.accountNameMatchGroup = accountNameMatchGroup;
127 public Integer getCurrency() {
130 public void setCurrency(Integer currency) {
131 this.currency = currency;
133 public Integer getCurrencyMatchGroup() {
134 return currencyMatchGroup;
136 public void setCurrencyMatchGroup(Integer currencyMatchGroup) {
137 this.currencyMatchGroup = currencyMatchGroup;
139 public Float getAmount() {
142 public void setAmount(Float amount) {
143 this.amount = amount;
145 public Integer getAmountMatchGroup() {
146 return amountMatchGroup;
148 public void setAmountMatchGroup(Integer amountMatchGroup) {
149 this.amountMatchGroup = amountMatchGroup;
151 public String getAccountComment() {
152 return accountComment;
154 public void setAccountComment(String accountComment) {
155 this.accountComment = accountComment;
157 public Integer getAccountCommentMatchGroup() {
158 return accountCommentMatchGroup;
160 public void setAccountCommentMatchGroup(Integer accountCommentMatchGroup) {
161 this.accountCommentMatchGroup = accountCommentMatchGroup;
163 public TemplateAccount createDuplicate() {
164 TemplateAccount dup = new TemplateAccount(this);
166 dup.templateId = null;