From a21585db9f2366a60de0ba6dfe94d9dc0bc8ca29 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 9 Nov 2014 18:28:59 +0100 Subject: [PATCH] added 'date selection' , todo: make iaa the only account data + add umsatzsteuervorerklaerung calcs --- gocash.go | 264 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 175 insertions(+), 89 deletions(-) diff --git a/gocash.go b/gocash.go index ae679b8..2c3646d 100644 --- a/gocash.go +++ b/gocash.go @@ -20,6 +20,7 @@ const pid_misc = string("e3acc2865dbf931e41cf2b90240de5c2") const pid_rep = string("b1d04ad157cac569f4299d4ddf94ed6f") const pid_room = string("4394ed4ffa7266f8f8731080926a7a61") const pid_cap = string("4196ee026d1bdb785df2c975fca91ae0") +const aid_werbe = string("cb67d346eac01c2b66e2394df4e8d6e8") // abziehbare vst 19% and 7% const aid_vst_n = string("7c449e13125d6b93043f963628106db2") const aid_vst_s = string("006643c1c0a91f2b40614c75a49c6295") @@ -33,6 +34,58 @@ const aid_dep = string("9772f4e231f6f5e3100132cc53eb3447") const aid_ust_n = string("e4bd6ff52408be8076f24aeb105893d9") const aid_ust_s = string("38bf40d16529f2a1e611c073c6c1dc9c") +type inv_accnts struct { + id string + taxval int + tax bool + buy bool +} + +// make these account data the only one, above p/aids redundant! +// we have all the information in here! + +var iaa []inv_accnts = []inv_accnts{ +// wareneingang 19% and 7% (note: pids!) + { "8e3b7c42e3173ed85f3d4736e82afb4d",19,false,true }, + { "0cfd2ceb45fff89b9d1b7ce3af66cdf3", 7,false,true }, + { "e3acc2865dbf931e41cf2b90240de5c2",19,false,true }, + { "b1d04ad157cac569f4299d4ddf94ed6f",19,false,true }, + { "4394ed4ffa7266f8f8731080926a7a61",19,false,true }, + { "4196ee026d1bdb785df2c975fca91ae0",19,false,true }, +// aids ... + { "cb67d346eac01c2b66e2394df4e8d6e8",19,false,true }, +// abziehbare vst 19% and 7% + { "7c449e13125d6b93043f963628106db2",19,true,true }, + { "006643c1c0a91f2b40614c75a49c6295", 7,true,true }, +// --- sales +// receipts + { "f3e905732b729ba096a50dab60559ce7",19,false,false }, + { "66c1b04bd897766cb2be538094e1db6a", 7,false,false }, + { "1d20024badc11a99a8e1cf3a9a64a501",19,false,false }, + { "9772f4e231f6f5e3100132cc53eb3447",19,false,false }, +// ust + { "e4bd6ff52408be8076f24aeb105893d9",19,true,false }, + { "38bf40d16529f2a1e611c073c6c1dc9c", 7,true,false }, +} + +// transacion exception list +var trn_exc = []string{ + "GEMA", + "Deutsche Post", + "gesetz IHK", + "Gesundheitsbelehrung", + "Gewerbezentralregister", + "Entgeltabrechnung siehe Anlage", + "ENTGELT SPK", + "ttenrecht und F", + "Unterrichtung Gastst", +} + +// account exception list +var account_exc = []string{ + "4970 Nebenkosten des", +} + // account maps type amap struct { pid string // parent id @@ -76,6 +129,12 @@ var data ParsedData func main() { + // argv + sel_date := "" + if len(os.Args) > 1 { + sel_date = os.Args[1] + } + // open xml file file, err := os.Open("c13_skr03.gnucash") if err != nil { @@ -101,6 +160,7 @@ func main() { // whooha, this is our data! fmt.Println("Parsed accounts:",len(data.Accnt)) fmt.Println("Parsed transactions:",len(data.Trn)) + fmt.Println("") accnt := make(map[string]amap) @@ -117,7 +177,7 @@ func main() { switch { // ---- buy // -- goods - case pid == pid_buy_n || pid == pid_misc || pid == pid_rep || pid == pid_room || pid == pid_cap: + case pid == pid_buy_n || pid == pid_misc || pid == pid_rep || pid == pid_room || pid == pid_cap || aid == aid_werbe: tmp.taxval=19 tmp.buy=true rid[0]=aid_vst_n @@ -132,7 +192,7 @@ func main() { tmp.taxval=19 tmp.buy=true tmp.tax=true - rid=[]string{pid_buy_n,pid_misc,pid_rep,pid_room,pid_cap,} + rid=[]string{pid_buy_n,pid_misc,pid_rep,pid_room,pid_cap,aid_werbe,} accnt[aid]=tmp case aid == aid_vst_s: tmp.taxval=7 @@ -166,110 +226,135 @@ func main() { // check transactions ... for tc := range data.Trn { - // ... and all the accounts involved - for tsc := range data.Trn[tc].Spl { - aid := data.Trn[tc].Spl[tsc].AccountId - if check_trn(&data.Trn[tc],accnt,aid) == false { - ac := accnt[aid].num - fmt.Println(" ",data.Trn[tc].Date) - fmt.Println(" ",data.Trn[tc].Description) - fmt.Println(" ",data.Accnt[ac].Name) - fmt.Println("") - } - } + // check balance ... + check_balance(&data.Trn[tc],accnt,sel_date) } } -func check_trn(ta *Transaction,accnt map[string]amap,aid string) bool { - //ac := accnt[aid].num - if accnt[aid].rid[0]=="NONE" { +func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool { + + // check date + tdate := strings.Fields(ta.Date)[0] + if !strings.Contains(tdate,sel_date) { return true + } else { } - for ra := range accnt[aid].rid { - for ea := range ta.Spl { - oaid := ta.Spl[ea].AccountId - switch { - case accnt[aid].tax && accnt[aid].buy: - // check pids - if accnt[oaid].pid == accnt[aid].rid[ra] { - return check_vals(accnt,aid,oaid,ta) - } - default: - // check aids - if ta.Spl[ea].AccountId == accnt[aid].rid[ra] { - return check_vals(accnt,aid,oaid,ta) + + // [taxval: 19=0 7=1][tax: no=0 yes=1][buy: no=0 yes=1] + var sum [2][2][2]int + + for sc := range ta.Spl { + aid := ta.Spl[sc].AccountId + //accnt[aid].tax + for iac := range iaa { + // taxval + tv := int(0) + if iaa[iac].taxval == 7 { + tv = 1 + } + // tax + tax := int(0) + if iaa[iac].tax { + tax = 1 + } + // buy + buy := int(0) + if iaa[iac].buy { + buy = 1 + } + // match! add to sum and break. + match := bool(false) + // check pids if ... + if tax == 0 && buy == 1 { + _, exists := accnt[aid] + if exists { + // pids + if accnt[aid].pid == iaa[iac].id { + match = true + } } } - //fmt.Println(data.Accnt[accnt[oaid].num].Name) + // ... however, always check aids + if aid == iaa[iac].id { + match = true + } + if match { + inc, _ := strconv.Atoi(strings.TrimSuffix(ta.Spl[sc].Value,"/100")) + sum[tv][tax][buy] += inc + break + } } } - // some exceptions - transaction description - desclist := []string{ - "GEMA", - "Deutsche Post", - "gesetz IHK", - "Gesundheitsbelehrung", - "Gewerbezentralregister", - "Entgeltabrechnung siehe Anlage", - "ENTGELT SPK", - "ttenrecht und F", - } - for dc := range desclist { - if strings.Contains(ta.Description,desclist[dc]){ - return true + // check for exceptions + exc := false + for ec := range trn_exc { + if ta.Description == trn_exc[ec] { + exc = true + break } } - // some exceptions - account name - accountlist := []string{ - "4970 Nebenkosten des", - } - anum := accnt[aid].num - for ac := range accountlist { - if strings.Contains(data.Accnt[anum].Name,accountlist[ac]){ - return true - } - } - - fmt.Println("E: No correpsonding account!") - - return false -} - -func check_vals(accnt map[string]amap,aid string,oaid string,ta *Transaction) bool { - qa, _ := strconv.Atoi(get_val(ta,aid)) - qb, _ := strconv.Atoi(get_val(ta,oaid)) - - var val, cmp int - - - switch { - case accnt[aid].tax: - // aid = taxval * oaid / 100 - val = int((qb*accnt[aid].taxval)/100.0) - cmp = qa - default: - // oaid = taxval * aid / 100 - val = int((qa*accnt[aid].taxval)/100.0) - cmp = qb - } + //for ac := range accountlist { + // if strings.Contains(data.Accnt[anum].Name,accountlist[ac]){ + // return true + // } + //} - if cmp >= val-1 && cmp <= val+1 { - return true - } else { - fmt.Println("E:",qa,qb,"<- ",accnt[aid].taxval,"->",cmp,val) - return false + // check + var expected [2]int + check := true + for buy := 0; buy < 2; buy++ { + expected[0]=int((sum[0][0][buy]*19)/100.0) + expected[1]=int((sum[1][0][buy]*7)/100.0) + for tv :=0; tv < 2; tv++ { + if expected[tv] < sum[tv][1][buy]-1 || + expected[tv] > sum[tv][1][buy]+1 { + var sb, st string + if buy == 0 { + sb = "Umsatzsteuer" + } else { + sb = "Vorsteuer" + } + if tv == 0 { + st = "19%" + } else { + st = " 7%" + } + check = false + fmt.Printf("%s %s: ",sb,st); + fmt.Printf("Erwarte %d statt %d aus %d! ", + expected[tv], + sum[tv][1][buy],sum[tv][0][buy]); + if(!exc) { + fmt.Printf("\n"); + } else { + fmt.Printf("Ausnahme greift!\n"); + fmt.Printf("(%s)\n\n",ta.Description) + } + } + } } -} - -func get_val(ta *Transaction,aid string) string { - for sc := range ta.Spl { - if ta.Spl[sc].AccountId == aid { - return strings.TrimSuffix(ta.Spl[sc].Value,"/100") + if !check && !exc { + fmt.Println("am",ta.Date) + fmt.Printf("(%s)\n",ta.Description) + fmt.Println("Beteiligte Konten:") + for ic := range ta.Spl { + found := strings.TrimSuffix(ta.Spl[ic].Value,"/100") + aid := ta.Spl[ic].AccountId + _, exists := accnt[aid] + if exists { + num := accnt[aid].num + fmt.Printf(" %s => %s\n",data.Accnt[num].Name, + found) + } else { + fmt.Printf(" %s => %s\n",aid,found) + } } + fmt.Println("") } - return "" + + return check } func round(v float64) int { @@ -280,3 +365,4 @@ func round(v float64) int { } return int(v) } + -- 2.39.2