some more development
This commit is contained in:
parent
fd5b658b1a
commit
0fda652827
|
|
@ -18,7 +18,7 @@ action can be one of the following:
|
||||||
|
|
||||||
<accounts file> is a text file with the following format (example line):
|
<accounts file> is a text file with the following format (example line):
|
||||||
|
|
||||||
1020,Kontokorrent UBS 235-566236.01G
|
1020,A:Kontokorrent UBS 235-566236.01G
|
||||||
|
|
||||||
1020: Account number: 1XXX => Assets
|
1020: Account number: 1XXX => Assets
|
||||||
2XXX => Liabilities
|
2XXX => Liabilities
|
||||||
|
|
@ -28,6 +28,8 @@ action can be one of the following:
|
||||||
6XXX => Operating Expenses
|
6XXX => Operating Expenses
|
||||||
8XXX => Expense
|
8XXX => Expense
|
||||||
|
|
||||||
|
A: Type (A)ssets, (L)iabilities, (E)xpenses, (I)ncome
|
||||||
|
|
||||||
Kontokorrent UBS 235-566236.01G: Account Text
|
Kontokorrent UBS 235-566236.01G: Account Text
|
||||||
|
|
||||||
<transactions file> is a CSV file with the following format (example line):
|
<transactions file> is a CSV file with the following format (example line):
|
||||||
|
|
|
||||||
124
bookkeeper.go
124
bookkeeper.go
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -43,13 +44,14 @@ var account_balance = make(map[string]Balance)
|
||||||
var balanceYear = "UNDEFINED"
|
var balanceYear = "UNDEFINED"
|
||||||
|
|
||||||
const reportTitle = "Jahresrechnung - nbit Informatik GmbH"
|
const reportTitle = "Jahresrechnung - nbit Informatik GmbH"
|
||||||
|
const MWST_ACCOUNT = "2201"
|
||||||
const defaultFontSize = 9
|
const defaultFontSize = 9
|
||||||
const smallFontSize = 7
|
const smallFontSize = 7
|
||||||
const marginTop = 10
|
const marginTop = 10
|
||||||
const smallLineSpacing = 4
|
const smallLineSpacing = 4
|
||||||
const lineSpacing = 5
|
const lineSpacing = 5
|
||||||
const tabstopLeft = 25
|
const tabstopLeft = 35
|
||||||
const tabstopRight = 100
|
const tabstopRight = 160
|
||||||
const widthAmount = 28
|
const widthAmount = 28
|
||||||
const dashCorrectionXleft = 1.2
|
const dashCorrectionXleft = 1.2
|
||||||
const dashCorrectionXright = -1.3
|
const dashCorrectionXright = -1.3
|
||||||
|
|
@ -64,8 +66,24 @@ func accountExists(s string) bool {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func accountType(s string) string {
|
||||||
|
return accounts[s][0:1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func accountDescription(s string) string {
|
||||||
|
return accounts[s][2:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func accountBalanceExists(s string) bool {
|
||||||
|
_, ok := account_balance[s]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateVAT(vat_code string, amount float64) float64 {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
func addTransaction(document_number string, date string, text string, account_number_debit string, account_number_credit string, amount string, vat_code string) {
|
func addTransaction(document_number string, date string, text string, account_number_debit string, account_number_credit string, amount string, vat_code string) {
|
||||||
//fmt.Printf("Calling addTransaction with amount: %s\n", amount)
|
|
||||||
dateString := "02.01.2006"
|
dateString := "02.01.2006"
|
||||||
mydate, error := time.Parse(dateString, date)
|
mydate, error := time.Parse(dateString, date)
|
||||||
|
|
||||||
|
|
@ -101,6 +119,45 @@ func addTransaction(document_number string, date string, text string, account_nu
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
myItem.Vat_code = vat_code
|
myItem.Vat_code = vat_code
|
||||||
|
myItem.Amount_Vat = calculateVAT(vat_code, myItem.Amount)
|
||||||
|
|
||||||
|
// adjust balance values
|
||||||
|
var myBalance Balance
|
||||||
|
myBalance = account_balance[account_number_debit]
|
||||||
|
account_type := accountType(account_number_debit)
|
||||||
|
|
||||||
|
if (account_type == "A") || (account_type == "E") || (account_type == "L") {
|
||||||
|
myBalance.balance_end = myBalance.balance_end + myItem.Amount
|
||||||
|
} else {
|
||||||
|
myBalance.balance_end = myBalance.balance_end - myItem.Amount
|
||||||
|
}
|
||||||
|
account_balance[account_number_debit] = myBalance
|
||||||
|
if account_number_debit == "2202" {
|
||||||
|
fmt.Printf("DEBUG DEBIT: %s,%s,%v,%v\n", account_number_debit, account_type, myItem.Amount, myBalance)
|
||||||
|
}
|
||||||
|
|
||||||
|
myBalance = account_balance[account_number_credit]
|
||||||
|
account_type2 := accountType(account_number_credit)
|
||||||
|
if (account_type2 == "A") || (account_type2 == "E") || (account_type2 == "L") {
|
||||||
|
myBalance.balance_end = myBalance.balance_end - myItem.Amount
|
||||||
|
} else {
|
||||||
|
myBalance.balance_end = myBalance.balance_end + myItem.Amount
|
||||||
|
}
|
||||||
|
account_balance[account_number_credit] = myBalance
|
||||||
|
if account_number_credit == "2202" {
|
||||||
|
fmt.Printf("DEBUG CREDIT: %s,%s,%v,%v\n", account_number_credit, account_type2, myItem.Amount, myBalance)
|
||||||
|
}
|
||||||
|
|
||||||
|
myBalance = account_balance[MWST_ACCOUNT]
|
||||||
|
myBalance.balance_end = myBalance.balance_end + myItem.Amount_Vat
|
||||||
|
account_balance[MWST_ACCOUNT] = myBalance
|
||||||
|
|
||||||
|
//if account_number_debit == "3400" {
|
||||||
|
// fmt.Printf("DEBUG DEBIT: Document %s, found 3400 transaction: %v\n", document_number, amount)
|
||||||
|
// }
|
||||||
|
// if account_number_credit == "3400" {
|
||||||
|
// fmt.Printf("DEBUG CREDIT: Document %s, found 3400 transaction: %v\n", document_number, account_balance["3400"])
|
||||||
|
// }
|
||||||
|
|
||||||
_, ok := transactions[uint16(document_number_i)]
|
_, ok := transactions[uint16(document_number_i)]
|
||||||
if ok {
|
if ok {
|
||||||
|
|
@ -126,15 +183,15 @@ func readAccountData(filename string) {
|
||||||
line_number := 1
|
line_number := 1
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
matched, _ := regexp.MatchString(`^[0-9][0-9][0-9][0-9],.*`, line)
|
matched, _ := regexp.MatchString(`^[0-9][0-9][0-9][0-9],[ALEI]:.*`, line)
|
||||||
if !matched {
|
if !matched {
|
||||||
fmt.Printf("WARNING: Line %v in Accountfile %s: line not four digits followed by a comma: %s and will be ignored.\n", line_number, filename, line)
|
fmt.Printf("WARNING: Line %v in Accountfile %s: line not four digits followed by a comma followed by ALEI (one of those), Colon and description: %s and will be ignored.\n", line_number, filename, line)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
token := strings.SplitN(line, ",", 2)
|
token := strings.SplitN(line, ",", 2)
|
||||||
account_number := token[0]
|
account_number := token[0]
|
||||||
account_description := token[1]
|
account_type_and_description := token[1]
|
||||||
|
|
||||||
if accountExists(account_number) {
|
if accountExists(account_number) {
|
||||||
fmt.Printf("WARNING: Line %v in Accountfile %s: Account Number %s already exists and will be ignored\n", line_number, filename, account_number)
|
fmt.Printf("WARNING: Line %v in Accountfile %s: Account Number %s already exists and will be ignored\n", line_number, filename, account_number)
|
||||||
|
|
@ -142,7 +199,7 @@ func readAccountData(filename string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts[account_number] = account_description
|
accounts[account_number] = account_type_and_description
|
||||||
|
|
||||||
line_number++
|
line_number++
|
||||||
}
|
}
|
||||||
|
|
@ -230,6 +287,7 @@ func readTransactionData(filename string) {
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
//fmt.Printf("DEBUG BLABLA: %v\n", account_balance["3400"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeText(x float64, y float64, w float64, text string, alignStr ...string) {
|
func writeText(x float64, y float64, w float64, text string, alignStr ...string) {
|
||||||
|
|
@ -265,20 +323,21 @@ func printPageHeader() {
|
||||||
|
|
||||||
func printSection(section string) {
|
func printSection(section string) {
|
||||||
var title string
|
var title string
|
||||||
var chars string
|
var change_sign bool = false
|
||||||
switch section {
|
switch section {
|
||||||
case "assets":
|
// Assets
|
||||||
|
case "A":
|
||||||
title = "AKTIVEN"
|
title = "AKTIVEN"
|
||||||
chars = "1"
|
// Liabilities
|
||||||
case "liabilities":
|
case "L":
|
||||||
title = "PASSIVEN"
|
title = "PASSIVEN"
|
||||||
chars = "2"
|
change_sign = true
|
||||||
case "expense":
|
// Expense
|
||||||
|
case "E":
|
||||||
title = "AUFWAND"
|
title = "AUFWAND"
|
||||||
chars = "568"
|
// Income
|
||||||
case "income":
|
case "I":
|
||||||
title = "ERTRAG"
|
title = "ERTRAG"
|
||||||
chars = "4"
|
|
||||||
default:
|
default:
|
||||||
fmt.Printf("WARNING: invalid section: %s\n", section)
|
fmt.Printf("WARNING: invalid section: %s\n", section)
|
||||||
return
|
return
|
||||||
|
|
@ -291,12 +350,26 @@ func printSection(section string) {
|
||||||
yPos = yPos + smallLineSpacing
|
yPos = yPos + smallLineSpacing
|
||||||
pdf.SetFont("Dejavusans", "", smallFontSize)
|
pdf.SetFont("Dejavusans", "", smallFontSize)
|
||||||
pdf.SetDashPattern([]float64{0.2, 0.2}, 0)
|
pdf.SetDashPattern([]float64{0.2, 0.2}, 0)
|
||||||
for key, element := range account_balance {
|
|
||||||
if strings.Contains(chars, key[0:1]) {
|
// Extract keys from map
|
||||||
writeText(tabstopLeft, yPos, 0, accounts[key])
|
keys := make([]string, 0, len(account_balance))
|
||||||
writeText(tabstopRight, yPos, widthAmount, floatToString(element.balance_end, "'"), "TR")
|
for k := range account_balance {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort keys
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
|
if accountType(key) == section {
|
||||||
|
writeText(tabstopLeft, yPos, 0, key+": "+accountDescription(key))
|
||||||
|
balance_end := account_balance[key].balance_end
|
||||||
|
if change_sign {
|
||||||
|
balance_end = 0 - balance_end
|
||||||
|
}
|
||||||
|
writeText(tabstopRight, yPos, widthAmount, floatToString(balance_end, "'"), "TR")
|
||||||
pdf.Line(tabstopLeft+dashCorrectionXleft, yPos+dashCorrectionY, tabstopRight+widthAmount+dashCorrectionXright, yPos+dashCorrectionY)
|
pdf.Line(tabstopLeft+dashCorrectionXleft, yPos+dashCorrectionY, tabstopRight+widthAmount+dashCorrectionXright, yPos+dashCorrectionY)
|
||||||
total = total + element.balance_end
|
total = total + balance_end
|
||||||
yPos = yPos + smallLineSpacing
|
yPos = yPos + smallLineSpacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -310,10 +383,10 @@ func printSection(section string) {
|
||||||
func createBalanceSheet() {
|
func createBalanceSheet() {
|
||||||
setupBalanceSheet()
|
setupBalanceSheet()
|
||||||
printPageHeader()
|
printPageHeader()
|
||||||
printSection("assets")
|
printSection("A")
|
||||||
printSection("liabilities")
|
printSection("L")
|
||||||
printSection("expense")
|
printSection("E")
|
||||||
printSection("income")
|
printSection("I")
|
||||||
err := pdf.OutputFileAndClose("output.pdf")
|
err := pdf.OutputFileAndClose("output.pdf")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Printf("Successfully created Balance Sheet in file output.pdf\n")
|
fmt.Printf("Successfully created Balance Sheet in file output.pdf\n")
|
||||||
|
|
@ -339,6 +412,7 @@ func main() {
|
||||||
|
|
||||||
//fmt.Printf("accounts: %#v\n", accounts)
|
//fmt.Printf("accounts: %#v\n", accounts)
|
||||||
//fmt.Printf("transactions: %#v\n", transactions)
|
//fmt.Printf("transactions: %#v\n", transactions)
|
||||||
|
fmt.Printf("transactions: %#v\n", transactions[18])
|
||||||
//fmt.Printf("account_balance: %#v\n", account_balance)
|
//fmt.Printf("account_balance: %#v\n", account_balance)
|
||||||
|
|
||||||
switch action := os.Args[1]; action {
|
switch action := os.Args[1]; action {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue