import org.jetbrains.annotations.NotNull;
-@Entity(tableName = "pattern_accounts",
- indices = {@Index(name = "un_pattern_accounts", unique = true, value = "id"),
- @Index(name = "fk_pattern_accounts_pattern", value = "pattern_id"),
- @Index(name = "fk_pattern_accounts_currency", value = "currency")
- }, foreignKeys = {@ForeignKey(childColumns = "pattern_id", parentColumns = "id",
- entity = TemplateHeader.class),
+@Entity(tableName = "template_accounts",
+ 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, 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 {
- @NonNull
- @ColumnInfo(name = "pattern_id")
- private Long patternId;
@PrimaryKey(autoGenerate = true)
- @NotNull
- private Long id;
+ private long id;
+ @ColumnInfo(name = "template_id")
+ private long templateId;
@ColumnInfo(name = "acc")
private String accountName;
@ColumnInfo(name = "position")
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")
private Integer accountCommentMatchGroup;
@ColumnInfo(name = "negate_amount")
private Boolean negateAmount;
- public TemplateAccount(@NotNull Long id, @NonNull Long patternId, @NonNull Long position) {
+ public TemplateAccount(@NotNull Long id, @NonNull Long templateId, @NonNull Long position) {
this.id = id;
- this.patternId = patternId;
+ 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() {
public void setNegateAmount(Boolean negateAmount) {
this.negateAmount = negateAmount;
}
- public @NotNull Long getPatternId() {
- return patternId;
+ public long getTemplateId() {
+ return templateId;
}
- public void setPatternId(@NonNull Long patternId) {
- this.patternId = patternId;
+ public void setTemplateId(long templateId) {
+ this.templateId = templateId;
}
@NonNull
public String getAccountName() {
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;
}
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;
+ }
}