From 1308154bfde61973308df8e908a45cd95781939c Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Wed, 8 May 2019 01:08:42 +0200 Subject: More Analysis - still test --- sqlite.go | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'sqlite.go') diff --git a/sqlite.go b/sqlite.go index c24aae6..1c92a17 100644 --- a/sqlite.go +++ b/sqlite.go @@ -81,6 +81,17 @@ type IdMap struct { New int } +// Methods + +func (t Task) Duration() float64 { + dur := t.Stop.Sub(t.Start) + return dur.Hours() +} + + + +// Global Variables + var db *sql.DB var err error var currproject Project @@ -823,7 +834,7 @@ func closeTask(loud bool) { } } -// TODO Make an uncheck function +// Mark bill as paid, connect it to payment func checkBill(billid, payid, projectid int, datestr string) { //boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() @@ -1334,6 +1345,27 @@ func GetAllBills() (out []bill) { return } + +// Returns Slice of All Payments +func GetAllPayments() (out []Payment) { + //var ids []int + rows, err := db.Query("SELECT * FROM payments") // ORDER BY id DESC") + checkErr(err) + var id,cuid int + var amt float64 + var dat time.Time + var bistr string + var bi []int + defer rows.Close() + for rows.Next() { + err = rows.Scan(&id,&cuid,&amt,&bistr,&dat) + checkErr(err) + bi = String2IntArray(bistr,";") + out = append(out,Payment{id,cuid,amt,dat,bi}) + } + return +} + // Get All Tasks of Project with prid as a slice of Tasknames and // a curresponding slice of strings to display func GetTaskSums(prid int) (names,strings []string ) { @@ -1487,7 +1519,6 @@ func showOpenProject(alone bool) { // Unser Input to create a new Payment func AddPayment(dat string) { - //TODO boldRed := color.New(color.FgRed, color.Bold).SprintFunc() boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() const form = "2006-01-02" @@ -1815,6 +1846,8 @@ func setProject(nid int) { showCurrentTask() } + +// GEt String Slice and corresponding Id Slice for Multicoice selection func GetPaymentList() (outint []int, outstr []string) { rows, err := db.Query("SELECT id, customerid, amount, bills, date FROM payments") checkErr(err) @@ -1827,6 +1860,14 @@ func GetPaymentList() (outint []int, outstr []string) { err = rows.Scan(&id, &cuid, &amt, &bills, &dat) checkErr(err) cun := getCustomerName(cuid) +// biids := String2IntArray(bills,";") +// mybills := loadBills(biids) +/* + bsum := 0.0 + hsum := 0.0 + for _,bi := range mybills{ + + } */ st := fmt.Sprintf("%v: (%s) %s : %.2f[€] - Bills: %s",id, dat.Local().Format("2006-01-02"),cun, amt,bills) outint = append(outint, id) outstr = append(outstr, st) -- cgit v1.2.3