From: hackbard Date: Fri, 1 May 2015 15:04:06 +0000 (+0200) Subject: added sum of chosen accounts + somemore comments X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;ds=inline;p=outofuni%2Fgocash.git added sum of chosen accounts + somemore comments --- diff --git a/gocash.go b/gocash.go index 9e74149..e9d37de 100644 --- a/gocash.go +++ b/gocash.go @@ -17,7 +17,7 @@ type inv_accnts struct { } // -// account data --- add accounts to consider here! +// accounts considered in tax included balance check // var iaa []inv_accnts = []inv_accnts{ // wareneingang 19% and 7% (note: pids!) @@ -75,6 +75,22 @@ var n2z_exc_ta = []string{ var trn_exc = []string{ } +// +// accounts which will be summed up +// + +type sum_accnt struct { + name string + aid string + valplus int + valminus int +} + +var summed_accounts = []sum_accnt{ + {"Bankkonto","02ea930fdcc500cf7d3a21b80a126eb0",0,0}, + {"Kasse","04e71353130ccb554ebaf4c2438d6b2f",0,0}, +} + // account maps type amap struct { pid string // parent id @@ -229,6 +245,16 @@ func main() { -tax_report.SalesTax[1]); fmt.Println("------------------------------------") + // summed accounts + fmt.Println("") + fmt.Println("Summen einiger Konten:") + fmt.Println("----------------------") + for sac := range summed_accounts { + saccnt := summed_accounts[sac] + fmt.Println(" Konto: ",saccnt.name) + fmt.Println(" +: ",saccnt.valplus) + fmt.Println(" -: ",saccnt.valminus) + } } func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool { @@ -257,12 +283,14 @@ func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool { // [taxval: 19=0 7=1][tax: no=0 yes=1][buy: no=0 yes=1] var sum [2][2][2]int + // loop over splits within the transaction for sc := range ta.Spl { aid := ta.Spl[sc].AccountId //accnt[aid].tax + // loop over all considered accounts (defined earlier as global) for iac := range iaa { tv := int(0) - // taxval - check accnt instead of iaa! + // taxval changed by exception if tv_ow != -1 { if tv_ow == 7 { tv=1 @@ -278,6 +306,7 @@ func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool { continue } } + // taxval as defined by account } else { if accnt[aid].taxval == 0 { if accnt[aid].tax { @@ -321,6 +350,17 @@ func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool { break } } + // now get the sums + for sac := range summed_accounts { + if summed_accounts[sac].aid == aid { + inc, _ := strconv.Atoi(strings.TrimSuffix(ta.Spl[sc].Value,"/100")) + if inc >= 0 { + summed_accounts[sac].valplus += inc + } else { + summed_accounts[sac].valminus += inc + } + } + } } // check for exceptions