mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 23:42:29 -05:00
lua: Add account types and type names
This commit is contained in:
parent
af704250e2
commit
6143924ed3
68
accounts.go
68
accounts.go
@ -10,27 +10,71 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AccountType int64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Bank int64 = 1
|
Bank AccountType = 1 // start at 1 so that the default (0) is invalid
|
||||||
Cash = 2
|
Cash = 2
|
||||||
Asset = 3
|
Asset = 3
|
||||||
Liability = 4
|
Liability = 4
|
||||||
Investment = 5
|
Investment = 5
|
||||||
Income = 6
|
Income = 6
|
||||||
Expense = 7
|
Expense = 7
|
||||||
Trading = 8
|
Trading = 8
|
||||||
Equity = 9
|
Equity = 9
|
||||||
Receivable = 10
|
Receivable = 10
|
||||||
Payable = 11
|
Payable = 11
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var AccountTypes = []AccountType{
|
||||||
|
Bank,
|
||||||
|
Cash,
|
||||||
|
Asset,
|
||||||
|
Liability,
|
||||||
|
Investment,
|
||||||
|
Income,
|
||||||
|
Expense,
|
||||||
|
Trading,
|
||||||
|
Equity,
|
||||||
|
Receivable,
|
||||||
|
Payable,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t AccountType) String() string {
|
||||||
|
switch t {
|
||||||
|
case Bank:
|
||||||
|
return "Bank"
|
||||||
|
case Cash:
|
||||||
|
return "Cash"
|
||||||
|
case Asset:
|
||||||
|
return "Asset"
|
||||||
|
case Liability:
|
||||||
|
return "Liability"
|
||||||
|
case Investment:
|
||||||
|
return "Investment"
|
||||||
|
case Income:
|
||||||
|
return "Income"
|
||||||
|
case Expense:
|
||||||
|
return "Expense"
|
||||||
|
case Trading:
|
||||||
|
return "Trading"
|
||||||
|
case Equity:
|
||||||
|
return "Equity"
|
||||||
|
case Receivable:
|
||||||
|
return "Receivable"
|
||||||
|
case Payable:
|
||||||
|
return "Payable"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
AccountId int64
|
AccountId int64
|
||||||
ExternalAccountId string
|
ExternalAccountId string
|
||||||
UserId int64
|
UserId int64
|
||||||
SecurityId int64
|
SecurityId int64
|
||||||
ParentAccountId int64 // -1 if this account is at the root
|
ParentAccountId int64 // -1 if this account is at the root
|
||||||
Type int64
|
Type AccountType
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
// monotonically-increasing account transaction version number. Used for
|
// monotonically-increasing account transaction version number. Used for
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const luaAccountTypeName = "account"
|
const luaAccountTypeName = "account"
|
||||||
@ -63,6 +64,10 @@ func luaRegisterAccounts(L *lua.LState) {
|
|||||||
L.SetField(mt, "__eq", L.NewFunction(luaAccount__eq))
|
L.SetField(mt, "__eq", L.NewFunction(luaAccount__eq))
|
||||||
L.SetField(mt, "__metatable", lua.LString("protected"))
|
L.SetField(mt, "__metatable", lua.LString("protected"))
|
||||||
|
|
||||||
|
for _, accttype := range AccountTypes {
|
||||||
|
L.SetField(mt, accttype.String(), lua.LNumber(float64(accttype)))
|
||||||
|
}
|
||||||
|
|
||||||
getAccountsFn := L.NewFunction(luaGetAccounts)
|
getAccountsFn := L.NewFunction(luaGetAccounts)
|
||||||
L.SetField(mt, "get_all", getAccountsFn)
|
L.SetField(mt, "get_all", getAccountsFn)
|
||||||
// also register the get_accounts function as a global in its own right
|
// also register the get_accounts function as a global in its own right
|
||||||
@ -121,6 +126,10 @@ func luaAccount__index(L *lua.LState) int {
|
|||||||
L.Push(lua.LString(a.Name))
|
L.Push(lua.LString(a.Name))
|
||||||
case "Type", "type":
|
case "Type", "type":
|
||||||
L.Push(lua.LNumber(float64(a.Type)))
|
L.Push(lua.LNumber(float64(a.Type)))
|
||||||
|
case "TypeName", "Typename":
|
||||||
|
L.Push(lua.LString(a.Type.String()))
|
||||||
|
case "typename":
|
||||||
|
L.Push(lua.LString(strings.ToLower(a.Type.String())))
|
||||||
case "Balance", "balance":
|
case "Balance", "balance":
|
||||||
L.Push(L.NewFunction(luaAccountBalance))
|
L.Push(L.NewFunction(luaAccountBalance))
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user