vehiclelease

package
v0.41.21 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package vehiclelease holds a vehicle's lease terms and computes where the driver stands against the mileage allowance. Distances are miles; the client converts to the user's unit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reading

type Reading struct {
	Mi float64
	At time.Time
}

Reading is an odometer reading.

type Status

type Status struct {
	OdometerMi *float64 `json:"odometer_mi"`
	OdometerAt *string  `json:"odometer_at"`

	UsedMi            *float64 `json:"used_mi"`
	AllowedToDateMi   float64  `json:"allowed_to_date_mi"`
	AheadBehindMi     *float64 `json:"ahead_behind_mi"` // allowed_to_date − used; negative = over the pro-rata allowance
	DaysTotal         int      `json:"days_total"`
	DaysElapsed       int      `json:"days_elapsed"`
	DaysLeft          int      `json:"days_left"`
	PaceMiPerDay      *float64 `json:"pace_mi_per_day"`
	PaceBasis         string   `json:"pace_basis,omitempty"` // last_90_days | lease_to_date
	ProjectedTotalMi  *float64 `json:"projected_total_mi"`
	ProjectedReturnMi *float64 `json:"projected_return_odometer_mi"`
	ProjectedOverMi   *float64 `json:"projected_overage_mi"`
	ProjectedOverCost *float64 `json:"projected_overage_cost"`
	MilesPerDayBudget *float64 `json:"miles_per_day_budget"`
	Currency          string   `json:"currency"`
}

Status is the computed standing. Pointer fields are null when they cannot be known (no recent odometer, not enough history for a pace).

func Compute

func Compute(t Terms, now time.Time, latest, past *Reading) (Status, error)

Compute works out the status at now. latest is the newest odometer reading (nil if none); past is the oldest reading inside the pace window (nil if none).

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the Postgres side.

func NewStore

func NewStore(d *sql.DB) *Store

NewStore wraps the pool.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, uid, vehicleID uuid.UUID) error

Delete removes the terms; absent is fine.

func (*Store) Get

func (s *Store) Get(ctx context.Context, uid, vehicleID uuid.UUID) (*Terms, error)

Get returns the vehicle's terms, or (nil, nil) when none are set.

func (*Store) Odometer

func (s *Store) Odometer(ctx context.Context, uid, vehicleID uuid.UUID, now time.Time) (latest, past *Reading, err error)

Odometer returns the newest reading and the oldest one inside the pace window (either may be nil).

func (*Store) Put

func (s *Store) Put(ctx context.Context, uid, vehicleID uuid.UUID, t Terms) error

Put saves validated terms, replacing any existing ones.

type Terms

type Terms struct {
	StartDate         string  `json:"start_date"`
	EndDate           string  `json:"end_date"`
	StartOdometerMi   float64 `json:"start_odometer_mi"`
	AllowedMilesTotal float64 `json:"allowed_miles_total"`
	OveragePerMile    float64 `json:"overage_per_mile"`
	Currency          string  `json:"currency"`
}

Terms are what the driver enters. Dates are calendar dates (YYYY-MM-DD).

func (*Terms) Validate

func (t *Terms) Validate() error

Validate normalises the currency and rejects impossible terms.

Jump to

Keyboard shortcuts

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