Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

34 lines
1.2 KiB
Go

package employee
import (
"math"
"github.com/hanzoai/commerce/models/types/currency"
)
// 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.
const Unlimited = currency.Cents(math.MaxInt64)
// 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 RemainingSpendCents(committedCents, limitCents currency.Cents) currency.Cents {
if limitCents == 0 {
return Unlimited
}
return limitCents - committedCents
}
// 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.
func WithinLimit(committed, requested, limit currency.Cents) bool {
if limit == 0 {
return true
}
return committed+requested <= limit
}