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",
73 // transacion exception list --- the rest, required?
74 var trn_exc = []string{
79 pid string // parent id
80 num int // account number
82 buy bool // buy or sales
83 tax bool // tax or non-tax(=goods) account
88 XMLName xml.Name `xml:"account"`
89 Name string `xml:"name"`
90 AccountId string `xml:"id"`
91 ParentId string `xml:"parent"`
94 XMLName xml.Name `xml:"split"`
96 Value string `xml:"value"`
97 Quantity string `xml:"quantity"`
98 AccountId string `xml:"account"`
100 type Transaction struct {
101 XMLName xml.Name `xml:"transaction"`
103 Date string `xml:"date-posted>date"`
104 Description string `xml:"description"`
105 Spl []Split `xml:"splits>split"`
107 type ParsedData struct {
108 XMLName xml.Name `xml:"gnc-v2"`
109 DataCnt []string `xml:"count-data"`
110 Accnt []Account `xml:"book>account"`
111 Trn []Transaction `xml:"book>transaction"`
115 type TaxReport struct {
126 var tax_report TaxReport
132 if len(os.Args) > 1 {
133 sel_date = os.Args[1]
137 file, err := os.Open("c13_skr03.gnucash")
139 fmt.Println("Error opening file:", err)
145 xmldata, err := ioutil.ReadAll(file)
147 fmt.Println("Error reading file:", err)
151 // unmarshal xml data
152 err = xml.Unmarshal(xmldata,&data)
154 fmt.Println("Error unmarshaling xml data:", err)
158 // whooha, this is our data!
159 fmt.Println("Parsed accounts:",len(data.Accnt))
160 fmt.Println("Parsed transactions:",len(data.Trn))
163 accnt := make(map[string]amap)
165 for ac := range data.Accnt {
166 aid := data.Accnt[ac].AccountId
167 pid := data.Accnt[ac].ParentId
168 for iac := range iaa {
169 // consider account if pid or aid matches
170 if pid == iaa[iac].id || aid == iaa[iac].id {
171 taxval := iaa[iac].taxval
172 for ec := range n2s_exc {
173 if strings.Contains(data.Accnt[ac].Name,
179 for ec := range n2z_exc {
180 if strings.Contains(data.Accnt[ac].Name,
198 // check transactions ...
199 for tc := range data.Trn {
201 check_balance(&data.Trn[tc],accnt,sel_date)
205 fmt.Println("Umsatzsteuervoranmeldung (19% | 7%):")
206 fmt.Println("------------------------------------")
207 fmt.Println("Aufwendungen:",tax_report.Expenses[0],
208 tax_report.Expenses[1]);
209 fmt.Println("ohne Ausn. :",tax_report.Expenses[0]-
210 tax_report.ExpExc[0],
211 tax_report.Expenses[1]-
212 tax_report.ExpExc[1]);
213 fmt.Println("gesch. Vst. :",int((tax_report.Expenses[0]*19)/100.0),
214 int((tax_report.Expenses[1]*7)/100.0))
215 fmt.Println("ohne Ausn. :",int(((tax_report.Expenses[0]-
216 tax_report.ExpExc[0])*19)/100.0),
217 int(((tax_report.Expenses[1]-
218 tax_report.ExpExc[1])*7)/100.0))
219 fmt.Println("Vorsteuer :",tax_report.InputTax[0],
220 tax_report.InputTax[1],
221 "->",tax_report.InputTax[0]+tax_report.InputTax[1]);
222 fmt.Println("------------------------------------")
223 fmt.Println("Einnahmen :",-tax_report.Receipts[0],
224 -tax_report.Receipts[1]);
225 fmt.Println("gesch. Ust. :",int((-tax_report.Receipts[0]*19)/100.0),
226 int((-tax_report.Receipts[1]*7)/100.0));
227 fmt.Println("Umsatzsteuer:",-tax_report.SalesTax[0],
228 -tax_report.SalesTax[1]);
229 fmt.Println("------------------------------------")
233 func check_balance(ta *Transaction,accnt map[string]amap,sel_date string) bool {
236 tdate := strings.Fields(ta.Date)[0]
237 if !strings.Contains(tdate,sel_date) {
243 for ec := range n2s_exc_ta {
244 if strings.Contains(ta.Description,n2s_exc_ta[ec]) {
249 for ec := range n2z_exc_ta {
250 if strings.Contains(ta.Description,n2z_exc_ta[ec]) {
256 // [taxval: 19=0 7=1][tax: no=0 yes=1][buy: no=0 yes=1]
259 for sc := range ta.Spl {
260 aid := ta.Spl[sc].AccountId
262 for iac := range iaa {
264 // taxval - check accnt instead of iaa!
270 // reset taxvalues of involved accounts
271 // (to drop an error)
273 if accnt[aid].taxval==7 {
281 if accnt[aid].taxval == 0 {
283 fmt.Println("FATAL!");
287 if accnt[aid].taxval == 7 {
301 // match! add to sum and break.
304 if tax == 0 && buy == 1 {
305 _, exists := accnt[aid]
308 if accnt[aid].pid == iaa[iac].id {
313 // ... however, always check aids
314 if aid == iaa[iac].id {
318 inc, _ := strconv.Atoi(strings.TrimSuffix(ta.Spl[sc].Value,"/100"))
319 sum[tv][tax][buy] += inc
325 // check for exceptions
327 for ec := range trn_exc {
328 if strings.Contains(ta.Description,trn_exc[ec]) {
333 //for ac := range accountlist {
334 // if strings.Contains(data.Accnt[anum].Name,accountlist[ac]){
340 for tv := 0; tv<2; tv++ {
341 tax_report.Expenses[tv] += sum[tv][0][1]
342 tax_report.InputTax[tv] += sum[tv][1][1]
343 tax_report.Receipts[tv] += sum[tv][0][0]
344 tax_report.SalesTax[tv] += sum[tv][1][0]
346 tax_report.ExpExc[tv] += sum[tv][0][1]
347 tax_report.ITExc[tv] += sum[tv][1][1]
354 for buy := 0; buy < 2; buy++ {
355 expected[0]=int((sum[0][0][buy]*19)/100.0)
356 expected[1]=int((sum[1][0][buy]*7)/100.0)
357 for tv :=0; tv < 2; tv++ {
358 if expected[tv] < sum[tv][1][buy]-1 ||
359 expected[tv] > sum[tv][1][buy]+1 {
372 fmt.Printf("%s %s: ",sb,st);
373 fmt.Printf("Erwarte %d statt %d aus %d! ",
375 sum[tv][1][buy],sum[tv][0][buy]);
379 fmt.Printf("Ausnahme greift!\n");
380 fmt.Printf("(%s)\n\n",ta.Description)
386 fmt.Println("am",ta.Date)
387 fmt.Printf("(%s)\n",ta.Description)
388 fmt.Println("Beteiligte Konten:")
389 for ic := range ta.Spl {
390 found := strings.TrimSuffix(ta.Spl[ic].Value,"/100")
391 aid := ta.Spl[ic].AccountId
392 _, exists := accnt[aid]
394 num := accnt[aid].num
395 fmt.Printf(" %s => %s\n",data.Accnt[num].Name,
398 fmt.Printf(" %s => %s\n",aid,found)
407 func round(v float64) int {