generator

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

GoDoc

Golang invoice generator

A super fast golang package to generate invoices, delivery notes and quotations as pdf using https://github.com/jung-kurt/gofpdf.

Download from Github

go get -u github.com/angelodlfrtr/go-invoice-generator

Exemple output

DeliveryNoteExample

Quick start

package main

import (
  generator "github.com/angelodlfrtr/go-invoice-generator"
)

func main() {
	doc := generator.New(generator.INVOICE, &generator.Options{})

	doc.SetHeader(&generator.HeaderFooter{
		Text: "Some header text",
	})

	doc.SetFooter(&generator.HeaderFooter{
		Text:           "<center>Some footer text</center>",
		Pagination:     true,
	})

	doc.SetNumber("testnumber")
	doc.SetVersion("test version")

	doc.SetDescription("Some text describing document")

	doc.SetCompany(&generator.Contact{
		Name: "Test Company",
		Logo: []byte{}, // Image as byte array, supported format: png, jpeg, gif
		Address: &generator.Address{
			Address:    "89 Rue de Brest",
			Address2:   "Appartement 2",
			PostalCode: "75000",
			City:       "Paris",
			Country:    "France",
		},
	})

	doc.SetCustomer(&generator.Contact{
		Name: "Test Customer",
		Address: &generator.Address{
			Address:    "89 Rue de Paris",
			PostalCode: "29200",
			City:       "Brest",
			Country:    "France",
		},
	})

	doc.AppendItem(&generator.Item{
		Name:     "Item one",
		UnitCost: "89",
		Quantity: "2",
		Tax: &generator.Tax{
			Percent: "20",
		},
	})

	doc.AppendItem(&generator.Item{
		Name:     "Item two",
		UnitCost: "5.89",
		Quantity: "11",
		Tax: &generator.Tax{
			Amount: "10",
		},
	})

	pdf, err := doc.Build()

	if err != nil {
		fmt.Println(err.Error())
	}

	err = pdf.OutputFileAndClose("./out.pdf")

	if err != nil {
		fmt.Println(err.Error())
	}
}

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.

Documentation

Overview

Package generator allows you to easily generate invoices, delivery notes and quotations in GoLang.

Index

Examples

Constants

View Source
const BaseMargin float64 = 10
View Source
const BaseMarginTop float64 = 20
View Source
const DeliveryNote string = "DELIVERY_NOTE"
View Source
const HeaderMarginTop float64 = 5
View Source
const Invoice string = "INVOICE"
View Source
const MaxPageHeight float64 = 260
View Source
const Quotation string = "QUOTATION"

Variables

View Source
var BaseTextColor = []int{35, 35, 35}
View Source
var DarkBgColor = []int{212, 212, 212}
View Source
var GreyBgColor = []int{232, 232, 232}

Functions

This section is empty.

Types

type Address

type Address struct {
	Address    string `validate:"required" json:"address"`
	Address2   string `json:"address2"`
	PostalCode string `validate:"required" json:"postalCode"`
	City       string `validate:"required" json:"city"`
	Country    string `json:"country"`
}

func (*Address) ToString

func (a *Address) ToString() string

ToString output address as string Line break are added for new lines

type Bank

type Bank struct {
	PayBy         string // Tax in percent ex 17
	BankName      string // Tax in amount ex 123.40
	Address       string
	AccountType   string
	IFSC          string
	SWIFT         string
	AccountNumber string
	// contains filtered or unexported fields
}

type Contact

type Contact struct {
	Name    string  `validate:"required,min=1,max=64"`
	Address *Address
}

type Discount

type Discount struct {
	Percent string // Tax in percent ex 17
	Amount  string // Tax in amount ex 123.40
}

type Document

type Document struct {
	Options      *Options
	Header       *HeaderFooter
	Footer       *HeaderFooter
	Type         string `validate:"required,oneof=INVOICE DELIVERY_NOTE QUOTATION"`
	Ref          string `validate:"required,min=1,max=32"`
	Version      string `validate:"max=32"`
	ClientRef    string `validate:"max=64"`
	Description  string `validate:"max=1024"`
	Notes        string
	Company      *Contact `validate:"required"`
	Customer     *Contact `validate:"required"`
	Items        []*Item
	Date         string
	ValidityDate string
	PaymentTerm  string
	Bank         *Bank
}

func New

func New(docType string, options *Options) (*Document, error)
Example
doc, _ := New(DeliveryNote, &Options{
	TextTypeInvoice: "FACTURE",
	AutoPrint:       true,
})

doc.SetHeader(&HeaderFooter{
	Text:       "<center>Cupcake ipsum dolor sit amet bonbon. I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder.</center>",
	Pagination: true,
})

