Documentation
¶
Overview ¶
Package employee is the B2B buyer domain: a person who purchases on behalf of a company (models/company). Each employee carries a spending limit; the pure spend arithmetic lives in spending.go so it can be unit-tested and reused by the approval workflow without a datastore.
Index ¶
Constants ¶
const Unlimited = currency.Cents(math.MaxInt64)
Unlimited is the sentinel remaining-spend returned when an employee's limit is 0 (meaning no cap). It is math.MaxInt64 cents so callers that compare against it treat any request as affordable.
Variables ¶
This section is empty.
Functions ¶
func RemainingSpendCents ¶
RemainingSpendCents reports how much an employee may still commit given the amount already committed and their limit. A limit of 0 means unlimited, in which case Unlimited is returned. Otherwise the remainder (limit-committed) is returned and may be negative if the employee is already over limit.
func WithinLimit ¶
WithinLimit reports whether adding requested cents to what is already committed stays within limit. A limit of 0 is unlimited and always passes. The boundary is inclusive: committing exactly up to the limit is allowed.
Types ¶
type Employee ¶
type Employee struct {
mixin.Model[Employee]
CompanyId string `json:"companyId"`
CustomerId string `json:"customerId"`
IsAdmin bool `json:"isAdmin"`
// SpendingLimitCents caps committed spend for this employee. 0 = unlimited.
SpendingLimitCents currency.Cents `json:"spendingLimitCents"`
Metadata Map `json:"metadata,omitempty" datastore:"-"`
Metadata_ string `json:"-" datastore:",noindex"`
}
Employee links a customer (the user placing orders) to a company and caps how much that user may commit against the company. A zero SpendingLimitCents means unlimited (see spending.go).