employee

package
v1.49.21 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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 Query

func RemainingSpendCents

func RemainingSpendCents(committedCents, limitCents currency.Cents) currency.Cents

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

func WithinLimit(committed, requested, limit currency.Cents) bool

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).

func New

func New(db *datastore.Datastore) *Employee

func (*Employee) Load

func (e *Employee) Load(ps []datastore.Property) (err error)

func (*Employee) Save

func (e *Employee) Save() ([]datastore.Property, error)

Jump to

Keyboard shortcuts

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