doc.SetFooter(&HeaderFooter{
	Text:       "<center>Cupcake ipsum dolor sit amet bonbon. I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder.</center>",
	Pagination: true,
})

doc.SetRef("testref")
doc.SetVersion("someversion")

doc.SetDescription("A description")

logoBytes, _ := ioutil.ReadFile("./example_logo.png")

doc.SetCompany(&Contact{
	Name: "Test Company",
	Logo: &logoBytes,
	Address: &Address{
		Address:    "89 Rue de Brest",
		Address2:   "Appartement 2",
		PostalCode: "75000",
		City:       "Paris",
		Country:    "France",
	},
})

doc.SetCustomer(&Contact{
	Name: "Test Customer",
	Address: &Address{
		Address:    "89 Rue de Paris",
		PostalCode: "29200",
		City:       "Brest",
		Country:    "France",
	},
})

for i := 0; i < 15; i++ {
	doc.AppendItem(&Item{
		Name:     "Test",
		UnitCost: "99876.89",
		Quantity: "2",
		Tax: &Tax{
			Percent: "20",
		},
	})
}

pdf, err := doc.Build()

if err != nil {
	fmt.Println(err.Error())
}

err = pdf.OutputFileAndClose("out.pdf")

if err != nil {
	fmt.Println(err.Error())
}
Output:

func (*Document) AppendItem

func (d *Document) AppendItem(item *Item) *Document

func (*Document) Build

func (d *Document) Build() (*gofpdf.Fpdf, error)

func (*Document) SetBank

func (d *Document) SetBank(b *Bank) *Document

func (*Document) SetCompany

func (d *Document) SetCompany(company *Contact) *Document

func (*Document) SetCustomer

func (d *Document) SetCustomer(customer *Contact) *Document

func (*Document) SetDate

func (d *Document) SetDate(date string) *Document

func (*Document) SetDescription

func (d *Document) SetDescription(desc string) *Document

func (*Document) SetFooter

func (d *Document) SetFooter(footer *HeaderFooter) *Document

func (*Document) SetHeader

func (d *Document) SetHeader(header *HeaderFooter) *Document

func (*Document) SetNotes

func (d *Document) SetNotes(notes string) *Document

func (*Document) SetPaymentTerm

func (d *Document) SetPaymentTerm(term string) *Document

func (*Document) SetRef

func (d *Document) SetRef(ref string) *Document

func (*Document) SetType

func (d *Document) SetType(docType string) *Document

func (*Document) SetVersion

func (d *Document) SetVersion(version string) *Document

func (*Document) Validate

func (d *Document) Validate() error

type HeaderFooter

type HeaderFooter struct {
	UseCustomFunc bool
	Text          string
	FontSize      float64 `default:"7"`
	Pagination    bool
}

func (*HeaderFooter) ApplyFunc

func (hf *HeaderFooter) ApplyFunc(pdf *gofpdf.Fpdf, fn fnc)

ApplyFunc allow user to apply custom func

type Item

type Item struct {
	Name        string `validate:"required"`
	Description string
	UnitCost    string
	Quantity    string
	Tax         *Tax
	Discount    *Discount
}

type Options

type Options struct {
	AutoPrint bool

	CurrencySymbol    string `default:"€ "`
	CurrencyPrecision int    `default:"2"`
	CurrencyDecimal   string `default:","`
	CurrencyThousand  string `default:"."`

	TextTypeInvoice      string `default:"INVOICE"`
	TextTypeQuotation    string `default:"QUOTATION"`
	TextTypeDeliveryNote string `default:"DELIVERY NOTE"`

	TextRefTitle         string `default:"Ref."`
	TextVersionTitle     string `default:"Version"`
	TextDateTitle        string `default:"Date"`
	TextPaymentTermTitle string `default:"Payment term"`

	TextItemsDescriptionTitle string `default:"Description"`
	TextItemsUnitCostTitle    string `default:"Unit price"`
	TextItemsQuantityTitle    string `default:"Quantity"`
	TextItemsTotalHTTitle     string `default:"Total"`
	TextItemsTaxTitle         string `default:"Tax"`
	TextItemsTotalTTCTitle    string `default:"Total with tax"`

	TextTotalTotal   string `default:"TOTAL"`
	TextTotalTax     string `default:"TAX"`
	TextTotalWithTax string `default:"TOTAL WITH TAX"`
}

type Tax

type Tax struct {
	Percent string // Tax in percent ex 17
	Amount  string // Tax in amount ex 123.40
}

Jump to

Keyboard shortcuts

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