reporting

package
v0.0.0-...-0041c27 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package reporting provides a way to import CSV files into the database.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHomeboxHeaders       = errors.New("no headers found")
	ErrMissingRequiredHeaders = errors.New("missing required headers `HB.location` or `HB.name`")
)

Functions

func BillOfMaterialsTSV

func BillOfMaterialsTSV(entities []repo.ItemOut) ([]byte, error)

BillOfMaterialsTSV returns a byte slice of the Bill of Materials for a given GID in TSV format See BillOfMaterialsEntry for the format of the output

Types

type BillOfMaterialsEntry

type BillOfMaterialsEntry struct {
	PurchaseDate types.Date `csv:"Purchase Date"`
	Name         string     `csv:"Name"`
	Description  string     `csv:"Description"`
	Manufacturer string     `csv:"Manufacturer"`
	SerialNumber string     `csv:"Serial Number"`
	ModelNumber  string     `csv:"Model Number"`
	Quantity     int        `csv:"Quantity"`
	Price        float64    `csv:"Price"`
	TotalPrice   float64    `csv:"Total Price"`
}

type ExportItemFields

type ExportItemFields struct {
	Name  string
	Value string
}

type ExportTSVRow

type ExportTSVRow struct {
	ImportRef string         `csv:"HB.import_ref"`
	Location  LocationString `csv:"HB.location"`
	LabelStr  LabelString    `csv:"HB.labels"`
	AssetID   repo.AssetID   `csv:"HB.asset_id"`
	Archived  bool           `csv:"HB.archived"`

	Name        string `csv:"HB.name"`
	Quantity    int    `csv:"HB.quantity"`
	Description string `csv:"HB.description"`
	Insured     bool   `csv:"HB.insured"`
	Notes       string `csv:"HB.notes"`

	PurchasePrice float64    `csv:"HB.purchase_price"`
	PurchaseFrom  string     `csv:"HB.purchase_from"`
	PurchaseTime  types.Date `csv:"HB.purchase_time"`

	Manufacturer string `csv:"HB.manufacturer"`
	ModelNumber  string `csv:"HB.model_number"`
	SerialNumber string `csv:"HB.serial_number"`

	LifetimeWarranty bool       `csv:"HB.lifetime_warranty"`
	WarrantyExpires  types.Date `csv:"HB.warranty_expires"`
	WarrantyDetails  string     `csv:"HB.warranty_details"`

	SoldTo    string     `csv:"HB.sold_to"`
	SoldPrice float64    `csv:"HB.sold_price"`
	SoldTime  types.Date `csv:"HB.sold_time"`
	SoldNotes string     `csv:"HB.sold_notes"`

	Fields []ExportItemFields `csv:"-"`
}

type IOSheet

type IOSheet struct {
	Rows []ExportTSVRow
	// contains filtered or unexported fields
}

IOSheet is the representation of a CSV/TSV sheet that is used for importing/exporting items from homebox. It is used to read/write the data from/to a CSV/TSV file given the standard format of the file.

See ExportTSVRow for the format of the data in the sheet.

func (*IOSheet) GetColumn

func (s *IOSheet) GetColumn(str string) (col int, ok bool)

func (*IOSheet) Read

func (s *IOSheet) Read(data io.Reader) error

Read reads a CSV/TSV and populates the "Rows" field with the data from the sheet Custom Fields are supported via the `HB.field.*` headers. The `HB.field.*` the "Name" of the field is the part after the `HB.field.` prefix. Additionally, Custom Fields with no value are excluded from the row.Fields slice, this includes empty strings.

Note That

  • the first row is assumed to be the header
  • at least 1 row of data is required
  • rows and columns must be rectangular (i.e. all rows must have the same number of columns)

func (*IOSheet) ReadItems

func (s *IOSheet) ReadItems(ctx context.Context, items []repo.ItemOut, GID uuid.UUID, repos *repo.AllRepos) error

ReadItems writes the sheet to a writer.

func (*IOSheet) TSV

func (s *IOSheet) TSV() ([][]string, error)

TSV writes the current sheet to a writer in TSV format.

type LabelString

type LabelString []string

LabelString is a string slice that is used to represent a list of labels.

For example, a list of labels "Important; Work" would be represented as a LabelString with the following values:

LabelString{"Important", "Work"}

func (LabelString) String

func (ls LabelString) String() string

type LocationString

type LocationString []string

LocationString is a string slice that is used to represent a location hierarchy.

For example, a location hierarchy of "Home / Bedroom / Desk" would be represented as a LocationString with the following values:

LocationString{"Home", "Bedroom", "Desk"}

func (LocationString) String

func (csf LocationString) String() string

Directories

Path Synopsis
Package eventbus provides an interface for event bus.
Package eventbus provides an interface for event bus.

Jump to

Keyboard shortcuts

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