From 46e3dccd2a5a88edea62caff48481d653c88a584 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Wed, 10 Jan 2024 19:51:54 +0100 Subject: [PATCH] complete first version of journal --- bookkeeper.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/bookkeeper.go b/bookkeeper.go index ce8e922..5b05e20 100644 --- a/bookkeeper.go +++ b/bookkeeper.go @@ -58,6 +58,7 @@ var balanceYear = "UNDEFINED" var profit float64 = 0.0 const reportTitle = "Jahresrechnung - nbit Informatik GmbH" +const journalTitle = "Journal - nbit Informatik GmbH" const MWST_ACCOUNT = "2201" const defaultFontSize = 12 const smallFontSize = 8 @@ -70,6 +71,7 @@ const widthAmount = 28 const dashCorrectionXleft = 1.2 const dashCorrectionXright = -1.3 const dashCorrectionY = 3.5 +const avoidMinusZero = 0.00001 func roundRappen(f float64) float64 { return (math.Round(f*100) / 100) @@ -653,6 +655,53 @@ func outputMwst(whatquarter string) { } } +func doAdd(isDebit bool, account string) bool { + account_type := accountType(account) + + if (account_type == "A") || (account_type == "E") || (account_type == "L") { + return isDebit + } else { + return !isDebit + } +} + +func outputAccount(account string) { + fmt.Printf("START ACCOUNT %s (%s), Balance: %.2f\n", account, accounts[account], account_balance[account].balance_start+avoidMinusZero) + var current_balance float64 = account_balance[account].balance_start + var document_numbers []int + for k := range transactions { + document_numbers = append(document_numbers, int(k)) + } + sort.Ints(document_numbers) + for _, k := range document_numbers { + for _, item := range transactions[uint16(k)].Items { + if item.Debit == account || item.Credit == account { + if doAdd(item.Debit == account, account) { + current_balance = current_balance + item.Amount + } else { + current_balance = current_balance - item.Amount + } + fmt.Printf("%-5d %s %-4v %-4v %-80v %11.2f %-5v %11.2f %11.2f\n", k, transactions[uint16(k)].Date.Format("02.01.2006"), item.Debit, item.Credit, item.Description, item.Amount, item.Vat_code, item.Amount_Vat, current_balance+avoidMinusZero) + } + } + + } + fmt.Printf("END ACCOUNT %s (%s), Balance: %.2f\n\n", account, accounts[account], account_balance[account].balance_end+avoidMinusZero) +} + +func outputJournal() { + fmt.Printf("%s - YEAR: %s\n", journalTitle, balanceYear) + fmt.Printf("Created at: %s\n\n", time.Now().Format("02.01.2006 15:04:05")) + var active_accounts []string + for k := range account_balance { + active_accounts = append(active_accounts, k) + } + sort.Strings(active_accounts) + for _, k := range active_accounts { + outputAccount(k) + } +} + func usage() { fmt.Fprintf(os.Stderr, "usage: bookkeeper \n") fmt.Fprintf(os.Stderr, "\n") @@ -681,6 +730,7 @@ func main() { createBalanceSheet() case "journal": fmt.Fprintln(os.Stderr, "INFO: Create Journal") + outputJournal() case "mwst1", "mwst2", "mwst3", "mwst4": fmt.Fprintln(os.Stderr, "INFO: Create Mwst Quarterly Report") outputMwst(action)