diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2018-10-08 21:44:05 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2018-10-08 21:44:05 +0200 |
| commit | 3ad0c5806b34c508152a23de87f084faddd32e53 (patch) | |
| tree | 8f761ddc3bb37caea35ec62e9b628c06289493c6 | |
| parent | e9bad489128dd526b44b08cc3bed6cce1cb731da (diff) | |
Checking Bills as Paid
| -rw-r--r-- | config.go | 5 | ||||
| -rw-r--r-- | interact.go | 24 | ||||
| -rw-r--r-- | sqlite.go | 88 | ||||
| -rw-r--r-- | utils.go | 1 |
4 files changed, 97 insertions, 21 deletions
@@ -79,7 +79,7 @@ func makeNewTOML(gibts bool) { if gibts { fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting") }else{ - fmt.Println("Making new Configuration File") + fmt.Println("\nMaking new Configuration File") //Examplenames Coming soon n := "" file,err := homedir.Expand("~/.mywork.db") @@ -112,10 +112,11 @@ func makeNewTOML(gibts bool) { panic(err) }else{ //fmt.Println("Conffile:\n",buf.String()) - fmt.Println("Writing Configuration File") + fmt.Println("\nWriting Configuration File") err = ioutil.WriteFile(conffile, buf.Bytes(), 0644) checkErr(err) } + fmt.Println(" ") } diff --git a/interact.go b/interact.go index 67e7f15..24f4e34 100644 --- a/interact.go +++ b/interact.go @@ -112,6 +112,30 @@ func interact() { }) shell.AddCmd(&ishell.Cmd{ + Name: "checkbill", + Help: "<id> check a Bill with the following id as paid", + LongHelp: ` Usage: checkbill <id> + Check the bill of the set <id> as paid on the current date`, + 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{ + checkBill(argi) + //stdOut() + }else{ + c.Println(boldRed(arg,"is not a valid id!")) + } + }else{ + c.Println(boldRed("checkbill <id> - Please enter an id")) + showLastBills(0) + } + c.Println(promptcol("______________________")) + }, + }) + + shell.AddCmd(&ishell.Cmd{ Name: "deletebill", Help: "<id> Delete a Bill with the following id", LongHelp: ` Usage: deletebill <id> @@ -129,8 +129,8 @@ func newTaskTime(proj int, tim string) { if (opentask.id == 0) { timstr := "1791-09-30 19:07" //zone, _ := time.Now().Zone() - if isDate(tim) { - timstr = getDate(tim) + if isDateTime(tim) { + timstr = getDateTime(tim) //timst = timstr+" "+zone }else if isTime(tim) { currdate := time.Now().Local().Format("2006-01-02") @@ -320,8 +320,8 @@ func closeTaskTime(tim string) { //timt,err := time.Parse("2006-01-02 15:04",tim) timst,timstr := "1791-09-30 19:07","1791-09-30 19:07" zone, _ := time.Now().Zone() - if isDate(tim) { - timstr = getDate(tim) + if isDateTime(tim) { + timstr = getDateTime(tim) timst = timstr+" "+zone } else if isTime(tim) { timstr = time.Now().Local().Format("2006-01-02")+" "+getTime(tim) @@ -372,6 +372,37 @@ func closeTask() { } } +func checkBill(bid int) { + boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() + fmt.Println(boldGreen("Checking Bill ",bid," as Paid:","BILLIDENTITY COMING SOON")) + if !isBill(bid) { + fmt.Println(bid,boldRed("is not a known bill ID")) + return + } + //timst,timstr := "1791-09-30 19:07","1791-09-30 19:07" + //zone, _ := time.Now().Zone() + timstr := "1791-09-30 19:07" + + timin := getInterInput("Specify Date (YYYY-MM-DD): ") + + if isDateTime(timin) { + timstr = getDateTime(timin) + }else if isDate(timin) { + //currdate := time.Now().Local().Format("2006-01-02") + timstr = getDate(timin)+" 12:00" + }else { + fmt.Println(timin,boldRed("is Not a Valid Datestring!"), "use: 'YYYY-MM-DD'") + return + } + //ti := + fmt.Println(boldGreen(timstr)) + stmt, err := db.Prepare("UPDATE bills SET paid = datetime(?,'utc') WHERE id = ?") + checkErr(err) + _, err = stmt.Exec(timstr,bid) + checkErr(err) +} + func checkTasks(in []int,billid int) { ins := strings.Trim(strings.Replace(fmt.Sprint(in)," "," , ",-1),"[]") que := fmt.Sprintf("UPDATE timetable SET checkout = ? WHERE id IN (%s)",ins) @@ -826,7 +857,7 @@ func getLastProject() { nprname=prname nfirst=first nlast=last - nfinish=finish + nfinish=finish ncustom=custom } } @@ -1059,31 +1090,40 @@ func editCustomer(id int) { rows.Close() //good habit to close //fmt.Println(boldGreen("Edit Customer",id)) - fmt.Println("Old Company Name:",comp) + /*fmt.Println("Old Company Name:",comp) in := getInterInput("Enter New:") if in!=""{ comp=in - } - fmt.Println("Old Name:",name) + }*/ + comp = getNewInterInput("New Company Name: ",comp) + /*fmt.Println("Old Name:",name) in = getInterInput("Enter New:") if in!=""{ name=in - } - fmt.Println("Old Adress:",addr) + }*/ + name = getNewInterInput("New Customer Name: ",name) + /*fmt.Println("Old Adress:",addr) in = getInterInput("Enter New:") if in!=""{ addr=in - } - fmt.Println("Old Hourly Rate:",satz) + }*/ + addr = getNewInterInput("New Adress: ",addr) + //fmt.Println("Old Hourly Rate:",satz) for{ - satzstr := getInterInput("Enter New:") + satzstr := getNewInterInput("New Hourly Rate: ",fmt.Sprintf("%.2f",satz)) + satz,err = strconv.ParseFloat(satzstr,64) + if err != nil { + fmt.Println(satzstr,boldRed("can not be Parsed as a Float."), "Try a shape of X.X") + //os.Exit(0) + }else{break} + /*satzstr := getInterInput("Enter New:") if satzstr!=""{ satz,err = strconv.ParseFloat(satzstr,64) if err != nil { fmt.Println(satzstr,boldRed("can not be Parsed as a Float."), "Try a shape of X.X") //os.Exit(0) }else{break} - }else{break} + }else{break}*/ } stmt, err := db.Prepare("UPDATE customers SET company = ?, name = ?, address = ?, satz = ? WHERE id = ?") checkErr(err) @@ -1122,7 +1162,7 @@ func editTask(id int) { fmt.Println("Old Start:",startstr) newstart := getInterInput("Enter New:") if newstart!=""{ - if isDate(newstart) { + if isDateTime(newstart) { startstr=newstart break }else{ @@ -1135,7 +1175,7 @@ func editTask(id int) { for{ newend := getInterInput("Enter New:") if newend!=""{ - if isDate(newend) { + if isDateTime(newend) { stopstr=newend break }else{ @@ -1189,7 +1229,7 @@ func editProject(id int) { for{ newfirst := getInterInput("Enter New:") if newfirst!=""{ - if isDate(newfirst) { + if isDateTime(newfirst) { nfirst=newfirst break }else{ @@ -1270,21 +1310,31 @@ func isCustomer(id int) bool { } } -func getDate(in string) string { +func getDateTime(in string) string { r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`) return r.FindString(in) } +func getDate(in string) string { + r := regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})`) + return r.FindString(in) +} + func getTime(in string) string { r := regexp.MustCompile(`(\d{2}):(\d{2})`) return r.FindString(in) } -func isDate(in string) bool { +func isDateTime(in string) bool { match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})`,in) return match } +func isDate(in string) bool { + match, _ := regexp.MatchString(`(\d{4})-(\d{2})-(\d{2})`,in) + return match +} + func isTime(in string) bool { match, _ := regexp.MatchString(`(\d{2}):(\d{2})`,in) return match @@ -70,6 +70,7 @@ func checkErr(err error) { } } +//make One String with Linebreaks out of an input String Array func strLines(in []string) (out string){ out = "" for _,s := range in { |
