summaryrefslogtreecommitdiff
path: root/sqlite.go
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2019-05-14 12:32:45 +0200
committerNikolaus Gotsche <n@softwarefools.com>2019-05-14 12:32:45 +0200
commit0c4c5ac1ba534425716c80d27dc72817718f0367 (patch)
tree109d394c83b48197abaf9a44f88238c8af7283ca /sqlite.go
parentbf7dfda3e67f67687109290209c8b09576a417fd (diff)
Payment Debug, Yearly Analysis0.4.4
Diffstat (limited to 'sqlite.go')
-rw-r--r--sqlite.go66
1 files changed, 42 insertions, 24 deletions
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("<continue>")
@@ -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("<continue>")
+ 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("<continue>")
}
}
}
@@ -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)