From 8ae371a94cd1fa75e74e91960783648e82aaf031 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Fri, 29 Mar 2019 12:20:08 +0100 Subject: Show Bills, no interface yet --- interact.go | 45 ++++++++++++++++++++++++++------------------- sqlite.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/interact.go b/interact.go index 640723e..4cdb1a7 100644 --- a/interact.go +++ b/interact.go @@ -789,6 +789,7 @@ func interact(fulldb bool) { //allaccounted := false //resttasks := seltasks + //SELECT SUBSET AND NAME BILLITEM //c.clear()//Println(some,"Str2:",str2) for { @@ -849,34 +850,40 @@ func interact(fulldb bool) { break } } - c.Printf("%T %v - %T %v\n", tsk, tsk, hrf, hrf) + //c.Printf("%T %v - %T %v\n", tsk, tsk, hrf, hrf) allitems = append(allitems, billitem{tsk, itdur, hrf, Round(hrf*cust.Satz, 1)}) c.Print("<>") c.ReadLine() //c.ShowPrompt(true) } } - billid, billident := newBill(billprojid) + halfbill := bill{0, "None", dur, proj.Id, proj.Name, time.Time{}, time.Time{}, allitems} + ShowBill(halfbill,false) + if isInterSure("Is this bill Correct?") { + billid, billident := newBill(billprojid) //c.Println(green("Bill Completed")) - fullbill := bill{billid, billident, dur, proj.Id, proj.Name, time.Time{}, time.Time{}, allitems} - saveBill(fullbill) - checkTasks(selids, billid) - c.ProgressBar().Indeterminate(true) - c.ProgressBar().Start() - testid := []int{billid} - testbill := loadBills(testid) + fullbill := bill{billid, billident, dur, proj.Id, proj.Name, time.Time{}, time.Time{}, allitems} + saveBill(fullbill) + checkTasks(selids, billid) + c.ProgressBar().Indeterminate(true) + c.ProgressBar().Start() + testid := []int{billid} + testbill := loadBills(testid) //c.Println(testbill[0].projectname,testbill[0].items) - files := billTemplate(testbill[0], cust) - c.Println(files) - err = runLatex(files.Main, testbill[0].identity) - c.ProgressBar().Stop() - if err == nil { - c.Println("Finished without Errors") - } else { - c.Println("Finished with error:", err) + files := billTemplate(testbill[0], cust) + c.Println(files) + err = runLatex(files.Main, testbill[0].identity) + c.ProgressBar().Stop() + if err == nil { + c.Println("Finished without Errors") + } else { + c.Println("Finished with error:", err) + } + c.Print("<>") + c.ReadLine() + }else{ + c.Println(boldRed("Charging Aborted")) } - c.Print("<>") - c.ReadLine() stdOut() } c.Println(promptcol("______________________")) diff --git a/sqlite.go b/sqlite.go index 6641a0b..d9d31db 100644 --- a/sqlite.go +++ b/sqlite.go @@ -428,6 +428,46 @@ func showLastBills(count int) { fmt.Println(frame("",false)) } +// Show Full Bill info of single bill, fullest to true for related tasks +func ShowBill(in bill,fullest bool) { + boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() + //boldRed := color.New(color.FgRed, color.Bold).SprintFunc() + addText := "" + projn,custn := getProjectName(in.project) + var tsks []Task + if fullest { + rows, err := db.Query("SELECT * FROM timetable WHERE checkout = ? ORDER BY stop DESC", in.id) + checkErr(err) + var id,prj,chk int + var start, stop time.Time + var tas,comm string + defer rows.Close() + for rows.Next() { + err = rows.Scan(&id, &prj, &start, &stop, &tas, &comm, &chk) + checkErr(err) + tsks = append(tsks,Task{id,prj,start,stop,tas,comm,chk}) + } + for _,t := range tsks { + addText += fmt.Sprintf("%sId: %v - Project: %v : %s\n",nli,t.Id,t.Projectid,t.Taskname) + } + } + fmt.Println(frame(boldGreen("Show Bill ", in.id),true)) + if fullest { + fmt.Printf("%sId: %v - InvoiceNumber: %v\n",nli,in.id,in.identity) + }else{ + fmt.Println(nli," This Bill:") + } + fmt.Printf("%sFor: %s\n",nli,custn) + fmt.Printf("%sProject: %s\n",nli,projn) + fmt.Println(sub("Bill Items")) + fmt.Println(StrLines(ShowItems(in.items),nli)) + if fullest { + fmt.Println(sub("Billed Tasks")) + fmt.Println(addText) + } + fmt.Println(frame("",false)) +} + func loadBills(in []int) (out []bill) { ins := strings.Trim(strings.Replace(fmt.Sprint(in), " ", " , ", -1), "[]") que := fmt.Sprintf("SELECT * FROM bills WHERE id IN (%s) ORDER BY project DESC", ins) @@ -1865,6 +1905,7 @@ func editBill(id int) { ident = getNewInterInput("New Bill Identifier: ", ident, nli) timran = getNewInterInput("New Timerange:", timran, nli) + paiyr := pai.Local().Format("2006-01-02") paistr = pai.Local().Format("2006-01-02 15:04") datstr = dat.Local().Format("2006-01-02 15:04") for { @@ -1876,13 +1917,17 @@ func editBill(id int) { break } } - for { - newpaistr := getNewInterInput("New Paid date: ", paistr, nli) - if !isDateTime(newpaistr) { - fmt.Println(nli, newpaistr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") - } else { - paistr = newpaistr - break + if paiyr == "1791-09-30" { + fmt.Println(nli,boldRed("Open")) + }else{ + for { + newpaistr := getNewInterInput("New Paid date: ", paistr, nli) + if !isDateTime(newpaistr) { + fmt.Println(nli, newpaistr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") + } else { + paistr = newpaistr + break + } } } for { -- cgit v1.2.3