diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2018-09-12 02:37:44 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2018-09-12 02:37:44 +0200 |
| commit | 06c06f5f6427f6da22b2476fa208e8c4ce54b7ee (patch) | |
| tree | b1ecc69ccc3ca6e915b6f4084598b530fbf24d04 | |
| parent | fd4a4409ee8e6b772db30611e968778b68eca0d6 (diff) | |
Conf/DB into Home Dir, general beautification and debug
| -rw-r--r-- | config.go | 16 | ||||
| -rw-r--r-- | interact.go | 40 | ||||
| -rw-r--r-- | main.go | 37 | ||||
| -rw-r--r-- | sqlite.go | 50 |
4 files changed, 114 insertions, 29 deletions
@@ -6,7 +6,9 @@ import ( //"os" "io/ioutil" //"strconv" + "github.com/fatih/color" "github.com/BurntSushi/toml" + "github.com/atrox/homedir" ) type Config struct { @@ -32,7 +34,8 @@ var conffile string var config Config func init() { - conffile = "laboravi.config.toml" + conffile,err = homedir.Expand("~/.laboravi.config.toml") //make ~ when finished + checkErr(err) } func editConf() { @@ -57,13 +60,16 @@ func editConf() { } func initConf() { + boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() for { if _, err := toml.DecodeFile(conffile, &config); err != nil { //fmt.Println(err) - fmt.Println("Configuration file not found") + fmt.Println(boldRed("Configuration file not found")) makeNewTOML(false) }else{ - fmt.Println("Configuration loaded Successfully") + //fmt.Println(boldGreen("Configuration loaded Successfully")) + fmt.Println("Config loaded...",boldGreen("Hello ",config.Name)) break } } @@ -76,7 +82,9 @@ func makeNewTOML(gibts bool) { fmt.Println("Making new Configuration File") //Examplenames Coming soon n := "" - config = Config{".mytimes.db",n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} + file,err := homedir.Expand("~/.mywork.db") + checkErr(err) + config = Config{file,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n} } //fmt.Println("Whats Your Namecount\n") database := getNewInput("DB File Path: ",config.Database) diff --git a/interact.go b/interact.go index b494222..e336535 100644 --- a/interact.go +++ b/interact.go @@ -16,8 +16,8 @@ func interact() { stdOut() shell := ishell.New() - cyan := color.New(color.FgCyan).SprintFunc() - yellow := color.New(color.FgYellow).SprintFunc() + //cyan := color.New(color.FgCyan).SprintFunc() + //yellow := color.New(color.FgYellow).SprintFunc() green := color.New(color.FgGreen).SprintFunc() // boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() boldRed := color.New(color.FgRed, color.Bold).SprintFunc() @@ -165,7 +165,6 @@ func interact() { arg = strings.Join(c.Args, " ") argi,err := strconv.Atoi(arg) if err == nil{ - //c.Println(boldGreen("Edit Project",argi)) editProject(argi) allProjects() //stdOut() @@ -239,7 +238,7 @@ func interact() { shell.AddCmd(&ishell.Cmd{ Name: "all", - Help: "Show all Projects Project", + Help: "Show all Projects", Func: func(c *ishell.Context) { //c.Print("\033[H\033[2J") //c.Println(boldGreen("Start New Project")) @@ -248,7 +247,38 @@ func interact() { }, }) + shell.AddCmd(&ishell.Cmd{ + Name: "allbills", + Help: "Show all Bills", + Func: func(c *ishell.Context) { + //c.Print("\033[H\033[2J") + //c.Println(boldGreen("Start New Project")) + showLastBills(0) + }, + }) + shell.AddCmd(&ishell.Cmd{ + Name: "showbills", + Help: "<n> - Show the last n bills", + Func: func(c *ishell.Context) { + arg := "none" + if len(c.Args) > 0 { + arg = strings.Join(c.Args, " ") + argi,err := strconv.Atoi(arg) + if err == nil{ + showLastBills(argi) + }else{ + c.Println(boldRed(arg,"is not a valid integer!")) + } + }else{ + c.Println(boldRed("showbills <n> - Please enter an integer")) + } + //c.Print("\033[H\033[2J") + //c.Println(boldGreen("Start New Project")) + stdOut() + }, + }) +/* shell.AddCmd(&ishell.Cmd{ Name: "color", Help: "color print", @@ -297,7 +327,7 @@ func interact() { c.Println("Your choices are", strings.Join(out(), ", ")) }, }) - +*/ // Gather Tasks For Bills shell.AddCmd(&ishell.Cmd{ Name: "bill", @@ -17,12 +17,13 @@ var starttime,stoptime string var projectid, edittaskid, editprojectid, editcustomerid int var deltask int var addcustomer bool -var newproject, newtask, stoptask, allproj, runinter, test, newconfig bool +var newproject, newtask, stoptask, allproj, allbills, runinter, test, newconfig bool +var billcount int //var red, green, yellow, cyan color //var boldRed, boldGreen color -func title() { +func title(frame bool) { bR := color.New(color.FgRed, color.Bold).SprintFunc() bHiR := color.New(color.FgHiRed, color.Bold).SprintFunc() bHiY := color.New(color.FgHiYellow, color.Bold).SprintFunc() @@ -33,10 +34,14 @@ func title() { bM := color.New(color.FgMagenta, color.Bold).SprintFunc() line := "___" - fmt.Printf("%s%s%s%s%s%s%s%s\n\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) + if frame { + fmt.Printf("%s%s%s%s%s%s%s%s\n\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) + } fmt.Println(" ",bR("L"),bHiR("A"),bHiY("B"),bHiG("O"),bHiC("R"),bHiB("A"),bHiM("V"),bM("I")) - fmt.Printf("%s%s%s%s%s%s%s%s\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) - fmt.Println("(c) 2018 - n@gotsche.at\n") + if frame { + fmt.Printf("%s%s%s%s%s%s%s%s\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) + fmt.Println("(c) 2018 - n@gotsche.at\n") + } } @@ -67,6 +72,14 @@ func init() { "all", false, "Show all Projects") + flag.BoolVar(&allbills, + "allbills", + false, + "Show all Bills") + flag.IntVar(&billcount, + "showbills", + 0, + "How Many of Previous bills should be shown") flag.BoolVar(&runinter, "run", false, @@ -132,12 +145,14 @@ func stdOut() { } func main() { + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() //fmt.Println("Laboravi Started") dbname := "./.mytimes.db" if flag.NFlag() > 0 { - title() + title(true) }else{ - fmt.Println("Laboravi Started") + title(false) + //fmt.Println("Laboravi Started") } initConf() dbname = config.Database @@ -159,7 +174,7 @@ func main() { } } if len(uar)>0 { - fmt.Println("Unknown Commands: ",uar) + fmt.Println("Unknown Commands: ",boldRed(uar)) } } @@ -182,6 +197,12 @@ func main() { allProjects() } + if allbills { + showLastBills(0) + } else if (billcount>0) { + showLastBills(billcount) + } + if runinter { interact() } @@ -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,×tr,&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 |
