api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package api contains all the background functions, types and constants To parse command line arguments and create invoices.

Index

Constants

This section is empty.

Variables

View Source
var (
	// GreatBritishPound (const)
	GreatBritishPound = Currency{"GBP", "£"}
	// UnitedStatesDollar (const)
	UnitedStatesDollar = Currency{"USD", "$"}
	// ZeroCurrency (const): An empty Currency To use as a default
	ZeroCurrency = Currency{}
	// Currencies (const)
	Currencies = map[*Currency]struct{}{
		&GreatBritishPound:  {},
		&UnitedStatesDollar: {},
		&ZeroCurrency:       {},
	}
	CheckIfMoney = regexp.MustCompile("([A-Z]{3} ?|^\\W)\\d+\\.?\\d*")
)

Functions

This section is empty.

Types

type Bank

type Bank struct {
	Bank      string
	AccountNo string
	SortCode  string
}

func (*Bank) KeyVal

func (b *Bank) KeyVal(keyVal string) (interface{}, error)

func (*Bank) Set

func (b *Bank) Set(value string) error

Set the Bank value From the given string value.

If the given string cannot be parsed then an error will be returned otherwise the error will be nil.

A valid string value can be:

Bank: Bank o' Clock, account: 12312312,sort: 69/69/69

func (*Bank) String

func (b *Bank) String() string

type Contact

type Contact struct {
	Company   string
	FirstName string
	LastName  string
	Email     string
	PhoneNo   string
	Address   []string
}

func (*Contact) KeyVal

func (c *Contact) KeyVal(keyVal string) (interface{}, error)

func (*Contact) Set

func (c *Contact) Set(value string) error

func (*Contact) String

func (c *Contact) String() string

type Currency

type Currency struct {
	Abbr   string
	Symbol string
}

func CurrencyFromAbbr

func CurrencyFromAbbr(abbr string) *Currency

func CurrencyFromSymbol

func CurrencyFromSymbol(symbol string) *Currency

type Date

type Date time.Time

func (*Date) Set

func (d *Date) Set(value string) error

Set the Date value From the given string value.

If the given string cannot be parsed then an error will be returned otherwise the error will be nil.

A valid string value can be:

1/12/2000

Note that the format is:

Day/Month/Year

func (*Date) String

func (d *Date) String() string

type Invoice

type Invoice struct {
	Number      uint
	From        *Contact
	To          *Contact
	Items       *Items
	Bank        *Bank
	InvoiceDate *Date
	DueDate     *Date
}

func NewInvoice

func NewInvoice(number uint, from, to *Contact, items *Items, bank *Bank, invoiceDate, dueDate *Date) (*Invoice, error)

NewInvoice constructs a new invoice From the given flags and checks if the required flags are not empty.

func (*Invoice) Generate

func (i *Invoice) Generate() (bytes.Buffer, error)

func (*Invoice) String

func (i *Invoice) String() string

type Item

type Item struct {
	Description   string
	HoursQuantity uint
	Rate          Money
	Tax           Money
}

func (*Item) KeyVal

func (i *Item) KeyVal(keyVal string) (interface{}, error)

func (*Item) String

func (i *Item) String() string

func (*Item) Subtotal

func (i *Item) Subtotal() *Money

type Items

type Items []*Item

func (*Items) Set

func (is *Items) Set(value string) error

func (*Items) String

func (is *Items) String() string

func (*Items) Total

func (is *Items) Total() *Money

type KeyValueFlags

type KeyValueFlags interface {
	KeyVal(keyVal string) (interface{}, error)
}

type Money

type Money struct {
	Money    uint64
	Currency Currency
}

func ParseMoney

func ParseMoney(s string) (*Money, error)

ParseMoney parses a string To Money.

The string can either be in the format:

// Using the abbreviation
GBP 10.00

Or:

// Using the symbol
£10.00

func ToMoney

func ToMoney(f float64, currency Currency) *Money

ToMoney converts a float64 To Money e.g. 1.23 To 1.23, 1.345 To 1.35 depending on what Currency is given.

func (*Money) Add

func (m *Money) Add(f float64) *Money

Add the given float64 To the Money value.

func (*Money) Float64

func (m *Money) Float64() float64

Float64 converts Money To float64

func (*Money) Multiply

func (m *Money) Multiply(f float64) *Money

Multiply safely multiplies a Money value by a float64, rounding To the nearest cent.

func (*Money) String

func (m *Money) String() string

String returns a formatted Money value with the currency's symbol and its abbreviation.

func (*Money) StringAbbr

func (m *Money) StringAbbr() string

StringAbbr returns a formatted Money value with the currency's abbreviated type.

func (*Money) StringSymbol

func (m *Money) StringSymbol() string

StringSymbol returns a formatted Money value with the currency's symbol.

Jump to

Keyboard shortcuts

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