summaryrefslogtreecommitdiff
path: root/sqlite.go
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite.go')
-rw-r--r--sqlite.go54
1 files changed, 52 insertions, 2 deletions
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()