goeasyinvoice

package module
v0.0.0-...-bab1021 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

goeasyinvoice

Create a PDF Invoice the easy way using Go Easy Invoice.

Special thanks to https://github.com/maaslalani/invoice and https://github.com/signintech/gopdf

GoDoc

Installation

go get github.com/mbarreca/goeasyinvoice

Go Easy Invoice was built and tested with Go 1.24, it may still work with prior versions however it has not been tested so use at your own risk.

Why would I use this library?

In an world thats increasingly going towards vendor lock-in I believe its important to keep yourself as agnostic as possible. Billing is a big culprit. I couldn't find an easy to use library to generate me a modern looking invoice so I decided to take whats out there, improve it and give it back to the open source world. Enjoy.

Core Concepts

This library is built to be extensible within a particular format and template. It's fairly simple to modify. Everything is error handled, well tested and should work without issue. See the example below to make it work.

Telemetry

A library like this does not have much in the way of telemetry outside of error handling. That has intentionally been made robust, make sure your errors are being handled well and it will integrate into your telemetry stack easily.

Example

package main

import (
	"embed"
	invoice "github.com/mbarreca/goeasyinvoice" // Apache 2.0
)
/*
Create Embeds for TTF Files
*/
var f embed.FS

//go:embed "assets/fonts/Go-Regular.ttf"
var regularFont []byte

//go:embed "assets/fonts/Go-Medium.ttf"
var boldFont []byte

//go:embed "assets/fonts/Go-Bold.ttf"
var headlineFont []byte

func main() {
	/*
		Setup Invoice Object
	*/
	// Setup Fonts
	var rFont invoice.Font
	var bFont invoice.Font
	var hFont invoice.Font
	rFont.Title = "Go-Regular"
	rFont.File = &regularFont
	bFont.Title = "Go-Medium"
	bFont.File = &boldFont
	hFont.Title = "Go-Bold"
	hFont.File = &headlineFont

	// Setup Currency
	var currency invoice.Currency
	currency.Label = "EUR"
	currency.Symbol = "€"

	// Generate Line Item
	var lineItems []invoice.InvoiceItem
	var lineItem invoice.InvoiceItem
	lineItem.Item = "Software Development Services"
	lineItem.Rate = 100.00
	lineItem.Quantity = 100
	lineItems = append(lineItems, lineItem)

	// Generate Invoice Object
	invoice, err := invoice.New(&rFont, &bFont, &hFont, &currency, "Subtotal", "Discount", "Tax", "Total", "assets/logo.png", "Test Company")
	if err != nil {
		t.Fatal(err)
	}
	id := "DEV-001"

	// Generate Invoice
	if err := invoice.Generate("Development Services", id, "2025-04-20", "2025-06-01", "Test Company\n123 Address Avenue\nMilan, Italy", "Thank you for your business!", "./invoice"+id+".pdf", 0.10, 0.15, lineItems); err != nil {
	panic(err)
	}
}

License

Goeasyinvoice is licensed under Apache 2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Currency

type Currency struct {
	Label  string
	Symbol string
}

Label - The Label of the Currency

type Font

type Font struct {
	Title string
	File  *[]byte
}

type Invoice

type Invoice struct {
	From     string
	Title    string
	Subtotal string
	Discount string
	Tax      string
	Total    string
	// contains filtered or unexported fields
}

func New

func New(regularFont, boldFont, headlineFont *Font, currency *Currency, subtotal, discount, tax, total, logopath, from string) (*Invoice, error)

Invoice Instantiator regularFont - A goeasyinvoice Font Object that contains a reference to the byte[] of the font and title of the font boldFont - A goeasyinvoice Font Object that contains a reference to the byte[] of the font and title of the font headlineFont - A goeasyinvoice Font Object that contains a reference to the byte[] of the font and title of the font subtotal - The label for your subtitle discount - The label for a discount tax - The label for taxes total - The label for the total sum logopath - The path to your logo from - Who the invoice is from

func (*Invoice) Generate

func (i *Invoice) Generate(title, id, issueDate, dueDate, to, note, filePathName string, discount, tax float64, lineItems []InvoiceItem) error

Generate a PDF with the following parameters title - The title of the Invoice in the PDF id - Your Invoice ID issueDate - The Invoice's Issue Date dueDate - The Invoice's Due Date to - Who the Invoice is addressed to note - A note at the bottom left corner of the invoice - typically used for remarks filePathName - Where you would like the invoice saved. Make sure to clean this up if you're using it for SaaS discount - A discount percentage that will be multiplied by the subtotal - i.e 0.25 is a 25% discount - Please note that the subtotal is calculated pre-tax and the tax is applied after this tax - The taxable percentage (we will add 1 to it so if you apply a 15% tax then you would put 0.15) lineItems - An array of Invoice Items that represent the line items in your invoice RETURNS err - We will return an error or nil if successful. Check your filePathName for a successful PDF on nil return

type InvoiceItem

type InvoiceItem struct {
	Item     string
	Quantity int
	Rate     float64
}

Jump to

Keyboard shortcuts

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