/
account_type.go
94 lines (78 loc) · 1.81 KB
/
account_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* SPDX-FileCopyrightText: 2022 Brian Welty
*
* SPDX-License-Identifier: MPL-2.0
*/
package model
import (
"gorm.io/gorm"
)
const (
AccountTypeUndefined uint = iota
AccountTypeCash
AccountTypeDeposit
AccountTypeCreditCard
AccountTypeInvestment
AccountTypeHealthCare
AccountTypeLoan
AccountTypeAsset
AccountTypeCrypto
)
type AccountType struct {
Model
Name string `form:"account_type.Name"`
}
type CurrencyType struct {
Model
Name string `form:"currency_type.Name"`
}
func (a AccountType) GetAltText() string {
return a.Name
}
func (a AccountType) GetIconPath() string {
var path string
switch a.ID {
case AccountTypeCash:
path = "images/icons/icn_small_deposit.png"
case AccountTypeDeposit:
path = "images/icons/icn_small_deposit.png"
case AccountTypeCreditCard:
path = "images/icons/icn_small_credit_card.gif"
case AccountTypeInvestment:
path = "images/icons/icn_investments.png"
case AccountTypeLoan:
path = "images/icons/icn_home.png"
case AccountTypeHealthCare:
path = "images/icons/icn_health.png"
case AccountTypeAsset:
path = "images/icons/icn_home.png"
case AccountTypeCrypto:
path = "images/icons/bitcoin.png"
default:
path = "images/icons/wrench.svg"
}
return path
}
func (a *AccountType) isCrypto() bool {
return a.ID == AccountTypeCrypto
}
func (a *AccountType) isInvestment() bool {
return a.ID == AccountTypeInvestment
}
func (a *AccountType) isType(askedType string) bool {
return a.Name == askedType
}
func (a *AccountType) supportsDownload() bool {
return a.ID >= AccountTypeDeposit &&
a.ID <= AccountTypeInvestment
}
func (*AccountType) List(db *gorm.DB) []AccountType {
entries := []AccountType{}
db.Find(&entries)
return entries
}
func (*CurrencyType) List(db *gorm.DB) []CurrencyType {
entries := []CurrencyType{}
db.Find(&entries)
return entries
}