-
Notifications
You must be signed in to change notification settings - Fork 53
/
generator.go
40 lines (31 loc) · 1023 Bytes
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Package generator allows you to easily generate invoices, delivery notes and quotations in GoLang.
package generator
import (
"errors"
"github.com/creasty/defaults"
"github.com/go-pdf/fpdf"
"github.com/leekchan/accounting"
)
var ErrInvalidDocumentType = errors.New("invalid document type")
// New return a new documents with provided types and defaults
func New(docType string, options *Options) (*Document, error) {
_ = defaults.Set(options)
if docType != Invoice && docType != Quotation && docType != DeliveryNote {
return nil, ErrInvalidDocumentType
}
doc := &Document{
Options: options,
Type: docType,
}
// Prepare pdf
doc.pdf = fpdf.New("P", "mm", "A4", "")
doc.Options.UnicodeTranslateFunc = doc.pdf.UnicodeTranslatorFromDescriptor("")
// Prepare accounting
doc.ac = accounting.Accounting{
Symbol: doc.Options.CurrencySymbol,
Precision: doc.Options.CurrencyPrecision,
Thousand: doc.Options.CurrencyThousand,
Decimal: doc.Options.CurrencyDecimal,
}
return doc, nil
}