summaryrefslogtreecommitdiff
path: root/sqlite.go
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-09-12 02:37:44 +0200
committerNikolaus Gotsche <n@softwarefools.com>2018-09-12 02:37:44 +0200
commit06c06f5f6427f6da22b2476fa208e8c4ce54b7ee (patch)
treeb1ecc69ccc3ca6e915b6f4084598b530fbf24d04 /sqlite.go
parentfd4a4409ee8e6b772db30611e968778b68eca0d6 (diff)
Conf/DB into Home Dir, general beautification and debug
Diffstat (limited to 'sqlite.go')
-rw-r--r--sqlite.go50
1 files changed, 38 insertions, 12 deletions
diff --git a/sqlite.go b/sqlite.go
index 2ad3850..1be6394 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -77,7 +77,7 @@ func initDB(filename string) {
name VARCHAR(240) NOT NULL,
first TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- finished INTEGER NOT NULL,
+ finished INTEGER DEFAULT NULL,
customer INTEGER DEFAULT NULL);
CREATE TABLE timetable(
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -85,7 +85,7 @@ func initDB(filename string) {
start TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
stop TIMESTAMP DEFAULT '1791-09-30 19:07',
task VARCHAR(240) NOT NULL,
- checkout INTEGER NOT NULL);
+ checkout INTEGER DEFAULT NULL);
CREATE TABLE customers(
id INTEGER PRIMARY KEY AUTOINCREMENT,
company VARCHAR(240),
@@ -109,11 +109,11 @@ func initDB(filename string) {
checkErr(err)
stmt, err := db.Prepare("INSERT INTO customers(id,company,name) values(?, ?, ?)")
checkErr(err)
- _, err = stmt.Exec(0,"None","Annonymus")
+ _, err = stmt.Exec(0,"No one","Specific")
checkErr(err)
- stmt, err = db.Prepare("INSERT INTO projects(id,name,customer) values(?, ?, ?)")
+ stmt, err = db.Prepare("INSERT INTO projects(id,name,customer,finished) values(?, ?, ?, ?)")
checkErr(err)
- _, err = stmt.Exec(0,"None",0)
+ _, err = stmt.Exec(0,"None",0,0)
checkErr(err)
}else{
db, err = sql.Open("sqlite3", filename)
@@ -209,8 +209,14 @@ func saveBill(in bill) {
}
func showLastBills(count int) {
- //boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
- rows, err := db.Query("SELECT * FROM bills ORDER BY date DESC LIMIT ?",count)
+ boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
+ boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
+ rows, err := db.Query("SELECT * FROM timetable")
+ if count == 0 {
+ rows, err = db.Query("SELECT * FROM bills ORDER BY date ASC")
+ }else if count > 0 {
+ rows, err = db.Query("SELECT * FROM bills ORDER BY date ASC LIMIT ?",count)
+ }
checkErr(err)
var id,proj int
var ident,timerange string
@@ -219,15 +225,31 @@ func showLastBills(count int) {
defer rows.Close()
//fmt.Println("___Open Task________________")
- fmt.Printf("___Previous %v Bills________\n",count)
+ if count == 0 {
+ fmt.Print("___All Previous Bills_______\n")
+ }else{
+ fmt.Printf("___Previous %v Bills________\n",count)
+ }
+ i := 0
for rows.Next() {
+ i++
err = rows.Scan(&id,&ident,&timerange,&proj,&taskstr,&timestr,&hourstr,&moneystr,&paid,&date)
checkErr(err)
prn,_ := getProjectName(proj)
hsum := sumFloatArray(string2FloatArray(hourstr,";"))
msum := sumFloatArray(string2FloatArray(moneystr,";"))
- fmt.Printf(" %s - %s (%v) %.1f[h]: %.2f[€]\n",ident,prn,date,hsum,msum)
+ fmt.Printf(" %v:%s - %s (%v) %.1f[h]: %.2f[€] - ",id,ident,prn,date.Local().Format("2006.01.02"),hsum,msum)
+ p := fmt.Sprintf("%v",paid)
+ if p == "1791-09-30 19:07:00 +0000 UTC" {
+ fmt.Print(boldRed("OPEN\n"))
+ }else{
+ fmt.Printf(boldGreen("%v\n"),paid.Local().Format("2006.01.02"))
+ }
+ }
+ if i == 0 {
+ fmt.Println(boldRed("\n NONE"))
}
+ fmt.Println(" ")
}
func loadBills(in []int) (out []bill){
@@ -869,9 +891,13 @@ func allProjects() {
}
//fmt.Printf(" %v:%s \n First: %s, Last:%s, Total:%.2f(h) ,Fin:%v, For:%v\n",uid,prname,first.Local().Format("2006-01-02 15:04 MST"),last.Local().Format("2006-01-02 15:04 MST"),sum,finish,customer)
- fmt.Printf(" %v:%s \n",uid,prname)
- fmt.Printf(" Unbilled: %.2f[h] Billed: %.2f[h] | Total: %.2f[h]\n",sumo,sumb,sumo+sumb)
- fmt.Printf(" First: %s, Last:%s, Fin:%v, For:%v\n",first.Local().Format("2006-01-02 15:04 MST"),last.Local().Format("2006-01-02 15:04 MST"),finish,customer)
+ if (sumo+sumb) > 0 {
+ fmt.Printf(" %v:%s \n",uid,prname)
+ fmt.Printf(" Unbilled: %.2f[h] Billed: %.2f[h] | Total: %.2f[h]\n",sumo,sumb,sumo+sumb)
+ fmt.Printf(" First: %s, Last:%s, Fin:%v, For:%v\n",first.Local().Format("2006-01-02 15:04 MST"),last.Local().Format("2006-01-02 15:04 MST"),finish,customer)
+ }else{
+ fmt.Print(" Nothing\n")
+ }
rows2.Close() //good habit to close
}
rows.Close() //good habit to close