invoice

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: BSD-3-Clause Imports: 6 Imported by: 2

Documentation

Overview

Package invoice allows generating invoices from a filled report database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Source string
	Target string
	Items  []Item
	// Total represents the total accumulated cost per category.
	Total float64
}

Category represents a category of the invoice i.e. a namespace.

type Invoice

type Invoice struct {
	Tenant Tenant

	PeriodStart time.Time
	PeriodEnd   time.Time

	Categories []Category
	// Total represents the total accumulated cost of the invoice.
	Total float64
}

Invoice represents an invoice for a tenant.

func Generate

func Generate(ctx context.Context, tx *sqlx.Tx, year int, month time.Month) ([]Invoice, error)

Generate generates invoices for the given month. No data is written to the database. The transaction can be read-only.

type Item

type Item struct {
	// Description describes the line item.
	Description string
	// QueryName is the name of the query that generated this line item
	QueryName string
	// Product describes the product this item is based on.
	ProductRef
	// Quantity represents the amount of the resource used.
	Quantity float64
	// QuantityMin represents the minimum amount of the resource used.
	QuantityMin float64
	// QuantityAvg represents the average amount of the resource used.
	QuantityAvg float64
	// QuantityMax represents the maximum amount of the resource used.
	QuantityMax float64
	// Unit represents the unit of the item. e.g. MiB
	Unit string
	// PricePerUnit represents the price per unit in Rappen
	PricePerUnit float64
	// Discount represents a discount in percent. 0.3 discount equals price per unit * 0.7
	Discount float64
	// Total represents the total accumulated cost.
	// (hour1 * quantity * price per unit * discount) + (hour2 * quantity * price
	// per unit * discount)
	Total float64
	// SubItems are entries created by the subqueries of the main invoice item.
	// The keys are the QueryNames of the sub items.
	SubItems map[string]SubItem
}

Item represents a line in the invoice.

type ProductRef

type ProductRef struct {
	Source string `db:"product_ref_source"`
	Target string `db:"product_ref_target"`
}

ProductRef represents a product reference in the invoice.

type SubItem added in v0.5.0

type SubItem struct {
	// Description describes the line item.
	Description string
	// QueryName is the name of the query that generated this line item
	QueryName string
	// Quantity represents the amount of the resource used.
	Quantity float64
	// QuantityMin represents the minimum amount of the resource used.
	QuantityMin float64
	// QuantityAvg represents the average amount of the resource used.
	QuantityAvg float64
	// QuantityMax represents the maximum amount of the resource used.
	QuantityMax float64
	// Unit represents the unit of the item. e.g. MiB
	Unit string
}

SubItem reflects additional information created by a subquery of the main invoice item

type Tenant

type Tenant struct {
	Source string
	Target string
}

Tenant represents a tenant in the invoice.

Jump to

Keyboard shortcuts

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