fix go names according to linter
This commit is contained in:
parent
1c89fd7af3
commit
58b0759c78
|
|
@ -1,5 +1,5 @@
|
||||||
mkinvoice
|
mkinvoice
|
||||||
makefont
|
makefont/makefont
|
||||||
temp/*
|
temp/*
|
||||||
qr-images/*
|
qr-images/*
|
||||||
output/*
|
output/*
|
||||||
|
|
|
||||||
175
mkinvoice.go
175
mkinvoice.go
|
|
@ -2,68 +2,73 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jung-kurt/gofpdf"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/jung-kurt/gofpdf"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Metadata type
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
Invoice_nr string
|
InvoiceNr string
|
||||||
Invoice_info string
|
InvoiceInfo string
|
||||||
Invoice_date string
|
InvoiceDdate string
|
||||||
Vat float64
|
Vat float64
|
||||||
Account string
|
Account string
|
||||||
Due_date string
|
DueDate string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Address type
|
||||||
type Address struct {
|
type Address struct {
|
||||||
Name string
|
Name string
|
||||||
Street string
|
Street string
|
||||||
Zip string
|
Zip string
|
||||||
City string
|
City string
|
||||||
Tel_no string
|
TelNo string
|
||||||
Email string
|
Email string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvoiceItem type
|
||||||
type InvoiceItem struct {
|
type InvoiceItem struct {
|
||||||
Text string
|
Text string
|
||||||
Quantity float64
|
Quantity float64
|
||||||
Pice_per_unit float64
|
PicePerUnit float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvoiceData type
|
||||||
type InvoiceData struct {
|
type InvoiceData struct {
|
||||||
Metadata Metadata
|
Metadata Metadata
|
||||||
Sender_address Address
|
SenderAddress Address
|
||||||
Billing_address Address
|
BillingAddress Address
|
||||||
Item []InvoiceItem
|
Item []InvoiceItem
|
||||||
}
|
}
|
||||||
|
|
||||||
/* global variable declaration */
|
/* global variable declaration */
|
||||||
var pdf *gofpdf.Fpdf
|
var pdf *gofpdf.Fpdf
|
||||||
var y_pos float64
|
var yPos float64
|
||||||
var invoice_data InvoiceData
|
var invoiceData InvoiceData
|
||||||
var prog_dir string
|
var progDir string
|
||||||
|
|
||||||
const margin_top = 7
|
const marginTop = 7
|
||||||
const logo_top = 6
|
const logoTop = 6
|
||||||
const logo_height = 20
|
const logoHeight = 20
|
||||||
const line_spacing = 5
|
const lineSpacing = 5
|
||||||
const address_top = 50
|
const addressTop = 50
|
||||||
const line1_top = 100
|
const line1Top = 100
|
||||||
const tabstop_left = 20
|
const tabstopLeft = 20
|
||||||
const tabstop_left_2 = 32
|
const tabstopLeftAlt = 32
|
||||||
const tabstop_address = 120
|
const tabstopAddress = 120
|
||||||
const tabstop_count = 10
|
const tabstopCount = 10
|
||||||
const tabstop_price = 10
|
const tabstopPrice = 10
|
||||||
const tabstop_total = 170
|
const tabstopTotal = 170
|
||||||
const tabstop_logo = 155
|
const tabstopLogo = 155
|
||||||
const tabstop_right = 200
|
const tabstopRight = 200
|
||||||
|
|
||||||
func ReadInvoiceData(filename string) {
|
func readInvoiceData(filename string) {
|
||||||
data, err := ioutil.ReadFile(filename)
|
data, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
@ -71,16 +76,16 @@ func ReadInvoiceData(filename string) {
|
||||||
|
|
||||||
//fmt.Printf("File contents: %s", data)
|
//fmt.Printf("File contents: %s", data)
|
||||||
|
|
||||||
err = yaml.Unmarshal([]byte(data), &invoice_data)
|
err = yaml.Unmarshal([]byte(data), &invoiceData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: %v", err)
|
log.Fatalf("error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("--- t:\n%v\n\n", invoice_data)
|
fmt.Printf("--- t:\n%v\n\n", invoiceData)
|
||||||
fmt.Printf("%s\n", invoice_data.Billing_address.Name)
|
fmt.Printf("%s\n", invoiceData.BillingAddress.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteText(x float64, y float64, text string, alignStr ...string) {
|
func writeText(x float64, y float64, text string, alignStr ...string) {
|
||||||
tr := pdf.UnicodeTranslatorFromDescriptor("")
|
tr := pdf.UnicodeTranslatorFromDescriptor("")
|
||||||
align := "LT"
|
align := "LT"
|
||||||
if len(alignStr) > 0 {
|
if len(alignStr) > 0 {
|
||||||
|
|
@ -90,7 +95,7 @@ func WriteText(x float64, y float64, text string, alignStr ...string) {
|
||||||
pdf.CellFormat(0, 11, tr(text), "", 0, align, false, 0, "")
|
pdf.CellFormat(0, 11, tr(text), "", 0, align, false, 0, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupInvoice() {
|
func setupInvoice() {
|
||||||
pdf = gofpdf.New("P", "mm", "A4", "")
|
pdf = gofpdf.New("P", "mm", "A4", "")
|
||||||
pdf.SetMargins(0, 0, 0)
|
pdf.SetMargins(0, 0, 0)
|
||||||
pdf.SetFontLocation("fonts")
|
pdf.SetFontLocation("fonts")
|
||||||
|
|
@ -99,64 +104,64 @@ func SetupInvoice() {
|
||||||
pdf.SetFont("Dejavusans", "", 10)
|
pdf.SetFont("Dejavusans", "", 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintPageHeader(firstPage bool) {
|
func printPageHeader(firstPage bool) {
|
||||||
var opt gofpdf.ImageOptions
|
var opt gofpdf.ImageOptions
|
||||||
|
|
||||||
pdf.AddPage()
|
pdf.AddPage()
|
||||||
y_pos = margin_top
|
yPos = marginTop
|
||||||
pdf.SetFont("Dejavusans-Bold", "", 10)
|
pdf.SetFont("Dejavusans-Bold", "", 10)
|
||||||
WriteText(tabstop_left, y_pos, "nbit Informatik GmbH")
|
writeText(tabstopLeft, yPos, "nbit Informatik GmbH")
|
||||||
pdf.SetFont("Dejavusans", "", 10)
|
pdf.SetFont("Dejavusans", "", 10)
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
WriteText(tabstop_left, y_pos, "Kirchweg 2")
|
writeText(tabstopLeft, yPos, "Kirchweg 2")
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
WriteText(tabstop_left, y_pos, "3510 Konolfingen")
|
writeText(tabstopLeft, yPos, "3510 Konolfingen")
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
WriteText(tabstop_left, y_pos, "Tel.")
|
writeText(tabstopLeft, yPos, "Tel.")
|
||||||
WriteText(tabstop_left_2, y_pos, "+41 31 792 00 40")
|
writeText(tabstopLeftAlt, yPos, "+41 31 792 00 40")
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
WriteText(tabstop_left, y_pos, "EMail")
|
writeText(tabstopLeft, yPos, "EMail")
|
||||||
WriteText(tabstop_left_2, y_pos, "joerg.lehmann@nbit.ch")
|
writeText(tabstopLeftAlt, yPos, "joerg.lehmann@nbit.ch")
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
|
|
||||||
opt.ImageType = "png"
|
opt.ImageType = "png"
|
||||||
opt.ReadDpi = true
|
opt.ReadDpi = true
|
||||||
pdf.ImageOptions("logos/nbit-logo.png", tabstop_logo, logo_top, 0, logo_height, false, opt, 0, "")
|
pdf.ImageOptions("logos/nbit-logo.png", tabstopLogo, logoTop, 0, logoHeight, false, opt, 0, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintAddress() {
|
func printAddress() {
|
||||||
fmt.Printf("Blabla: %s\n", invoice_data.Billing_address.Name)
|
fmt.Printf("Blabla: %s\n", invoiceData.BillingAddress.Name)
|
||||||
y_pos = address_top
|
yPos = addressTop
|
||||||
WriteText(tabstop_address, y_pos, invoice_data.Billing_address.Name)
|
writeText(tabstopAddress, yPos, invoiceData.BillingAddress.Name)
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
WriteText(tabstop_address, y_pos, invoice_data.Billing_address.Street)
|
writeText(tabstopAddress, yPos, invoiceData.BillingAddress.Street)
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
WriteText(tabstop_address, y_pos, invoice_data.Billing_address.Zip+" "+invoice_data.Billing_address.City)
|
writeText(tabstopAddress, yPos, invoiceData.BillingAddress.Zip+" "+invoiceData.BillingAddress.City)
|
||||||
y_pos = y_pos + line_spacing
|
yPos = yPos + lineSpacing
|
||||||
|
|
||||||
pdf.Line(tabstop_left, line1_top, tabstop_right, line1_top)
|
pdf.Line(tabstopLeft, line1Top, tabstopRight, line1Top)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintQR() {
|
func printQR() {
|
||||||
var opt gofpdf.ImageOptions
|
var opt gofpdf.ImageOptions
|
||||||
|
|
||||||
cmd := exec.Command(filepath.Join(prog_dir, "qrbill.sh"),
|
cmd := exec.Command(filepath.Join(progDir, "qrbill.sh"),
|
||||||
"--account", invoice_data.Metadata.Account,
|
"--account", invoiceData.Metadata.Account,
|
||||||
"--amount", "123.00",
|
"--amount", "123.00",
|
||||||
"--creditor-name", invoice_data.Sender_address.Name,
|
"--creditor-name", invoiceData.SenderAddress.Name,
|
||||||
"--creditor-street", invoice_data.Sender_address.Street,
|
"--creditor-street", invoiceData.SenderAddress.Street,
|
||||||
"--creditor-postalcode", invoice_data.Sender_address.Zip,
|
"--creditor-postalcode", invoiceData.SenderAddress.Zip,
|
||||||
"--creditor-city", invoice_data.Sender_address.City,
|
"--creditor-city", invoiceData.SenderAddress.City,
|
||||||
"--extra-infos", invoice_data.Metadata.Invoice_info,
|
"--extra-infos", invoiceData.Metadata.InvoiceInfo,
|
||||||
"--debtor-name", invoice_data.Billing_address.Name,
|
"--debtor-name", invoiceData.BillingAddress.Name,
|
||||||
"--debtor-street", invoice_data.Billing_address.Street,
|
"--debtor-street", invoiceData.BillingAddress.Street,
|
||||||
"--debtor-postalcode", invoice_data.Billing_address.Zip,
|
"--debtor-postalcode", invoiceData.BillingAddress.Zip,
|
||||||
"--debtor-city", invoice_data.Billing_address.City,
|
"--debtor-city", invoiceData.BillingAddress.City,
|
||||||
"--due-date", invoice_data.Metadata.Due_date,
|
"--due-date", invoiceData.Metadata.DueDate,
|
||||||
"--language", "de")
|
"--language", "de")
|
||||||
cmd.Env = append(os.Environ(),
|
cmd.Env = append(os.Environ(),
|
||||||
"INVNO="+invoice_data.Metadata.Invoice_nr,
|
"INVNO="+invoiceData.Metadata.InvoiceNr,
|
||||||
)
|
)
|
||||||
stdoutStderr, err := cmd.CombinedOutput()
|
stdoutStderr, err := cmd.CombinedOutput()
|
||||||
fmt.Printf("%s\n", stdoutStderr)
|
fmt.Printf("%s\n", stdoutStderr)
|
||||||
|
|
@ -167,7 +172,7 @@ func PrintQR() {
|
||||||
|
|
||||||
opt.ImageType = "jpeg"
|
opt.ImageType = "jpeg"
|
||||||
opt.ReadDpi = true
|
opt.ReadDpi = true
|
||||||
pdf.ImageOptions("qr-images/"+invoice_data.Metadata.Invoice_nr+".jpg", 0, 200, 0, 0, false, opt, 0, "")
|
pdf.ImageOptions("qr-images/"+invoiceData.Metadata.InvoiceNr+".jpg", 0, 200, 0, 0, false, opt, 0, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -175,20 +180,20 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
prog_dir = dir
|
progDir = dir
|
||||||
|
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
fmt.Printf("usage: mkinvoice <yaml-file>\n")
|
fmt.Printf("usage: mkinvoice <yaml-file>\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadInvoiceData(os.Args[1])
|
readInvoiceData(os.Args[1])
|
||||||
SetupInvoice()
|
setupInvoice()
|
||||||
PrintPageHeader(true)
|
printPageHeader(true)
|
||||||
PrintAddress()
|
printAddress()
|
||||||
PrintQR()
|
printQR()
|
||||||
|
|
||||||
err = pdf.OutputFileAndClose(filepath.Join(prog_dir, "output", invoice_data.Metadata.Invoice_nr+".pdf"))
|
err = pdf.OutputFileAndClose(filepath.Join(progDir, "output", invoiceData.Metadata.InvoiceNr+".pdf"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Printf("Successfully created invoice\n")
|
fmt.Printf("Successfully created invoice\n")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue