From 0c4c5ac1ba534425716c80d27dc72817718f0367 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Tue, 14 May 2019 12:32:45 +0200 Subject: Payment Debug, Yearly Analysis --- sqlite.go | 66 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'sqlite.go') diff --git a/sqlite.go b/sqlite.go index bacb21b..8bfd83e 100644 --- a/sqlite.go +++ b/sqlite.go @@ -84,8 +84,9 @@ type IdMap struct { // Methods func (t Task) Duration() float64 { - dur := t.Stop.Sub(t.Start) - return dur.Hours() + //dur := t.Stop.Sub(t.Start) + dur := float64(t.Stop.Sub(t.Start)) / (1000000000 * 60 * 60) + return dur//.Hours() } func (t Task) Money() float64 { _,cu := GetProject(t.Projectid) @@ -1362,7 +1363,9 @@ func GetAllPayments() (out []Payment) { for rows.Next() { err = rows.Scan(&id,&cuid,&amt,&bistr,&dat) checkErr(err) - bi = String2IntArray(bistr,";") + if len(bistr)>0 { + bi = String2IntArray(bistr,";") + } out = append(out,Payment{id,cuid,amt,dat,bi}) } return @@ -1567,7 +1570,6 @@ func AddPayment(dat string) { if len(selids)>0{ break }else{ - // TODO allow no bills and ask fmt.Println(boldRed("At least one Bill should Correspont to a payment!")) if isInterSure(sli+"Do you want to continue without a selection?") { //getInterInput("") @@ -1596,7 +1598,6 @@ func AddPayment(dat string) { hsum += it.Hours } fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bsum) - //sum += bsum } if amtfl != sum { fmt.Println(sli,boldRed(" The sum of the bills (",sum,"€) does not match Payment amount!")) @@ -2186,29 +2187,39 @@ func EditPayment(id int) { } } fmt.Println(sub("Bills")) - biids := String2IntArray(billstr,";") - mybills := loadBills(biids) + var biids []int + var mybills []bill bsum := 0.0 hsum := 0.0 - for _,bi := range mybills{ - bisum := 0.0 - for _,it := range bi.items { - bisum += it.Money - hsum += it.Hours - } - fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bisum) - bsum += bisum - } - if amount != bsum { - fmt.Println(sub("")) - fmt.Println(nli,boldRed(" The sum of the bills (",bsum,"€ for",hsum,"h) does not match Payment amount!")) - if amount > bsum { - fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum) ) + + if len(billstr)>0 { + biids = String2IntArray(billstr,";") + mybills = loadBills(biids) + + //bsum := 0.0 + //hsum := 0.0 + for _,bi := range mybills{ + bisum := 0.0 + for _,it := range bi.items { + bisum += it.Money + hsum += it.Hours + } + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bisum) + bsum += bisum } - if amount < bsum { - fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum) ) + if amount != bsum { + fmt.Println(sub("")) + fmt.Println(nli,boldRed(" The sum of the bills (",bsum,"€ for",hsum,"h) does not match Payment amount!")) + if amount > bsum { + fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum) ) + } + if amount < bsum { + fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum) ) + } } + }else{ + fmt.Println(nli,boldRed(" None")) } if isInterSure(sli+"Do You want to renew Selection?") { for _,i := range biids { @@ -2232,8 +2243,13 @@ func EditPayment(id int) { billstr = IntArray2String(selids,";") break }else{ + billstr = "-1" fmt.Println(boldRed("At least one Bill should Correspont to a payment!")) - getInterInput("") + if isInterSure(sli+"Do you want to continue without a selection?") { + break + } + //fmt.Println(boldRed("At least one Bill should Correspont to a payment!")) + //getInterInput("") } } } @@ -2242,6 +2258,8 @@ func EditPayment(id int) { _, err = stmt.Exec(cuid, amount, billstr, datstr, id) checkErr(err) custr := getCustomerName(cuid) + biids = String2IntArray(billstr,";") + mybills = loadBills(biids) fmt.Println(frame(boldGreen("Editing Payment ", id),true)) fmt.Printf("%s From %s Amount %.2f [€]\n",nli,custr,amount) -- cgit v1.2.3