summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--interact.go32
-rw-r--r--sqlite.go54
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)
}
/*
diff --git a/sqlite.go b/sqlite.go
index 4391b12..073559d 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -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()