]> hackdaworld.org Git - outofuni/gocash.git/commitdiff
more rules, need to add exceptions
authorhackbard <hackbard@hackdaworld.org>
Mon, 13 Oct 2014 23:46:24 +0000 (01:46 +0200)
committerhackbard <hackbard@hackdaworld.org>
Mon, 13 Oct 2014 23:46:24 +0000 (01:46 +0200)
gocash.go

index 0ca0fdf4c0213899624e139dc45ef5b16e257359..254916482789f82882be8203f903b5505c4a4a83 100644 (file)
--- a/gocash.go
+++ b/gocash.go
@@ -7,13 +7,47 @@ import (
        "os"
 )
 
+//
+// hardcoded account ids we have to look at
+//
+// --- buy
+// wareneingang 19% and 7%
+const pid_buy_n = string("8e3b7c42e3173ed85f3d4736e82afb4d")
+const pid_buy_s = string("0cfd2ceb45fff89b9d1b7ce3af66cdf3")
+const pid_misc  = string("e3acc2865dbf931e41cf2b90240de5c2")
+const pid_rep   = string("b1d04ad157cac569f4299d4ddf94ed6f")
+const pid_room  = string("4394ed4ffa7266f8f8731080926a7a61")
+const pid_cap   = string("4196ee026d1bdb785df2c975fca91ae0")
+// abziehbare vst 19% and 7%
+const aid_vst_n = string("7c449e13125d6b93043f963628106db2")
+const aid_vst_s = string("006643c1c0a91f2b40614c75a49c6295")
+// --- sales
+// receipts
+const aid_rec_n = string("f3e905732b729ba096a50dab60559ce7")
+const aid_rec_s = string("66c1b04bd897766cb2be538094e1db6a")
+const aid_tip   = string("1d20024badc11a99a8e1cf3a9a64a501")
+const aid_dep   = string("9772f4e231f6f5e3100132cc53eb3447")
+// ust
+const aid_ust_n = string("e4bd6ff52408be8076f24aeb105893d9")
+const aid_ust_s = string("38bf40d16529f2a1e611c073c6c1dc9c")
+
+// account maps
+type amap struct {
+       pid string // parent id
+       num int // account number
+       taxval int // 7 or 19
+       buy bool // buy or sales
+       tax bool // tax or non-tax(=goods) account
+       rid []string // required transaction account(s)
+}
+
+// xml
 type Account struct {
        XMLName xml.Name `xml:"account"`
        Name string `xml:"name"`
        AccountId string `xml:"id"`
        ParentId string `xml:"parent"`
 }
