-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
49 lines (42 loc) · 1.04 KB
/
utils.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
41
42
43
44
45
46
47
48
49
/*
Package invoice_generator
Copyright 2021 @chunvv. All Rights Reserved.
Created by Trung Vu on AD 2021/07/10.
*/
package invoice_generator
import (
"golang.org/x/text/currency"
"golang.org/x/text/language"
"golang.org/x/text/message"
"golang.org/x/text/number"
"math/rand"
"time"
)
var Letters = []rune("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
func encodeString(str string) string {
return str
}
func (d *Document) typeAsString() string {
if d.Type == Invoice {
return d.Options.TextTypeInvoice
}
if d.Type == Receipt {
return d.Options.TextTypeInvoice
}
return d.Options.TextTypeInvoice
}
func formatAmount(v int) string {
cur := currency.MustParseISO("JPY")
scale, _ := currency.Cash.Rounding(cur)
dec := number.Decimal(v, number.Scale(scale))
p := message.NewPrinter(language.Japanese)
return p.Sprintf("%v%v", currency.Symbol(cur), dec)
}
func GenerateInvoiceNumber() string {
rand.Seed(time.Now().UnixNano())
b := make([]rune, 8)
for i := range b {
b[i] = Letters[rand.Intn(len(Letters))]
}
return string(b) + "-001"
}