12 type inv_accnts struct {
20 // account data --- add accounts to consider here!
22 var iaa []inv_accnts = []inv_accnts{
23 // wareneingang 19% and 7% (note: pids!)
24 { "8e3b7c42e3173ed85f3d4736e82afb4d",19,false,true },
25 { "0cfd2ceb45fff89b9d1b7ce3af66cdf3", 7,false,true },
26 { "e3acc2865dbf931e41cf2b90240de5c2",19,false,true },
27 { "b1d04ad157cac569f4299d4ddf94ed6f",19,false,true },
28 { "4394ed4ffa7266f8f8731080926a7a61",19,false,true },
29 { "4196ee026d1bdb785df2c975fca91ae0",19,false,true },
31 { "cb67d346eac01c2b66e2394df4e8d6e8",19,false,true },
32 // abziehbare vst 19% and 7%
33 { "7c449e13125d6b93043f963628106db2",19,true,true },
34 { "006643c1c0a91f2b40614c75a49c6295", 7,true,true },
37 { "f3e905732b729ba096a50dab60559ce7",19,false,false },
38 { "66c1b04bd897766cb2be538094e1db6a", 7,false,false },
39 { "1d20024badc11a99a8e1cf3a9a64a501",19,false,false },
40 { "9772f4e231f6f5e3100132cc53eb3447",19,false,false },
42 { "e4bd6ff52408be8076f24aeb105893d9",19,true,false },
43 { "38bf40d16529f2a1e611c073c6c1dc9c", 7,true,false },
49 // account exceptions: nineteen to seven
50 var n2s_exc = []string{
52 // account exceptions: nineteen to zero
53 var n2z_exc = []string{
54 "4970 Nebenkosten des",
57 // transaction exceptions: nineteen to seven
58 var n2s_exc_ta = []string{
61 // transaction exceptions: nineteen to zero
62 var n2z_exc_ta = []string{
65 "Gesundheitsbelehrung",
66 "Gewerbezentralregister",
67 "Entgeltabrechnung siehe Anlage",
70 "Unterrichtung Gastst",
74 // transacion exception list --- the rest, required?
75 var trn_exc = []string{
80 pid string // parent id
81 num int // account number
83 buy bool // buy or sales
84 tax bool // tax or non-tax(=goods) account
89 XMLName xml.Name `xml:"account"`
90 Name string `xml:"name"`
91 AccountId string `xml:"id"`
92 ParentId string `xml:"parent"`
95 XMLName xml.Name `xml:"split"`
97 Value string `xml:"value"`
98 Quantity string `xml:"quantity"`
99 AccountId string `xml:"account"`
101 type Transaction struct {
102 XMLName xml.Name `xml:"transaction"`
104 Date string `xml:"date-posted>date"`
105 Description string `xml:"description"`
106 Spl []Split `xml:"splits>split"`
108 type ParsedData struct {
109 XMLName xml.Name `xml:"gnc-v2"`
110 DataCnt []string `xml:"count-data"`
111 Accnt []Account `xml:"book>account"`
112 Trn []Transaction `xml:"book>transaction"`
116 type TaxReport struct {
127 var tax_report TaxReport
133 if len(os.Args) > 1 {
134 sel_date = os.Args[1]
138 file, err := os.Open("c13_skr03.gnucash")
140 fmt.Println("Error opening file:", err)
146 xmldata, err := ioutil.ReadAll(file)
148 fmt.Println("Error reading file:", err)
152 // unmarshal xml data
153 err = xml.Unmarshal(xmldata,&data)
155 fmt.Println("Error unmarshaling xml data:", err)
159 // whooha, this is our data!
160 fmt.Println("Parsed accounts:",len(data.Accnt))
161 fmt.Println("Parsed transactions:",len(data.Trn))
164 accnt := make(map[string]amap)
166 for ac := range data.Accnt {
167 aid := data.Accnt[ac].AccountId
168 pid := data.Accnt[ac].ParentId
169 for iac := range iaa {
170 // consider account if pid or aid matches
171 if pid == iaa[iac].id || aid == iaa[iac].id {
172 taxval := iaa[iac].taxval
173 for ec := range n2s_exc {
174 if strings.Contains(data.Accnt[ac].Name,
180 for ec := range n2z_exc {
181 if strings.Contains(data.Accnt[ac].Name,
199 // check transactions ...
200 for tc := range data.Trn {
202 check_balance(&data.Trn[tc],accnt,sel_date)
206 fmt.Println("Umsatzsteuervoranmeldung (19% | 7%):")
207 fmt.Println("------------------------------------")
208 fmt.Println("Aufwendungen:",tax_report.Expenses[0],
209 tax_report.Expenses[1]);
210 fmt.Println("ohne Ausn. :",tax_report.Expenses[0]-
211 tax_report.ExpExc[0],
212 tax_report.Expenses[1]-
213 tax_report.ExpExc[1]);
214 fmt.Println("gesch. Vst. :",int((tax_report.Expenses[0]*19)/100.0),
215 int((tax_report.Expenses[1]*7)/100.0))
216 fmt.Println("ohne Ausn. :",int(((tax_report.Expenses[0]-
217 tax_report.ExpExc[0])*19)/100.0),
218 int(((tax_report.Expenses[1]-
219 tax_report.ExpExc[1])*7)/100.0))
220 fmt.Println("Vorsteuer :",tax_report.InputTax[0],
221 tax_report.InputTax[1],
222 "->",tax_report.InputTax[0]+tax_report.InputTax[1]);
223 fmt.Println("------------------------------------")
224 fmt.Println("Einnahmen :",-tax_report.Receipts[0],
225 -tax_report.Receipts[1]);
226 fmt.Println("gesch. Ust. :",int((-tax_report.Receipts[0]*19)/100.0),
227 int((-tax_report.Receipts[1]*7)/100.0));
228 fmt.Println("Umsatzsteuer:",-tax_report.SalesTax[0],
229 -tax_report.SalesTax[1]);
230 fmt.Println("------------------------------------")
234 func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool {
237 tdate := strings.Fields(ta.Date)[0]
238 if !strings.Contains(tdate,sel_date) {
244 for ec := range n2s_exc_ta {
245 if strings.Contains(ta.Description,n2s_exc_ta[ec]) {
250 for ec := range n2z_exc_ta {
251 if strings.Contains(ta.Description,n2z_exc_ta[ec]) {
257 // [taxval: 19=0 7=1][tax: no=0 yes=1][buy: no=0 yes=1]
260 for sc := range ta.Spl {
261 aid := ta.Spl[sc].AccountId
263 for iac := range iaa {
265 // taxval - check accnt instead of iaa!
271 // reset taxvalues of involved accounts
272 // (to drop an error)
274 if accnt[aid].taxval==7 {
282 if accnt[aid].taxval == 0 {
284 fmt.Println("FATAL!");
288 if accnt[aid].taxval == 7 {
302 // match! add to sum and break.
305 if tax == 0 && buy == 1 {
306 _, exists := accnt[aid]
309 if accnt[aid].pid == iaa[iac].id {
314 // ... however, always check aids
315 if aid == iaa[iac].id {
319 inc, _ := strconv.Atoi(strings.TrimSuffix(ta.Spl[sc].Value,"/100"))
320 sum[tv][tax][buy] += inc
326 // check for exceptions
328 for ec := range trn_exc {
329 if strings.Contains(ta.Description,trn_exc[ec]) {
334 //for ac := range accountlist {
335 // if strings.Contains(data.Accnt[anum].Name,accountlist[ac]){
341 for tv := 0; tv<2; tv++ {
342 tax_report.Expenses[tv] += sum[tv][0][1]
343 tax_report.InputTax[tv] += sum[tv][1][1]
344 tax_report.Receipts[tv] += sum[tv][0][0]
345 tax_report.SalesTax[tv] += sum[tv][1][0]
347 tax_report.ExpExc[tv] += sum[tv][0][1]
348 tax_report.ITExc[tv] += sum[tv][1][1]
355 for buy := 0; buy < 2; buy++ {
356 expected[0]=int((sum[0][0][buy]*19)/100.0)
357 expected[1]=int((sum[1][0][buy]*7)/100.0)
358 for tv :=0; tv < 2; tv++ {
359 if expected[tv] < sum[tv][1][buy]-1 ||
360 expected[tv] > sum[tv][1][buy]+1 {
373 fmt.Printf("%s %s: ",sb,st);
374 fmt.Printf("Erwarte %d statt %d aus %d! ",
376 sum[tv][1][buy],sum[tv][0][buy]);
380 fmt.Printf("Ausnahme greift!\n");
381 fmt.Printf("(%s)\n\n",ta.Description)
387 fmt.Println("am",ta.Date)
388 fmt.Printf("(%s)\n",ta.Description)
389 fmt.Println("Beteiligte Konten:")
390 for ic := range ta.Spl {
391 found := strings.TrimSuffix(ta.Spl[ic].Value,"/100")
392 aid := ta.Spl[ic].AccountId
393 _, exists := accnt[aid]
395 num := accnt[aid].num
396 fmt.Printf(" %s => %s\n",data.Accnt[num].Name,
399 fmt.Printf(" %s => %s\n",aid,found)
408 func round(v float64) int {