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)
42 @ColumnInfo(name = "template_id")
43 private long templateId;
44 @ColumnInfo(name = "acc")
45 private String accountName;
46 @ColumnInfo(name = "position")
48 private Long position;
49 @ColumnInfo(name = "acc_match_group")
50 private Integer accountNameMatchGroup;
52 private Long currency;
53 @ColumnInfo(name = "currency_match_group")
54 private Integer currencyMatchGroup;
55 @ColumnInfo(name = "amount")
57 @ColumnInfo(name = "amount_match_group")
58 private Integer amountMatchGroup;
59 @ColumnInfo(name = "comment")
60 private String accountComment;
61 @ColumnInfo(name = "comment_match_group")
62 private Integer accountCommentMatchGroup;
63 @ColumnInfo(name = "negate_amount")
64 private Boolean negateAmount;
65 public TemplateAccount(@NotNull Long id, @NonNull Long templateId, @NonNull Long position) {
67 this.templateId = templateId;
68 this.position = position;
70 public TemplateAccount(TemplateAccount o) {
72 templateId = o.templateId;
73 accountName = o.accountName;
74 position = o.position;
75 accountNameMatchGroup = o.accountNameMatchGroup;
76 currency = o.currency;
77 currencyMatchGroup = o.currencyMatchGroup;
79 amountMatchGroup = o.amountMatchGroup;
80 accountComment = o.accountComment;
81 accountCommentMatchGroup = o.accountCommentMatchGroup;
82 negateAmount = o.negateAmount;
87 public void setId(long id) {
90 public Boolean getNegateAmount() {
93 public void setNegateAmount(Boolean negateAmount) {
94 this.negateAmount = negateAmount;
96 public long getTemplateId() {
99 public void setTemplateId(long templateId) {
100 this.templateId = templateId;
103 public String getAccountName() {
106 public void setAccountName(@NonNull String accountName) {
107 this.accountName = accountName;
110 public Long getPosition() {
113 public void setPosition(@NonNull Long position) {
114 this.position = position;
116 public void setPosition(int position) {
117 this.position = (long) position;
119 public Integer getAccountNameMatchGroup() {
120 return accountNameMatchGroup;
122 public void setAccountNameMatchGroup(Integer accountNameMatchGroup) {
123 this.accountNameMatchGroup = accountNameMatchGroup;
125 public Long getCurrency() {
128 public void setCurrency(Long currency) {
129 this.currency = currency;
131 public Currency getCurrencyObject() {
132 if (currency == null || currency <= 0)
136 .getByIdSync(currency);
138 public Integer getCurrencyMatchGroup() {
139 return currencyMatchGroup;
141 public void setCurrencyMatchGroup(Integer currencyMatchGroup) {
142 this.currencyMatchGroup = currencyMatchGroup;
144 public Float getAmount() {
147 public void setAmount(Float amount) {
148 this.amount = amount;
150 public Integer getAmountMatchGroup() {
151 return amountMatchGroup;
153 public void setAmountMatchGroup(Integer amountMatchGroup) {
154 this.amountMatchGroup = amountMatchGroup;
156 public String getAccountComment() {
157 return accountComment;
159 public void setAccountComment(String accountComment) {
160 this.accountComment = accountComment;
162 public Integer getAccountCommentMatchGroup() {
163 return accountCommentMatchGroup;
165 public void setAccountCommentMatchGroup(Integer accountCommentMatchGroup) {
166 this.accountCommentMatchGroup = accountCommentMatchGroup;
168 public TemplateAccount createDuplicate(TemplateHeader header) {
169 TemplateAccount dup = new TemplateAccount(this);
171 dup.templateId = header.getId();