diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2019-05-17 23:55:24 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2019-05-17 23:55:24 +0200 |
| commit | 83410ee498d56f18ccab0abb9c69f112f4d9f008 (patch) | |
| tree | 9720ea00a12791a5f86755ba59f51dcceec2df7e | |
| parent | 19d611f02ebf83f751c0f21e4bcaf56377711c8a (diff) | |
show Payment
| -rw-r--r-- | interact.go | 32 | ||||
| -rw-r--r-- | sqlite.go | 54 |
2 files changed, 83 insertions, 3 deletions
diff --git a/interact.go b/interact.go index 71e40a3..d849eca 100644 --- a/interact.go +++ b/interact.go @@ -699,7 +699,7 @@ func interact(fulldb bool) { showcmd.AddCmd(&ishell.Cmd{ Name: "project", Help: "<id> - Show details of the project with given id.", - LongHelp: ` Usage: show invoice <id> + LongHelp: ` Usage: show project <id> Show detailed information of Project with given id. If no <id> is specified a selection screen is shown.`, Func: func(c *ishell.Context) { arg := "none" @@ -724,6 +724,36 @@ func interact(fulldb bool) { c.Println(promptcol("______________________")) }, }) + showcmd.AddCmd(&ishell.Cmd{ + Name: "payment", + Help: "<id> - Show details of the payment with given id.", + LongHelp: ` Usage: show invoice <id> + Show detailed information of payment with given id. If no <id> is specified a selection screen is shown.`, + 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 { + ShowPayment(argi) + //fmt.Println("COMING SOON") + //ShowProjectStatus(argi) + //allProjects() + //stdOut() + } else { + c.Println(boldRed(arg, "is not a valid id!")) + } + } else { + //pids := GetProjectIds() + selids, lids := GetPaymentList() + choice := c.MultiChoice(lids, "Select a Payment to Show") + if choice > -1 { + ShowPayment(selids[choice]) + } + } + c.Println(promptcol("______________________")) + }, + }) shell.AddCmd(showcmd) } /* @@ -594,7 +594,7 @@ func SaveBill(in bill) (int) { return int(newid) } -// Loop through Array of []Customers, []Projects and []Tasks, update new db ids and call their respected SaveFunctions +// Loop through Array of []Customers, []Projects, []Payment and []Tasks, update new db ids and call their respected SaveFunctions func SaveImportsToDB(cus []Customer, prs []Project, tsk []Task, bls []bill, pays []Payment) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() var cusids, prids, bilids, payids []IdMap @@ -620,7 +620,7 @@ func SaveImportsToDB(cus []Customer, prs []Project, tsk []Task, bls []bill, pays p.Id = 0 // Special behaviour aof SavePayments! id ==0 -> INSERT; id!=0 UPDATE id := SavePayment(p) payids=append(payids,IdMap{py.Id,id}) - fmt.Println("DEBUG PayId Old:",py.Id,"New:", id) + //fmt.Println("DEBUG PayId Old:",py.Id,"New:", id) i++ } for _,p := range prs { @@ -2171,6 +2171,56 @@ func deleteTask(id int) { fmt.Println(frame("",false)) } +// Show Payment of given id +func ShowPayment(id int) { + boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() + fmt.Println(frame(boldGreen("Show Payment ", id),true)) + + var cuid int + var amount float64 + var date time.Time + var billstr string + rows, err := db.Query("SELECT customerid, amount, bills, date FROM payments WHERE id = $1", id) + checkErr(err) + if rows.Next() { + err = rows.Scan(&cuid, &amount, &billstr, &date) + checkErr(err) + rows.Close() //good habit to close + //custr := getCustomerName(cuid) + custr := getCustomerName(cuid) + fmt.Printf("%s From %s Amount %.2f [€]\n",nli,custr,amount) + fmt.Printf("%s Date: %s\n",nli,date.Local().Format("2006 Mon Jan _2")) + fmt.Println(sub("Bills")) + biids := String2IntArray(billstr,";") + mybills := loadBills(biids) + + bsum := 0.0 + hsum := 0.0 + for _,bi := range mybills{ + bisum := 0.0 + for _,it := range bi.items { + bisum += it.Money + hsum += it.Hours + } + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bisum) + bsum += bisum + } + if amount != bsum { + fmt.Println(sli,boldRed(" The sum of the bills (",bsum,"€ for",hsum,"h) does not match Payment amount!")) + if amount > bsum { + fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum) ) + } + if amount < bsum { + fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum) ) + } + } + } else { + fmt.Println(nli+boldRed("There Is No Payment"), id) + return + } + fmt.Println(frame("",false)) +} // Edit a Payment of given id func EditPayment(id int) { boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() |
