X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FTemplateAccount.java;h=949bd9da9127d5f48f3015951dea37b4670d2238;hb=833544eb24cb630dc1ce221e4aa3dedb3f6341e3;hp=c662ff1c18092121ebf6f6b74bbffe1ec98be595;hpb=3ab99e1679326277d6ba7f8ce28f17a96dfa07aa;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java index c662ff1c..949bd9da 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateAccount.java @@ -30,17 +30,17 @@ import org.jetbrains.annotations.NotNull; indices = {@Index(name = "fk_template_accounts_template", value = "template_id"), @Index(name = "fk_template_accounts_currency", value = "currency") }, foreignKeys = {@ForeignKey(childColumns = "template_id", parentColumns = "id", - entity = TemplateHeader.class), + entity = TemplateHeader.class, onDelete = ForeignKey.CASCADE, + onUpdate = ForeignKey.RESTRICT), @ForeignKey(childColumns = "currency", parentColumns = "id", - entity = Currency.class) + entity = Currency.class, onDelete = ForeignKey.RESTRICT, + onUpdate = ForeignKey.RESTRICT) }) public class TemplateAccount extends TemplateBase { @PrimaryKey(autoGenerate = true) - @NotNull - private Long id; - @NonNull + private long id; @ColumnInfo(name = "template_id") - private Long templateId; + private long templateId; @ColumnInfo(name = "acc") private String accountName; @ColumnInfo(name = "position") @@ -48,8 +48,8 @@ public class TemplateAccount extends TemplateBase { private Long position; @ColumnInfo(name = "acc_match_group") private Integer accountNameMatchGroup; - @ColumnInfo(name = "currency") - private Integer currency; + @ColumnInfo + private Long currency; @ColumnInfo(name = "currency_match_group") private Integer currencyMatchGroup; @ColumnInfo(name = "amount") @@ -67,10 +67,24 @@ public class TemplateAccount extends TemplateBase { this.templateId = templateId; this.position = position; } - public Long getId() { + public TemplateAccount(TemplateAccount o) { + id = o.id; + templateId = o.templateId; + accountName = o.accountName; + position = o.position; + accountNameMatchGroup = o.accountNameMatchGroup; + currency = o.currency; + currencyMatchGroup = o.currencyMatchGroup; + amount = o.amount; + amountMatchGroup = o.amountMatchGroup; + accountComment = o.accountComment; + accountCommentMatchGroup = o.accountCommentMatchGroup; + negateAmount = o.negateAmount; + } + public long getId() { return id; } - public void setId(Long id) { + public void setId(long id) { this.id = id; } public Boolean getNegateAmount() { @@ -79,10 +93,10 @@ public class TemplateAccount extends TemplateBase { public void setNegateAmount(Boolean negateAmount) { this.negateAmount = negateAmount; } - public @NotNull Long getTemplateId() { + public long getTemplateId() { return templateId; } - public void setTemplateId(@NonNull Long templateId) { + public void setTemplateId(long templateId) { this.templateId = templateId; } @NonNull @@ -108,12 +122,19 @@ public class TemplateAccount extends TemplateBase { public void setAccountNameMatchGroup(Integer accountNameMatchGroup) { this.accountNameMatchGroup = accountNameMatchGroup; } - public Integer getCurrency() { + public Long getCurrency() { return currency; } - public void setCurrency(Integer currency) { + public void setCurrency(Long currency) { this.currency = currency; } + public Currency getCurrencyObject() { + if (currency == null || currency <= 0) + return null; + return DB.get() + .getCurrencyDAO() + .getByIdSync(currency); + } public Integer getCurrencyMatchGroup() { return currencyMatchGroup; } @@ -144,4 +165,11 @@ public class TemplateAccount extends TemplateBase { public void setAccountCommentMatchGroup(Integer accountCommentMatchGroup) { this.accountCommentMatchGroup = accountCommentMatchGroup; } + public TemplateAccount createDuplicate(TemplateHeader header) { + TemplateAccount dup = new TemplateAccount(this); + dup.id = 0; + dup.templateId = header.getId(); + + return dup; + } }