From: hackbard Date: Tue, 14 Oct 2014 22:15:06 +0000 (+0200) Subject: doing calcs, for !exceptions X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e4b45c1dbe463fffdf2eb426c03ff86f067c225;p=outofuni%2Fgocash.git doing calcs, for !exceptions --- diff --git a/gocash.go b/gocash.go index 2d0416b..ae679b8 100644 --- a/gocash.go +++ b/gocash.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "strings" + "strconv" ) // @@ -170,10 +171,10 @@ func main() { aid := data.Trn[tc].Spl[tsc].AccountId if check_trn(&data.Trn[tc],accnt,aid) == false { ac := accnt[aid].num - fmt.Println("") - fmt.Println(data.Trn[tc].Date) + fmt.Println(" ",data.Trn[tc].Date) fmt.Println(" ",data.Trn[tc].Description) fmt.Println(" ",data.Accnt[ac].Name) + fmt.Println("") } } } @@ -192,20 +193,20 @@ func check_trn(ta *Transaction,accnt map[string]amap,aid string) bool { case accnt[aid].tax && accnt[aid].buy: // check pids if accnt[oaid].pid == accnt[aid].rid[ra] { - return true + return check_vals(accnt,aid,oaid,ta) } default: // check aids if ta.Spl[ea].AccountId == accnt[aid].rid[ra] { - return true + return check_vals(accnt,aid,oaid,ta) } } //fmt.Println(data.Accnt[accnt[oaid].num].Name) } } - // some exceptions - wordlist := []string{ + // some exceptions - transaction description + desclist := []string{ "GEMA", "Deutsche Post", "gesetz IHK", @@ -215,12 +216,67 @@ func check_trn(ta *Transaction,accnt map[string]amap,aid string) bool { "ENTGELT SPK", "ttenrecht und F", } - for wc := range wordlist { - if strings.Contains(ta.Description,wordlist[wc]){ + for dc := range desclist { + if strings.Contains(ta.Description,desclist[dc]){ + return true + } + } + // 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 + } + + if cmp >= val-1 && cmp <= val+1 { + return true + } else { + fmt.Println("E:",qa,qb,"<- ",accnt[aid].taxval,"->",cmp,val) + return false + } +} + +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") + } + } + return "" +} + +func round(v float64) int { + if v < 0.0 { + v -= 0.5 + } else { + v += 0.5 + } + return int(v) +}