-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.go
More file actions
38 lines (31 loc) · 940 Bytes
/
customer.go
File metadata and controls
38 lines (31 loc) · 940 Bytes
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
package accounting
import "github.com/fgrid/money"
type Customer struct {
Name string
serviceAgreement *ServiceAgreement
accounts map[EntryType]*Account
}
func NewCustomer(name string, serviceAgreement *ServiceAgreement) *Customer {
c := &Customer{
Name: name,
serviceAgreement: serviceAgreement,
accounts: make(map[EntryType]*Account, 0),
}
for _, at := range EntryTypes {
c.accounts[at] = NewAccount(money.NewCurrency("EUR"))
}
return c
}
func (c *Customer) BalanceFor(accountType EntryType) *money.Money {
return c.accountFor(accountType).Balance()
}
func (c *Customer) AddEntry(entry *Entry, accountType EntryType) {
c.accountFor(accountType).post(entry)
}
func (c *Customer) Entries(accountType EntryType) []*Entry {
return c.accountFor(accountType).entries
}
func (c *Customer) accountFor(accountType EntryType) *Account {
a, _ := c.accounts[accountType]
return a
}