-
 type Split struct {
        XMLName xml.Name `xml:"split"`
        Id string `xml:"id"`
@@ -21,7 +55,6 @@ type Split struct {
        Quantity string `xml:"quantity"`
        AccountId string `xml:"account"`
 }
-
 type Transaction struct {
        XMLName xml.Name `xml:"transaction"`
        Id string `xml:"id"`
@@ -29,7 +62,6 @@ type Transaction struct {
        Description string `xml:"description"`
        Spl []Split `xml:"splits>split"`
 }
-
 type ParsedData struct {
        XMLName xml.Name `xml:"gnc-v2"`
        DataCnt []string `xml:"count-data"`
@@ -68,49 +100,17 @@ func main() {
        fmt.Println("Parsed accounts:",len(data.Accnt))
        fmt.Println("Parsed transactions:",len(data.Trn))
 
-       //
-       // hardcoded account ids we have to look at
-       //
-       // --- buy
-       // wareneingang 19% and 7%
-       pid_buy_n := string("8e3b7c42e3173ed85f3d4736e82afb4d")
-       pid_buy_s := string("0cfd2ceb45fff89b9d1b7ce3af66cdf3")
-       pid_misc  := string("e3acc2865dbf931e41cf2b90240de5c2")
-       pid_rep   := string("b1d04ad157cac569f4299d4ddf94ed6f")
-       pid_room  := string("4394ed4ffa7266f8f8731080926a7a61")
-       pid_cap   := string("4196ee026d1bdb785df2c975fca91ae0")
-       // abziehbare vst 19% and 7%
-       aid_vst_n := string("7c449e13125d6b93043f963628106db2")
-       aid_vst_s := string("006643c1c0a91f2b40614c75a49c6295")
-       // --- sales
-       // receipts
-/*
-       aid_rec_n := string("f3e905732b729ba096a50dab60559ce7")
-       aid_rec_s := string("66c1b04bd897766cb2be538094e1db6a")
-       aid_tip   := string("1d20024badc11a99a8e1cf3a9a64a501")
-       aid_dep   := string("9772f4e231f6f5e3100132cc53eb3447")
-*/
-       // ust
-       aid_ust_n := string("e4bd6ff52408be8076f24aeb105893d9")
-       aid_ust_s := string("38bf40d16529f2a1e611c073c6c1dc9c")
-
-       // account maps
-       type amap struct {
-               pid string
-               num int
-               taxval int
-               buy bool
-               tax bool
-       }
        accnt := make(map[string]amap)
 
        for ac := range data.Accnt {
                aid := data.Accnt[ac].AccountId
                pid := data.Accnt[ac].ParentId
                // general map
+               rid := make ([]string,10,10)
                accnt[aid]=amap{
-                       pid,ac,0,false,false,
+                       pid,ac,0,false,false,rid,
                }
+               rid[0]="NONE"
                tmp := accnt[aid]
                switch {
                // ---- buy
@@ -118,70 +118,91 @@ func main() {
                case pid == pid_buy_n || pid == pid_misc || pid == pid_rep || pid == pid_room || pid == pid_cap:
                        tmp.taxval=19
                        tmp.buy=true
+                       rid[0]=aid_vst_n
                        accnt[aid]=tmp
                case pid == pid_buy_s:
                        tmp.taxval=7
                        tmp.buy=true
+                       rid[0]=aid_vst_s
                        accnt[aid]=tmp
-               // mathc pid: verschiedene kosten, reparatur/instandhaltung
-               //            raumkosten + anlage/kapitalkonten
-               //         -> buy, 19, notax
-               //
                //   -- tax
                case aid == aid_vst_n:
                        tmp.taxval=19
                        tmp.buy=true
                        tmp.tax=true
+                       rid=[]string{pid_buy_n,pid_misc,pid_rep,pid_room,pid_cap,}
                        accnt[aid]=tmp
                case aid == aid_vst_s:
                        tmp.taxval=7
                        tmp.buy=true
                        tmp.tax=true
+                       rid[0]=pid_buy_s
                        accnt[aid]=tmp
                // ---- sales ----
                //   -- receipts
-               //      match pid: erloeskonten
+               case aid == aid_rec_n || aid == aid_tip || aid == aid_dep:
+                       tmp.taxval=19
+                       rid[0]=aid_ust_n
+                       accnt[aid]=tmp
+               case aid == aid_rec_s:
+                       tmp.taxval=7
+                       rid[0]=aid_ust_s
+                       accnt[aid]=tmp
                //   -- tax
                case aid == aid_ust_n:
                        tmp.taxval=19
                        tmp.tax=true
+                       rid=[]string{aid_rec_n,aid_tip,aid_dep,}
                        accnt[aid]=tmp
                case aid == aid_ust_s:
                        tmp.taxval=7
                        tmp.tax=true
+                       rid[0]=aid_rec_s
                        accnt[aid]=tmp
                }
        }
 
-       // check transactions
+       // 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
-                       switch {
-                       case accnt[aid].buy:
-                               var ret bool
-                               switch accnt[aid].taxval {
-                               case 19:
-                                       ret=check_buy(&data.Trn[tc],aid_vst_n)
-                               case 7:
-                                       ret=check_buy(&data.Trn[tc],aid_vst_s)
-                               }
-                               anum := accnt[aid].num
-                               if ret == false {
-                                       fmt.Println("Problem:", data.Accnt[anum].Name,data.Trn[tc].Date)
-                               }
+                       if check_trn(&data.Trn[tc],accnt,aid) == false {
+                               ac := accnt[aid].num
+                               fmt.Println("P:",data.Accnt[ac].Name,"at",data.Trn[tc].Date)
+
                        }
                }
        }
 
 }
 
-func check_buy(ta *Transaction,id string) bool {
-       for  sc := range ta.Spl {
-               if ta.Spl[sc].AccountId == id {
-                       return true
+func check_trn(ta *Transaction,accnt map[string]amap,aid string) bool {
+       //ac := accnt[aid].num
+       if accnt[aid].rid[0]=="NONE" {
+               return true
+       }
+       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 true
+                               }
+                       default:
+                               // check aids
+                               if ta.Spl[ea].AccountId == accnt[aid].rid[ra] {
+                                       return true
+                               }
+                       }
+                       //fmt.Println(data.Accnt[accnt[oaid].num].Name)
                }
        }
+       // exceptions
+       //if !ok {
+       //}
        return false
 }