diff options
Diffstat (limited to 'sqlite.go')
| -rw-r--r-- | sqlite.go | 56 |
1 files changed, 53 insertions, 3 deletions
@@ -412,8 +412,10 @@ func showLastBills(count int) { hsum := sumFloatArray(string2FloatArray(hourstr, ";")) msum := sumFloatArray(string2FloatArray(moneystr, ";")) fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[€] - ",nli, 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" { + p := fmt.Sprintf("%v", paid.Local().Format("2006.01.02")) + //fmt.Println(p) + //if p == "1791-09-30 19:07:00 +0000 UTC" { + if p == "1791.09.30" { fmt.Print(boldRed("OPEN\n")) } else { fmt.Printf(boldGreen("%v\n"), paid.Local().Format("2006.01.02")) @@ -484,8 +486,19 @@ func SaveTask(in Task) { checkErr(err) } +// Save Bill in DB +func SaveBill(in bill) { + tidat := in.date.Local().Format("2006-01-02 15:04") + tipai := in.paid.Local().Format("2006-01-02 15:04") + tsks,dats,tims,mos := items2strings(in.items) + stmt, err := db.Prepare("INSERT INTO bills (identity, timerange, project, tasks, times, hours, moneys, paid, date) values(?, ?, ?,?, ?, ?, ?, datetime(?,'utc'), datetime(?,'utc'))") + checkErr(err) + _, err = stmt.Exec(in.identity, in.timerange, in.project, tsks, dats, tims,mos, tidat, tipai) + checkErr(err) +} + // Loop through Array of []Customers, []Projects and []Tasks, update new db ids and call their respected SaveFunctions -func SaveImportsToDB(cus []Customer, prs []Project, tsk []Task) { +func SaveImportsToDB(cus []Customer, prs []Project, tsk []Task, bls []bill) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() var cusids, prids []IdMap //var acc,rej []Project @@ -493,6 +506,7 @@ func SaveImportsToDB(cus []Customer, prs []Project, tsk []Task) { fmt.Println(nli," Customers:",len(cus)) fmt.Println(nli," Projects:",len(prs)) fmt.Println(nli," Tasks:",len(tsk)) + fmt.Println(nli," Bills:",len(bls)) fmt.Println(sub("")) if isInterSure(nli+" Are You sure to Import them all?") { i := 0 @@ -514,6 +528,11 @@ func SaveImportsToDB(cus []Customer, prs []Project, tsk []Task) { SaveTask(t) i++ } + bls = ChangeBillIds(prids,bls) + for _,t := range bls { + SaveBill(t) + i++ + } fmt.Println(nli,i,"items imported") fmt.Println(frame(posR(),false)) }else{ @@ -541,6 +560,16 @@ func ChangeProjectIds(idm []IdMap, tsk []Task) ([]Task) { return out } +// Swap the old Ids in []bill array from imported +// projects to the new ones +func ChangeBillIds(idm []IdMap, bll []bill) ([]bill) { + out := bll + for it,t := range bll { + out[it].project = GetMapId(t.project,idm) + } + return out +} + // Check which entry holds the old id and return the new one func GetMapId(id int, idm []IdMap) (int) { if id == 0 { @@ -1118,6 +1147,27 @@ func GetTaskIds() []int { } return ids } +// Returns Slice of All Bills +func GetAllBills() (out []bill) { + //var ids []int + rows, err := db.Query("SELECT * FROM bills") // ORDER BY id DESC") + checkErr(err) + var id,prj int + var ide,trg,prn string + var dat,pai time.Time + var itms []billitem + var tsks,tims,hrs,mos string + + defer rows.Close() + for rows.Next() { + err = rows.Scan(&id,&ide,&trg,&prj,&tsks,&tims,&hrs,&mos,&pai,&dat) + checkErr(err) + prn,_ = getProjectName(id) + itms = strings2items(tsks,tims,hrs,mos) + out = append(out, bill{id,ide,trg,prj,prn,dat,pai,itms}) + } + return +} // Get All Tasks of Project with prid as a slice of Tasknames and // a curresponding slice of strings to display |
