invoices

package module
v0.0.0-...-78cba8a Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

README

invoices

Package invoices generates invoice pdf files.

Issues

This package probably still has quite a number of issues because it was extracted from an application that had few ways to configure how the invoice would look. An example is the inability to change language beyond English and Dutch which I sort of hacked in. But also the layout is not much configurable. It sort of works for now.

Images

Images need to be sent as base64 jgp/png/gif. This package uses my other package imagebase64 to decode the encoded image. You can use the same package to encode your image as to ensure everything works well together.

Example

The file main.go provides an example implementation of how you can use this package to host a micro service to generate invoices. Of course you can also simply import the packe in your own application bypassing main.go altogether. In main.go you can remove the custom logger and use the default log package if you prefer. The invoices package itself does not log anything and therefore does not refer to any logger at all.

Documentation

Index

Constants

View Source
const (
	// AlignDefault does not express any text alignment.
	AlignDefault alignment = ""

	// AlignLeft expresses that text should be aligned left.
	AlignLeft alignment = "L"

	// AlignCenter expresses that text should be aligned center.
	AlignCenter alignment = "C"

	// AlignRight expresses that text should be aligned right.
	AlignRight alignment = "R"
)
View Source
const (
	// BorderNone indicates that no border should be added.
	BorderNone border = ""

	// BorderFull indicates that a border should be added to every side.
	BorderFull border = "1"

	// BorderBottom indicates that a border should be added only to the bottem.
	BorderBottom border = "B"
)

Variables

View Source
var LabelsEnglish = Labels{
	BankAccount:     "Bank account",
	HeaderText:      "INVOICE",
	Identification:  "Invoice number",
	InvoiceDate:     "Invoice date",
	PaymentSpan:     "Please pay within",
	PaymentSpanUnit: "days",
	Period:          "Period",
	PeriodFromTo:    "-",
	Taxnumber:       "VAT registration",
	Total:           "Total",
	TotalTax:        "VAT",
	TotalWithoutTax: "Total without VAT",
}

LabelsEnglish represents the labels in English.

View Source
var LabelsNederlands = Labels{
	BankAccount:     "Bankrekening",
	HeaderText:      "FACTUUR",
	Identification:  "Factuurnummer",
	InvoiceDate:     "Factuurdatum",
	PaymentSpan:     "Gelieve te betalen binnen",
	PaymentSpanUnit: "dagen",
	Period:          "Periode",
	PeriodFromTo:    "t/m",
	Taxnumber:       "BTW-nummer",
	Total:           "Totaal",
	TotalTax:        "BTW",
	TotalWithoutTax: "Totaal excl. BTW",
}

LabelsNederlands represents the labels in Dutch.

View Source
var StyleDefault = Style{
	DateFormat:  "yyyy-MM-dd",
	Font:        &Font{"Arial", "", 11, &Color{0, 0, 0}},
	ItemBorders: BorderNone,
	ItemFont:    &Font{"Arial", "", 11, &Color{0, 0, 0}},
	ItemSubFont: &Font{"Arial", "I", 8, &Color{100, 100, 100}},
}

StyleDefault represents a default visual style.

Functions

This section is empty.

Types

type Color

type Color struct {
	Red   int
	Green int
	Blue  int
}

Color represents a color, expressed in RGB components (0 - 255).

type Font

type Font struct {
	Name  string
	Style string
	Size  float64
	Color *Color
}

Font represents a text font.

type Invoice

type Invoice struct {
	Sender          Organisation
	Recipient       Organisation
	Labels          Labels
	Style           Style
	PaymentSpan     int
	BankAccount     string
	Taxnumber       string
	Identification  string
	InvoiceDate     time.Time
	FromDate        time.Time
	ToDate          time.Time
	TotalWithoutTax string
	TotalTax        string
	Total           string
	// contains filtered or unexported fields
}

Invoice represents an invoice.

func New

func New(identification string) *Invoice

NewInvoice is the constructor for Invoice.

func (*Invoice) AddItem

func (i *Invoice) AddItem(item []string)

AddItem adds an item to this invoice.

func (*Invoice) AddItemHeader

func (i *Invoice) AddItemHeader(widthPercentage int, text string, textAlignment alignment, borderSetting border)

AddItemHeader adds an items header to this invoice.

func (*Invoice) Items

func (i *Invoice) Items() []Item

Items returns the item collection of this invoice.

func (*Invoice) Write

func (i *Invoice) Write(w io.Writer) error

Write generates the pdf invoice document and writes it to w.

func (*Invoice) WriteToFile

func (i *Invoice) WriteToFile(outFile string) error

WriteToFile generates the pdf invoice document and writes it to outFile.

type Item

type Item []string

Item represents an invoice line for a sold product or service.

func (Item) GetAsAssetFileBase

func (i Item) GetAsAssetFileBase(index int) string

GetAsAssetFileBase returns the asset filename for the element of this item as the provided index.

func (Item) GetAsAssetName

func (i Item) GetAsAssetName(index int) string

GetAsAssetName returns the asset full file path for the element of this item as the provided index.

type Labels

type Labels struct {
	BankAccount     string
	HeaderText      string
	Identification  string
	InvoiceDate     string
	PaymentSpan     string
	PaymentSpanUnit string
	Period          string
	PeriodFromTo    string
	Taxnumber       string
	Total           string
	TotalTax        string
	TotalWithoutTax string
}

Labels represents the collection of simple text labels in a certain language used in the invoice.

type Organisation

type Organisation struct {
	Name      string
	Reference string
	Address   string
	PostCode  string
	City      string
	Website   string
	Email     string
	EmailCC   string
	Telephone string
}

Organisation represents an organisation, for example the invoice issuer or the client.

type Style

type Style struct {
	DateFormat  string
	Font        *Font
	ItemBorders border
	ItemFont    *Font
	ItemSubFont *Font
}

Style represents the settings for the visual style of the invoice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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