docutron

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

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

Go to latest
Published: Nov 20, 2022 License: AGPL-3.0 Imports: 16 Imported by: 0

README

docutron

Minimalist invoice generation.

Docutron allows you to easily generate invoices from plain text JSON files.

It's deliberately simple and should be easy to customise to suit your needs.

Why JSON files?

Because the world has enough YAML (and the Go standard library handles it nicely).

Build and install

git clone git@github.com:minimalistsoftware/docutron.git
cd docutron/cmd/docutron
go install .

Dependencies

Go
Chrome/Chromium (optional, for PDF generation)

Usage

Make a directory to work in, with required config and directories.
docutron -init mybusiness/

Create a new invoice

cd mybusiness
docutron -new
2022/11/18 17:40:58 wrote json/INV1.json

Generate an HTML version

docutron -name json/INV1.json -html

Generate a PDF version using Chrome/Chromium

docutron -name json/INV1.json -pdf
Customing the template

The invoice template is in templates/invoice.html

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CentsToString

func CentsToString(c int) string

CentsToString converts integer cents to a human-readable currency string

func FormatDate

func FormatDate(t time.Time) string

Format Date in a readable way for the invoice.

func InitProject

func InitProject(dirName string)

InitProject creates a new directory and the skeleton config files.

func MarshalJSONFile

func MarshalJSONFile(inv Invoice, name string)

MarshalJSONFile writes inv to name.json as JSON.

func NewJSONFile

func NewJSONFile(name string)

NewJSONFile creates a new file json/name.json.

func NextNumber

func NextNumber() int

NextNumber determines the next filename number based on number of files in json/ directory + 1. TODO make this aware of different document types.

func WriteConfig

func WriteConfig(name string)

WriteConfig initialises a new config JSON file

func WriteHTML

func WriteHTML(inv Invoice, name string, templatePath string)

WriteHTML outputs html/name.html.

func WritePDF

func WritePDF(inv Invoice)

WritePDF writes a pdf to pdf/title.pdf using wkhtmltopdf.

func WritePDFChrome

func WritePDFChrome(inv Invoice)
WrotePDFChrome writes a PDF to disk using Chrome via chromedp.

This got me better results than wkhtmltopdf for tables split across pages.

I'd rather not have this dependency though.

func WriteTemplates

func WriteTemplates(dir string)

WriteTemplates writes templates from the embedded FS to the new project templates/ directory.

Types

type Config

type Config struct {
	GSTPercent int
	Invoice    struct {
		NumOffset   int    // padd this to the numbers generated
		Template    string // path to template file
		Prefix      string // prefix to the numeric filename. eg. MIN to generate MIN46
		CompanyName string // TODO this should move out of the Invoice struct
		CompanyURL  string
	}
}

func ReadConfig

func ReadConfig() Config

type Invoice

type Invoice struct {
	Title          string     `json:"title"`
	CustomerName   string     `json:"customer_name"`
	Date           time.Time  `json:"date"`
	Items          []LineItem `json:"items"`
	CurrencyCode   string     `json:"currency_code"`
	CurrencySymbol string     `json:"currency_symbol"`
	Subtotal       int        `json:"subtotal"`    // cents
	GSTApplies     bool       `json:"gst_applies"` // do we calculate GST
	GST            int        `json:"gst"`         // cents
	Total          int        `json:"total" `      // cents
}

func CalculateTotals

func CalculateTotals(inv Invoice) Invoice

func UnmarshalJSONFile

func UnmarshalJSONFile(name string) Invoice

UnmarshalJSONFile opens a file in json/name.json.

type LineItem

type LineItem struct {
	Position         int     `json:"position"`
	Quantity         int     `json:"quantity"`
	Description      string  `json:"description"`
	UnitPriceDollars float64 `json:"unit_price_dollars"` // UnitPrice in dollars
	UnitPrice        int     // UnitPrice in cents
	TotalPrice       int     // TotalPrice in cents
	GST              int     // GST in cents
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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