models

package
v0.0.0-...-b4821ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrentBillSchemaVersion = 1
)
View Source
const (
	MoneyPrecision = 2
)

Variables

View Source
var (
	ErrDiscrepancy       = errors.New("total price and total payments must be equal")
	ErrInternalAssertion = errors.New("internal assertion")
)
View Source
var (
	ErrNoShares     = errors.New("shares are empty")
	ErrZeroQuantity = errors.New("quantity is zero")
)
View Source
var (
	ErrBalanceNotZero = errors.New("balance isn't zero")
)
View Source
var (
	ErrMoneyPrecision = errors.Errorf("target's exponent greater then %d", MoneyPrecision)
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Credit Money
	Debit  Money
}

func NewBalance

func NewBalance() *Account

func (*Account) AbsNet

func (b *Account) AbsNet() (Money, NetKind)

func (*Account) IsScarcity

func (b *Account) IsScarcity() (Money, bool)

func (*Account) IsSurplus

func (b *Account) IsSurplus() (Money, bool)

func (*Account) IsZero

func (b *Account) IsZero() bool

type Bill

type Bill struct {
	ID       BillID        `json:"-"`
	Items    []BillItem    `json:",omitempty"`
	Payments []BillPayment `json:",omitempty"`
}

func (*Bill) BalanceByUser

func (b *Bill) BalanceByUser() map[UserID]MoneyRat

func (*Bill) CreditByUser

func (b *Bill) CreditByUser() map[UserID]MoneyRat

func (*Bill) DebitByUser

func (b *Bill) DebitByUser() map[UserID]MoneyRat

func (*Bill) GetSchemaVersion

func (b *Bill) GetSchemaVersion() int

func (*Bill) ToInvoices

func (b *Bill) ToInvoices() ([]Invoice, error)

func (*Bill) TotalPayment

func (b *Bill) TotalPayment() Money

func (*Bill) TotalPrice

func (b *Bill) TotalPrice() Money

func (*Bill) Validate

func (b *Bill) Validate() error

type BillID

type BillID int64

func (BillID) String

func (bid BillID) String() string

type BillItem

type BillItem struct {
	Title       string
	PricePerOne Money
	Quantity    uint
	Type        uint8
	Shares      []BillShare
}

func (*BillItem) SharePricesByUser

func (bi *BillItem) SharePricesByUser() map[UserID]MoneyRat

func (*BillItem) SimplifyShares

func (bi *BillItem) SimplifyShares()

func (*BillItem) TotalPrice

func (bi *BillItem) TotalPrice() Money

func (*BillItem) TotalShare

func (bi *BillItem) TotalShare() int64

func (*BillItem) Validate

func (bi *BillItem) Validate() error

type BillPayment

type BillPayment struct {
	UserID UserID
	Amount Money
}

func (*BillPayment) Validate

func (bp *BillPayment) Validate() error

type BillShare

type BillShare struct {
	UserID UserID
	Share  uint32
}

type Invoice

type Invoice struct {
	UserFrom UserID
	UserTo   UserID
	Value    Money
}

func FixInvocesTotal

func FixInvocesTotal(invoices []Invoice, targetTotal Money) ([]Invoice, error)

func InvoicesFromBalances

func InvoicesFromBalances(balancesMap map[UserID]MoneyRat) ([]Invoice, error)

type Money

type Money struct{ decimal.Decimal }

Деньги для БД. Конечный результат цепочки вычислений. То, сколько нужно пересести. Рациональное число может быть не выразимо в десятичной системе счисления. Если требуется отдать 100/3 рублей, то в decimal это 33.33 и 0.00(3) - невязка.

func InvoicesTotal

func InvoicesTotal(invoices []Invoice) Money

func NewMoney

func NewMoney() Money

func NewMoneyFromBig

func NewMoneyFromBig(v *big.Int) Money

func (Money) Validate

func (m Money) Validate() error

type MoneyRat

type MoneyRat struct{ *big.Rat }

Тип для вычисления с деньгами. Абсолютная точность в операциях. https://github.com/nethruster/go-fraction

func NewMoneyRat

func NewMoneyRat() MoneyRat

func (*MoneyRat) Copy

func (m *MoneyRat) Copy() MoneyRat

func (*MoneyRat) Money

func (m *MoneyRat) Money() Money

type NetKind

type NetKind int
const (
	Unknown NetKind = iota
	Zero
	Surplus
	Scarcity
)

type User

type User struct {
	ID    UserID
	Title string
}

type UserID

type UserID int64

func (UserID) String

func (uid UserID) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL