From d9e2ed5e2f30e78f701f1d00ebc5eafd2c2f0204 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Thu, 28 Dec 2023 13:37:38 +0100 Subject: [PATCH] first roughly working balance sheet... --- bookkeeper.go | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/bookkeeper.go b/bookkeeper.go index b90781d..a74e130 100644 --- a/bookkeeper.go +++ b/bookkeeper.go @@ -80,7 +80,24 @@ func accountBalanceExists(s string) bool { } func calculateVAT(vat_code string, amount float64) float64 { - return 0.0 + if vat_code == "" { + return 0.0 + } + vat_type := string(vat_code[0]) + vat_perc, err := strconv.Atoi(vat_code[1:]) + if err != nil { + fmt.Println(err) + return 0.0 + } + vat_perc_f64 := float64(vat_perc) + if vat_type == "V" { + return 0 - (amount / (1000.0 + vat_perc_f64) * vat_perc_f64) + } else if vat_type == "I" { + return (amount / (1000.0 + vat_perc_f64) * vat_perc_f64) + } else { + fmt.Printf("WARNING: Invalid Vat Type: %s\n", vat_type) + 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) { @@ -131,8 +148,11 @@ func addTransaction(document_number string, date string, text string, account_nu } else { myBalance.balance_end = myBalance.balance_end - myItem.Amount } + if myItem.Amount_Vat > 0 { + myBalance.balance_end = myBalance.balance_end - myItem.Amount_Vat + } account_balance[account_number_debit] = myBalance - if account_number_debit == "2202" { + if account_number_debit == "3400" { fmt.Printf("DEBUG DEBIT: %s,%s,%v,%v\n", account_number_debit, account_type, myItem.Amount, myBalance) } @@ -143,21 +163,25 @@ func addTransaction(document_number string, date string, text string, account_nu } else { myBalance.balance_end = myBalance.balance_end + myItem.Amount } + if myItem.Amount_Vat < 0 { + myBalance.balance_end = myBalance.balance_end + myItem.Amount_Vat + } account_balance[account_number_credit] = myBalance - if account_number_credit == "2202" { + if account_number_credit == "3400" { 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 + fmt.Printf("DEBUG MWST: %s: %v,%v\n", document_number, myItem.Amount_Vat, myBalance) 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"]) - // } + 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)] if ok {