Documentation ¶
Index ¶
- func CentsToString(c int) string
- func FormatDate(t time.Time) string
- func InitProject(dirName string)
- func MarshalJSONFile(inv Invoice, name string)
- func NewJSONFile(name string)
- func NextNumber() int
- func WriteConfig(name string)
- func WriteHTML(inv Invoice, name string, templatePath string)
- func WritePDF(inv Invoice)
- func WritePDFChrome(inv Invoice)
- func WriteTemplates(dir string)
- type Config
- type Invoice
- type LineItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CentsToString ¶
CentsToString converts integer cents to a human-readable currency string
func FormatDate ¶
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 ¶
MarshalJSONFile writes inv to name.json as 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 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 UnmarshalJSONFile ¶
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 }